]> git.ipfire.org Git - pakfire.git/commitdiff
libpakfire: parser: Handle templates
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 31 May 2019 04:27:08 +0000 (05:27 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 31 May 2019 04:27:08 +0000 (05:27 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/parser/scanner.l

index 442c751bd3168d8d4fa28c709166ddc2b80e6b53..90250a214dcf58d1c4870d063f3a044a0afca562 100644 (file)
@@ -25,6 +25,7 @@
 
 int num_lines;
 
+#include <ctype.h>
 #include <pakfire/parser.h>
 #include <pakfire/util.h>
 #include "grammar.h"
@@ -45,7 +46,8 @@ word                  ({quoted_string}|({digit}|{letter}|{special})+)
        We automatically prepend "define" in front of some keywords, because
        generally the language requires it.
 */
-keywords               (description|{whitespace}(build(_cmds)?|install(_cmds)?|prepare_cmds|requires))
+keywords               (description|{whitespace}(build(_cmds)?|files|install(_cmds)?|prepare_cmds|provides|(pre)?requires|_posttrans))
+template               {whitespace}template.*$
 
 %s DEFINE
 
@@ -55,6 +57,29 @@ keywords             (description|{whitespace}(build(_cmds)?|install(_cmds)?|prepare_cmds|r
 {whitespace}   {}
 \n                             { num_lines++; return T_EOL; }
 
+<INITIAL>^{template} {
+                                       // Find the name of the template
+                                       char* name = NULL;
+                                       for (unsigned int i = yyleng; i > 0; i--) {
+                                               if (isspace(yytext[i]))
+                                                       break;
+
+                                               name = yytext + i;
+                                       }
+
+                                       size_t length = strlen("template:") + strlen(name);
+
+                                       char* buffer = pakfire_malloc(length + 1);
+                                       snprintf(buffer, length + 1, "template:%s", name);
+
+                                       // Put the whole string back onto the stack (backwards)
+                                       for (int i = length - 1; i >= 0; i--) {
+                                               unput(buffer[i]);
+                                       }
+
+                                       pakfire_free(buffer);
+                               }
+
 <INITIAL>^{keywords}$ {
                                        // Determine the length of the string
                                        size_t length = strlen("define ") + yyleng;