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

index 90250a214dcf58d1c4870d063f3a044a0afca562..6b0c573ea27d0f8bba4228fb11298ace3d101128 100644 (file)
@@ -48,6 +48,7 @@ word                  ({quoted_string}|({digit}|{letter}|{special})+)
 */
 keywords               (description|{whitespace}(build(_cmds)?|files|install(_cmds)?|prepare_cmds|provides|(pre)?requires|_posttrans))
 template               {whitespace}template.*$
+script                 {whitespace}script.*$
 
 %s DEFINE
 
@@ -80,6 +81,29 @@ template             {whitespace}template.*$
                                        pakfire_free(buffer);
                                }
 
+<INITIAL>^{script} {
+                                       // 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("define script:") + strlen(name);
+
+                                       char* buffer = pakfire_malloc(length + 1);
+                                       snprintf(buffer, length + 1, "define script:%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;