]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: parser: Add convenience function to parse from FILE*
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 13 Mar 2019 14:32:59 +0000 (14:32 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 13 Mar 2019 14:32:59 +0000 (14:32 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/libpakfire/include/pakfire/parser.h
src/libpakfire/libpakfire.sym
src/libpakfire/parser/parser.c [new file with mode: 0644]

index e39d8a07d31fff47152e967bbe38de9ef23c41aa..7329af45bd395d103e3da6fb8e20d9aedfa7eb62 100644 (file)
@@ -251,6 +251,7 @@ noinst_LTLIBRARIES += \
 libpakfire_parser_la_SOURCES = \
        src/libpakfire/parser/grammar.h \
        src/libpakfire/parser/grammar.y \
+       src/libpakfire/parser/parser.c \
        src/libpakfire/parser/scanner.l
 
 libpakfire_parser_la_CFLAGS = \
index f08da6b242e3def108ce1a9eee6b9cb7a2cf51d3..1d18ae69c385c7ed121ed3de714435b8420006c0 100644 (file)
@@ -23,6 +23,9 @@
 
 #ifdef PAKFIRE_PRIVATE
 
+#include <stddef.h>
+#include <stdio.h>
+
 #include <pakfire/types.h>
 
 struct pakfire_parser_declaration {
@@ -33,6 +36,9 @@ struct pakfire_parser_declaration {
 struct pakfire_parser_declaration** pakfire_parser_parse_metadata(Pakfire pakfire,
        const char* data, size_t len);
 
+struct pakfire_parser_declaration** pakfire_parser_parse_metadata_from_file(
+       Pakfire pakfire, FILE* f);
+
 #endif /* PAKFIRE_PRIVATE */
 
 #endif /* PAKFIRE_PARSER_H */
index 471155082333cf47170d0b9e2a93f81d83bc4281..3f436ca7a5e635edd2f1731a871cf94a1cc729c0 100644 (file)
@@ -208,6 +208,10 @@ global:
        pakfire_packagelist_sort;
        pakfire_packagelist_unref;
 
+       # parser
+       pakfire_parser_parse_metadata;
+       pakfire_parser_parse_metadata_from_file;
+
        # problem
        pakfire_problem_append;
        pakfire_problem_create;
diff --git a/src/libpakfire/parser/parser.c b/src/libpakfire/parser/parser.c
new file mode 100644 (file)
index 0000000..403f4bc
--- /dev/null
@@ -0,0 +1,43 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2019 Pakfire development team                                 #
+#                                                                             #
+# This program is free software: you can redistribute it and/or modify        #
+# it under the terms of the GNU General Public License as published by        #
+# the Free Software Foundation, either version 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program is distributed in the hope that it will be useful,             #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of              #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               #
+# GNU General Public License for more details.                                #
+#                                                                             #
+# You should have received a copy of the GNU General Public License           #
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <pakfire/errno.h>
+#include <pakfire/parser.h>
+#include <pakfire/util.h>
+
+struct pakfire_parser_declaration** pakfire_parser_parse_metadata_from_file(
+               Pakfire pakfire, FILE* f) {
+       char* data;
+       size_t len;
+
+       int r = pakfire_read_file_into_buffer(f, &data, &len);
+       if (r) {
+               pakfire_errno = r;
+               return NULL;
+       }
+
+       struct pakfire_parser_declaration** declarations = \
+               pakfire_parser_parse_metadata(pakfire, data, len);
+
+       if (data)
+               pakfire_free(data);
+
+       return declarations;
+}