]> mj.ucw.cz Git - libucw.git/commitdiff
conf2: dumper of the configuration polished; support printing names of user types
authorRobert Spalek <robert@ucw.cz>
Thu, 27 Apr 2006 08:39:27 +0000 (10:39 +0200)
committerRobert Spalek <robert@ucw.cz>
Thu, 27 Apr 2006 08:39:27 +0000 (10:39 +0200)
lib/conf2-test.c
lib/conf2.c
lib/conf2.h

index 3580f407679413c2d7cce0beebd14e02d4f5b213..6d3578604ae91fc6837105db417719dff8047fed 100644 (file)
@@ -98,6 +98,7 @@ dump_u16(struct fastbuf *fb, u16 *ptr)
 
 static struct cf_user_type u16_type = {
   .size = sizeof(u16),
+  .name = "u16",
   .parser = (cf_parser1*) parse_u16,
   .dumper = (cf_dumper1*) dump_u16
 };
index 66b9bfe78efa77114ddbb4a7aaa1601c8b04797d..3201286cbb2939ce9fcb508ab3a6ffcb094c64c9 100644 (file)
@@ -1451,6 +1451,9 @@ dump_basic(struct fastbuf *fb, void *ptr, enum cf_type type, union cf_union *u)
 
 static void dump_section(struct fastbuf *fb, struct cf_section *sec, int level, void *ptr);
 
+static byte *class_names[] = { "end", "static", "dynamic", "parser", "section", "list" };
+static byte *type_names[] = { "int", "u64", "double", "ip", "string", "lookup", "user" };
+
 static void
 dump_item(struct fastbuf *fb, struct cf_item *item, int level, void *ptr)
 {
@@ -1459,21 +1462,24 @@ dump_item(struct fastbuf *fb, struct cf_item *item, int level, void *ptr)
   uns size = type_size(item->type, item->u.utype);
   int i;
   spaces(fb, level);
-  bprintf(fb, "%s: c%d #%d ", item->name, item->cls, item->number);
-  if (item->cls == CC_STATIC || item->cls == CC_DYNAMIC)
-    bprintf(fb, "t%d ", type);
-  if (item->cls == CC_STATIC) {
+  bprintf(fb, "%s: C%s #", item->name, class_names[item->cls]);
+  if (item->number == CF_ANY_NUM)
+    bputs(fb, "any ");
+  else
+    bprintf(fb, "%d ", item->number);
+  if (item->cls == CC_STATIC || item->cls == CC_DYNAMIC) {
+    bprintf(fb, "T%s ", type_names[type]);
     if (item->type == CT_USER)
-      bprintf(fb, "S%d ", size);
+      bprintf(fb, "U%s S%d ", item->u.utype->name, size);
+  }
+  if (item->cls == CC_STATIC) {
     for (i=0; i<item->number; i++)
       dump_basic(fb, ptr + i * size, type, &item->u);
   } else if (item->cls == CC_DYNAMIC) {
-    if (item->type == CT_USER)
-      bprintf(fb, "S%d ", size);
     ptr = * (void**) ptr;
     if (ptr) {
       int real_nr = * (int*) (ptr - size);
-      bprintf(fb, "##%d ", real_nr);
+      bprintf(fb, "N%d ", real_nr);
       for (i=0; i<real_nr; i++)
        dump_basic(fb, ptr + i * size, type, &item->u);
     } else
index 17c0912b3ce44b5ed42575c51087b0e6911f14e0..3da4ce6c40bede4afdd2b72b717d44bc4e63577d 100644 (file)
@@ -53,6 +53,7 @@ typedef void cf_dumper1(struct fastbuf *fb, void *ptr);
 
 struct cf_user_type {
   uns size;                            // of the parsed attribute
+  byte *name;                          // name of the type (for dumping)
   cf_parser1 *parser;                  // how to parse it
   cf_dumper1 *dumper;                  // how to dump the type
 };