diff options
Diffstat (limited to 'epan/dfilter/scanner.l')
-rw-r--r-- | epan/dfilter/scanner.l | 75 |
1 files changed, 53 insertions, 22 deletions
diff --git a/epan/dfilter/scanner.l b/epan/dfilter/scanner.l index c213ac8351..ce138da8b6 100644 --- a/epan/dfilter/scanner.l +++ b/epan/dfilter/scanner.l @@ -1,4 +1,9 @@ /* + * We want a reentrant scanner. + */ +%option reentrant + +/* * We don't use input, so don't generate code for it. */ %option noinput @@ -24,6 +29,24 @@ */ %option noyywrap +/* + * The type for the state we keep for a scanner. + */ +%option extra-type="df_scanner_state_t *" + +/* + * 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 + %{ /* * Wireshark - Network traffic analyzer @@ -54,7 +77,6 @@ #include "syntax-tree.h" #include "grammar.h" #include "dfunctions.h" -#include "scanner_lex.h" #ifdef _WIN32 /* disable Windows VC compiler warning "signed/unsigned mismatch" associated */ @@ -76,9 +98,20 @@ static int set_lval(int token, gpointer data); static int set_lval_int(dfwork_t *dfw, int token, char *s); static int simple(int token); static gboolean str_to_gint32(dfwork_t *dfw, char *s, gint32* pint); -GString* quoted_string = NULL; static void mark_lval_deprecated(const char *s); +/* + * 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 df_alloc(size, yyscanner) (void *)malloc(size) +#define df_realloc(ptr, size, yyscanner) (void *)realloc((char *)(ptr), (size)) +#define df_free(ptr, yyscanner) free((char *)ptr) + %} %x RANGE_INT @@ -136,12 +169,12 @@ static void mark_lval_deprecated(const char *s); <RANGE_INT>[+-]?[[:digit:]]+ { BEGIN(RANGE_PUNCT); - return set_lval_int(global_dfw, TOKEN_INTEGER, yytext); + return set_lval_int(yyextra->dfw, TOKEN_INTEGER, yytext); } <RANGE_INT>[+-]?0x[[:xdigit:]]+ { BEGIN(RANGE_PUNCT); - return set_lval_int(global_dfw, TOKEN_INTEGER, yytext); + return set_lval_int(yyextra->dfw, TOKEN_INTEGER, yytext); } <RANGE_INT,RANGE_PUNCT>":" { @@ -167,7 +200,7 @@ static void mark_lval_deprecated(const char *s); /* Error if none of the above while scanning a range (slice) */ <RANGE_PUNCT>[^:\-,\]]+ { - dfilter_fail(global_dfw, "Invalid string \"%s\" found while scanning slice.", yytext); + dfilter_fail(yyextra->dfw, "Invalid string \"%s\" found while scanning slice.", yytext); return SCAN_FAILED; } @@ -176,7 +209,7 @@ static void mark_lval_deprecated(const char *s); */ <RANGE_INT>. { - dfilter_fail(global_dfw, "Invalid character \"%s\" found while scanning slice; expected integer.", yytext); + dfilter_fail(yyextra->dfw, "Invalid character \"%s\" found while scanning slice; expected integer.", yytext); return SCAN_FAILED; } @@ -192,13 +225,13 @@ static void mark_lval_deprecated(const char *s); a missing end quote will have left quoted_string set to something. Clear it now that we are starting a new quoted string. */ - if (quoted_string) { - g_string_free(quoted_string, TRUE); + if (yyextra->quoted_string) { + g_string_free(yyextra->quoted_string, TRUE); /* Don't set quoted_string to NULL, as we do in other quoted_string-cleanup code, as we're about to set it in the next line. */ } - quoted_string = g_string_new(""); + yyextra->quoted_string = g_string_new(""); } <DQUOTE><<EOF>> { @@ -208,7 +241,7 @@ static void mark_lval_deprecated(const char *s); See: http://www.gnu.org/software/flex/manual/html_node/flex_13.html */ - dfilter_fail(global_dfw, "The final quote was missing from a quoted string."); + dfilter_fail(yyextra->dfw, "The final quote was missing from a quoted string."); return SCAN_FAILED; } @@ -216,9 +249,9 @@ static void mark_lval_deprecated(const char *s); /* end quote */ int token; BEGIN(INITIAL); - token = set_lval(TOKEN_STRING, quoted_string->str); - g_string_free(quoted_string, TRUE); - quoted_string = NULL; + token = set_lval(TOKEN_STRING, yyextra->quoted_string->str); + g_string_free(yyextra->quoted_string, TRUE); + yyextra->quoted_string = NULL; return token; } @@ -227,30 +260,30 @@ static void mark_lval_deprecated(const char *s); unsigned long result; result = strtoul(yytext + 1, NULL, 8); if (result > 0xff) { - g_string_free(quoted_string, TRUE); - quoted_string = NULL; - dfilter_fail(global_dfw, "%s is larger than 255.", yytext); + g_string_free(yyextra->quoted_string, TRUE); + yyextra->quoted_string = NULL; + dfilter_fail(yyextra->dfw, "%s is larger than 255.", yytext); return SCAN_FAILED; } - g_string_append_c(quoted_string, (gchar) result); + g_string_append_c(yyextra->quoted_string, (gchar) result); } <DQUOTE>\\x[[:xdigit:]]{1,2} { /* hex sequence */ unsigned long result; result = strtoul(yytext + 2, NULL, 16); - g_string_append_c(quoted_string, (gchar) result); + g_string_append_c(yyextra->quoted_string, (gchar) result); } <DQUOTE>\\. { /* escaped character */ - g_string_append_c(quoted_string, yytext[1]); + g_string_append_c(yyextra->quoted_string, yytext[1]); } <DQUOTE>[^\\\042]+ { /* non-escaped string */ - g_string_append(quoted_string, yytext); + g_string_append(yyextra->quoted_string, yytext); } @@ -429,5 +462,3 @@ mark_lval_deprecated(const char *s) { df_lval->deprecated_token = s; } - -#include <lemonflex-tail.inc> |