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 * This program is free software; you can redistribute it and/or
67 * modify it under the terms of the GNU General Public License
68 * as published by the Free Software Foundation; either version 2
69 * of the License, or (at your option) any later version.
71 * This program is distributed in the hope that it will be useful,
72 * but WITHOUT ANY WARRANTY; without even the implied warranty of
73 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
74 * GNU General Public License for more details.
76 * You should have received a copy of the GNU General Public License
77 * along with this program; if not, write to the Free Software
78 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
80 *******************************************************************************/
85 #include "text_import_scanner.h"
88 * Flex (v 2.5.35) uses this symbol to "exclude" unistd.h
91 # define YY_NO_UNISTD_H
93 /* disable Windows VC compiler warning "signed/unsigned mismatch" associated */
94 /* with YY_INPUT code generated by flex versions such as 2.5.35. */
95 # pragma warning (disable:4018)
99 * Sleazy hack to suppress compiler warnings in yy_fatal_error().
101 #define YY_EXIT_FAILURE ((void)yyscanner, 2)
104 * Macros for the allocators, to discard the extra argument.
106 #define text_import_alloc(size, yyscanner) (void *)malloc(size)
107 #define text_import_realloc(ptr, size, yyscanner) (void *)realloc((char *)(ptr), (size))
108 #define text_import_free(ptr, yyscanner) free((char *)ptr)
113 directive ^#TEXT2PCAP.*\r?\n
114 comment ^[\t ]*#.*\r?\n
115 byte [0-9A-Fa-f][0-9A-Fa-f][ \t]
116 byte_eol [0-9A-Fa-f][0-9A-Fa-f]\r?\n
117 offset [0-9A-Fa-f]+[: \t]
118 offset_eol [0-9A-Fa-f]+\r?\n
125 {byte} { parse_token(T_BYTE, yytext); }
126 {byte_eol} { parse_token(T_BYTE, yytext); parse_token(T_EOL, NULL); }
127 {offset} { parse_token(T_OFFSET, yytext); }
128 {offset_eol} { parse_token(T_OFFSET, yytext); parse_token(T_EOL, NULL); }
129 {mailfwd}{offset} { parse_token(T_OFFSET, yytext+1); }
130 {eol} { parse_token(T_EOL, NULL); }
131 [ \t] ; /* ignore whitespace */
132 {directive} { parse_token(T_DIRECTIVE, yytext); parse_token(T_EOL, NULL); }
133 {comment} { parse_token(T_EOL, NULL); }
134 {text} { parse_token(T_TEXT, yytext); }
136 <<EOF>> { write_current_packet(); yyterminate(); }