IRQ handler rewrite by Gabor Juhos, uses C no longer assembly
[openwrt/staging/chunkeey.git] / target / linux / etrax-2.6 / image / e100boot / src / libpcap-0.4 / scanner.l
1 %{
2 /*
3 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
4 * The Regents of the University of California. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that: (1) source code distributions
8 * retain the above copyright notice and this paragraph in its entirety, (2)
9 * distributions including binary code include the above copyright notice and
10 * this paragraph in its entirety in the documentation or other materials
11 * provided with the distribution, and (3) all advertising materials mentioning
12 * features or use of this software display the following acknowledgement:
13 * ``This product includes software developed by the University of California,
14 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
15 * the University nor the names of its contributors may be used to endorse
16 * or promote products derived from this software without specific prior
17 * written permission.
18 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
19 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 */
22
23 #ifndef lint
24 static const char rcsid[] =
25 "@(#) $Header: /usr/local/cvs/linux/tools/build/e100boot/libpcap-0.4/scanner.l,v 1.1 1999/08/26 10:05:27 johana Exp $ (LBL)";
26 #endif
27
28 #include <sys/types.h>
29 #include <sys/time.h>
30
31 #include <ctype.h>
32 #include <unistd.h>
33
34 #include "pcap-int.h"
35
36 #include "gencode.h"
37 #include <pcap-namedb.h>
38 #include "tokdefs.h"
39
40 #include "gnuc.h"
41 #ifdef HAVE_OS_PROTO_H
42 #include "os-proto.h"
43 #endif
44
45 static int stoi(char *);
46 static inline int xdtoi(int);
47
48 #ifdef FLEX_SCANNER
49 #define YY_NO_UNPUT
50 #undef YY_INPUT
51 #define YY_INPUT(buf, result, max)\
52 {\
53 char *src = in_buffer;\
54 int i;\
55 \
56 if (*src == 0)\
57 result = YY_NULL;\
58 else {\
59 for (i = 0; *src && i < max; ++i)\
60 buf[i] = *src++;\
61 in_buffer += i;\
62 result = i;\
63 }\
64 }
65 #else
66 #undef getc
67 #define getc(fp) (*in_buffer == 0 ? EOF : *in_buffer++)
68 #endif
69
70 #define yylval pcap_lval
71 extern YYSTYPE yylval;
72
73 static char *in_buffer;
74
75 %}
76
77 N ([0-9]+|(0X|0x)[0-9A-Fa-f]+)
78 B ([0-9A-Fa-f][0-9A-Fa-f]?)
79
80 %a 3000
81
82 %%
83 dst return DST;
84 src return SRC;
85
86 link|ether|ppp|slip return LINK;
87 fddi return LINK;
88 arp return ARP;
89 rarp return RARP;
90 ip return IP;
91 tcp return TCP;
92 udp return UDP;
93 icmp return ICMP;
94 igmp return IGMP;
95 igrp return IGRP;
96
97 atalk return ATALK;
98 decnet return DECNET;
99 lat return LAT;
100 sca return SCA;
101 moprc return MOPRC;
102 mopdl return MOPDL;
103
104 host return HOST;
105 net return NET;
106 mask return MASK;
107 port return PORT;
108 proto return PROTO;
109
110 gateway return GATEWAY;
111
112 less return LESS;
113 greater return GREATER;
114 byte return BYTE;
115 broadcast return TK_BROADCAST;
116 multicast return TK_MULTICAST;
117
118 and|"&&" return AND;
119 or|"||" return OR;
120 not return '!';
121
122 len|length return LEN;
123 inbound return INBOUND;
124 outbound return OUTBOUND;
125
126 [ \n\t] ;
127 [+\-*/:\[\]!<>()&|=] return yytext[0];
128 ">=" return GEQ;
129 "<=" return LEQ;
130 "!=" return NEQ;
131 "==" return '=';
132 "<<" return LSH;
133 ">>" return RSH;
134 {N} { yylval.i = stoi((char *)yytext); return NUM; }
135 ({N}\.{N})|({N}\.{N}\.{N})|({N}\.{N}\.{N}\.{N}) {
136 yylval.s = sdup((char *)yytext); return HID; }
137 {B}:{B}:{B}:{B}:{B}:{B} { yylval.e = pcap_ether_aton((char *)yytext);
138 return EID; }
139 {B}:+({B}:+)+ { bpf_error("bogus ethernet address %s", yytext); }
140 [A-Za-z0-9][-_.A-Za-z0-9]*[.A-Za-z0-9] {
141 yylval.s = sdup((char *)yytext); return ID; }
142 "\\"[^ !()\n\t]+ { yylval.s = sdup((char *)yytext + 1); return ID; }
143 [^ \[\]\t\n\-_.A-Za-z0-9!<>()&|=]+i {
144 bpf_error("illegal token: %s\n", yytext); }
145 . { bpf_error("illegal char '%c'", *yytext); }
146 %%
147 void
148 lex_init(buf)
149 char *buf;
150 {
151 in_buffer = buf;
152 }
153
154 /*
155 * Also define a yywrap. Note that if we're using flex, it will
156 * define a macro to map this identifier to pcap_wrap.
157 */
158 int
159 yywrap()
160 {
161 return 1;
162 }
163
164 /* Hex digit to integer. */
165 static inline int
166 xdtoi(c)
167 register int c;
168 {
169 if (isdigit(c))
170 return c - '0';
171 else if (islower(c))
172 return c - 'a' + 10;
173 else
174 return c - 'A' + 10;
175 }
176
177 /*
178 * Convert string to integer. Just like atoi(), but checks for
179 * preceding 0x or 0 and uses hex or octal instead of decimal.
180 */
181 static int
182 stoi(s)
183 char *s;
184 {
185 int base = 10;
186 int n = 0;
187
188 if (*s == '0') {
189 if (s[1] == 'x' || s[1] == 'X') {
190 s += 2;
191 base = 16;
192 }
193 else {
194 base = 8;
195 s += 1;
196 }
197 }
198 while (*s)
199 n = n * base + xdtoi(*s++);
200
201 return n;
202 }
203