]> mj.ucw.cz Git - libucw.git/blobdiff - lib/shell/config.c
Merge with git+ssh://cvs.ucw.cz/projects/sherlock/GIT/sherlock.git
[libucw.git] / lib / shell / config.c
index 2395458408e5e36d466ba8f7f7dccd5324c50dc7..a4ac005a40300cbe54a627eb5da1ae808ee41590 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();
@@ -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)
 {
@@ -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);
        }