Hopefully the last time I have to change my e-mail address.
[metze/wireshark/wip.git] / wiretap / ascend-scanner.l
1 %{
2 /* ascend-scanner.l
3  *
4  * $Id: ascend-scanner.l,v 1.21 2001/11/13 23:55:43 gram Exp $
5  *
6  * Wiretap Library
7  * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
8  * 
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  * 
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  * 
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22  *
23  */
24
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32
33 #ifdef HAVE_IO_H
34 #include <io.h>         /* for isatty() on win32 */
35 #endif
36
37 #include "wtap-int.h"
38 #include "ascend.h"
39 #include "ascend-grammar.h"
40 #include "ascend-int.h"
41 #include "file_wrappers.h"
42
43 FILE_T yy_fh;
44 extern char *ascend_ra_ptr;
45 extern char *ascend_ra_last;
46 #define YY_INPUT(buf,result,max_size) { int c = file_getc(yy_fh);  \
47 result = (c==EOF) ? YY_NULL : (buf[0] = c, 1); } 
48
49 #define YY_NEVER_INTERACTIVE 1
50
51 int at_eof;
52 int mul, scratch;
53
54 #define NO_USER "<none>"
55
56 %}
57
58 /* %option debug */
59 %option nostdinit
60 %option noyywrap
61
62 D [0-9]
63 H [A-Fa-f0-9]
64
65 XPFX XMIT-
66 RPFX RECV-
67
68 WDD_DATE    "Date:"
69 WDD_TIME    "Time:"
70 WDD_CAUSE   "Cause an attempt to place call to "
71 WDD_CALLNUM [^\n\r\t ]+
72 WDD_CHUNK   "WD_DIALOUT_DISP: chunk"
73 WDD_TYPE    "type "[^\n\r\t ]+
74
75 %s sc_gen_task
76 %s sc_gen_time_s
77 %s sc_gen_time_u
78 %s sc_gen_octets
79 %s sc_gen_counter
80 %s sc_gen_byte
81
82 %s sc_wds_user
83 %s sc_wds_sess
84
85 %s sc_wdd_date_d
86 %s sc_wdd_date_m
87 %s sc_wdd_date_y
88 %s sc_wdd_time
89 %s sc_wdd_time_h
90 %s sc_wdd_time_m
91 %s sc_wdd_time_s
92 %s sc_wdd_cause
93 %s sc_wdd_callnum
94 %s sc_wdd_chunk
95 %s sc_wdd_chunknum
96 %s sc_wdd_type
97
98 %%
99
100 <INITIAL,sc_gen_byte>{XPFX} {
101   BEGIN(sc_wds_user);
102   ascendlval.d = ASCEND_PFX_WDS_X;
103   return WDS_PREFIX;
104 }
105
106 <INITIAL,sc_gen_byte>{RPFX} {
107   BEGIN(sc_wds_user);
108   ascendlval.d = ASCEND_PFX_WDS_R;
109   return WDS_PREFIX;
110 }
111
112 <sc_wds_user>[^:]+ {
113   char *atcopy = strdup(ascendtext);
114   char colon = input();
115   char after = input();
116   int retval = STRING;
117
118   unput(after); unput(colon);
119
120   if (after != '(') {
121     BEGIN(sc_wds_sess);
122     if (pseudo_header != NULL) {
123       strncpy(pseudo_header->user, atcopy, ASCEND_MAX_STR_LEN);
124       pseudo_header->user[ASCEND_MAX_STR_LEN - 1] = '\0';
125     }
126   } else {      /* We have a version 7 file */
127     BEGIN(sc_gen_task);
128     if (pseudo_header != NULL) {
129       strncpy(pseudo_header->user, NO_USER, ASCEND_MAX_STR_LEN);
130     }
131     ascendlval.d = strtol(ascendtext, NULL, 10);
132     retval = DECNUM;
133   }
134   free (atcopy);
135   return retval;
136 }
137
138 <sc_wds_sess>{D}* {
139   BEGIN(sc_gen_task);
140   ascendlval.d = strtol(ascendtext, NULL, 10);
141   return DECNUM;
142 }
143
144 <sc_gen_task>{H}+ {
145   BEGIN(sc_gen_time_s);
146   ascendlval.d = strtoul(ascendtext, NULL, 16);
147   return HEXNUM;
148 }
149
150 <sc_gen_time_s>{D}+ {
151   BEGIN(sc_gen_time_u);
152   ascendlval.d = strtol(ascendtext, NULL, 10);
153   return DECNUM;
154 }
155
156 <sc_gen_time_u>{D}+ {
157   BEGIN(sc_gen_octets);
158   /* We have the fractional portion of the time.  We want it converted
159      to microseconds. */
160   mul = 1000000;
161   ascendlval.d = strtol(ascendtext, NULL, 10);
162   for (scratch = ascendlval.d; scratch > 0; scratch /= 10)
163     mul /= 10;
164   ascendlval.d *= mul;
165   return DECNUM;
166 }
167
168 <sc_gen_octets>{D}+ {
169   BEGIN(sc_gen_counter);
170   ascendlval.d = strtol(ascendtext, NULL, 10);
171   return DECNUM;
172 }
173
174 <sc_gen_counter,sc_gen_byte>"["{H}{4}"]:" {
175   BEGIN(sc_gen_byte);
176   return COUNTER;
177 }
178
179 <sc_gen_byte>{H}{2} {
180   ascendlval.b = strtol(ascendtext, NULL, 16);
181   return HEXBYTE;
182 }
183
184 <INITIAL,sc_gen_byte>{WDD_DATE} {
185   BEGIN(sc_wdd_date_d);
186   return WDD_DATE;
187 }
188
189 <sc_wdd_date_d>{D}{2} {
190   BEGIN(sc_wdd_date_m);
191   ascendlval.d = strtol(ascendtext, NULL, 10);
192   return DECNUM;
193 }
194
195 <sc_wdd_date_m>{D}{2} {
196   BEGIN(sc_wdd_date_y);
197   ascendlval.d = strtol(ascendtext, NULL, 10);
198   return DECNUM;
199 }
200
201 <sc_wdd_date_y>{D}{4} {
202   BEGIN(sc_wdd_time);
203   ascendlval.d = strtol(ascendtext, NULL, 10);
204   return DECNUM;
205 }
206
207 <sc_wdd_time>{WDD_TIME} {
208   BEGIN(sc_wdd_time_h);
209   return KEYWORD;
210 }
211
212 <sc_wdd_time_h>{D}{2} {
213   BEGIN(sc_wdd_time_m);
214   ascendlval.d = strtol(ascendtext, NULL, 10);
215   return DECNUM;
216 }
217
218 <sc_wdd_time_m>{D}{2} {
219   BEGIN(sc_wdd_time_s);
220   ascendlval.d = strtol(ascendtext, NULL, 10);
221   return DECNUM;
222 }
223
224 <sc_wdd_time_s>{D}{2} {
225   BEGIN(sc_wdd_cause);
226   ascendlval.d = strtol(ascendtext, NULL, 10);
227   return DECNUM;
228 }
229
230 <sc_wdd_cause>{WDD_CAUSE} {
231   BEGIN(sc_wdd_callnum);
232   return KEYWORD;
233 }
234
235 <sc_wdd_callnum>{WDD_CALLNUM} {
236   BEGIN(sc_wdd_chunk);
237   if (pseudo_header != NULL) {
238     strncpy(pseudo_header->call_num, ascendtext, ASCEND_MAX_STR_LEN);
239     pseudo_header->call_num[ASCEND_MAX_STR_LEN - 1] = '\0';
240   }
241   return STRING;
242 }
243
244 <INITIAL,sc_wdd_chunk,sc_gen_byte>{WDD_CHUNK} {
245   BEGIN(sc_wdd_chunknum);
246   return WDD_CHUNK;
247 }
248
249 <sc_wdd_chunknum>{H}+ {
250   BEGIN(sc_wdd_type);
251   ascendlval.d = strtoul(ascendtext, NULL, 16);
252   return HEXNUM;
253 }
254
255 <sc_wdd_type>{WDD_TYPE} {
256   BEGIN(sc_gen_task);
257   return KEYWORD;
258 }
259
260
261 {H}+ { return HEXNUM; }
262
263 task:|time:|octets { return KEYWORD; }
264
265 <<EOF>> { at_eof++; yyterminate(); }
266
267 . ;
268
269 %%
270
271 int ascendwrap() { return 1; }
272
273 void ascend_init_lexer(FILE_T fh, FILE *nfh)
274 {
275   yyrestart(0);
276   yyout = nfh;
277   yy_fh = fh;
278   BEGIN(INITIAL);
279 }