From: Michael Tremer Date: Wed, 13 Mar 2019 14:32:59 +0000 (+0000) Subject: libpakfire: parser: Add convenience function to parse from FILE* X-Git-Tag: 0.9.28~1285^2~1071 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=89045ec6d9420d315bc475b80bf6736780c22111;p=pakfire.git libpakfire: parser: Add convenience function to parse from FILE* Signed-off-by: Michael Tremer --- diff --git a/Makefile.am b/Makefile.am index e39d8a07d..7329af45b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 = \ diff --git a/src/libpakfire/include/pakfire/parser.h b/src/libpakfire/include/pakfire/parser.h index f08da6b24..1d18ae69c 100644 --- a/src/libpakfire/include/pakfire/parser.h +++ b/src/libpakfire/include/pakfire/parser.h @@ -23,6 +23,9 @@ #ifdef PAKFIRE_PRIVATE +#include +#include + #include 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 */ diff --git a/src/libpakfire/libpakfire.sym b/src/libpakfire/libpakfire.sym index 471155082..3f436ca7a 100644 --- a/src/libpakfire/libpakfire.sym +++ b/src/libpakfire/libpakfire.sym @@ -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 index 000000000..403f4bca6 --- /dev/null +++ b/src/libpakfire/parser/parser.c @@ -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 . # +# # +#############################################################################*/ + +#include +#include +#include + +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; +}