]> mj.ucw.cz Git - libucw.git/blobdiff - lib/shell/config.c
documented fbpool briefly
[libucw.git] / lib / shell / config.c
index 2395458408e5e36d466ba8f7f7dccd5324c50dc7..ba60f0350980861c1ee24a21456e7425744efe4f 100644 (file)
@@ -20,6 +20,7 @@
 #include "lib/lib.h"
 #include "lib/conf.h"
 #include "lib/getopt.h"
+#include "lib/conf-internal.h"
 #include "lib/clists.h"
 #include "lib/mempool.h"
 #include "lib/chartype.h"
@@ -46,7 +47,7 @@ Usage: config [-C<configfile>] [-S<section>.<option>=<value>] <sections>\n\
 <value>\t\t[a-zA-Z0-9.-/]* | 'string without single quotes'<value> | \"c-like string\"<value>\n\
 \n\
 Types:\n\
-:\t\tString\n\
+<empty>\t\tString\n\
 #\t\t32-bit integer\n\
 ##\t\t64-bit integer\n\
 $\t\tFloating point number\n\
@@ -157,10 +158,10 @@ parse_section(struct section *section)
            }
          item->cf.cls = CC_STATIC;
          item->cf.number = 1;
-         switch (*pos++)
+         switch (*pos)
            {
              case '#':
-               if (*pos == '#')
+               if (*++pos == '#')
                  {
                    pos++;
                    item->cf.type = CT_U64;
@@ -169,13 +170,14 @@ parse_section(struct section *section)
                  item->cf.type = CT_INT;
                break;
              case '$':
+               pos++;
                item->cf.type = CT_DOUBLE;
                break;
-             case ':':
+             default:
+               if (!Cword(*pos))
+                 die("Invalid type syntax");
                item->cf.type = CT_STRING;
                break;
-             default:
-               die("Invalid type syntax");
            }
          parse_white();
          item->cf.name = parse_name();
@@ -272,7 +274,7 @@ parse_section(struct section *section)
        }
       if (section->item.cf.cls == CC_LIST)
         {
-          item->cf.ptr = (void *)section->size;
+          item->cf.ptr = (void *)(uintptr_t)section->size;
           section->size += sizeof(union value);
         }
       else
@@ -330,19 +332,6 @@ generate_section(struct section *section)
 
 static bb_t path;
 
-static uns
-type_size(enum cf_type type)
-{
-  switch (type)
-    {
-      case CT_INT: return sizeof(int);
-      case CT_U64: return sizeof(u64);
-      case CT_DOUBLE: return sizeof(double);
-      case CT_STRING: return sizeof(byte *);
-      default: ASSERT(0);
-    }
-}
-
 static void
 dump_value(uns array, struct item *item, void *v)
 {
@@ -357,7 +346,7 @@ dump_value(uns array, struct item *item, void *v)
         sprintf(buf, "%d", *(int *)v);
         break;
       case CT_U64:
-        sprintf(buf, "%Lu", *(u64 *)v);
+        sprintf(buf, "%llu", (long long) *(u64 *)v);
        break;
       case CT_DOUBLE:
        sprintf(buf, "%g", *(double *)v);
@@ -386,7 +375,7 @@ dump_item(struct item *item, void *ptr, uns path_len)
 {
   if (item->flags & FLAG_HIDE)
     return;
-  byte *val = (byte *)((addr_int_t)ptr + (addr_int_t)item->cf.ptr);
+  byte *val = (byte *)((uintptr_t)ptr + (uintptr_t)item->cf.ptr);
   if (item->cf.cls == CC_LIST)
     {
       uns len = strlen(item->cf.name);
@@ -406,7 +395,7 @@ dump_item(struct item *item, void *ptr, uns path_len)
         {
          val = *(void **)val;
          uns len = DARY_LEN(val);
-         uns size = type_size(item->cf.type);
+         uns size = cf_type_size(item->cf.type, NULL);
          for (uns i = 0; i < len; i++, val += size)
            dump_value(1, item, val);
        }