aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/ascend_scanner.l
diff options
context:
space:
mode:
Diffstat (limited to 'wiretap/ascend_scanner.l')
-rw-r--r--wiretap/ascend_scanner.l126
1 files changed, 81 insertions, 45 deletions
diff --git a/wiretap/ascend_scanner.l b/wiretap/ascend_scanner.l
index 950df9fd3d..24b539e512 100644
--- a/wiretap/ascend_scanner.l
+++ b/wiretap/ascend_scanner.l
@@ -1,4 +1,15 @@
/*
+ * We want a reentrant scanner.
+ */
+%option reentrant
+
+/*
+ * We want to generate code that can be used by a reentrant parser
+ * generated by Bison or Berkeley YACC.
+ */
+%option bison-bridge
+
+/*
* We don't read interactively from the terminal.
*/
%option never-interactive
@@ -14,6 +25,19 @@
*/
%option prefix="ascend"
+/*
+ * We have to override the memory allocators so that we don't get
+ * "unused argument" warnings from the yyscanner argument (which
+ * we don't use, as we have a global memory allocator).
+ *
+ * We provide, as macros, our own versions of the routines generated by Flex,
+ * which just call malloc()/realloc()/free() (as the Flex versions do),
+ * discarding the extra argument.
+ */
+%option noyyalloc
+%option noyyrealloc
+%option noyyfree
+
%{
/* ascend_scanner.l
*
@@ -42,14 +66,24 @@
#include "wtap-int.h"
#include "ascendtext.h"
-#include "ascend.h"
#include "ascend-int.h"
+#include "ascend.h"
#include "file_wrappers.h"
-#include "ascend_scanner_lex.h"
-FILE_T yy_fh;
-#define YY_INPUT(buf,result,max_size) { int c = file_getc(yy_fh); \
-result = (c==EOF) ? YY_NULL : (buf[0] = c, 1); }
+#define YY_INPUT(buf,result,max_size) { \
+ ascend_state_t *parser_state = ascendget_extra(yyscanner); \
+ int c = file_getc(parser_state->fh); \
+ if (c == EOF) { \
+ *(parser_state->err) = file_error(parser_state->fh, \
+ parser_state->err_info); \
+ if (*(parser_state->err) == 0) \
+ *(parser_state->err) = WTAP_ERR_SHORT_READ; \
+ result = YY_NULL; \
+ } else { \
+ buf[0] = c; \
+ result = 1; \
+ } \
+}
#define NO_USER "<none>"
@@ -57,6 +91,17 @@ result = (c==EOF) ? YY_NULL : (buf[0] = c, 1); }
#define YY_NO_UNISTD_H
#endif
+/*
+ * Sleazy hack to suppress compiler warnings in yy_fatal_error().
+ */
+#define YY_EXIT_FAILURE ((void)yyscanner, 2)
+
+/*
+ * Macros for the allocators, to discard the extra argument.
+ */
+#define ascendtext_alloc(size, yyscanner) (void *)malloc(size)
+#define ascendtext_realloc(ptr, size, yyscanner) (void *)realloc((char *)(ptr), (size))
+#define ascendtext_free(ptr, yyscanner) free((char *)ptr)
%}
@@ -110,43 +155,43 @@ WDD_TYPE "type "[^\n\r\t ]+
<INITIAL,sc_gen_byte>{ETHER_PFX} {
BEGIN(sc_ether_direction);
- ascendlval.d = ASCEND_PFX_ETHER;
+ yylval->d = ASCEND_PFX_ETHER;
return ETHER_PREFIX;
}
<INITIAL,sc_gen_byte>{ISDN_XPFX} {
BEGIN(sc_isdn_call);
- ascendlval.d = ASCEND_PFX_ISDN_X;
+ yylval->d = ASCEND_PFX_ISDN_X;
return ISDN_PREFIX;
}
<INITIAL,sc_gen_byte>{ISDN_RPFX} {
BEGIN(sc_isdn_call);
- ascendlval.d = ASCEND_PFX_ISDN_R;
+ yylval->d = ASCEND_PFX_ISDN_R;
return ISDN_PREFIX;
}
<INITIAL,sc_gen_byte>{WAN_XPFX} {
BEGIN(sc_wds_user);
- ascendlval.d = ASCEND_PFX_WDS_X;
+ yylval->d = ASCEND_PFX_WDS_X;
return WDS_PREFIX;
}
<INITIAL,sc_gen_byte>{WAN_RPFX} {
BEGIN(sc_wds_user);
- ascendlval.d = ASCEND_PFX_WDS_R;
+ yylval->d = ASCEND_PFX_WDS_R;
return WDS_PREFIX;
}
<INITIAL,sc_gen_byte>{PPP_XPFX} {
BEGIN(sc_wds_user);
- ascendlval.d = ASCEND_PFX_WDS_X;
+ yylval->d = ASCEND_PFX_WDS_X;
return WDS_PREFIX;
}
<INITIAL,sc_gen_byte>{PPP_RPFX} {
BEGIN(sc_wds_user);
- ascendlval.d = ASCEND_PFX_WDS_R;
+ yylval->d = ASCEND_PFX_WDS_R;
return WDS_PREFIX;
}
@@ -161,26 +206,26 @@ WDD_TYPE "type "[^\n\r\t ]+
}
<sc_wds_user>[^:]{2,20} {
- char *atcopy = g_strdup(ascendtext);
- char colon = input();
- char after = input();
+ char *atcopy = g_strdup(yytext);
+ char colon = input(yyscanner);
+ char after = input(yyscanner);
int retval = STRING;
unput(after); unput(colon);
if (after != '(' && after != ' ') {
BEGIN(sc_wds_sess);
- if (pseudo_header != NULL) {
- g_strlcpy(pseudo_header->user, atcopy, ASCEND_MAX_STR_LEN);
+ if (yyextra->pseudo_header != NULL) {
+ g_strlcpy(yyextra->pseudo_header->user, atcopy, ASCEND_MAX_STR_LEN);
}
} else { /* We have a version 7 file */
BEGIN(sc_gen_task);
- if (pseudo_header != NULL) {
- g_strlcpy(pseudo_header->user, NO_USER, ASCEND_MAX_STR_LEN);
+ if (yyextra->pseudo_header != NULL) {
+ g_strlcpy(yyextra->pseudo_header->user, NO_USER, ASCEND_MAX_STR_LEN);
}
/* Are valid values ever > 2^32? If so we need to adjust YYSTYPE and a lot of */
/* upstream code accordingly. */
- ascendlval.d = (guint32) strtoul(ascendtext, NULL, 10);
+ yylval->d = (guint32) strtoul(yytext, NULL, 10);
retval = DECNUM;
}
g_free (atcopy);
@@ -189,13 +234,13 @@ WDD_TYPE "type "[^\n\r\t ]+
<sc_wds_sess>{D}* {
BEGIN(sc_gen_task);
- ascendlval.d = (guint32) strtoul(ascendtext, NULL, 10);
+ yylval->d = (guint32) strtoul(yytext, NULL, 10);
return DECNUM;
}
<sc_gen_task>(0x|0X)?{H}{2,8} {
BEGIN(sc_gen_time_s);
- ascendlval.d = (guint32) strtoul(ascendtext, NULL, 16);
+ yylval->d = (guint32) strtoul(yytext, NULL, 16);
return HEXNUM;
}
@@ -205,24 +250,24 @@ WDD_TYPE "type "[^\n\r\t ]+
<sc_gen_time_s>{D}{1,10} {
BEGIN(sc_gen_time_u);
- ascendlval.d = (guint32) strtoul(ascendtext, NULL, 10);
+ yylval->d = (guint32) strtoul(yytext, NULL, 10);
return DECNUM;
}
<sc_gen_time_u>{D}{1,6} {
- char *atcopy = g_strdup(ascendtext);
+ char *atcopy = g_strdup(yytext);
BEGIN(sc_gen_octets);
/* only want the most significant 2 digits. convert to usecs */
if (strlen(atcopy) > 2)
atcopy[2] = '\0';
- ascendlval.d = (guint32) strtoul(atcopy, NULL, 10) * 10000;
+ yylval->d = (guint32) strtoul(atcopy, NULL, 10) * 10000;
g_free(atcopy);
return DECNUM;
}
<sc_gen_octets>{D}{1,10} {
BEGIN(sc_gen_counter);
- ascendlval.d = (guint32) strtoul(ascendtext, NULL, 10);
+ yylval->d = (guint32) strtoul(yytext, NULL, 10);
return DECNUM;
}
@@ -232,7 +277,7 @@ WDD_TYPE "type "[^\n\r\t ]+
}
<sc_gen_byte>{H}{2} {
- ascendlval.b = (guint8)(guint32) strtoul(ascendtext, NULL, 16);
+ yylval->b = (guint8)(guint32) strtoul(yytext, NULL, 16);
return HEXBYTE;
}
@@ -251,19 +296,19 @@ WDD_TYPE "type "[^\n\r\t ]+
<sc_wdd_date_d>{D}{2} {
BEGIN(sc_wdd_date_m);
- ascendlval.d = (guint32) strtoul(ascendtext, NULL, 10);
+ yylval->d = (guint32) strtoul(yytext, NULL, 10);
return DECNUM;
}
<sc_wdd_date_m>{D}{2} {
BEGIN(sc_wdd_date_y);
- ascendlval.d = (guint32) strtoul(ascendtext, NULL, 10);
+ yylval->d = (guint32) strtoul(yytext, NULL, 10);
return DECNUM;
}
<sc_wdd_date_y>{D}{4} {
BEGIN(sc_wdd_time);
- ascendlval.d = (guint32) strtoul(ascendtext, NULL, 10);
+ yylval->d = (guint32) strtoul(yytext, NULL, 10);
return DECNUM;
}
@@ -274,19 +319,19 @@ WDD_TYPE "type "[^\n\r\t ]+
<sc_wdd_time_h>{D}{2} {
BEGIN(sc_wdd_time_m);
- ascendlval.d = (guint32) strtoul(ascendtext, NULL, 10);
+ yylval->d = (guint32) strtoul(yytext, NULL, 10);
return DECNUM;
}
<sc_wdd_time_m>{D}{2} {
BEGIN(sc_wdd_time_s);
- ascendlval.d = (guint32) strtoul(ascendtext, NULL, 10);
+ yylval->d = (guint32) strtoul(yytext, NULL, 10);
return DECNUM;
}
<sc_wdd_time_s>{D}{2} {
BEGIN(sc_wdd_cause);
- ascendlval.d = (guint32) strtoul(ascendtext, NULL, 10);
+ yylval->d = (guint32) strtoul(yytext, NULL, 10);
return DECNUM;
}
@@ -297,8 +342,8 @@ WDD_TYPE "type "[^\n\r\t ]+
<sc_wdd_callnum>{WDD_CALLNUM} {
BEGIN(sc_wdd_chunk);
- if (pseudo_header != NULL) {
- g_strlcpy(pseudo_header->call_num, ascendtext, ASCEND_MAX_STR_LEN);
+ if (yyextra->pseudo_header != NULL) {
+ g_strlcpy(yyextra->pseudo_header->call_num, yytext, ASCEND_MAX_STR_LEN);
}
return STRING;
}
@@ -310,7 +355,7 @@ WDD_TYPE "type "[^\n\r\t ]+
<sc_wdd_chunknum>{H}{1,8} {
BEGIN(sc_wdd_type);
- ascendlval.d = (guint32) strtoul(ascendtext, NULL, 16);
+ yylval->d = (guint32) strtoul(yytext, NULL, 16);
return HEXNUM;
}
@@ -330,12 +375,3 @@ task:|task|at|time:|octets { return KEYWORD; }
<<EOF>> { yyterminate(); }
(.|\n) ;
-
-%%
-
-void ascend_init_lexer(FILE_T fh)
-{
- yyrestart(0);
- yy_fh = fh;
- BEGIN(INITIAL);
-}