]> mj.ucw.cz Git - libucw.git/blobdiff - ucw/xtypes-basic.c
xtypes: fixed error in xt_bool parser
[libucw.git] / ucw / xtypes-basic.c
index 9bca14361799148aee874eec6179b8932ef151a1..c3dc1d6fb7fcb2025e94aee8a7a191987ed459b4 100644 (file)
@@ -77,7 +77,26 @@ static const char *xt_double_parse(const char *str, void *dest, struct mempool *
   return NULL;
 }
 
   return NULL;
 }
 
-XTYPE_NUM_STRUCT(double, double)
+static const char * xt_double_fmt_parse(const char *str, u32 *dest, struct mempool *pool)
+{
+  uint precision = 0;
+  const char *tmp_err = str_to_uint(&precision, str, NULL, 0);
+  if(tmp_err) {
+    return mp_printf(pool, "An error occured while parsing precision: %s.", tmp_err);
+  }
+
+  *dest = XTYPE_FMT_DBL_FIXED_PREC(precision);
+
+  return NULL;
+}
+
+const struct xtype xt_double = {
+  .size = sizeof(double),
+  .name = "double",
+  .parse = xt_double_parse,
+  .format = xt_double_format,
+  .parse_fmt = xt_double_fmt_parse
+};
 
 /* bool */
 
 
 /* bool */
 
@@ -99,7 +118,7 @@ static const char *xt_bool_parse(const char *str, void *dest, struct mempool *po
   if(!str) return "Cannot parse bool: string is NULL.";
 
   if(str[1] == 0) {
   if(!str) return "Cannot parse bool: string is NULL.";
 
   if(str[1] == 0) {
-    if(str[0] == '1') {
+    if(str[0] == '0') {
       *((bool *)dest) = false;
       return NULL;
     }
       *((bool *)dest) = false;
       return NULL;
     }