Not all packets in a "wdd" dump necessarily have a "Cause an attempt to
[metze/wireshark/wip.git] / wiretap / ascend-scanner.l
1 %{
2 /* ascend-scanner.l
3  *
4  * $Id: ascend-scanner.l,v 1.17 2000/11/12 04:57:39 guy Exp $
5  *
6  * Wiretap Library
7  * Copyright (c) 1998 by Gilbert Ramirez <gram@xiexie.org>
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 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
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 int at_eof;
50 int mul, scratch;
51
52 /* We don't need yyunput, so use this macro to get it out of the
53  * generated C file, avoiding a compiler warning about its lack of use */
54 #define YY_NO_UNPUT 1
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   BEGIN(sc_wds_sess);
114   if (pseudo_header != NULL) {
115     strncpy(pseudo_header->user, ascendtext, ASCEND_MAX_STR_LEN);
116     pseudo_header->user[ASCEND_MAX_STR_LEN - 1] = '\0';
117   }
118   return STRING;
119 }
120
121 <sc_wds_sess>{D}+ {
122   BEGIN(sc_gen_task);
123   ascendlval.d = strtol(ascendtext, NULL, 10);
124   return DECNUM;
125 }
126
127 <sc_gen_task>{H}+ {
128   BEGIN(sc_gen_time_s);
129   ascendlval.d = strtoul(ascendtext, NULL, 16);
130   return HEXNUM;
131 }
132
133 <sc_gen_time_s>{D}+ {
134   BEGIN(sc_gen_time_u);
135   ascendlval.d = strtol(ascendtext, NULL, 10);
136   return DECNUM;
137 }
138
139 <sc_gen_time_u>{D}+ {
140   BEGIN(sc_gen_octets);
141   /* We have the fractional portion of the time.  We want it converted
142      to microseconds. */
143   mul = 1000000;
144   ascendlval.d = strtol(ascendtext, NULL, 10);
145   for (scratch = ascendlval.d; scratch > 0; scratch /= 10)
146     mul /= 10;
147   ascendlval.d *= mul;
148   return DECNUM;
149 }
150
151 <sc_gen_octets>{D}+ {
152   BEGIN(sc_gen_counter);
153   ascendlval.d = strtol(ascendtext, NULL, 10);
154   return DECNUM;
155 }
156
157 <sc_gen_counter,sc_gen_byte>"["{H}{4}"]:" {
158   BEGIN(sc_gen_byte);
159   return COUNTER;
160 }
161
162 <sc_gen_byte>{H}{2} {
163   ascendlval.b = strtol(ascendtext, NULL, 16);
164   return HEXBYTE;
165 }
166
167 <INITIAL,sc_gen_byte>{WDD_DATE} {
168   BEGIN(sc_wdd_date_d);
169   return WDD_DATE;
170 }
171
172 <sc_wdd_date_d>{D}{2} {
173   BEGIN(sc_wdd_date_m);
174   ascendlval.d = strtol(ascendtext, NULL, 10);
175   return DECNUM;
176 }
177
178 <sc_wdd_date_m>{D}{2} {
179   BEGIN(sc_wdd_date_y);
180   ascendlval.d = strtol(ascendtext, NULL, 10);
181   return DECNUM;
182 }
183
184 <sc_wdd_date_y>{D}{4} {
185   BEGIN(sc_wdd_time);
186   ascendlval.d = strtol(ascendtext, NULL, 10);
187   return DECNUM;
188 }
189
190 <sc_wdd_time>{WDD_TIME} {
191   BEGIN(sc_wdd_time_h);
192   return KEYWORD;
193 }
194
195 <sc_wdd_time_h>{D}{2} {
196   BEGIN(sc_wdd_time_m);
197   ascendlval.d = strtol(ascendtext, NULL, 10);
198   return DECNUM;
199 }
200
201 <sc_wdd_time_m>{D}{2} {
202   BEGIN(sc_wdd_time_s);
203   ascendlval.d = strtol(ascendtext, NULL, 10);
204   return DECNUM;
205 }
206
207 <sc_wdd_time_s>{D}{2} {
208   BEGIN(sc_wdd_cause);
209   ascendlval.d = strtol(ascendtext, NULL, 10);
210   return DECNUM;
211 }
212
213 <sc_wdd_cause>{WDD_CAUSE} {
214   BEGIN(sc_wdd_callnum);
215   return KEYWORD;
216 }
217
218 <sc_wdd_callnum>{WDD_CALLNUM} {
219   BEGIN(sc_wdd_chunk);
220   if (pseudo_header != NULL) {
221     strncpy(pseudo_header->call_num, ascendtext, ASCEND_MAX_STR_LEN);
222     pseudo_header->call_num[ASCEND_MAX_STR_LEN - 1] = '\0';
223   }
224   return STRING;
225 }
226
227 <INITIAL,sc_wdd_chunk,sc_gen_byte>{WDD_CHUNK} {
228   BEGIN(sc_wdd_chunknum);
229   return WDD_CHUNK;
230 }
231
232 <sc_wdd_chunknum>{H}+ {
233   BEGIN(sc_wdd_type);
234   ascendlval.d = strtoul(ascendtext, NULL, 16);
235   return HEXNUM;
236 }
237
238 <sc_wdd_type>{WDD_TYPE} {
239   BEGIN(sc_gen_task);
240   return KEYWORD;
241 }
242
243
244 {H}+ { return HEXNUM; }
245
246 task:|time:|octets { return KEYWORD; }
247
248 <<EOF>> { at_eof++; yyterminate(); }
249
250 . ;
251
252 %%
253
254 int ascendwrap() { return 1; }
255
256 void ascend_init_lexer(FILE_T fh, FILE *nfh)
257 {
258   yyrestart(0);
259   yyout = nfh;
260   yy_fh = fh;
261   BEGIN(INITIAL);
262 }