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