2 * We want a reentrant scanner.
7 * We want to generate code that can be used by a reentrant parser
8 * generated by Bison or Berkeley YACC.
13 * We don't read interactively from the terminal.
15 %option never-interactive
18 * We want to stop processing when we get to the end of the input.
23 * The type for the state we keep for the scanner (and parser).
25 %option extra-type="ascend_state_t *"
28 * Prefix scanner routines with "ascend" rather than "yy", so this scanner
29 * can coexist with other scanners.
31 %option prefix="ascend"
34 * We have to override the memory allocators so that we don't get
35 * "unused argument" warnings from the yyscanner argument (which
36 * we don't use, as we have a global memory allocator).
38 * We provide, as macros, our own versions of the routines generated by Flex,
39 * which just call malloc()/realloc()/free() (as the Flex versions do),
40 * discarding the extra argument.
50 * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
52 * This program is free software; you can redistribute it and/or
53 * modify it under the terms of the GNU General Public License
54 * as published by the Free Software Foundation; either version 2
55 * of the License, or (at your option) any later version.
57 * This program is distributed in the hope that it will be useful,
58 * but WITHOUT ANY WARRANTY; without even the implied warranty of
59 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
60 * GNU General Public License for more details.
62 * You should have received a copy of the GNU General Public License
63 * along with this program; if not, write to the Free Software
64 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
73 #include "ascendtext.h"
74 #include "ascend-int.h"
76 #include "file_wrappers.h"
78 #define YY_INPUT(buf,result,max_size) { \
79 ascend_state_t *parser_state = ascendget_extra(yyscanner); \
80 int c = file_getc(parser_state->fh); \
82 *(parser_state->err) = file_error(parser_state->fh, \
83 parser_state->err_info); \
84 if (*(parser_state->err) == 0) \
85 *(parser_state->err) = WTAP_ERR_SHORT_READ; \
93 #define NO_USER "<none>"
96 #define YY_NO_UNISTD_H
100 * Sleazy hack to suppress compiler warnings in yy_fatal_error().
102 #define YY_EXIT_FAILURE ((void)yyscanner, 2)
105 * Macros for the allocators, to discard the extra argument.
107 #define ascendalloc(size, yyscanner) (void *)malloc(size)
108 #define ascendrealloc(ptr, size, yyscanner) (void *)realloc((char *)(ptr), (size))
109 #define ascendfree(ptr, yyscanner) free((char *)ptr)
126 WDD_CAUSE "Cause an attempt to place call to "
127 WDD_CALLNUM [^\n\r\t ]+
128 WDD_CHUNK "WD_DIALOUT_DISP: chunk"
129 WDD_TYPE "type "[^\n\r\t ]+
157 %s sc_ether_direction
161 <INITIAL,sc_gen_byte>{ETHER_PFX} {
162 BEGIN(sc_ether_direction);
163 yylval->d = ASCEND_PFX_ETHER;
167 <INITIAL,sc_gen_byte>{ISDN_XPFX} {
169 yylval->d = ASCEND_PFX_ISDN_X;
173 <INITIAL,sc_gen_byte>{ISDN_RPFX} {
175 yylval->d = ASCEND_PFX_ISDN_R;
179 <INITIAL,sc_gen_byte>{WAN_XPFX} {
181 yylval->d = ASCEND_PFX_WDS_X;
185 <INITIAL,sc_gen_byte>{WAN_RPFX} {
187 yylval->d = ASCEND_PFX_WDS_R;
191 <INITIAL,sc_gen_byte>{PPP_XPFX} {
193 yylval->d = ASCEND_PFX_WDS_X;
197 <INITIAL,sc_gen_byte>{PPP_RPFX} {
199 yylval->d = ASCEND_PFX_WDS_R;
203 <sc_ether_direction>[^\(]{2,20} {
208 <sc_isdn_call>[^\/\(:]{2,20} {
213 <sc_wds_user>[^:]{2,20} {
214 char *atcopy = g_strdup(yytext);
215 char colon = input(yyscanner);
216 char after = input(yyscanner);
219 unput(after); unput(colon);
221 if (after != '(' && after != ' ') {
223 if (yyextra->pseudo_header != NULL) {
224 g_strlcpy(yyextra->pseudo_header->user, atcopy, ASCEND_MAX_STR_LEN);
226 } else { /* We have a version 7 file */
228 if (yyextra->pseudo_header != NULL) {
229 g_strlcpy(yyextra->pseudo_header->user, NO_USER, ASCEND_MAX_STR_LEN);
231 /* Are valid values ever > 2^32? If so we need to adjust YYSTYPE and a lot of */
232 /* upstream code accordingly. */
233 yylval->d = (guint32) strtoul(yytext, NULL, 10);
242 yylval->d = (guint32) strtoul(yytext, NULL, 10);
246 <sc_gen_task>(0x|0X)?{H}{2,8} {
247 BEGIN(sc_gen_time_s);
248 yylval->d = (guint32) strtoul(yytext, NULL, 16);
252 <sc_gen_task>\"[A-Za-z0-9_ ]+\" {
256 <sc_gen_time_s>{D}{1,10} {
257 BEGIN(sc_gen_time_u);
258 yylval->d = (guint32) strtoul(yytext, NULL, 10);
262 <sc_gen_time_u>{D}{1,6} {
263 char *atcopy = g_strdup(yytext);
264 BEGIN(sc_gen_octets);
265 /* only want the most significant 2 digits. convert to usecs */
266 if (strlen(atcopy) > 2)
268 yylval->d = (guint32) strtoul(atcopy, NULL, 10) * 10000;
273 <sc_gen_octets>{D}{1,10} {
274 BEGIN(sc_gen_counter);
275 yylval->d = (guint32) strtoul(yytext, NULL, 10);
279 <sc_gen_counter,sc_gen_byte>"["{H}{4}"]:" {
284 <sc_gen_byte>{H}{2} {
285 yylval->b = (guint8)(guint32) strtoul(yytext, NULL, 16);
289 <sc_gen_byte>" "{4} {
297 <INITIAL,sc_gen_byte>{WDD_DATE} {
298 BEGIN(sc_wdd_date_d);
302 <sc_wdd_date_d>{D}{2} {
303 BEGIN(sc_wdd_date_m);
304 yylval->d = (guint32) strtoul(yytext, NULL, 10);
308 <sc_wdd_date_m>{D}{2} {
309 BEGIN(sc_wdd_date_y);
310 yylval->d = (guint32) strtoul(yytext, NULL, 10);
314 <sc_wdd_date_y>{D}{4} {
316 yylval->d = (guint32) strtoul(yytext, NULL, 10);
320 <sc_wdd_time>{WDD_TIME} {
321 BEGIN(sc_wdd_time_h);
325 <sc_wdd_time_h>{D}{2} {
326 BEGIN(sc_wdd_time_m);
327 yylval->d = (guint32) strtoul(yytext, NULL, 10);
331 <sc_wdd_time_m>{D}{2} {
332 BEGIN(sc_wdd_time_s);
333 yylval->d = (guint32) strtoul(yytext, NULL, 10);
337 <sc_wdd_time_s>{D}{2} {
339 yylval->d = (guint32) strtoul(yytext, NULL, 10);
343 <sc_wdd_cause>{WDD_CAUSE} {
344 BEGIN(sc_wdd_callnum);
348 <sc_wdd_callnum>{WDD_CALLNUM} {
350 if (yyextra->pseudo_header != NULL) {
351 g_strlcpy(yyextra->pseudo_header->call_num, yytext, ASCEND_MAX_STR_LEN);
356 <INITIAL,sc_wdd_chunk,sc_gen_byte>{WDD_CHUNK} {
357 BEGIN(sc_wdd_chunknum);
361 <sc_wdd_chunknum>{H}{1,8} {
363 yylval->d = (guint32) strtoul(yytext, NULL, 16);
367 <sc_wdd_type>{WDD_TYPE} {
372 <sc_gen_task>\/{D}+ {
376 (0x|0X)?{H}+ { return HEXNUM; }
378 task:|task|at|time:|octets { return KEYWORD; }
380 <<EOF>> { yyterminate(); }