]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: parser: Concat lines and words
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 10 Mar 2019 16:59:44 +0000 (16:59 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 10 Mar 2019 17:07:13 +0000 (17:07 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/parser/grammar.y

index 9699f1e5094d6c321fa15c5833dbbde012246749..cafcb5e33401d6eeac81f062a26e82c3aad789eb 100644 (file)
@@ -19,6 +19,8 @@
 #############################################################################*/
 
 %{
+#include <stdio.h>
+
 #include <pakfire/logging.h>
 #include <pakfire/types.h>
 
@@ -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;