From: Robert Spalek Date: Thu, 27 Apr 2006 08:39:27 +0000 (+0200) Subject: conf2: dumper of the configuration polished; support printing names of user types X-Git-Tag: holmes-import~645^2~11^2~27 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=50897d4c9042cb071dd4f16d30e1140248caf29a;p=libucw.git conf2: dumper of the configuration polished; support printing names of user types --- diff --git a/lib/conf2-test.c b/lib/conf2-test.c index 3580f407..6d357860 100644 --- a/lib/conf2-test.c +++ b/lib/conf2-test.c @@ -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 }; diff --git a/lib/conf2.c b/lib/conf2.c index 66b9bfe7..3201286c 100644 --- a/lib/conf2.c +++ b/lib/conf2.c @@ -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; inumber; 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; iu); } else diff --git a/lib/conf2.h b/lib/conf2.h index 17c0912b..3da4ce6c 100644 --- a/lib/conf2.h +++ b/lib/conf2.h @@ -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 };