]> git.ipfire.org Git - pakfire.git/commitdiff
parser: Create its own types
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 14:35:34 +0000 (14:35 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 27 Jun 2025 14:35:34 +0000 (14:35 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/build.c
src/pakfire/dist.c
src/pakfire/dist.h
src/pakfire/parser.c
src/pakfire/parser.h
src/pakfire/parser/grammar.y
src/pakfire/parser/scanner.l
tests/libpakfire/makefile.c
tests/libpakfire/parser.c
tests/parser/test.c

index a4040fc767bec78182ca08545c264caddaf744bc..17dd124ca3e4ba041d3d430fd67bcd91093805bc 100644 (file)
@@ -843,7 +843,7 @@ ERROR:
 }
 
 static int pakfire_build_find_dependencies(pakfire_build* build,
-               struct pakfire_parser* makefile, const char* namespace,
+               pakfire_parser* makefile, const char* namespace,
                pakfire_package* pkg, pakfire_filelist* filelist) {
        char* filter_provides = NULL;
        char* filter_requires = NULL;
@@ -928,7 +928,7 @@ static int __pakfire_build_package_mark_config_files(
 }
 
 static int pakfire_build_package_mark_config_files(pakfire_build* build,
-               pakfire_filelist* filelist, struct pakfire_parser* makefile, const char* namespace) {
+               pakfire_filelist* filelist, pakfire_parser* makefile, const char* namespace) {
        char** configfiles = NULL;
        int r;
 
@@ -954,7 +954,7 @@ ERROR:
 }
 
 static int pakfire_build_package_add_files(pakfire_build* build,
-               struct pakfire_parser* makefile, const char* buildroot, const char* namespace,
+               pakfire_parser* makefile, const char* buildroot, const char* namespace,
                pakfire_package* pkg, pakfire_packager* packager) {
        pakfire_filelist* filelist = NULL;
        char** includes = NULL;
@@ -1183,7 +1183,7 @@ ERROR:
 }
 
 static int pakfire_build_package_add_scriptlets(pakfire_build* build,
-               struct pakfire_parser* makefile, const char* namespace,
+               pakfire_parser* makefile, const char* namespace,
                pakfire_package* pkg, pakfire_packager* packager) {
        char name[NAME_MAX];
        int r;
@@ -1211,7 +1211,7 @@ static int pakfire_build_package_add_scriptlets(pakfire_build* build,
        return 0;
 }
 
-static int pakfire_build_package(pakfire_build* build, struct pakfire_parser* makefile,
+static int pakfire_build_package(pakfire_build* build, pakfire_parser* makefile,
                const char* buildroot, const char* namespace) {
        pakfire_archive* archive = NULL;
        pakfire_package* pkg = NULL;
@@ -1335,7 +1335,7 @@ static int pakfire_build_package_dump(pakfire_ctx* ctx,
 }
 
 static int pakfire_build_packages(pakfire_build* build,
-               struct pakfire_parser* makefile) {
+               pakfire_parser* makefile) {
        INFO(build->ctx, "Creating packages...");
        int r = 1;
 
@@ -1377,7 +1377,7 @@ ERROR:
 }
 
 static int pakfire_build_stage(pakfire_build* build,
-               struct pakfire_parser* makefile, const char* stage) {
+               pakfire_parser* makefile, const char* stage) {
        pakfire_env* env = NULL;
        char* script = NULL;
        char template[1024];
@@ -2190,11 +2190,11 @@ int pakfire_build_set_ccache_path(
 }
 
 static int pakfire_build_read_makefile(pakfire_build* build,
-               struct pakfire_parser** parser, pakfire_package* package) {
+               pakfire_parser** parser, pakfire_package* package) {
        char path[PATH_MAX];
        int r;
 
-       struct pakfire_parser_error* error = NULL;
+       pakfire_parser_error* error = NULL;
 
        const char* nevra = pakfire_package_get_string(package, PAKFIRE_PKG_NEVRA);
        const char* name  = pakfire_package_get_string(package, PAKFIRE_PKG_NAME);
@@ -2230,7 +2230,7 @@ ERROR:
 }
 
 static int pakfire_build_perform(pakfire_build* build,
-               struct pakfire_parser* makefile) {
+               pakfire_parser* makefile) {
        int r;
 
        // Prepare the build
@@ -2512,7 +2512,7 @@ static int __pakfire_build_result(pakfire_ctx* ctx, pakfire_package* pkg,
 int pakfire_build_exec(pakfire_build* build, const char* path,
                pakfire_build_result_callback result_callback, void* data) {
        pakfire_package* package = NULL;
-       struct pakfire_parser* makefile = NULL;
+       pakfire_parser* makefile = NULL;
        char* problems = NULL;
        char duration[TIME_STRING_MAX];
        int r;
index 2eef14568b96ba3496574befba9497ca1264c298..59c274a7b82ee4a6984ed75b17cb5ee6a1f9c084 100644 (file)
@@ -57,7 +57,7 @@ static const char* pakfire_dist_excludes[] = {
 };
 
 static int pakfire_makefile_set_defaults(struct pakfire* pakfire,
-               struct pakfire_parser* parser, const char* path) {
+               pakfire_parser* parser, const char* path) {
        char dirname[PATH_MAX];
        char buffer[1024];
        int r;
@@ -149,8 +149,8 @@ static int pakfire_makefile_set_defaults(struct pakfire* pakfire,
        return 0;
 }
 
-int pakfire_read_makefile(struct pakfire_parser** parser, struct pakfire* pakfire,
-               const char* path, struct pakfire_parser_error** error) {
+int pakfire_read_makefile(pakfire_parser** parser, struct pakfire* pakfire,
+               const char* path, pakfire_parser_error** error) {
        int r;
 
        // Fetch context
@@ -231,7 +231,7 @@ ERROR:
 }
 
 static int pakfire_dist_get_mirrorlist(pakfire_ctx* ctx, struct pakfire* pakfire,
-               struct pakfire_parser* makefile, pakfire_mirrorlist** list) {
+               pakfire_parser* makefile, pakfire_mirrorlist** list) {
        pakfire_mirrorlist* m = NULL;
        pakfire_mirror* mirror = NULL;
        char* p = NULL;
@@ -352,7 +352,7 @@ static int pakfire_dist_add_source(struct pakfire* pakfire, pakfire_packager* pa
 }
 
 static int pakfire_dist_add_sources(pakfire_ctx* ctx, struct pakfire* pakfire,
-               pakfire_packager* packager, pakfire_package* pkg, struct pakfire_parser* makefile) {
+               pakfire_packager* packager, pakfire_package* pkg, pakfire_parser* makefile) {
        pakfire_mirrorlist* mirrorlist = NULL;
        char* sources = NULL;
        char* p = NULL;
@@ -454,8 +454,8 @@ int pakfire_dist(struct pakfire* pakfire,
                const char* path, pakfire_archive** archive) {
        pakfire_packager* packager = NULL;
        pakfire_package* pkg = NULL;
-       struct pakfire_parser* makefile = NULL;
-       struct pakfire_parser_error* error = NULL;
+       pakfire_parser* makefile = NULL;
+       pakfire_parser_error* error = NULL;
        pakfire_archive* a = NULL;
        int r;
 
index 7301325efb4ce3de70bc4394077726efa4e68876..4b2c19ac86eeed7f8ec89e67d8c9e773c3b814c9 100644 (file)
@@ -28,7 +28,7 @@
 int pakfire_dist(struct pakfire* pakfire,
        const char* path, pakfire_archive** archive);
 
-int pakfire_read_makefile(struct pakfire_parser** parser, struct pakfire* pakfire,
-       const char* path, struct pakfire_parser_error** error);
+int pakfire_read_makefile(pakfire_parser** parser, struct pakfire* pakfire,
+       const char* path, pakfire_parser_error** error);
 
 #endif /* PAKFIRE_DIST_H */
index 34e5c14a9d9479618daa2dc24f0a3347bbbc12c5..bc2433a33f4a155227b388a9fdbc518a5185d576 100644 (file)
@@ -56,23 +56,23 @@ struct pakfire_parser {
        struct pakfire* pakfire;
        int nrefs;
 
-       struct pakfire_parser* parent;
+       pakfire_parser* parent;
        int flags;
 
        // Namespace
        char namespace[NAME_MAX];
 
-       struct pakfire_parser_declaration** declarations;
+       pakfire_parser_declaration** declarations;
        size_t num_declarations;
 };
 
-static void pakfire_parser_free_declaration(struct pakfire_parser_declaration* d) {
+static void pakfire_parser_free_declaration(pakfire_parser_declaration* d) {
        if (d->value)
                free(d->value);
        free(d);
 }
 
-static void pakfire_parser_free_declarations(struct pakfire_parser* parser) {
+static void pakfire_parser_free_declarations(pakfire_parser* parser) {
        if (parser->declarations) {
                for (unsigned int i = 0; i < parser->num_declarations; i++)
                        pakfire_parser_free_declaration(parser->declarations[i]);
@@ -82,7 +82,7 @@ static void pakfire_parser_free_declarations(struct pakfire_parser* parser) {
        }
 }
 
-static void pakfire_parser_free(struct pakfire_parser* parser) {
+static void pakfire_parser_free(pakfire_parser* parser) {
        pakfire_parser_free_declarations(parser);
 
        if (parser->parent)
@@ -94,9 +94,9 @@ static void pakfire_parser_free(struct pakfire_parser* parser) {
        free(parser);
 }
 
-int pakfire_parser_create(struct pakfire_parser** parser,
-               struct pakfire* pakfire, struct pakfire_parser* parent, const char* namespace, int flags) {
-       struct pakfire_parser* self = NULL;
+int pakfire_parser_create(pakfire_parser** parser,
+               struct pakfire* pakfire, pakfire_parser* parent, const char* namespace, int flags) {
+       pakfire_parser* self = NULL;
        int r;
 
        // Allocate some memory
@@ -135,8 +135,8 @@ ERROR:
        return r;
 }
 
-struct pakfire_parser* pakfire_parser_create_child(struct pakfire_parser* parser, const char* namespace) {
-       struct pakfire_parser* child = NULL;
+pakfire_parser* pakfire_parser_create_child(pakfire_parser* parser, const char* namespace) {
+       pakfire_parser* child = NULL;
        int r;
 
        // Create the parser
@@ -147,17 +147,17 @@ struct pakfire_parser* pakfire_parser_create_child(struct pakfire_parser* parser
        return child;
 }
 
-struct pakfire_parser* pakfire_parser_ref(struct pakfire_parser* parser) {
+pakfire_parser* pakfire_parser_ref(pakfire_parser* parser) {
        ++parser->nrefs;
 
        return parser;
 }
 
-struct pakfire* pakfire_parser_get_pakfire(struct pakfire_parser* parser) {
+struct pakfire* pakfire_parser_get_pakfire(pakfire_parser* parser) {
        return pakfire_ref(parser->pakfire);
 }
 
-struct pakfire_parser* pakfire_parser_unref(struct pakfire_parser* parser) {
+pakfire_parser* pakfire_parser_unref(pakfire_parser* parser) {
        if (--parser->nrefs > 0)
                return parser;
 
@@ -165,15 +165,15 @@ struct pakfire_parser* pakfire_parser_unref(struct pakfire_parser* parser) {
        return NULL;
 }
 
-struct pakfire_parser* pakfire_parser_get_parent(struct pakfire_parser* parser) {
+pakfire_parser* pakfire_parser_get_parent(pakfire_parser* parser) {
        if (parser->parent)
                return pakfire_parser_ref(parser->parent);
 
        return NULL;
 }
 
-static struct pakfire_parser_declaration* pakfire_parser_get_declaration(
-               struct pakfire_parser* parser, const char* namespace, const char* name) {
+static pakfire_parser_declaration* pakfire_parser_get_declaration(
+               pakfire_parser* parser, const char* namespace, const char* name) {
        if (!name) {
                errno = EINVAL;
                return NULL;
@@ -189,7 +189,7 @@ static struct pakfire_parser_declaration* pakfire_parser_get_declaration(
                DEBUG(parser->ctx, "%p: Looking up %s\n", parser, name);
 #endif /* PAKFIRE_DEBUG_PARSER */
 
-       struct pakfire_parser_declaration* d;
+       pakfire_parser_declaration* d;
        for (unsigned i = 0; i < parser->num_declarations; i++) {
                d = parser->declarations[i];
                if (!d)
@@ -217,9 +217,9 @@ static struct pakfire_parser_declaration* pakfire_parser_get_declaration(
        return NULL;
 }
 
-static struct pakfire_parser_declaration* pakfire_parser_get_declaration_recursive(
-               struct pakfire_parser* parser, const char* namespace, const char* name) {
-       struct pakfire_parser_declaration* d = pakfire_parser_get_declaration(
+static pakfire_parser_declaration* pakfire_parser_get_declaration_recursive(
+               pakfire_parser* parser, const char* namespace, const char* name) {
+       pakfire_parser_declaration* d = pakfire_parser_get_declaration(
                        parser, namespace, name);
        if (d)
                return d;
@@ -262,9 +262,9 @@ static char* pakfire_parser_join(const char* c, const char* val1, const char* va
        return result;
 }
 
-static struct pakfire_parser_declaration* pakfire_parser_find_declaration(
-               struct pakfire_parser* parser, const char* namespace, const char* name) {
-       struct pakfire_parser_declaration* d = NULL;
+static pakfire_parser_declaration* pakfire_parser_find_declaration(
+               pakfire_parser* parser, const char* namespace, const char* name) {
+       pakfire_parser_declaration* d = NULL;
        char n[NAME_MAX] = "";
        int r;
 
@@ -292,9 +292,9 @@ static struct pakfire_parser_declaration* pakfire_parser_find_declaration(
        return NULL;
 }
 
-int pakfire_parser_set(struct pakfire_parser* parser,
+int pakfire_parser_set(pakfire_parser* parser,
                const char* namespace, const char* name, const char* value, int flags) {
-       struct pakfire_parser_declaration* d = NULL;
+       pakfire_parser_declaration* d = NULL;
        char* buffer = NULL;
        int r;
 
@@ -399,15 +399,15 @@ ERROR:
        return r;
 }
 
-int pakfire_parser_apply_declaration(struct pakfire_parser* parser,
-               struct pakfire_parser_declaration* declaration) {
+int pakfire_parser_apply_declaration(pakfire_parser* parser,
+               pakfire_parser_declaration* declaration) {
        return pakfire_parser_set(parser, declaration->namespace,
                declaration->name, declaration->value, declaration->flags);
 }
 
-static int pakfire_parser_find_template(struct pakfire_parser* parser,
+static int pakfire_parser_find_template(pakfire_parser* parser,
                char* template, const size_t length, const char* namespace) {
-       struct pakfire_parser_declaration* d = NULL;
+       pakfire_parser_declaration* d = NULL;
        const char* value = "MAIN";
 
        DEBUG(parser->ctx, "Looking up template in namespace '%s'\n", namespace);
@@ -421,8 +421,8 @@ static int pakfire_parser_find_template(struct pakfire_parser* parser,
        return __pakfire_string_format(template, length, "packages.template:%s", value);
 }
 
-static const char* pakfire_parser_get_raw(struct pakfire_parser* parser, const char* namespace, const char* name) {
-       struct pakfire_parser_declaration* d = NULL;
+static const char* pakfire_parser_get_raw(pakfire_parser* parser, const char* namespace, const char* name) {
+       pakfire_parser_declaration* d = NULL;
        char template[NAME_MAX];
        int r;
 
@@ -458,7 +458,7 @@ static const char* pakfire_parser_get_raw(struct pakfire_parser* parser, const c
        return NULL;
 }
 
-int pakfire_parser_append(struct pakfire_parser* parser,
+int pakfire_parser_append(pakfire_parser* parser,
                const char* namespace, const char* name, const char* value) {
        char* buffer = NULL;
 
@@ -484,7 +484,7 @@ int pakfire_parser_append(struct pakfire_parser* parser,
        return r;
 }
 
-static int pakfire_parser_expand_commands(struct pakfire_parser* parser, char** buffer) {
+static int pakfire_parser_expand_commands(pakfire_parser* parser, char** buffer) {
        pcre2_match_data* match = NULL;
        PCRE2_UCHAR* command = NULL;
        PCRE2_SIZE command_length;
@@ -594,7 +594,7 @@ ERROR:
        return r;
 }
 
-static int pakfire_parser_expand_variables(struct pakfire_parser* parser,
+static int pakfire_parser_expand_variables(pakfire_parser* parser,
                const char* namespace, char** buffer) {
        char parent_namespace[NAME_MAX];
        pcre2_match_data* match = NULL;
@@ -713,7 +713,7 @@ ERROR:
        return r;
 }
 
-char* pakfire_parser_expand(struct pakfire_parser* parser,
+char* pakfire_parser_expand(pakfire_parser* parser,
                const char* namespace, const char* value) {
        char* buffer = NULL;
        int r;
@@ -761,7 +761,7 @@ ERROR:
        return NULL;
 }
 
-char* pakfire_parser_get(struct pakfire_parser* parser, const char* namespace, const char* name) {
+char* pakfire_parser_get(pakfire_parser* parser, const char* namespace, const char* name) {
        const char* value = pakfire_parser_get_raw(parser, namespace, name);
 
        // Return NULL when nothing was found
@@ -772,7 +772,7 @@ char* pakfire_parser_get(struct pakfire_parser* parser, const char* namespace, c
        return pakfire_parser_expand(parser, namespace, value);
 }
 
-int pakfire_parser_get_filelist(struct pakfire_parser* parser, const char* namespace,
+int pakfire_parser_get_filelist(pakfire_parser* parser, const char* namespace,
                const char* name, char*** includes, char*** excludes) {
        const char* file = NULL;
        char* p = NULL;
@@ -814,8 +814,8 @@ ERROR:
        return r;
 }
 
-char** pakfire_parser_list_namespaces(struct pakfire_parser* parser, const char* filter) {
-       struct pakfire_parser_declaration* d = NULL;
+char** pakfire_parser_list_namespaces(pakfire_parser* parser, const char* filter) {
+       pakfire_parser_declaration* d = NULL;
        char** namespaces = NULL;
        int r;
 
@@ -854,8 +854,8 @@ ERROR:
        return NULL;
 }
 
-int pakfire_parser_merge(struct pakfire_parser* parser1, struct pakfire_parser* parser2) {
-       struct pakfire_parser_declaration* d = NULL;
+int pakfire_parser_merge(pakfire_parser* parser1, pakfire_parser* parser2) {
+       pakfire_parser_declaration* d = NULL;
        char* namespace = NULL;
        char* value = NULL;
        int r = 0;
@@ -921,8 +921,8 @@ OUT:
        return r;
 }
 
-int pakfire_parser_read(struct pakfire_parser* parser, FILE* f,
-               struct pakfire_parser_error** error) {
+int pakfire_parser_read(pakfire_parser* parser, FILE* f,
+               pakfire_parser_error** error) {
        char* data = NULL;
        size_t length = 0;
        int fd = -EBADF;
@@ -952,8 +952,8 @@ ERROR:
        return r;
 }
 
-int pakfire_parser_read_file(struct pakfire_parser* parser, const char* path,
-               struct pakfire_parser_error** error) {
+int pakfire_parser_read_file(pakfire_parser* parser, const char* path,
+               pakfire_parser_error** error) {
        FILE* f = NULL;
        int r;
 
@@ -974,18 +974,18 @@ int pakfire_parser_read_file(struct pakfire_parser* parser, const char* path,
        return r;
 }
 
-int pakfire_parser_parse(struct pakfire_parser* parser,
-               const char* data, size_t size, struct pakfire_parser_error** error) {
+int pakfire_parser_parse(pakfire_parser* parser,
+               const char* data, size_t size, pakfire_parser_error** error) {
        return pakfire_parser_parse_data(parser, data, size, error);
 }
 
-char* pakfire_parser_dump(struct pakfire_parser* parser) {
+char* pakfire_parser_dump(pakfire_parser* parser) {
        char buffer[NAME_MAX*2 + 1];
        char* s = NULL;
        int r;
 
        for (unsigned int i = 0; i < parser->num_declarations; i++) {
-               struct pakfire_parser_declaration* d = parser->declarations[i];
+               pakfire_parser_declaration* d = parser->declarations[i];
 
                if (d) {
                        if (*d->namespace)
@@ -1002,16 +1002,16 @@ char* pakfire_parser_dump(struct pakfire_parser* parser) {
        return s;
 }
 
-const char* pakfire_parser_get_namespace(struct pakfire_parser* parser) {
+const char* pakfire_parser_get_namespace(pakfire_parser* parser) {
        return parser->namespace;
 }
 
-int pakfire_parser_set_namespace(struct pakfire_parser* parser, const char* namespace) {
+int pakfire_parser_set_namespace(pakfire_parser* parser, const char* namespace) {
        return pakfire_string_set(parser->namespace, namespace);
 }
 
-int pakfire_parser_set_env(struct pakfire_parser* parser, pakfire_env* env) {
-       struct pakfire_parser_declaration* d = NULL;
+int pakfire_parser_set_env(pakfire_parser* parser, pakfire_env* env) {
+       pakfire_parser_declaration* d = NULL;
        char* value = NULL;
        int r;
 
@@ -1037,7 +1037,7 @@ int pakfire_parser_set_env(struct pakfire_parser* parser, pakfire_env* env) {
        return 0;
 }
 
-int pakfire_parser_create_package(struct pakfire_parser* parser,
+int pakfire_parser_create_package(pakfire_parser* parser,
                pakfire_package** pkg, struct pakfire_repo* repo, const char* namespace, const char* default_arch) {
        int r = 1;
 
@@ -1179,7 +1179,7 @@ CLEANUP:
 // Error
 
 struct pakfire_parser_error {
-       struct pakfire_parser* parser;
+       pakfire_parser* parser;
        int nrefs;
 
        char* filename;
@@ -1187,9 +1187,9 @@ struct pakfire_parser_error {
        char* message;
 };
 
-int pakfire_parser_error_create(struct pakfire_parser_error** error,
-               struct pakfire_parser* parser, const char* filename, int line, const char* message) {
-       struct pakfire_parser_error* e = calloc(1, sizeof(*e));
+int pakfire_parser_error_create(pakfire_parser_error** error,
+               pakfire_parser* parser, const char* filename, int line, const char* message) {
+       pakfire_parser_error* e = calloc(1, sizeof(*e));
        if (!e)
                return ENOMEM;
 
@@ -1212,14 +1212,14 @@ int pakfire_parser_error_create(struct pakfire_parser_error** error,
        return 0;
 }
 
-struct pakfire_parser_error* pakfire_parser_error_ref(
-               struct pakfire_parser_error* error) {
+pakfire_parser_error* pakfire_parser_error_ref(
+               pakfire_parser_error* error) {
        ++error->nrefs;
 
        return error;
 }
 
-static void pakfire_parser_error_free(struct pakfire_parser_error* error) {
+static void pakfire_parser_error_free(pakfire_parser_error* error) {
        if (error->parser)
                pakfire_parser_unref(error->parser);
        if (error->filename)
@@ -1229,8 +1229,8 @@ static void pakfire_parser_error_free(struct pakfire_parser_error* error) {
        free(error);
 }
 
-struct pakfire_parser_error* pakfire_parser_error_unref(
-               struct pakfire_parser_error* error) {
+pakfire_parser_error* pakfire_parser_error_unref(
+               pakfire_parser_error* error) {
        if (--error->nrefs > 0)
                return error;
 
@@ -1239,15 +1239,15 @@ struct pakfire_parser_error* pakfire_parser_error_unref(
 }
 
 const char* pakfire_parser_error_get_filename(
-               struct pakfire_parser_error* error) {
+               pakfire_parser_error* error) {
        return error->filename;
 }
 
-int pakfire_parser_error_get_line(struct pakfire_parser_error* error) {
+int pakfire_parser_error_get_line(pakfire_parser_error* error) {
        return error->line;
 }
 
 const char* pakfire_parser_error_get_message(
-               struct pakfire_parser_error* error) {
+               pakfire_parser_error* error) {
        return error->message;
 }
index e8dc1c6ff5d7dc1e483945a9a9ec3e720c4dd563..91f213c5b3045b8ad960aa3fcb938927bb021dd1 100644 (file)
@@ -24,7 +24,7 @@
 #include <linux/limits.h>
 #include <stdio.h>
 
-struct pakfire_parser;
+typedef struct pakfire_parser pakfire_parser;
 
 #include <pakfire/env.h>
 #include <pakfire/package.h>
@@ -36,55 +36,55 @@ enum pakfire_parser_flags {
        PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS = (1 << 0),
 };
 
-struct pakfire_parser_error;
+typedef struct pakfire_parser_error pakfire_parser_error;
 
-int pakfire_parser_create(struct pakfire_parser** parser, struct pakfire* pakfire,
-       struct pakfire_parser* parent, const char* namespace, int flags);
-struct pakfire_parser* pakfire_parser_create_child(struct pakfire_parser* parser,
+int pakfire_parser_create(pakfire_parser** parser, struct pakfire* pakfire,
+       pakfire_parser* parent, const char* namespace, int flags);
+pakfire_parser* pakfire_parser_create_child(pakfire_parser* parser,
        const char* namespace);
-struct pakfire_parser* pakfire_parser_ref(struct pakfire_parser* parser);
-struct pakfire_parser* pakfire_parser_unref(struct pakfire_parser* parser);
-struct pakfire_parser* pakfire_parser_get_parent(struct pakfire_parser* parser);
+pakfire_parser* pakfire_parser_ref(pakfire_parser* parser);
+pakfire_parser* pakfire_parser_unref(pakfire_parser* parser);
+pakfire_parser* pakfire_parser_get_parent(pakfire_parser* parser);
 
-int pakfire_parser_set(struct pakfire_parser* parser,
+int pakfire_parser_set(pakfire_parser* parser,
        const char* namespace, const char* name, const char* value, int flags);
-int pakfire_parser_append(struct pakfire_parser* parser,
+int pakfire_parser_append(pakfire_parser* parser,
        const char* namespace, const char* name, const char* value);
 
-char* pakfire_parser_expand(struct pakfire_parser* parser, const char* namespace, const char* value);
-char* pakfire_parser_get(struct pakfire_parser* parser, const char* namespace, const char* name);
-int pakfire_parser_get_filelist(struct pakfire_parser* parser, const char* namespace,
+char* pakfire_parser_expand(pakfire_parser* parser, const char* namespace, const char* value);
+char* pakfire_parser_get(pakfire_parser* parser, const char* namespace, const char* name);
+int pakfire_parser_get_filelist(pakfire_parser* parser, const char* namespace,
        const char* name, char*** includes, char*** excludes);
-char** pakfire_parser_list_namespaces(struct pakfire_parser* parser, const char* filter);
+char** pakfire_parser_list_namespaces(pakfire_parser* parser, const char* filter);
 
-int pakfire_parser_merge(struct pakfire_parser* parser1, struct pakfire_parser* parser2);
+int pakfire_parser_merge(pakfire_parser* parser1, pakfire_parser* parser2);
 
-int pakfire_parser_read(struct pakfire_parser* parser, FILE* f, struct pakfire_parser_error** error);
-int pakfire_parser_read_file(struct pakfire_parser* parser, const char* path,
-       struct pakfire_parser_error** error);
-int pakfire_parser_parse(struct pakfire_parser* parser, const char* data, size_t size,
-       struct pakfire_parser_error** error);
-char* pakfire_parser_dump(struct pakfire_parser* parser);
+int pakfire_parser_read(pakfire_parser* parser, FILE* f, pakfire_parser_error** error);
+int pakfire_parser_read_file(pakfire_parser* parser, const char* path,
+       pakfire_parser_error** error);
+int pakfire_parser_parse(pakfire_parser* parser, const char* data, size_t size,
+       pakfire_parser_error** error);
+char* pakfire_parser_dump(pakfire_parser* parser);
 
-const char* pakfire_parser_get_namespace(struct pakfire_parser* parser);
-int pakfire_parser_set_namespace(struct pakfire_parser* parser, const char* namespace);
+const char* pakfire_parser_get_namespace(pakfire_parser* parser);
+int pakfire_parser_set_namespace(pakfire_parser* parser, const char* namespace);
 
-int pakfire_parser_create_package(struct pakfire_parser* parser,
+int pakfire_parser_create_package(pakfire_parser* parser,
        pakfire_package** pkg, struct pakfire_repo* repo, const char* namespace, const char* default_arch);
 
 // Errors
-int pakfire_parser_error_create(struct pakfire_parser_error** error,
-               struct pakfire_parser* parser, const char* filename, int line, const char* message);
-struct pakfire_parser_error* pakfire_parser_error_ref(struct pakfire_parser_error* error);
-struct pakfire_parser_error* pakfire_parser_error_unref(struct pakfire_parser_error* error);
+int pakfire_parser_error_create(pakfire_parser_error** error,
+               pakfire_parser* parser, const char* filename, int line, const char* message);
+pakfire_parser_error* pakfire_parser_error_ref(pakfire_parser_error* error);
+pakfire_parser_error* pakfire_parser_error_unref(pakfire_parser_error* error);
 
-const char* pakfire_parser_error_get_filename(struct pakfire_parser_error* error);
-int pakfire_parser_error_get_line(struct pakfire_parser_error* error);
-const char* pakfire_parser_error_get_message(struct pakfire_parser_error* error);
+const char* pakfire_parser_error_get_filename(pakfire_parser_error* error);
+int pakfire_parser_error_get_line(pakfire_parser_error* error);
+const char* pakfire_parser_error_get_message(pakfire_parser_error* error);
 
-struct pakfire* pakfire_parser_get_pakfire(struct pakfire_parser* parser);
+struct pakfire* pakfire_parser_get_pakfire(pakfire_parser* parser);
 
-struct pakfire_parser_state {
+typedef struct pakfire_parser_state {
        unsigned int lineno;
 
        // Indentation level
@@ -93,9 +93,9 @@ struct pakfire_parser_state {
        // Remember current indentation
        unsigned int current_indent;
        unsigned int readline_indent;
-};
+} pakfire_parser_state;
 
-struct pakfire_parser_declaration {
+typedef struct pakfire_parser_declaration {
        char namespace[NAME_MAX];
        char name[NAME_MAX];
        char* value;
@@ -104,14 +104,14 @@ struct pakfire_parser_declaration {
                PAKFIRE_PARSER_DECLARATION_EXPORT                       = (1 << 0),
                PAKFIRE_PARSER_DECLARATION_APPEND                       = (1 << 1),
        } flags;
-};
+} pakfire_parser_declaration;
 
 int pakfire_parser_apply_declaration(
-       struct pakfire_parser* parser, struct pakfire_parser_declaration* declaration);
+       pakfire_parser* parser, pakfire_parser_declaration* declaration);
 
-int pakfire_parser_parse_data(struct pakfire_parser* parent, const char* data, size_t len,
-       struct pakfire_parser_error** error);
+int pakfire_parser_parse_data(pakfire_parser* parent, const char* data, size_t len,
+       pakfire_parser_error** error);
 
-int pakfire_parser_set_env(struct pakfire_parser* parser, pakfire_env* env);
+int pakfire_parser_set_env(pakfire_parser* parser, pakfire_env* env);
 
 #endif /* PAKFIRE_PARSER_H */
index b51bbc199a28343ef5ee66b839f0e0a9ff160ad1..eb17159974637bae93da2fac0b63e7539a31146e 100644 (file)
@@ -24,9 +24,9 @@
        {yyscan_t* scanner}
        {pakfire_ctx* ctx}
        {struct pakfire* pakfire}
-       {struct pakfire_parser** parser}
-       {struct pakfire_parser* parent}
-       {struct pakfire_parser_error** error}
+       {pakfire_parser** parser}
+       {pakfire_parser* parent}
+       {pakfire_parser_error** error}
 
 // Make the parser reentrant
 %define api.pure full
 #endif
 
 typedef void* yyscan_t;
-extern int yylex_init_extra(struct pakfire_parser_state* state, yyscan_t* scanner);
+extern int yylex_init_extra(pakfire_parser_state* state, yyscan_t* scanner);
 int yylex_destroy(yyscan_t scanner);
 
 typedef struct yy_buffer_state* YY_BUFFER_STATE;
 extern YY_BUFFER_STATE yy_scan_bytes(const char* buffer, int len, yyscan_t scanner);
 extern void yy_delete_buffer(YY_BUFFER_STATE buffer, yyscan_t scanner);
 
-#define YY_EXTRA_TYPE struct pakfire_parser_state*
+#define YY_EXTRA_TYPE pakfire_parser_state*
 YY_EXTRA_TYPE yyget_extra(yyscan_t scanner);
 
 #include "grammar.h"
@@ -78,9 +78,9 @@ enum operator {
 };
 
 static void yyerror(yyscan_t* scanner, pakfire_ctx* ctx, struct pakfire* pakfire,
-               struct pakfire_parser** parser, struct pakfire_parser* parent,
-               struct pakfire_parser_error** error, const char* s) {
-       const struct pakfire_parser_state* state = yyget_extra(scanner);
+               pakfire_parser** parser, pakfire_parser* parent,
+               pakfire_parser_error** error, const char* s) {
+       const pakfire_parser_state* state = yyget_extra(scanner);
 
        ERROR(ctx, "Error (line %u): %s\n", state->lineno, s);
 
@@ -93,15 +93,15 @@ static void yyerror(yyscan_t* scanner, pakfire_ctx* ctx, struct pakfire* pakfire
        }
 }
 
-static struct pakfire_parser* make_if_stmt(pakfire_ctx* ctx, const enum operator op,
-               const char* val1, const char* val2, struct pakfire_parser* if_block, struct pakfire_parser* else_block);
+static pakfire_parser* make_if_stmt(pakfire_ctx* ctx, const enum operator op,
+               const char* val1, const char* val2, pakfire_parser* if_block, pakfire_parser* else_block);
 
 static int pakfire_parser_new_declaration(
-               struct pakfire_parser_declaration** declaration, const char* name, const char* value, int flags) {
+               pakfire_parser_declaration** declaration, const char* name, const char* value, int flags) {
        if (!name)
                return EINVAL;
 
-       struct pakfire_parser_declaration* d = calloc(1, sizeof(*d));
+       pakfire_parser_declaration* d = calloc(1, sizeof(*d));
        if (!d)
                return ENOMEM;
 
@@ -122,7 +122,7 @@ static int pakfire_parser_new_declaration(
        return 0;
 }
 
-static void pakfire_parser_free_declaration(struct pakfire_parser_declaration* declaration) {
+static void pakfire_parser_free_declaration(pakfire_parser_declaration* declaration) {
        if (declaration->value)
                free(declaration->value);
 
@@ -165,9 +165,9 @@ static void pakfire_parser_free_declaration(struct pakfire_parser_declaration* d
 %type <string>                         line
 
 %union {
-       struct pakfire_parser* parser;
+       pakfire_parser* parser;
        char* string;
-       struct pakfire_parser_declaration* declaration;
+       pakfire_parser_declaration* declaration;
 }
 
 %initial-action {
@@ -233,7 +233,7 @@ grammar                                             : %empty
 block                                          : T_INDENT grammar T_OUTDENT
                                                        {
                                                                // Reset the top parser
-                                                               struct pakfire_parser* p = pakfire_parser_get_parent(*parser);
+                                                               pakfire_parser* p = pakfire_parser_get_parent(*parser);
                                                                pakfire_parser_unref(*parser);
                                                                *parser = p;
 
@@ -409,14 +409,14 @@ else_stmt                                 : T_ELSE T_EOL block
 
 %%
 
-int pakfire_parser_parse_data(struct pakfire_parser* parent, const char* data, size_t len,
-               struct pakfire_parser_error** error) {
+int pakfire_parser_parse_data(pakfire_parser* parent, const char* data, size_t len,
+               pakfire_parser_error** error) {
        struct pakfire* pakfire = pakfire_parser_get_pakfire(parent);
        yyscan_t scanner;
        int r;
 
        // Initialize the parser's state
-       struct pakfire_parser_state state = {
+       pakfire_parser_state state = {
                .lineno = 1,
                .indent_level = 0,
                .current_indent = 0,
@@ -437,7 +437,7 @@ int pakfire_parser_parse_data(struct pakfire_parser* parent, const char* data, s
        yylex_init_extra(&state, &scanner);
 
        // Create a new sub-parser
-       struct pakfire_parser* parser = NULL;
+       pakfire_parser* parser = NULL;
 
        YY_BUFFER_STATE buffer = yy_scan_bytes(data, len, scanner);
        r = yyparse(scanner, ctx, pakfire, &parser, parent, error);
@@ -491,15 +491,15 @@ ERROR:
        return r;
 }
 
-static struct pakfire_parser* make_if_stmt(pakfire_ctx* ctx, const enum operator op,
-               const char* val1, const char* val2, struct pakfire_parser* if_block, struct pakfire_parser* else_block) {
+static pakfire_parser* make_if_stmt(pakfire_ctx* ctx, const enum operator op,
+               const char* val1, const char* val2, pakfire_parser* if_block, pakfire_parser* else_block) {
        switch (op) {
                case OP_EQUALS:
                        DEBUG(ctx, "Evaluating if statement: %s == %s?\n", val1, val2);
                        break;
        }
 
-       struct pakfire_parser* parent = pakfire_parser_get_parent(if_block);
+       pakfire_parser* parent = pakfire_parser_get_parent(if_block);
 
        DEBUG(ctx, "  parent = %p, if = %p, else = %p\n", parent, if_block, else_block);
 
@@ -507,7 +507,7 @@ static struct pakfire_parser* make_if_stmt(pakfire_ctx* ctx, const enum operator
        char* v1 = pakfire_parser_expand(parent, NULL, val1);
        char* v2 = pakfire_parser_expand(parent, NULL, val2);
 
-       struct pakfire_parser* result = NULL;
+       pakfire_parser* result = NULL;
 
        switch (op) {
                case OP_EQUALS:
index 9510b9c14d5e8756f89ad5e0f908c60372167d9f..4fbd7ea09807217f2f37ba866b74ef542e99676f 100644 (file)
@@ -24,7 +24,7 @@
 %option reentrant
 %option stack noyy_top_state
 %option warn
-%option extra-type="struct pakfire_parser_state*"
+%option extra-type="pakfire_parser_state*"
 
 /* Enable to debug the scanner */
 /* %option debug */
index 7d04e797999099f2aad3af1fb51fc48243671dc2..d1359aaee72f95131ed60728f6f158930b5a3895 100644 (file)
@@ -38,7 +38,7 @@ static const char* makefiles[] = {
        NULL,
 };
 
-static int load_macros(struct pakfire_parser* parser) {
+static int load_macros(pakfire_parser* parser) {
        const char* macros = TEST_SRC_PATH "../macros/*.macro";
 
        glob_t buffer;
@@ -58,7 +58,7 @@ FAIL:
 }
 
 static int test_parse(const struct test* t) {
-       struct pakfire_parser* parser = NULL;
+       pakfire_parser* parser = NULL;
        const char** makefile = makefiles;
        char path[PATH_MAX];
        int r = EXIT_FAILURE;
@@ -93,7 +93,7 @@ FAIL:
 }
 
 static int test_macros(const struct test* t) {
-       struct pakfire_parser* parser = NULL;
+       pakfire_parser* parser = NULL;
        int r = EXIT_FAILURE;
 
        ASSERT_SUCCESS(pakfire_parser_create(&parser, t->pakfire, NULL, NULL, 0));
@@ -112,7 +112,7 @@ FAIL:
 }
 
 static int test_packages(const struct test* t) {
-       struct pakfire_parser* parser = NULL;
+       pakfire_parser* parser = NULL;
        pakfire_package* pkg = NULL;
        struct pakfire_repo* repo = NULL;
        char* s = NULL;
index 5eb434e4a322fed3a9d253dacda2258ef67b359f..07d79f849003a945967f6b0c6d25fbe492f94c98 100644 (file)
@@ -29,8 +29,8 @@
 #include "../testsuite.h"
 
 static int test_parser(const struct test* t) {
-       struct pakfire_parser* parser = NULL;
-       struct pakfire_parser* subparser = NULL;
+       pakfire_parser* parser = NULL;
+       pakfire_parser* subparser = NULL;
        int r = EXIT_FAILURE;
        char* s = NULL;
 
@@ -110,7 +110,7 @@ static const char* files[] = {
 };
 
 static int test_parser_files(const struct test* t) {
-       struct pakfire_parser* parser = NULL;
+       pakfire_parser* parser = NULL;
        const char** file = files;
        char path[PATH_MAX];
        int r = EXIT_FAILURE;
@@ -145,7 +145,7 @@ FAIL:
 }
 
 static int test_append(const struct test* t) {
-       struct pakfire_parser* parser = NULL;
+       pakfire_parser* parser = NULL;
        int r = EXIT_FAILURE;
        char* s = NULL;
 
@@ -199,7 +199,7 @@ FAIL:
 #if 0
 static int test_parser_command(const struct test* t) {
        const char* command = "%(echo \"ABC\")";
-       struct pakfire_parser* parser = NULL;
+       pakfire_parser* parser = NULL;
        int r = EXIT_FAILURE;
 
        ASSERT_SUCCESS(pakfire_parser_create(&parser, t->pakfire, NULL, NULL, PAKFIRE_PARSER_FLAGS_EXPAND_COMMANDS));
index 9848dfdff51ec851e1cadb9c877c76bb51dce2d0..a737c979c243a1a9cd801736822e455df96da11f 100644 (file)
@@ -29,8 +29,8 @@ int main(int argc, const char* argv[]) {
        pakfire_config* config = NULL;
        pakfire_ctx* ctx = NULL;
        struct pakfire* pakfire = NULL;
-       struct pakfire_parser* parser = NULL;
-       struct pakfire_parser_error* error = NULL;
+       pakfire_parser* parser = NULL;
+       pakfire_parser_error* error = NULL;
        const char* message = NULL;
        FILE* f = NULL;
        int r = 1;