]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: parser: Dump state of parser after parse
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 31 May 2019 03:22:12 +0000 (04:22 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 31 May 2019 03:22:12 +0000 (04:22 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/parser.h
src/libpakfire/libpakfire.sym
src/libpakfire/parser.c
src/libpakfire/parser/grammar.y

index f10fb27c921d5da7ae34132f76966ca90f7382aa..98efe3a22ab5730e45e047d1ab73fae4455c1ed8 100644 (file)
@@ -40,6 +40,7 @@ char* pakfire_parser_get(PakfireParser parser, const char* name);
 PakfireParser pakfire_parser_merge(PakfireParser parser1, PakfireParser parser2);
 
 int pakfire_parser_read(PakfireParser parser, FILE* f);
+char* pakfire_parser_dump(PakfireParser parser);
 
 #ifdef PAKFIRE_PRIVATE
 
index a018e1b6ed917d499b7cdbef7ff26f700442e5f5..d7e96a641f82837e8d9de76cbd56b77ab9c96dc7 100644 (file)
@@ -211,6 +211,7 @@ global:
 
        # parser
        pakfire_parser_create;
+       pakfire_parser_dump;
        pakfire_parser_expand;
        pakfire_parser_get;
        pakfire_parser_parse_data;
index 1961c81d00511e2982fdecf84685063dd27704b4..ea7ba9a215401a252879d8ebffd7e2d622d6a9ac 100644 (file)
@@ -393,3 +393,20 @@ PAKFIRE_EXPORT int pakfire_parser_read(PakfireParser parser, FILE* f) {
 
        return r;
 }
+
+PAKFIRE_EXPORT char* pakfire_parser_dump(PakfireParser parser) {
+       char* s = NULL;
+
+       for (unsigned int i = 0; i < parser->num_declarations; i++) {
+               struct pakfire_parser_declaration* d = parser->declarations[i];
+
+               if (d) {
+                       if (s)
+                               asprintf(&s, "%s%-24s = %s\n", s, d->name, d->value);
+                       else
+                               asprintf(&s, "%-24s = %s\n", d->name, d->value);
+               }
+       }
+
+       return s;
+}
index 62d1b5a0c871f8fef044d5437738ec66d4ca1894..5ebd300e9cbb77afb0cdd01467ab894c4bb1977e 100644 (file)
@@ -274,7 +274,7 @@ static char* pakfire_parser_make_canonical_name(const char* name) {
 }
 
 int pakfire_parser_parse_data(PakfireParser parent, const char* data, size_t len) {
-       Pakfire pakfire = pakfire_parser_get_pakfire(parser);
+       Pakfire pakfire = pakfire_parser_get_pakfire(parent);
 
        DEBUG(pakfire, "Parsing the following data:\n%s\n", data);
 
@@ -294,9 +294,18 @@ int pakfire_parser_parse_data(PakfireParser parent, const char* data, size_t len
                parent = pakfire_parser_merge(parent, parser);
        }
 
-       pakfire_unref(pakfire);
+       // Destroy the parser
        pakfire_parser_unref(parser);
 
+       // Log what we have in the parent parser now
+       char* dump = pakfire_parser_dump(parent);
+
+       DEBUG(pakfire, "Status of the parser %p:\n%s\n", parent, dump);
+       pakfire_free(dump);
+
+       // Cleanup
+       pakfire_unref(pakfire);
+
        return r;
 }