4 /* Include this before everything else, for various large-file definitions */
10 * We want a reentrant scanner.
15 * We don't use input, so don't generate code for it.
20 * We don't use unput, so don't generate code for it.
25 * We don't read interactively from the terminal.
27 %option never-interactive
30 * We want to stop processing when we get to the end of the input.
35 * Prefix scanner routines with "text_import_" rather than "yy", so this scanner
36 * can coexist with other scanners.
38 %option prefix="text_import_"
41 * We have to override the memory allocators so that we don't get
42 * "unused argument" warnings from the yyscanner argument (which
43 * we don't use, as we have a global memory allocator).
45 * We provide, as macros, our own versions of the routines generated by Flex,
46 * which just call malloc()/realloc()/free() (as the Flex versions do),
47 * discarding the extra argument.
55 /********************************************************************************
57 * text_import_scanner.l
58 * Scanner for text import
59 * November 2010, Jaap Keuter <jaap.keuter@xs4all.nl>
61 * Wireshark - Network traffic analyzer
62 * By Gerald Combs <gerald@wireshark.org>
63 * Copyright 1998 Gerald Combs
65 * Based on text2pcap-scanner.l by Ashok Narayanan <ashokn@cisco.com>
67 * SPDX-License-Identifier: GPL-2.0-or-later
69 *******************************************************************************/
74 #include "text_import_scanner.h"
77 * Disable diagnostics in the code generated by Flex.
82 * Flex (v 2.5.35) uses this symbol to "exclude" unistd.h
85 # define YY_NO_UNISTD_H
89 * Sleazy hack to suppress compiler warnings in yy_fatal_error().
91 #define YY_EXIT_FAILURE ((void)yyscanner, 2)
94 * Macros for the allocators, to discard the extra argument.
96 #define text_import_alloc(size, yyscanner) (void *)malloc(size)
97 #define text_import_realloc(ptr, size, yyscanner) (void *)realloc((char *)(ptr), (size))
98 #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} { if (parse_token(T_BYTE, yytext) != IMPORT_SUCCESS) return IMPORT_FAILURE; }
115 {byte_eol} { if (parse_token(T_BYTE, yytext) != IMPORT_SUCCESS) return IMPORT_FAILURE;
116 if (parse_token(T_EOL, NULL) != IMPORT_SUCCESS) return IMPORT_FAILURE; }
117 {offset} { if (parse_token(T_OFFSET, yytext) != IMPORT_SUCCESS) return IMPORT_FAILURE; }
118 {offset_eol} { if (parse_token(T_OFFSET, yytext) != IMPORT_SUCCESS) return IMPORT_FAILURE;
119 if (parse_token(T_EOL, NULL) != IMPORT_SUCCESS) return IMPORT_FAILURE; }
120 {mailfwd}{offset} { if (parse_token(T_OFFSET, yytext+1) != IMPORT_SUCCESS) return IMPORT_FAILURE; }
121 {eol} { if (parse_token(T_EOL, NULL) != IMPORT_SUCCESS) return IMPORT_FAILURE; }
122 [ \t] ; /* ignore whitespace */
123 {directive} { if (parse_token(T_DIRECTIVE, yytext) != IMPORT_SUCCESS) return IMPORT_FAILURE;
124 if (parse_token(T_EOL, NULL) != IMPORT_SUCCESS) return IMPORT_FAILURE; }
125 {comment} { if (parse_token(T_EOL, NULL) != IMPORT_SUCCESS) return IMPORT_FAILURE; }
126 {text} { if (parse_token(T_TEXT, yytext) != IMPORT_SUCCESS) return IMPORT_FAILURE; }
128 <<EOF>> { if (parse_token(T_EOF, NULL) != IMPORT_SUCCESS) return IMPORT_FAILURE; yyterminate(); }
133 * Turn diagnostics back on, so we check the code that we've written.
138 text_import_scan(FILE *input_file)
143 if (text_import_lex_init(&scanner) != 0)
144 return IMPORT_INIT_FAILED;
146 text_import_set_in(input_file, scanner);
148 ret = text_import_lex(scanner);
150 text_import_lex_destroy(scanner);