support for additionally SIZE constrained Typereference
[obnox/wireshark/wip.git] / wiretap / ascend-scanner.l
1 /*
2  * We want to stop processing when we get to the end of the input.
3  */
4 %option noyywrap
5
6 /*
7  * We don't read from the terminal.
8  */
9 %option never-interactive
10
11 /*
12  * Prefix scanner routines with "ascend" rather than "yy", so this scanner
13  * can coexist with other scanners.
14  */
15 %option prefix="ascend"
16
17 %{
18 /* ascend-scanner.l
19  *
20  * $Id$
21  *
22  * Wiretap Library
23  * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
24  * 
25  * This program is free software; you can redistribute it and/or
26  * modify it under the terms of the GNU General Public License
27  * as published by the Free Software Foundation; either version 2
28  * of the License, or (at your option) any later version.
29  * 
30  * This program is distributed in the hope that it will be useful,
31  * but WITHOUT ANY WARRANTY; without even the implied warranty of
32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33  * GNU General Public License for more details.
34  * 
35  * You should have received a copy of the GNU General Public License
36  * along with this program; if not, write to the Free Software
37  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
38  */
39
40 #ifdef HAVE_CONFIG_H
41 #include "config.h"
42 #endif
43
44 #include <stdio.h>
45 #include <stdlib.h>
46 #include <string.h>
47
48 #ifdef HAVE_IO_H
49 #include <io.h>         /* for isatty() on win32 */
50 #endif
51
52 #include "wtap-int.h"
53 #include "ascend.h"
54 #include "ascend-grammar.h"
55 #include "ascend-int.h"
56 #include "file_wrappers.h"
57 #include "ascend-scanner_lex.h"
58
59 FILE_T yy_fh;
60 extern char *ascend_ra_ptr;
61 extern char *ascend_ra_last;
62 #define YY_INPUT(buf,result,max_size) { int c = file_getc(yy_fh);  \
63 result = (c==EOF) ? YY_NULL : (buf[0] = c, 1); } 
64
65 int at_eof;
66 int mul, scratch;
67
68 #define NO_USER "<none>"
69
70 #ifndef HAVE_UNISTD_H
71 #define YY_NO_UNISTD_H
72 #endif
73
74
75 %}
76
77 D [0-9]
78 H [A-Fa-f0-9]
79
80 PPP_XPFX PPP-OUT
81 PPP_RPFX PPP-IN
82 ISDN_XPFX PRI-XMIT-
83 ISDN_RPFX PRI-RCV-
84 WAN_XPFX XMIT[\-:]*
85 WAN_RPFX RECV[\-:]*
86 ETHER_PFX ETHER
87
88 WDD_DATE    "Date:"
89 WDD_TIME    "Time:"
90 WDD_CAUSE   "Cause an attempt to place call to "
91 WDD_CALLNUM [^\n\r\t ]+
92 WDD_CHUNK   "WD_DIALOUT_DISP: chunk"
93 WDD_TYPE    "type "[^\n\r\t ]+
94
95 %s sc_gen_task
96 %s sc_gen_time_s
97 %s sc_gen_time_u
98 %s sc_gen_octets
99 %s sc_gen_counter
100 %s sc_gen_byte
101
102 %s sc_wds_user
103 %s sc_wds_sess
104
105 %s sc_wdd_date_d
106 %s sc_wdd_date_m
107 %s sc_wdd_date_y
108 %s sc_wdd_time
109 %s sc_wdd_time_h
110 %s sc_wdd_time_m
111 %s sc_wdd_time_s
112 %s sc_wdd_cause
113 %s sc_wdd_callnum
114 %s sc_wdd_chunk
115 %s sc_wdd_chunknum
116 %s sc_wdd_type
117
118 %s sc_chardisp
119
120 %s sc_isdn_call
121 %s sc_ether_direction
122
123 %%
124
125 <INITIAL,sc_gen_byte>{ETHER_PFX} {
126   BEGIN(sc_ether_direction);
127   ascendlval.d = ASCEND_PFX_ETHER;
128   return ETHER_PREFIX;
129 }
130
131 <INITIAL,sc_gen_byte>{ISDN_XPFX} {
132   BEGIN(sc_isdn_call);
133   ascendlval.d = ASCEND_PFX_ISDN_X;
134   return ISDN_PREFIX;
135 }
136
137 <INITIAL,sc_gen_byte>{ISDN_RPFX} {
138   BEGIN(sc_isdn_call);
139   ascendlval.d = ASCEND_PFX_ISDN_R;
140   return ISDN_PREFIX;
141 }
142
143 <INITIAL,sc_gen_byte>{WAN_XPFX} {
144   BEGIN(sc_wds_user);
145   ascendlval.d = ASCEND_PFX_WDS_X;
146   return WDS_PREFIX;
147 }
148
149 <INITIAL,sc_gen_byte>{WAN_RPFX} {
150   BEGIN(sc_wds_user);
151   ascendlval.d = ASCEND_PFX_WDS_R;
152   return WDS_PREFIX;
153 }
154
155 <INITIAL,sc_gen_byte>{PPP_XPFX} {
156   BEGIN(sc_wds_user);
157   ascendlval.d = ASCEND_PFX_WDS_X;
158   return WDS_PREFIX;
159 }
160
161 <INITIAL,sc_gen_byte>{PPP_RPFX} {
162   BEGIN(sc_wds_user);
163   ascendlval.d = ASCEND_PFX_WDS_R;
164   return WDS_PREFIX;
165 }
166
167 <sc_ether_direction>[^\(]+ {
168   BEGIN(sc_gen_task);
169   return STRING; 
170 }
171
172 <sc_isdn_call>[^\/\(:]+ {
173   BEGIN(sc_gen_task);
174   return DECNUM;
175 }
176
177 <sc_wds_user>[^:]+ {
178   char *atcopy = strdup(ascendtext);
179   char colon = input();
180   char after = input();
181   int retval = STRING;
182
183   unput(after); unput(colon);
184
185   if (after != '(' && after != ' ') {
186     BEGIN(sc_wds_sess);
187     if (pseudo_header != NULL) {
188       strncpy(pseudo_header->user, atcopy, ASCEND_MAX_STR_LEN);
189       pseudo_header->user[ASCEND_MAX_STR_LEN - 1] = '\0';
190     }
191   } else {      /* We have a version 7 file */
192     BEGIN(sc_gen_task);
193     if (pseudo_header != NULL) {
194       strncpy(pseudo_header->user, NO_USER, ASCEND_MAX_STR_LEN);
195     }
196     ascendlval.d = strtol(ascendtext, NULL, 10);
197     retval = DECNUM;
198   }
199   free (atcopy);
200   return retval;
201 }
202
203 <sc_wds_sess>{D}* {
204   BEGIN(sc_gen_task);
205   ascendlval.d = strtol(ascendtext, NULL, 10);
206   return DECNUM;
207 }
208
209 <sc_gen_task>(0x|0X)?{H}+ {
210   BEGIN(sc_gen_time_s);
211   ascendlval.d = strtoul(ascendtext, NULL, 16);
212   return HEXNUM;
213 }
214
215 <sc_gen_task>\"[A-Za-z0-9_ ]+\" {
216   return STRING;
217 }
218
219 <sc_gen_time_s>{D}+ {
220   BEGIN(sc_gen_time_u);
221   ascendlval.d = strtol(ascendtext, NULL, 10);
222   return DECNUM;
223 }
224
225 <sc_gen_time_u>{D}+ {
226   char *atcopy = strdup(ascendtext);
227   BEGIN(sc_gen_octets);
228   /* only want the most significant 2 digits. convert to usecs */
229   if (strlen(atcopy) > 2)
230     atcopy[2] = '\0';
231   ascendlval.d = strtol(atcopy, NULL, 10) * 10000;
232   free(atcopy);
233   return DECNUM;
234 }
235
236 <sc_gen_octets>{D}+ {
237   BEGIN(sc_gen_counter);
238   ascendlval.d = strtol(ascendtext, NULL, 10);
239   return DECNUM;
240 }
241
242 <sc_gen_counter,sc_gen_byte>"["{H}{4}"]:" {
243   BEGIN(sc_gen_byte);
244   return COUNTER;
245 }
246
247 <sc_gen_byte>{H}{2} {
248   ascendlval.b = (guint8)strtol(ascendtext, NULL, 16);
249   return HEXBYTE;
250 }
251
252 <sc_gen_byte>" "{4} { 
253   BEGIN(sc_chardisp);
254 }
255
256 <sc_chardisp>.* { 
257   BEGIN(sc_gen_byte);
258 }
259
260 <INITIAL,sc_gen_byte>{WDD_DATE} {
261   BEGIN(sc_wdd_date_d);
262   return WDD_DATE;
263 }
264
265 <sc_wdd_date_d>{D}{2} {
266   BEGIN(sc_wdd_date_m);
267   ascendlval.d = strtol(ascendtext, NULL, 10);
268   return DECNUM;
269 }
270
271 <sc_wdd_date_m>{D}{2} {
272   BEGIN(sc_wdd_date_y);
273   ascendlval.d = strtol(ascendtext, NULL, 10);
274   return DECNUM;
275 }
276
277 <sc_wdd_date_y>{D}{4} {
278   BEGIN(sc_wdd_time);
279   ascendlval.d = strtol(ascendtext, NULL, 10);
280   return DECNUM;
281 }
282
283 <sc_wdd_time>{WDD_TIME} {
284   BEGIN(sc_wdd_time_h);
285   return KEYWORD;
286 }
287
288 <sc_wdd_time_h>{D}{2} {
289   BEGIN(sc_wdd_time_m);
290   ascendlval.d = strtol(ascendtext, NULL, 10);
291   return DECNUM;
292 }
293
294 <sc_wdd_time_m>{D}{2} {
295   BEGIN(sc_wdd_time_s);
296   ascendlval.d = strtol(ascendtext, NULL, 10);
297   return DECNUM;
298 }
299
300 <sc_wdd_time_s>{D}{2} {
301   BEGIN(sc_wdd_cause);
302   ascendlval.d = strtol(ascendtext, NULL, 10);
303   return DECNUM;
304 }
305
306 <sc_wdd_cause>{WDD_CAUSE} {
307   BEGIN(sc_wdd_callnum);
308   return KEYWORD;
309 }
310
311 <sc_wdd_callnum>{WDD_CALLNUM} {
312   BEGIN(sc_wdd_chunk);
313   if (pseudo_header != NULL) {
314     strncpy(pseudo_header->call_num, ascendtext, ASCEND_MAX_STR_LEN);
315     pseudo_header->call_num[ASCEND_MAX_STR_LEN - 1] = '\0';
316   }
317   return STRING;
318 }
319
320 <INITIAL,sc_wdd_chunk,sc_gen_byte>{WDD_CHUNK} {
321   BEGIN(sc_wdd_chunknum);
322   return WDD_CHUNK;
323 }
324
325 <sc_wdd_chunknum>{H}+ {
326   BEGIN(sc_wdd_type);
327   ascendlval.d = strtoul(ascendtext, NULL, 16);
328   return HEXNUM;
329 }
330
331 <sc_wdd_type>{WDD_TYPE} {
332   BEGIN(sc_gen_task);
333   return KEYWORD;
334 }
335
336 <sc_gen_task>\/{D}+ {
337   return SLASH_SUFFIX;
338 }
339
340 (0x|0X)?{H}+ { return HEXNUM; }
341
342 task:|task|at|time:|octets { return KEYWORD; }
343
344 <<EOF>> { at_eof++; yyterminate(); }
345
346 (.|\n) ;
347
348 %%
349
350 void ascend_init_lexer(FILE_T fh)
351 {
352   yyrestart(0);
353   yy_fh = fh;
354   BEGIN(INITIAL);
355 }