#define unput_string(s) for (int i = strlen(s) - 1; i >= 0; i--) unput(s[i])
+static char* copy_string(const char* s) {
+ if (!s)
+ return NULL;
+
+ // Remove any leading whitespace
+ while (*s && isspace(*s))
+ s++;
+
+ // Remove any trailing whitespace
+ const char* e = s + strlen(s);
+ while (*e && isspace(*s))
+ e--;
+
+ // Determine the length of the string
+ const size_t l = strlen(s);
+
+ // Allocate a working buffer
+ char* buffer = malloc(l + 1);
+
+ // Copy input string to buffer
+ memcpy(buffer, s, l + 1);
+
+ // Pointer to the start of the string
+ char* p = buffer;
+
+ char* linebreak = strstr(p, "\\\n");
+ while (linebreak) {
+ // Move p to the beginning of the linebreak
+ p = linebreak;
+
+ // Skip \\\n
+ linebreak += strlen("\\\n");
+
+ // Find any whitespace after the linebreak
+ while (*linebreak && isspace(*linebreak))
+ linebreak++;
+
+ if (!linebreak)
+ break;
+
+ // Splice together
+ memmove(p, linebreak, buffer + l - linebreak + 1);
+
+ // Find another linebreak
+ linebreak = strstr(p, "\\\n");
+ }
+
+ return buffer;
+}
+
%}
%x INDENT
yy_push_state(NOKEYWORD);
}
+<READLINE>.*\\\n {
+ // Continue if a line ends with a "\"
+ yymore();
+ }
+
<READLINE>.*$ {
// Return to caller
yy_pop_state();
// Copy the entire string
- yylval.string = pakfire_lstrip(yytext);
+ yylval.string = copy_string(yytext);
return T_STRING;
}