%{
/* ascend-scanner.l
*
- * $Id: ascend-scanner.l,v 1.7 1999/10/08 07:41:31 guy Exp $
+ * $Id$
*
* Wiretap Library
- * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
+ * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#ifdef HAVE_CONFIG_H
-#include "config.h"
+#ifdef HAVE_IO_H
+#include <io.h> /* for isatty() on win32 */
#endif
-#include "wtap.h"
+
+#include "wtap-int.h"
#include "ascend.h"
#include "ascend-grammar.h"
#include "ascend-int.h"
-#include "file.h"
+#include "file_wrappers.h"
-void *yy_fh;
+FILE_T yy_fh;
extern char *ascend_ra_ptr;
extern char *ascend_ra_last;
#define YY_INPUT(buf,result,max_size) { int c = file_getc(yy_fh); \
result = (c==EOF) ? YY_NULL : (buf[0] = c, 1); }
-struct ascend_phdr *pseudo_header;
+#define YY_NEVER_INTERACTIVE 1
int at_eof;
int mul, scratch;
+
+#define NO_USER "<none>"
+
+#ifndef HAVE_UNISTD_H
+#define YY_NO_UNISTD_H
+#endif
+
+
%}
-/* %option debug */
%option nostdinit
%option noyywrap
D [0-9]
H [A-Fa-f0-9]
-XPFX XMIT-
-RPFX RECV-
+PPP_XPFX PPP-OUT
+PPP_RPFX PPP-IN
+ISDN_XPFX PRI-XMIT-
+ISDN_RPFX PRI-RCV-
+WAN_XPFX XMIT[\-:]*
+WAN_RPFX RECV[\-:]*
+ETHER_PFX ETHER
WDD_DATE "Date:"
WDD_TIME "Time:"
%s sc_wdd_chunknum
%s sc_wdd_type
+%s sc_chardisp
+
+%s sc_isdn_call
+%s sc_ether_direction
+
%%
-<INITIAL,sc_gen_byte>{XPFX} {
+<INITIAL,sc_gen_byte>{ETHER_PFX} {
+ BEGIN(sc_ether_direction);
+ ascendlval.d = ASCEND_PFX_ETHER;
+ return ETHER_PREFIX;
+}
+
+<INITIAL,sc_gen_byte>{ISDN_XPFX} {
+ BEGIN(sc_isdn_call);
+ ascendlval.d = ASCEND_PFX_ISDN_X;
+ return ISDN_PREFIX;
+}
+
+<INITIAL,sc_gen_byte>{ISDN_RPFX} {
+ BEGIN(sc_isdn_call);
+ ascendlval.d = ASCEND_PFX_ISDN_R;
+ return ISDN_PREFIX;
+}
+
+<INITIAL,sc_gen_byte>{WAN_XPFX} {
BEGIN(sc_wds_user);
ascendlval.d = ASCEND_PFX_WDS_X;
return WDS_PREFIX;
}
-<INITIAL,sc_gen_byte>{RPFX} {
+<INITIAL,sc_gen_byte>{WAN_RPFX} {
BEGIN(sc_wds_user);
ascendlval.d = ASCEND_PFX_WDS_R;
return WDS_PREFIX;
}
+<INITIAL,sc_gen_byte>{PPP_XPFX} {
+ BEGIN(sc_wds_user);
+ ascendlval.d = ASCEND_PFX_WDS_X;
+ return WDS_PREFIX;
+}
+
+<INITIAL,sc_gen_byte>{PPP_RPFX} {
+ BEGIN(sc_wds_user);
+ ascendlval.d = ASCEND_PFX_WDS_R;
+ return WDS_PREFIX;
+}
+
+<sc_ether_direction>[^\(]+ {
+ BEGIN(sc_gen_task);
+ return STRING;
+}
+
+<sc_isdn_call>[^\/\(:]+ {
+ BEGIN(sc_gen_task);
+ return DECNUM;
+}
+
<sc_wds_user>[^:]+ {
- BEGIN(sc_wds_sess);
- if (pseudo_header != NULL) {
- strncpy(pseudo_header->user, ascendtext, ASCEND_MAX_STR_LEN);
- pseudo_header->user[ASCEND_MAX_STR_LEN - 1] = '\0';
+ char *atcopy = strdup(ascendtext);
+ char colon = input();
+ char after = input();
+ int retval = STRING;
+
+ unput(after); unput(colon);
+
+ if (after != '(' && after != ' ') {
+ BEGIN(sc_wds_sess);
+ if (pseudo_header != NULL) {
+ strncpy(pseudo_header->user, atcopy, ASCEND_MAX_STR_LEN);
+ pseudo_header->user[ASCEND_MAX_STR_LEN - 1] = '\0';
+ }
+ } else { /* We have a version 7 file */
+ BEGIN(sc_gen_task);
+ if (pseudo_header != NULL) {
+ strncpy(pseudo_header->user, NO_USER, ASCEND_MAX_STR_LEN);
+ }
+ ascendlval.d = strtol(ascendtext, NULL, 10);
+ retval = DECNUM;
}
- return STRING;
+ free (atcopy);
+ return retval;
}
-<sc_wds_sess>{D}+ {
+<sc_wds_sess>{D}* {
BEGIN(sc_gen_task);
ascendlval.d = strtol(ascendtext, NULL, 10);
return DECNUM;
}
-<sc_gen_task>{H}+ {
+<sc_gen_task>(0x|0X)?{H}+ {
BEGIN(sc_gen_time_s);
ascendlval.d = strtoul(ascendtext, NULL, 16);
return HEXNUM;
}
+<sc_gen_task>\"[A-Za-z0-9_ ]+\" {
+ return STRING;
+}
+
<sc_gen_time_s>{D}+ {
BEGIN(sc_gen_time_u);
ascendlval.d = strtol(ascendtext, NULL, 10);
}
<sc_gen_time_u>{D}+ {
+ char *atcopy = strdup(ascendtext);
BEGIN(sc_gen_octets);
- /* We have the fractional portion of the time. We want it converted
- to microseconds. */
- mul = 1000000;
- ascendlval.d = strtol(ascendtext, NULL, 10);
- for (scratch = ascendlval.d; scratch > 0; scratch /= 10)
- mul /= 10;
- ascendlval.d *= mul;
+ /* only want the most significant 2 digits. convert to usecs */
+ if (strlen(atcopy) > 2)
+ atcopy[2] = '\0';
+ ascendlval.d = strtol(atcopy, NULL, 10) * 10000;
+ free(atcopy);
return DECNUM;
}
}
<sc_gen_byte>{H}{2} {
- ascendlval.b = strtol(ascendtext, NULL, 16);
- return BYTE;
+ ascendlval.b = (guint8)strtol(ascendtext, NULL, 16);
+ return HEXBYTE;
+}
+
+<sc_gen_byte>" "{4} {
+ BEGIN(sc_chardisp);
+}
+
+<sc_chardisp>.* {
+ BEGIN(sc_gen_byte);
}
<INITIAL,sc_gen_byte>{WDD_DATE} {
BEGIN(sc_wdd_date_d);
- return KEYWORD;
+ return WDD_DATE;
}
<sc_wdd_date_d>{D}{2} {
return STRING;
}
-<sc_wdd_chunk>{WDD_CHUNK} {
+<INITIAL,sc_wdd_chunk,sc_gen_byte>{WDD_CHUNK} {
BEGIN(sc_wdd_chunknum);
- return KEYWORD;
+ return WDD_CHUNK;
}
<sc_wdd_chunknum>{H}+ {
return KEYWORD;
}
+<sc_gen_task>\/{D}+ {
+ return SLASH_SUFFIX;
+}
-{H}+ { return HEXNUM; }
+(0x|0X)?{H}+ { return HEXNUM; }
-task:|time:|octets { return KEYWORD; }
+task:|task|at|time:|octets { return KEYWORD; }
<<EOF>> { at_eof++; yyterminate(); }
-. ;
+(.|\n) ;
%%
-int ascendwrap() { return 1; };
-
-void ascend_init_lexer(FILE *fh, FILE *nfh)
+void ascend_init_lexer(FILE_T fh)
{
yyrestart(0);
- yyout = nfh;
yy_fh = fh;
BEGIN(INITIAL);
}