/* dfs_parser.h */ #include "config.h" void indent(int level); class lookup_tag_t; class dfs_object_t { public: virtual ~dfs_object_t() { } dfs_object_t(const char *name) { do_name = name; next = NULL; first = last = NULL; } void add_child(dfs_object_t *child) { if (!first) first = last = child; else { last->next = child; last = child; } } virtual void dump(int level) { dfs_object_t *child; indent(level); printf("object(%s) {\n", do_name); for (child = first; child; child = child->next) child->dump(level + 1); indent(level); printf("}\n"); } virtual int is_object(void) { return 1; } virtual int is_tag(void) { return 0; } dfs_object_t *find_child_object(lookup_tag_t *tag); dfs_object_t *find_next_object(lookup_tag_t *tag); int tag_int(lookup_tag_t *tag, int *ptr = NULL); long tag_long(lookup_tag_t *tag, long *ptr = NULL); const char *tag_str(lookup_tag_t *tag, int may_fail = 0); void tag_bytes(lookup_tag_t *tag, u8 *ptr, size_t size); private: const char *do_name; dfs_object_t *next; dfs_object_t *first; dfs_object_t *last; friend const char *dfs_str(dfs_object_t *parent, lookup_tag_t *tag); }; class dfs_tag_t : public dfs_object_t { public: const char *tag; const char *value; dfs_tag_t(const char *t, const char *v) : dfs_object_t(t) { tag = t; value = v; } virtual void dump(int level) { indent(level); printf("tag(%s)(\"%s\")\n", tag, value); } virtual int is_object(void) { return 0; } virtual int is_tag(void) { return 1; } }; dfs_object_t *dfs_parse_state(FILE *fp); int dfs_build_state(dfs_object_t *top);