Set the svn:eol-style property on all text files to "native", so that
[obnox/wireshark/wip.git] / wiretap / ascend-scanner.l
1 %{
2 /* ascend-scanner.l
3  *
4  * $Id$
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 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31
32 #ifdef HAVE_IO_H
33 #include <io.h>         /* for isatty() on win32 */
34 #endif
35
36 #include "wtap-int.h"
37 #include "ascend.h"
38 #include "ascend-grammar.h"
39 #include "ascend-int.h"
40 #include "file_wrappers.h"
41
42 FILE_T yy_fh;
43 extern char *ascend_ra_ptr;
44 extern char *ascend_ra_last;
45 #define YY_INPUT(buf,result,max_size) { int c = file_getc(yy_fh);  \
46 result = (c==EOF) ? YY_NULL : (buf[0] = c, 1); } 
47
48 #define YY_NEVER_INTERACTIVE 1
49
50 int at_eof;
51 int mul, scratch;
52
53 #define NO_USER "<none>"
54
55 #ifndef HAVE_UNISTD_H
56 #define YY_NO_UNISTD_H
57 #endif
58
59 %}
60
61 /* %option debug */
62 %option nostdinit
63 %option noyywrap
64
65 D [0-9]
66 H [A-Fa-f0-9]
67
68 XPFX XMIT-
69 RPFX RECV-
70
71 WDD_DATE    "Date:"
72 WDD_TIME    "Time:"
73 WDD_CAUSE   "Cause an attempt to place call to "
74 WDD_CALLNUM [^\n\r\t ]+
75 WDD_CHUNK   "WD_DIALOUT_DISP: chunk"
76 WDD_TYPE    "type "[^\n\r\t ]+
77
78 %s sc_gen_task
79 %s sc_gen_time_s
80 %s sc_gen_time_u
81 %s sc_gen_octets
82 %s sc_gen_counter
83 %s sc_gen_byte
84
85 %s sc_wds_user
86 %s sc_wds_sess
87
88 %s sc_wdd_date_d
89 %s sc_wdd_date_m
90 %s sc_wdd_date_y
91 %s sc_wdd_time
92 %s sc_wdd_time_h
93 %s sc_wdd_time_m
94 %s sc_wdd_time_s
95 %s sc_wdd_cause
96 %s sc_wdd_callnum
97 %s sc_wdd_chunk
98 %s sc_wdd_chunknum
99 %s sc_wdd_type
100
101 %s sc_chardisp
102
103 %%
104
105 <INITIAL,sc_gen_byte>{XPFX} {
106   BEGIN(sc_wds_user);
107   ascendlval.d = ASCEND_PFX_WDS_X;
108   return WDS_PREFIX;
109 }
110
111 <INITIAL,sc_gen_byte>{RPFX} {
112   BEGIN(sc_wds_user);
113   ascendlval.d = ASCEND_PFX_WDS_R;
114   return WDS_PREFIX;
115 }
116
117 <sc_wds_user>[^:]+ {
118   char *atcopy = strdup(ascendtext);
119   char colon = input();
120   char after = input();
121   int retval = STRING;
122
123   unput(after); unput(colon);
124
125   if (after != '(' && after != ' ') {
126     BEGIN(sc_wds_sess);
127     if (pseudo_header != NULL) {
128       strncpy(pseudo_header->user, atcopy, ASCEND_MAX_STR_LEN);
129       pseudo_header->user[ASCEND_MAX_STR_LEN - 1] = '\0';
130     }
131   } else {      /* We have a version 7 file */
132     BEGIN(sc_gen_task);
133     if (pseudo_header != NULL) {
134       strncpy(pseudo_header->user, NO_USER, ASCEND_MAX_STR_LEN);
135     }
136     ascendlval.d = strtol(ascendtext, NULL, 10);
137     retval = DECNUM;
138   }
139   free (atcopy);
140   return retval;
141 }
142
143 <sc_wds_sess>{D}* {
144   BEGIN(sc_gen_task);
145   ascendlval.d = strtol(ascendtext, NULL, 10);
146   return DECNUM;
147 }
148
149 <sc_gen_task>(0x|0X)?{H}+ {
150   BEGIN(sc_gen_time_s);
151   ascendlval.d = strtoul(ascendtext, NULL, 16);
152   return HEXNUM;
153 }
154
155 <sc_gen_task>\"[A-Za-z0-9_ ]+\" {
156   return STRING;
157 }
158
159 <sc_gen_time_s>{D}+ {
160   BEGIN(sc_gen_time_u);
161   ascendlval.d = strtol(ascendtext, NULL, 10);
162   return DECNUM;
163 }
164
165 <sc_gen_time_u>{D}+ {
166   BEGIN(sc_gen_octets);
167   /* We have the fractional portion of the time.  We want it converted
168      to microseconds. */
169   mul = 1000000;
170   ascendlval.d = strtol(ascendtext, NULL, 10);
171   for (scratch = ascendlval.d; scratch > 0; scratch /= 10)
172     mul /= 10;
173   ascendlval.d *= mul;
174   return DECNUM;
175 }
176
177 <sc_gen_octets>{D}+ {
178   BEGIN(sc_gen_counter);
179   ascendlval.d = strtol(ascendtext, NULL, 10);
180   return DECNUM;
181 }
182
183 <sc_gen_counter,sc_gen_byte>"["{H}{4}"]:" {
184   BEGIN(sc_gen_byte);
185   return COUNTER;
186 }
187
188 <sc_gen_byte>{H}{2} {
189   ascendlval.b = (guint8)strtol(ascendtext, NULL, 16);
190   return HEXBYTE;
191 }
192
193 <sc_gen_byte>" "{4} { 
194   BEGIN(sc_chardisp);
195 }
196
197 <sc_chardisp>.* { 
198   BEGIN(sc_gen_byte);
199 }
200
201 <INITIAL,sc_gen_byte>{WDD_DATE} {
202   BEGIN(sc_wdd_date_d);
203   return WDD_DATE;
204 }
205
206 <sc_wdd_date_d>{D}{2} {
207   BEGIN(sc_wdd_date_m);
208   ascendlval.d = strtol(ascendtext, NULL, 10);
209   return DECNUM;
210 }
211
212 <sc_wdd_date_m>{D}{2} {
213   BEGIN(sc_wdd_date_y);
214   ascendlval.d = strtol(ascendtext, NULL, 10);
215   return DECNUM;
216 }
217
218 <sc_wdd_date_y>{D}{4} {
219   BEGIN(sc_wdd_time);
220   ascendlval.d = strtol(ascendtext, NULL, 10);
221   return DECNUM;
222 }
223
224 <sc_wdd_time>{WDD_TIME} {
225   BEGIN(sc_wdd_time_h);
226   return KEYWORD;
227 }
228
229 <sc_wdd_time_h>{D}{2} {
230   BEGIN(sc_wdd_time_m);
231   ascendlval.d = strtol(ascendtext, NULL, 10);
232   return DECNUM;
233 }
234
235 <sc_wdd_time_m>{D}{2} {
236   BEGIN(sc_wdd_time_s);
237   ascendlval.d = strtol(ascendtext, NULL, 10);
238   return DECNUM;
239 }
240
241 <sc_wdd_time_s>{D}{2} {
242   BEGIN(sc_wdd_cause);
243   ascendlval.d = strtol(ascendtext, NULL, 10);
244   return DECNUM;
245 }
246
247 <sc_wdd_cause>{WDD_CAUSE} {
248   BEGIN(sc_wdd_callnum);
249   return KEYWORD;
250 }
251
252 <sc_wdd_callnum>{WDD_CALLNUM} {
253   BEGIN(sc_wdd_chunk);
254   if (pseudo_header != NULL) {
255     strncpy(pseudo_header->call_num, ascendtext, ASCEND_MAX_STR_LEN);
256     pseudo_header->call_num[ASCEND_MAX_STR_LEN - 1] = '\0';
257   }
258   return STRING;
259 }
260
261 <INITIAL,sc_wdd_chunk,sc_gen_byte>{WDD_CHUNK} {
262   BEGIN(sc_wdd_chunknum);
263   return WDD_CHUNK;
264 }
265
266 <sc_wdd_chunknum>{H}+ {
267   BEGIN(sc_wdd_type);
268   ascendlval.d = strtoul(ascendtext, NULL, 16);
269   return HEXNUM;
270 }
271
272 <sc_wdd_type>{WDD_TYPE} {
273   BEGIN(sc_gen_task);
274   return KEYWORD;
275 }
276
277 (0x|0X)?{H}+ { return HEXNUM; }
278
279 task:|task|at|time:|octets { return KEYWORD; }
280
281 <<EOF>> { at_eof++; yyterminate(); }
282
283 (.|\n) ;
284
285 %%
286
287 void ascend_init_lexer(FILE_T fh)
288 {
289   yyrestart(0);
290   yy_fh = fh;
291   BEGIN(INITIAL);
292 }