From 4f2a7bce2148cb4fef42bdf394b6e87aa7a642b6 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Sun, 10 Mar 2019 16:59:44 +0000 Subject: [PATCH] libpakfire: parser: Concat lines and words Signed-off-by: Michael Tremer --- src/libpakfire/parser/grammar.y | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/libpakfire/parser/grammar.y b/src/libpakfire/parser/grammar.y index 9699f1e50..cafcb5e33 100644 --- a/src/libpakfire/parser/grammar.y +++ b/src/libpakfire/parser/grammar.y @@ -19,6 +19,8 @@ #############################################################################*/ %{ +#include + #include #include @@ -35,6 +37,9 @@ extern int num_lines; static Pakfire pakfire; static void yyerror(const char* s); +static void cleanup(void); +#define ABORT do { cleanup(); YYABORT; } while (0); + %} %token APPEND @@ -92,6 +97,13 @@ words : WORD $$ = $1; } | words WHITESPACE WORD + { + int r = asprintf(&$$, "%s %s", $1, $3); + if (r < 0) { + ERROR(pakfire, "Could not allocate memory"); + ABORT; + } + } | /* empty */ { $$ = NULL; @@ -99,10 +111,18 @@ words : WORD line : whitespace words NEWLINE { - printf("line = %s\n", $2); + // Only forward words + $$ = $2; }; text : text line + { + int r = asprintf(&$$, "%s\n%s", $1, $2); + if (r < 0) { + ERROR(pakfire, "Could not allocate memory"); + ABORT; + } + } | line | /* empty */ { @@ -142,6 +162,11 @@ block_assignment : whitespace DEFINE WHITESPACE variable NEWLINE text whitespa %% +static void cleanup(void) { + // Reset Pakfire pointer + pakfire = NULL; +} + int pakfire_parser_parse_metadata(Pakfire _pakfire, const char* data, size_t len) { pakfire = _pakfire; -- 2.39.5