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