]> git.proxmox.com Git - mirror_iproute2.git/blob - tc/emp_ematch.l
iproute: Set ip/ip6 lwtunnel flags
[mirror_iproute2.git] / tc / emp_ematch.l
1 /* SPDX-License-Identifier: GPL-2.0 */
2 %{
3 #include "emp_ematch.yacc.h"
4 #include "m_ematch.h"
5
6 extern int ematch_argc;
7 extern char **ematch_argv;
8
9 #define yylval ematch_lval
10
11 #define NEXT_EM_ARG() do { ematch_argc--; ematch_argv++; } while(0);
12
13 #define YY_INPUT(buf, result, max_size) \
14 { \
15 next: \
16 if (ematch_argc <= 0) \
17 result = YY_NULL; \
18 else if (**ematch_argv == '\0') { \
19 NEXT_EM_ARG(); \
20 goto next; \
21 } else { \
22 if (max_size <= strlen(*ematch_argv) + 1) { \
23 fprintf(stderr, "match argument too long.\n"); \
24 result = YY_NULL; \
25 } else { \
26 strcpy(buf, *ematch_argv); \
27 result = strlen(*ematch_argv) + 1; \
28 buf[result-1] = ' '; \
29 buf[result] = '\0'; \
30 NEXT_EM_ARG(); \
31 } \
32 } \
33 }
34
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 );
39
40 static char *strbuf;
41 static unsigned int strbuf_size;
42 static unsigned int strbuf_index;
43
44 static void strbuf_enlarge(void)
45 {
46 strbuf_size += 512;
47 strbuf = realloc(strbuf, strbuf_size);
48 }
49
50 static void strbuf_append_char(char c)
51 {
52 while (strbuf_index >= strbuf_size)
53 strbuf_enlarge();
54 strbuf[strbuf_index++] = c;
55 }
56
57 static void strbuf_append_charp(char *s)
58 {
59 while (strbuf_index >= strbuf_size)
60 strbuf_enlarge();
61 memcpy(strbuf + strbuf_index, s, strlen(s));
62 strbuf_index += strlen(s);
63 }
64
65 %}
66
67 %x lexstr
68
69 %option 8bit stack warn noyywrap prefix="ematch_"
70 %%
71 [ \t\r\n]+
72
73 \" {
74 if (strbuf == NULL) {
75 strbuf_size = 512;
76 strbuf = calloc(1, strbuf_size);
77 if (strbuf == NULL)
78 return ERROR;
79 }
80 strbuf_index = 0;
81
82 BEGIN(lexstr);
83 }
84
85 <lexstr>\" {
86 BEGIN(INITIAL);
87 yylval.b = bstr_new(strbuf, strbuf_index);
88 yylval.b->quoted = 1;
89 return ATTRIBUTE;
90 }
91
92 <lexstr>\\[0-7]{1,3} { /* octal escape sequence */
93 int res;
94
95 sscanf(yytext + 1, "%o", &res);
96 if (res > 0xFF) {
97 fprintf(stderr, "error: octal escape sequence" \
98 " out of range\n");
99 return ERROR;
100 }
101 strbuf_append_char((unsigned char) res);
102 }
103
104 <lexstr>\\[0-9]+ { /* catch wrong octal escape seq. */
105 fprintf(stderr, "error: invalid octale escape sequence\n");
106 return ERROR;
107 }
108
109 <lexstr>\\x[0-9a-fA-F]{1,2} {
110 int res;
111
112 sscanf(yytext + 2, "%x", &res);
113
114 if (res > 0xFF) {
115 fprintf(stderr, "error: hexadecimal escape " \
116 "sequence out of range\n");
117 return ERROR;
118 }
119 strbuf_append_char((unsigned char) res);
120 }
121
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');
129
130 <lexstr>\\(.|\n) strbuf_append_char(yytext[1]);
131 <lexstr>[^\\\n\"]+ strbuf_append_charp(yytext);
132
133 [aA][nN][dD] return AND;
134 [oO][rR] return OR;
135 [nN][oO][tT] return NOT;
136 "(" |
137 ")" {
138 return yylval.i = *yytext;
139 }
140 [^" \t\r\n()][^ \t\r\n()]* {
141 yylval.b = bstr_alloc(yytext);
142 if (yylval.b == NULL)
143 return ERROR;
144 return ATTRIBUTE;
145 }
146 %%