4 /* Include this before everything else, for various large-file definitions */
9 * We want a reentrant scanner.
14 * We don't use input, so don't generate code for it.
19 * We don't use unput, so don't generate code for it.
24 * We don't read interactively from the terminal.
26 %option never-interactive
29 * We want to stop processing when we get to the end of the input.
34 * Prefix scanner routines with "text_import_" rather than "yy", so this scanner
35 * can coexist with other scanners.
37 %option prefix="text_import_"
40 * We have to override the memory allocators so that we don't get
41 * "unused argument" warnings from the yyscanner argument (which
42 * we don't use, as we have a global memory allocator).
44 * We provide, as macros, our own versions of the routines generated by Flex,
45 * which just call malloc()/realloc()/free() (as the Flex versions do),
46 * discarding the extra argument.
54 /********************************************************************************
56 * text_import_scanner.l
57 * Scanner for text import
58 * November 2010, Jaap Keuter <jaap.keuter@xs4all.nl>
60 * Wireshark - Network traffic analyzer
61 * By Gerald Combs <gerald@wireshark.org>
62 * Copyright 1998 Gerald Combs
64 * Based on text2pcap-scanner.l by Ashok Narayanan <ashokn@cisco.com>
66 * SPDX-License-Identifier: GPL-2.0-or-later
68 *******************************************************************************/
73 #include "text_import_scanner.h"
76 * Disable diagnostics in the code generated by Flex.
81 * Flex (v 2.5.35) uses this symbol to "exclude" unistd.h
84 # define YY_NO_UNISTD_H
88 * Sleazy hack to suppress compiler warnings in yy_fatal_error().
90 #define YY_EXIT_FAILURE ((void)yyscanner, 2)
93 * Macros for the allocators, to discard the extra argument.
95 #define text_import_alloc(size, yyscanner) (void *)malloc(size)
96 #define text_import_realloc(ptr, size, yyscanner) (void *)realloc((char *)(ptr), (size))
97 #define text_import_free(ptr, yyscanner) free((char *)ptr)
102 directive ^#TEXT2PCAP.*\r?\n
103 comment ^[\t ]*#.*\r?\n
104 byte [0-9A-Fa-f][0-9A-Fa-f][ \t]
105 byte_eol [0-9A-Fa-f][0-9A-Fa-f]\r?\n
106 offset [0-9A-Fa-f]+[: \t]
107 offset_eol [0-9A-Fa-f]+\r?\n
114 {byte} { parse_token(T_BYTE, yytext); }
115 {byte_eol} { parse_token(T_BYTE, yytext); parse_token(T_EOL, NULL); }
116 {offset} { parse_token(T_OFFSET, yytext); }
117 {offset_eol} { parse_token(T_OFFSET, yytext); parse_token(T_EOL, NULL); }
118 {mailfwd}{offset} { parse_token(T_OFFSET, yytext+1); }
119 {eol} { parse_token(T_EOL, NULL); }
120 [ \t] ; /* ignore whitespace */
121 {directive} { parse_token(T_DIRECTIVE, yytext); parse_token(T_EOL, NULL); }
122 {comment} { parse_token(T_EOL, NULL); }
123 {text} { parse_token(T_TEXT, yytext); }
125 <<EOF>> { write_current_packet(); yyterminate(); }
130 * Turn diagnostics back on, so we check the code that we've written.
135 text_import_scan(FILE *input_file)
139 if (text_import_lex_init(&scanner) != 0)
142 text_import_set_in(input_file, scanner);
144 text_import_lex(scanner);
146 text_import_lex_destroy(scanner);