dfilter: Minor flex clean up

Replace flex prefix to improve readability.

Remove two no-longer-needed workarounds to suppress warnings.
This commit is contained in:
João Valverde 2023-01-02 00:40:41 +00:00
parent f2218ae5f0
commit 5d8f495233
2 changed files with 9 additions and 34 deletions

View File

@ -413,20 +413,20 @@ dfilter_compile_real(const gchar *text, dfilter_t **dfp,
ws_noisy("Verbatim text: %s", dfw->expanded_text);
}
if (df_lex_init(&scanner) != 0) {
if (df_yylex_init(&scanner) != 0) {
dfw_error_set_msg(errpp, "Can't initialize scanner: %s", g_strerror(errno));
goto FAILURE;
}
in_buffer = df__scan_string(dfw->expanded_text, scanner);
in_buffer = df_yy_scan_string(dfw->expanded_text, scanner);
memset(&state, 0, sizeof(state));
state.dfw = dfw;
df_set_extra(&state, scanner);
df_yyset_extra(&state, scanner);
/* Enable/disable debugging for Flex. */
df_set_debug(flags & DF_DEBUG_FLEX, scanner);
df_yyset_debug(flags & DF_DEBUG_FLEX, scanner);
#ifndef NDEBUG
/* Enable/disable debugging for Lemon. */
@ -439,7 +439,7 @@ dfilter_compile_real(const gchar *text, dfilter_t **dfp,
while (1) {
df_lval = stnode_new_empty(STTYPE_UNINITIALIZED);
token = df_lex(scanner);
token = df_yylex(scanner);
/* Check for scanner failure */
if (token == SCAN_FAILED) {
@ -492,8 +492,8 @@ dfilter_compile_real(const gchar *text, dfilter_t **dfp,
/* Free scanner state */
if (state.quoted_string != NULL)
g_string_free(state.quoted_string, TRUE);
df__delete_buffer(in_buffer, scanner);
df_lex_destroy(scanner);
df_yy_delete_buffer(in_buffer, scanner);
df_yylex_destroy(scanner);
if (failure)
goto FAILURE;

View File

@ -46,10 +46,10 @@
%option never-interactive
/*
* Prefix scanner routines with "df_" rather than "yy", so this scanner
* Prefix scanner routines with "df_yy" rather than "yy", so this scanner
* can coexist with other scanners.
*/
%option prefix="df_"
%option prefix="df_yy"
/*
* We're reading from a string, so we don't need yywrap.
@ -61,19 +61,6 @@
*/
%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
@ -116,18 +103,6 @@ static void update_string_loc(df_scanner_state_t *state, const char *text);
dfilter_fail(yyextra->dfw, DF_ERROR_GENERIC, yyextra->location, __VA_ARGS__); \
} while (0)
/*
* 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)
%}
Identifier [[:alnum:]_][[:alnum:]_-]*(\.[[:alnum:]_-]+)*