1 /* SPDX-License-Identifier: GPL-2.0 */
3 #include "emp_ematch.tab.h"
6 extern int ematch_argc;
7 extern char **ematch_argv;
9 #define yylval ematch_lval
11 #define NEXT_EM_ARG() do { ematch_argc--; ematch_argv++; } while(0);
13 #define YY_INPUT(buf, result, max_size) \
16 if (ematch_argc <= 0) \
18 else if (**ematch_argv == '\0') { \
22 if (max_size <= strlen(*ematch_argv) + 1) { \
23 fprintf(stderr, "match argument too long.\n"); \
26 strcpy(buf, *ematch_argv); \
27 result = strlen(*ematch_argv) + 1; \
28 buf[result-1] = ' '; \
35 static void __attribute__ ((unused)) yyunput (int c,char *buf_ptr );
36 static void __attribute__ ((unused)) yy_push_state (int new_state );
37 static void __attribute__ ((unused)) yy_pop_state (void);
38 static int __attribute__ ((unused)) yy_top_state (void );
41 static unsigned int strbuf_size;
42 static unsigned int strbuf_index;
44 static void strbuf_enlarge(void)
47 strbuf = realloc(strbuf, strbuf_size);
50 static void strbuf_append_char(char c)
52 while (strbuf_index >= strbuf_size)
54 strbuf[strbuf_index++] = c;
57 static void strbuf_append_charp(char *s)
59 while (strbuf_index >= strbuf_size)
61 memcpy(strbuf + strbuf_index, s, strlen(s));
62 strbuf_index += strlen(s);
69 %option 8bit stack warn noyywrap prefix="ematch_"
76 strbuf = calloc(1, strbuf_size);
87 yylval.b = bstr_new(strbuf, strbuf_index);
92 <lexstr>\\[0-7]{1,3} { /* octal escape sequence */
95 sscanf(yytext + 1, "%o", &res);
97 fprintf(stderr, "error: octal escape sequence" \
101 strbuf_append_char((unsigned char) res);
104 <lexstr>\\[0-9]+ { /* catch wrong octal escape seq. */
105 fprintf(stderr, "error: invalid octale escape sequence\n");
109 <lexstr>\\x[0-9a-fA-F]{1,2} {
112 sscanf(yytext + 2, "%x", &res);
115 fprintf(stderr, "error: hexadecimal escape " \
116 "sequence out of range\n");
119 strbuf_append_char((unsigned char) res);
122 <lexstr>\\n strbuf_append_char('\n');
123 <lexstr>\\r strbuf_append_char('\r');
124 <lexstr>\\t strbuf_append_char('\t');
125 <lexstr>\\v strbuf_append_char('\v');
126 <lexstr>\\b strbuf_append_char('\b');
127 <lexstr>\\f strbuf_append_char('\f');
128 <lexstr>\\a strbuf_append_char('\a');
130 <lexstr>\\(.|\n) strbuf_append_char(yytext[1]);
131 <lexstr>[^\\\n\"]+ strbuf_append_charp(yytext);
133 [aA][nN][dD] return AND;
135 [nN][oO][tT] return NOT;
138 return yylval.i = *yytext;
140 [^" \t\r\n()][^ \t\r\n()]* {
141 yylval.b = bstr_alloc(yytext);
142 if (yylval.b == NULL)