2 #include "emp_ematch.yacc.h"
5 extern int ematch_argc;
6 extern char **ematch_argv;
8 #define yylval ematch_lval
10 #define NEXT_EM_ARG() do { ematch_argc--; ematch_argv++; } while(0);
12 #define YY_INPUT(buf, result, max_size) \
15 if (ematch_argc <= 0) \
17 else if (**ematch_argv == '\0') { \
21 if (max_size <= strlen(*ematch_argv) + 1) { \
22 fprintf(stderr, "match argument too long.\n"); \
25 strcpy(buf, *ematch_argv); \
26 result = strlen(*ematch_argv) + 1; \
27 buf[result-1] = ' '; \
34 static void __attribute__ ((unused)) yyunput (int c,char *buf_ptr );
35 static void __attribute__ ((unused)) yy_push_state (int new_state );
36 static void __attribute__ ((unused)) yy_pop_state (void);
37 static int __attribute__ ((unused)) yy_top_state (void );
40 static unsigned int strbuf_size;
41 static unsigned int strbuf_index;
43 static void strbuf_enlarge(void)
46 strbuf = realloc(strbuf, strbuf_size);
49 static void strbuf_append_char(char c)
51 while (strbuf_index >= strbuf_size)
53 strbuf[strbuf_index++] = c;
56 static void strbuf_append_charp(char *s)
58 while (strbuf_index >= strbuf_size)
60 memcpy(strbuf + strbuf_index, s, strlen(s));
61 strbuf_index += strlen(s);
68 %option 8bit stack warn noyywrap prefix="ematch_"
75 strbuf = calloc(1, strbuf_size);
86 yylval.b = bstr_new(strbuf, strbuf_index);
91 <str>\\[0-7]{1,3} { /* octal escape sequence */
94 sscanf(yytext + 1, "%o", &res);
96 fprintf(stderr, "error: octal escape sequence" \
100 strbuf_append_char((unsigned char) res);
103 <str>\\[0-9]+ { /* catch wrong octal escape seq. */
104 fprintf(stderr, "error: invalid octale escape sequence\n");
108 <str>\\x[0-9a-fA-F]{1,2} {
111 sscanf(yytext + 2, "%x", &res);
114 fprintf(stderr, "error: hexadecimal escape " \
115 "sequence out of range\n");
118 strbuf_append_char((unsigned char) res);
121 <str>\\n strbuf_append_char('\n');
122 <str>\\r strbuf_append_char('\r');
123 <str>\\t strbuf_append_char('\t');
124 <str>\\v strbuf_append_char('\v');
125 <str>\\b strbuf_append_char('\b');
126 <str>\\f strbuf_append_char('\f');
127 <str>\\a strbuf_append_char('\a');
129 <str>\\(.|\n) strbuf_append_char(yytext[1]);
130 <str>[^\\\n\"]+ strbuf_append_charp(yytext);
132 [aA][nN][dD] return AND;
134 [nN][oO][tT] return NOT;
137 return yylval.i = *yytext;
140 yylval.b = bstr_alloc(yytext);
141 if (yylval.b == NULL)