Просмотр исходного кода

ncd: modules: more number generation updates

ambrop7 13 лет назад
Родитель
Сommit
bb03d3d244
3 измененных файлов с 11 добавлено и 22 удалено
  1. 7 14
      ncd/modules/list.c
  2. 3 4
      ncd/modules/sys_evdev.c
  3. 1 4
      ncd/modules/value.c

+ 7 - 14
ncd/modules/list.c

@@ -93,6 +93,7 @@
 #include <inttypes.h>
 
 #include <misc/offset.h>
+#include <misc/parse_number.h>
 #include <structure/IndexedList.h>
 #include <ncd/NCDModule.h>
 #include <ncd/value_utils.h>
@@ -385,12 +386,9 @@ static int func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValRef *o
     }
     
     if (!strcmp(name, "length")) {
-        char str[64];
-        snprintf(str, sizeof(str), "%"PRIu64, list_count(o));
-        
-        *out = NCDVal_NewString(mem, str);
+        *out = ncd_make_uintmax(mem, list_count(o));
         if (NCDVal_IsInvalid(*out)) {
-            ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewString failed");
+            ModuleLog(o->i, BLOG_ERROR, "ncd_make_uintmax failed");
         }
         return 1;
     }
@@ -493,12 +491,9 @@ static int length_func_getvar (void *vo, const char *name, NCDValMem *mem, NCDVa
     struct length_instance *o = vo;
     
     if (!strcmp(name, "")) {
-        char str[64];
-        snprintf(str, sizeof(str), "%"PRIu64, o->length);
-        
-        *out = NCDVal_NewString(mem, str);
+        *out = ncd_make_uintmax(mem, o->length);
         if (NCDVal_IsInvalid(*out)) {
-            ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewString failed");
+            ModuleLog(o->i, BLOG_ERROR, "ncd_make_uintmax failed");
         }
         return 1;
     }
@@ -716,12 +711,10 @@ static int find_func_getvar (void *vo, const char *name, NCDValMem *mem, NCDValR
     struct find_instance *o = vo;
     
     if (!strcmp(name, "pos")) {
-        char value[64];
+        char value[64] = "none";
         
         if (o->is_found) {
-            snprintf(value, sizeof(value), "%"PRIu64, o->found_pos);
-        } else {
-            snprintf(value, sizeof(value), "none");
+            generate_decimal_repr_string(o->found_pos, value);
         }
         
         *out = NCDVal_NewString(mem, value);

+ 3 - 4
ncd/modules/sys_evdev.c

@@ -58,6 +58,7 @@
 
 #include <misc/nonblocking.h>
 #include <misc/debug.h>
+#include <ncd/value_utils.h>
 
 #include <ncd/NCDModule.h>
 
@@ -243,11 +244,9 @@ static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValR
     }
     
     if (name == strings[STRING_CODE_NUMERIC].id) {
-        char str[50];
-        snprintf(str, sizeof(str), "%"PRIu16, o->event.code);
-        *out = NCDVal_NewString(mem, str);
+        *out = ncd_make_uintmax(mem, o->event.code);
         if (NCDVal_IsInvalid(*out)) {
-            ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewString failed");
+            ModuleLog(o->i, BLOG_ERROR, "ncd_make_uintmax failed");
         }
         return 1;
     }

+ 1 - 4
ncd/modules/value.c

@@ -1033,10 +1033,7 @@ static int func_getvar2 (void *vo, NCD_string_id_t name, NCDValMem *mem, NCDValR
                 ASSERT(0);
         }
         
-        char str[64];
-        snprintf(str, sizeof(str), "%zu", len);
-        
-        *out = NCDVal_NewString(mem, str);
+        *out = ncd_make_uintmax(mem, len);
         if (NCDVal_IsInvalid(*out)) {
             ModuleLog(o->i, BLOG_ERROR, "NCDVal_NewString failed");
         }