2 * UCW Library -- Configuration files: dumping
4 * (c) 2001--2006 Robert Spalek <robert@ucw.cz>
5 * (c) 2003--2006 Martin Mares <mj@ucw.cz>
7 * This software may be freely distributed and used according to the terms
8 * of the GNU Lesser General Public License.
13 #include "lib/getopt.h"
14 #include "lib/conf-internal.h"
15 #include "lib/clists.h"
16 #include "lib/fastbuf.h"
19 spaces(struct fastbuf *fb, uns nr)
21 for (uns i=0; i<nr; i++)
26 dump_basic(struct fastbuf *fb, void *ptr, enum cf_type type, union cf_union *u)
29 case CT_INT: bprintf(fb, "%d ", *(uns*)ptr); break;
30 case CT_U64: bprintf(fb, "%llu ", (long long) *(u64*)ptr); break;
31 case CT_DOUBLE: bprintf(fb, "%lg ", *(double*)ptr); break;
32 case CT_IP: bprintf(fb, "%08x ", *(uns*)ptr); break;
35 bprintf(fb, "'%s' ", *(char**)ptr);
39 case CT_LOOKUP: bprintf(fb, "%s ", *(int*)ptr >= 0 ? u->lookup[ *(int*)ptr ] : "???"); break;
42 u->utype->dumper(fb, ptr);
49 static void dump_section(struct fastbuf *fb, struct cf_section *sec, int level, void *ptr);
51 static char *class_names[] = { "end", "static", "dynamic", "parser", "section", "list", "bitmap" };
54 dump_item(struct fastbuf *fb, struct cf_item *item, int level, void *ptr)
56 ptr += (uintptr_t) item->ptr;
57 enum cf_type type = item->type;
58 uns size = cf_type_size(item->type, item->u.utype);
61 bprintf(fb, "%s: C%s #", item->name, class_names[item->cls]);
62 if (item->number == CF_ANY_NUM)
65 bprintf(fb, "%d ", item->number);
66 if (item->cls == CC_STATIC || item->cls == CC_DYNAMIC || item->cls == CC_BITMAP) {
67 bprintf(fb, "T%s ", cf_type_names[type]);
68 if (item->type == CT_USER)
69 bprintf(fb, "U%s S%d ", item->u.utype->name, size);
71 if (item->cls == CC_STATIC) {
72 for (i=0; i<item->number; i++)
73 dump_basic(fb, ptr + i * size, type, &item->u);
74 } else if (item->cls == CC_DYNAMIC) {
77 int real_nr = DARY_LEN(ptr);
78 bprintf(fb, "N%d ", real_nr);
79 for (i=0; i<real_nr; i++)
80 dump_basic(fb, ptr + i * size, type, &item->u);
83 } else if (item->cls == CC_BITMAP) {
84 u32 mask = * (u32*) ptr;
85 for (i=0; i<32; i++) {
86 if (item->type == CT_LOOKUP && !item->u.lookup[i])
89 if (item->type == CT_INT)
90 bprintf(fb, "%d ", i);
91 else if (item->type == CT_LOOKUP)
92 bprintf(fb, "%s ", item->u.lookup[i]);
97 if (item->cls == CC_SECTION)
98 dump_section(fb, item->u.sec, level+1, ptr);
99 else if (item->cls == CC_LIST) {
101 CLIST_FOR_EACH(cnode *, n, * (clist*) ptr) {
103 bprintf(fb, "item %d\n", ++idx);
104 dump_section(fb, item->u.sec, level+2, n);
110 dump_section(struct fastbuf *fb, struct cf_section *sec, int level, void *ptr)
113 bprintf(fb, "S%d F%x:\n", sec->size, sec->flags);
114 for (struct cf_item *item=sec->cfg; item->cls; item++)
115 dump_item(fb, item, level, ptr);
119 cf_dump_sections(struct fastbuf *fb)
121 dump_section(fb, &cf_sections, 0, NULL);