]> mj.ucw.cz Git - libucw.git/commitdiff
conf2: MJ's objections taken care of
authorRobert Spalek <robert@ucw.cz>
Sun, 23 Apr 2006 12:44:40 +0000 (14:44 +0200)
committerRobert Spalek <robert@ucw.cz>
Sun, 23 Apr 2006 12:44:40 +0000 (14:44 +0200)
lib/conf2-test.c
lib/conf2.c
lib/conf2.h
lib/conf2.t

index 670190c3815cb238bd7b9688f46b4605420f8c4b..fae56c5288dc59a5679c933616506679f4b2f865 100644 (file)
@@ -24,13 +24,13 @@ struct sub_sect_1 {
   double *list;
 };
 
-static struct sub_sect_1 sec1 = { {}, "Charlie", "WBAFC", { 0, -1}, DYN_ALLOC(double, 3, 1e4, -1e-4, 8) };
+static struct sub_sect_1 sec1 = { {}, "Charlie", "WBAFC", { 0, -1}, DARY_ALLOC(double, 3, 1e4, -1e-4, 8) };
 
 static byte *
 init_sec_1(struct sub_sect_1 *s)
 {
   if (s == &sec1) {                    // this is a static variable; skip clearing
-    DYN_LEN(sec1.list) = 3;            // XXX: fix for the bug in DYN_ALLOC()
+    DARY_LEN(sec1.list) = 3;           // XXX: fix for the bug in DARY_ALLOC()
     return NULL;
   }
   s->name = "unknown";
@@ -65,10 +65,10 @@ static struct cf_section cf_sec_1 = {
 };
 
 static uns nr1 = 15;
-static int *nrs1 = DYN_ALLOC(int, 5, 5, 4, 3, 2, 1);
+static int *nrs1 = DARY_ALLOC(int, 5, 5, 4, 3, 2, 1);
 static int nrs2[5];
 static byte *str1 = "no worries";
-static byte **str2 = DYN_ALLOC(byte *, 2, "Alice", "Bob");
+static byte **str2 = DARY_ALLOC(byte *, 2, "Alice", "Bob");
 static u64 u1 = 0xCafeBeefDeadC00ll;
 static double d1 = -1.1;
 static struct clist secs;
@@ -135,7 +135,7 @@ Usage: conf2-test <options>\n\
 \n\
 Options:\n"
 CF_USAGE
-"-v\t\tBe verbose\n\
+"-v\t\t\tBe verbose\n\
 ";
 
 static void NONRET
index 6b470ef513d836d7c7913b267d314cebe4614644..e8533596eb48973617d8a804ca6c507eb9f36808 100644 (file)
@@ -107,7 +107,7 @@ static struct journal_item *
 journal_new_section(uns new_pool)
 {
   if (new_pool)
-    cf_pool = mp_new(1<<14);
+    cf_pool = mp_new(1<<10);
   struct journal_item *oldj = journal;
   journal = NULL;
   return oldj;
@@ -566,7 +566,7 @@ interpret_set_dynamic(struct cf_item *item, int number, byte **pars, void **ptr)
 }
 
 static byte *
-interpret_add_dynamic(struct cf_item *item, int number, byte **pars, int *processed, void **ptr, enum operation op)
+interpret_add_dynamic(struct cf_item *item, int number, byte **pars, int *processed, void **ptr, enum cf_operation op)
 {
   enum cf_type type = item->u.type;
   void *old_p = *ptr;
@@ -610,7 +610,7 @@ interpret_section(struct cf_section *sec, int number, byte **pars, int *processe
 }
 
 static void
-add_to_list(struct cnode *where, struct cnode *new_node, enum operation op)
+add_to_list(struct cnode *where, struct cnode *new_node, enum cf_operation op)
 {
   switch (op)
   {
@@ -640,7 +640,7 @@ add_to_list(struct cnode *where, struct cnode *new_node, enum operation op)
 }
 
 static byte *
-interpret_add_list(struct cf_item *item, int number, byte **pars, int *processed, void *ptr, enum operation op)
+interpret_add_list(struct cf_item *item, int number, byte **pars, int *processed, void *ptr, enum cf_operation op)
 {
   if (op >= OP_REMOVE)
     return cf_printf("You have to open a block for operation %s", op_names[op]);
@@ -772,7 +772,7 @@ record_selector(struct cf_item *item, struct cf_section *sec, u32 *mask)
 static struct item_stack {
   struct cf_section *sec;      // nested section
   void *base_ptr;              // because original pointers are often relative
-  enum operation op;           // it is performed when a closing brace is encountered
+  enum cf_operation op;                // it is performed when a closing brace is encountered
   void *list;                  // list the operations should be done on
   u32 mask;                    // bit array of selectors searching in a list
   struct cf_item *item;                // cf_item of the list
@@ -780,7 +780,7 @@ static struct item_stack {
 static uns level;
 
 static byte *
-opening_brace(struct cf_item *item, void *ptr, enum operation op)
+opening_brace(struct cf_item *item, void *ptr, enum cf_operation op)
 {
   if (level >= MAX_STACK_SIZE-1)
     return "Too many nested sections";
@@ -814,16 +814,16 @@ opening_brace(struct cf_item *item, void *ptr, enum operation op)
 }
 
 static byte *
-closing_brace(struct item_stack *st, enum operation op, int number, byte **pars)
+closing_brace(struct item_stack *st, enum cf_operation op, int number, byte **pars)
 {
   if (st->op == OP_CLOSE)      // top-level
-    return "Unmatched } parenthese";
+    return "Unmatched } parenthesis";
   if (!st->sec) {              // dummy run on unknown section
     if (!(op & OP_OPEN))
       level--;
     return NULL;
   }
-  enum operation pure_op = st->op & OP_MASK;
+  enum cf_operation pure_op = st->op & OP_MASK;
   if (st->op & OP_1ST)
   {
     st->list = find_list_node(st->list, st->base_ptr, st->sec, st->mask);
@@ -859,7 +859,7 @@ closing_brace(struct item_stack *st, enum operation op, int number, byte **pars)
 }
 
 static byte *
-interpret_line(byte *name, enum operation op, int number, byte **pars)
+interpret_line(byte *name, enum cf_operation op, int number, byte **pars)
 {
   byte *msg;
   if ((op & OP_MASK) == OP_CLOSE)
@@ -886,7 +886,7 @@ interpret_line(byte *name, enum operation op, int number, byte **pars)
   else if (item->cls == CC_LIST)
     msg = interpret_add_list(item, number, pars, &taken, ptr, op);
   else
-    return cf_printf("Operation %s not supported on attribute class %d", op_names[op], item->cls);
+    return cf_printf("Operation %s not supported on attribute %s", op_names[op], name);
   if (msg)
     return msg;
   if (taken < number)
@@ -896,7 +896,7 @@ interpret_line(byte *name, enum operation op, int number, byte **pars)
 }
 
 byte *
-cf_write_item(struct cf_item *item, enum operation op, int number, byte **pars)
+cf_write_item(struct cf_item *item, enum cf_operation op, int number, byte **pars)
 {
   byte *msg;
   int taken;
@@ -956,6 +956,7 @@ done_stack(void)
 
 /* Text file parser */
 
+static byte *name_parse_fb;
 static struct fastbuf *parse_fb;
 static uns line_num;
 
@@ -1095,7 +1096,7 @@ get_token(uns is_command_name, byte **msg)
        return NULL;
       }
       if (!*line || *line == '#')
-       log(L_WARN, "The line following the backslash is empty");
+       log(L_WARN, "The line %s:%d following a backslash is empty", name_parse_fb, line_num);
     } else {
       split_grow(&word_buf, words+1);
       uns start = copied;
@@ -1145,6 +1146,7 @@ static byte *
 parse_fastbuf(byte *name_fb, struct fastbuf *fb, uns depth)
 {
   byte *msg;
+  name_parse_fb = name_fb;
   parse_fb = fb;
   line_num = 0;
   line = line_buf;
@@ -1183,7 +1185,7 @@ parse_fastbuf(byte *name_fb, struct fastbuf *fb, uns depth)
       line_num = ll;
       parse_fb = fb;
     }
-    enum operation op;
+    enum cf_operation op;
     byte *c = strchr(name, ':');
     if (!c)
       op = strcmp(name, "}") ? OP_SET : OP_CLOSE;
index 528a6b8496a7ef54c69a02ee8dd38fcf3b90e29e..01a3fee7a358a47c942932a7e816a5b99781989d 100644 (file)
@@ -57,7 +57,7 @@ struct cf_item {
 
 struct cf_section {
   uns size;                            // 0 for a global block, sizeof(struct) for a section
-  cf_hook *init;                       // fills in default values (otherwise 0's are used)
+  cf_hook *init;                       // fills in default values (no need to bzero)
   cf_hook *commit;                     // verifies parsed data (optional)
   struct cf_item *cfg;                 // CC_END-terminated array of items
   uns flags;                           // for internal use only
@@ -96,9 +96,9 @@ struct clist;
 #define CF_STRING_ARY(n,p,c)   CF_STATIC(n,p,STRING,byte*,c)
 #define CF_STRING_DYN(n,p,c)   CF_DYNAMIC(n,p,STRING,byte*,c)
 
-#define DYN_LEN(a) *(uns*)(a-1)
+#define DARY_LEN(a) *(uns*)(a-1)
   // length of a dynamic array
-#define DYN_ALLOC(type,len,val...) (type[]) { (type)len, ##val } + 1
+#define DARY_ALLOC(type,len,val...) (type[]) { (type)len, ##val } + 1
   // creates a static instance of a dynamic array
   // FIXME: overcast doesn't work for the double type
 
@@ -140,12 +140,12 @@ byte *cf_parse_ip(byte *p, u32 *varp);
    * Sections can be used with SET.
    * Lists can be used with everything. */
 #define T(x) OP_##x,
-enum operation { CF_OPERATIONS };
+enum cf_operation { CF_OPERATIONS };
 #undef T
 
 struct fastbuf;
 byte *cf_find_item(byte *name, struct cf_item *item);
-byte *cf_write_item(struct cf_item *item, enum operation op, int number, byte **pars);
+byte *cf_write_item(struct cf_item *item, enum cf_operation op, int number, byte **pars);
 void cf_dump_sections(struct fastbuf *fb);
 
 /*
@@ -161,15 +161,15 @@ void cf_dump_sections(struct fastbuf *fb);
  * override it manually before calling cf_get_opt().
  */
 
-#define        CF_SHORT_OPTS   "S:C:"
-#define        CF_LONG_OPTS    {"set",         1, 0, 'S'}, {"config",  1, 0, 'C'},
+#define        CF_SHORT_OPTS   "C:S:"
+#define        CF_LONG_OPTS    {"config",      1, 0, 'C'}, {"set",             1, 0, 'S'},
 #define CF_NO_LONG_OPTS (const struct option []) { CF_LONG_OPTS { NULL, 0, 0, 0 } }
 #ifndef CF_USAGE_TAB
 #define CF_USAGE_TAB ""
 #endif
 #define        CF_USAGE        \
-"-S, --set sec.item=val\t" CF_USAGE_TAB "Manual setting of a configuration item\n\
--C, --config filename\t" CF_USAGE_TAB "Overwrite default configuration file\n"
+"-C, --config filename\t" CF_USAGE_TAB "Override the default configuration file\n\
+-S, --set sec.item=val\t" CF_USAGE_TAB "Manual setting of a configuration item\n"
 
 struct option;
 int cf_get_opt(int argc, char * const argv[], const char *short_opts, const struct option *long_opts, int *long_index);
index 836c9fd0fea135ce5197c6523daba41a8db12ac8..42b35f9c739ce41f2c4eb8f4c7116fcad2ff0f6b 100644 (file)
@@ -13,6 +13,8 @@ Top { \
       the best' "\
       " qu'est-ce que c'est?
   u1   0xbadcafebadbeefc0
+  str2:prepend prepended
+  str2:append appended
   d1 7%
   d1   -1.14e-25
   firsttime ; secondtime 56