From: Michael Tremer Date: Wed, 3 Mar 2021 10:35:10 +0000 (+0000) Subject: parser: Add support for flags X-Git-Tag: 0.9.28~1285^2~658 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2dd267d4243ac70ac3b28a3bba391a3659a5bc3c;p=pakfire.git parser: Add support for flags Signed-off-by: Michael Tremer --- diff --git a/src/_pakfire/parser.c b/src/_pakfire/parser.c index 651b7f58e..1e7df2955 100644 --- a/src/_pakfire/parser.c +++ b/src/_pakfire/parser.c @@ -55,12 +55,13 @@ static void Parser_dealloc(ParserObject* self) { static int Parser_init(ParserObject* self, PyObject* args, PyObject* kwds) { PakfireObject* pakfire = NULL; const char* namespace = NULL; + int flags = 0; - if (!PyArg_ParseTuple(args, "O!|z", &PakfireType, &pakfire, &namespace)) + if (!PyArg_ParseTuple(args, "O!|zi", &PakfireType, &pakfire, &namespace, &flags)) return -1; // Allocate a new parser - self->parser = pakfire_parser_create(pakfire->pakfire, NULL, namespace); + self->parser = pakfire_parser_create(pakfire->pakfire, NULL, namespace, flags); if (!self->parser) { // What went wrong here? return -1; diff --git a/src/libpakfire/archive.c b/src/libpakfire/archive.c index f5e964af3..b41d76918 100644 --- a/src/libpakfire/archive.c +++ b/src/libpakfire/archive.c @@ -326,7 +326,7 @@ PAKFIRE_EXPORT PakfireArchive pakfire_archive_create(Pakfire pakfire) { archive->nrefs = 1; archive->format = -1; - archive->parser = pakfire_parser_create(pakfire, NULL, NULL); + archive->parser = pakfire_parser_create(pakfire, NULL, NULL, 0); archive->signatures = NULL; } diff --git a/src/libpakfire/include/pakfire/parser.h b/src/libpakfire/include/pakfire/parser.h index 8f2dc3ac8..f65def9c7 100644 --- a/src/libpakfire/include/pakfire/parser.h +++ b/src/libpakfire/include/pakfire/parser.h @@ -25,10 +25,15 @@ #include +enum pakfire_parser_flags { + PAKFIRE_PARSER_FLAGS_NONE = 0, + PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS = (1 << 0), +}; + struct pakfire_parser_error; PakfireParser pakfire_parser_create(Pakfire pakfire, PakfireParser parser, - const char* namespace); + const char* namespace, int flags); PakfireParser pakfire_parser_create_child(PakfireParser parser, const char* namespace); PakfireParser pakfire_parser_ref(PakfireParser parser); diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 824c2c6ec..526e96a84 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -780,7 +780,7 @@ PAKFIRE_EXPORT int pakfire_read_makefile(PakfireParser* parser, Pakfire pakfire, const char* path, struct pakfire_parser_error** error) { int r = 1; - *parser = pakfire_parser_create(pakfire, NULL, NULL); + *parser = pakfire_parser_create(pakfire, NULL, NULL, PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS); if (!*parser) { r = 1; goto ERROR; diff --git a/src/libpakfire/parser.c b/src/libpakfire/parser.c index abf475c50..44bf29aa0 100644 --- a/src/libpakfire/parser.c +++ b/src/libpakfire/parser.c @@ -37,6 +37,7 @@ struct _PakfireParser { struct _PakfireParser* parent; int nrefs; + int flags; char* namespace; struct pakfire_parser_declaration** declarations; @@ -57,7 +58,8 @@ static char* pakfire_parser_make_canonical_name(const char* namespace, const cha return buffer; } -PAKFIRE_EXPORT PakfireParser pakfire_parser_create(Pakfire pakfire, PakfireParser parent, const char* namespace) { +PAKFIRE_EXPORT PakfireParser pakfire_parser_create(Pakfire pakfire, + PakfireParser parent, const char* namespace, int flags) { PakfireParser parser = calloc(1, sizeof(*parser)); if (parser) { parser->pakfire = pakfire_ref(pakfire); @@ -67,6 +69,9 @@ PAKFIRE_EXPORT PakfireParser pakfire_parser_create(Pakfire pakfire, PakfireParse if (parent) parser->parent = pakfire_parser_ref(parent); + // Store flags + parser->flags = flags; + // Make namespace pakfire_parser_set_namespace(parser, namespace); @@ -78,7 +83,7 @@ PAKFIRE_EXPORT PakfireParser pakfire_parser_create(Pakfire pakfire, PakfireParse } PAKFIRE_EXPORT PakfireParser pakfire_parser_create_child(PakfireParser parser, const char* namespace) { - return pakfire_parser_create(parser->pakfire, parser, namespace); + return pakfire_parser_create(parser->pakfire, parser, namespace, parser->flags); } PAKFIRE_EXPORT PakfireParser pakfire_parser_ref(PakfireParser parser) { diff --git a/src/libpakfire/parser/grammar.y b/src/libpakfire/parser/grammar.y index 47432bd1a..b08ddf4e4 100644 --- a/src/libpakfire/parser/grammar.y +++ b/src/libpakfire/parser/grammar.y @@ -163,7 +163,7 @@ static void pakfire_parser_free_declaration(struct pakfire_parser_declaration* d grammar : %empty { - $$ = pakfire_parser_create(pakfire, NULL, NULL); + $$ = pakfire_parser_create(pakfire, NULL, NULL, 0); if (!$$) ABORT; @@ -293,7 +293,7 @@ subparser : subparser_name T_EOL subgrammar T_END T_EOL char* value; // Create a new parser - $$ = pakfire_parser_create(pakfire, NULL, NULL); + $$ = pakfire_parser_create(pakfire, NULL, NULL, 0); if (!$$) ABORT; diff --git a/tests/libpakfire/parser.c b/tests/libpakfire/parser.c index bd3c5d01c..6fc51f11e 100644 --- a/tests/libpakfire/parser.c +++ b/tests/libpakfire/parser.c @@ -30,7 +30,7 @@ static int test_parser(const struct test* t) { char* value = NULL; // Create a new parser - PakfireParser parser = pakfire_parser_create(t->pakfire, NULL, NULL); + PakfireParser parser = pakfire_parser_create(t->pakfire, NULL, NULL, 0); // Retrieve a value that does not exist value = pakfire_parser_get(parser, NULL, "null"); @@ -118,7 +118,7 @@ static int test_parser_files(const struct test* t) { ASSERT(path); // Create a new parser - PakfireParser parser = pakfire_parser_create(t->pakfire, NULL, NULL); + PakfireParser parser = pakfire_parser_create(t->pakfire, NULL, NULL, 0); FILE* f = fopen(path, "r"); ASSERT(f);