4 /* Include this before everything else, for various large-file definitions */
9 * We don't use input, so don't generate code for it.
14 * We don't use unput, so don't generate code for it.
19 * We don't read interactively from the terminal.
21 %option never-interactive
24 * We want to stop processing when we get to the end of the input.
29 * Prefix scanner routines with "text2pcap_" rather than "yy" to avoid a
30 * "redefined macro" warning with flex 2.6.3.
32 %option prefix="text2pcap_"
36 /********************************************************************************
40 * Utility to convert an ASCII hexdump into a libpcap-format capture file
42 * (c) Copyright 2001 Ashok Narayanan <ashokn@cisco.com>
44 * Wireshark - Network traffic analyzer
45 * By Gerald Combs <gerald@wireshark.org>
46 * Copyright 1998 Gerald Combs
48 * SPDX-License-Identifier: GPL-2.0-or-later
50 *******************************************************************************/
55 #include "text2pcap.h"
58 * Disable diagnostics in the code generated by Flex.
63 * Flex (v 2.5.35) uses this symbol to "exclude" unistd.h
66 #define YY_NO_UNISTD_H
71 directive ^#TEXT2PCAP.*\r?\n
72 comment ^[\t ]*#.*\r?\n
73 byte [0-9A-Fa-f][0-9A-Fa-f][ \t]?
74 byte_eol [0-9A-Fa-f][0-9A-Fa-f]\r?\n
75 offset [0-9A-Fa-f]+[: \t]
76 offset_eol [0-9A-Fa-f]+\r?\n
83 {byte} { if (parse_token(T_BYTE, yytext) != EXIT_SUCCESS) return EXIT_FAILURE; }
84 {byte_eol} { if (parse_token(T_BYTE, yytext) != EXIT_SUCCESS) return EXIT_FAILURE;
85 if (parse_token(T_EOL, NULL) != EXIT_SUCCESS) return EXIT_FAILURE; }
86 {offset} { if (parse_token(T_OFFSET, yytext) != EXIT_SUCCESS) return EXIT_FAILURE; }
87 {offset_eol} { if (parse_token(T_OFFSET, yytext) != EXIT_SUCCESS) return EXIT_FAILURE;
88 if (parse_token(T_EOL, NULL) != EXIT_SUCCESS) return EXIT_FAILURE; }
89 {mailfwd}{offset} { if (parse_token(T_OFFSET, yytext+1) != EXIT_SUCCESS) return EXIT_FAILURE; }
90 {eol} { if (parse_token(T_EOL, NULL) != EXIT_SUCCESS) return EXIT_FAILURE; }
91 [ \t] ; /* ignore whitespace */
92 {directive} { if (parse_token(T_DIRECTIVE, yytext) != EXIT_SUCCESS) return EXIT_FAILURE;
93 if (parse_token(T_EOL, NULL) != EXIT_SUCCESS) return EXIT_FAILURE; }
94 {comment} { if (parse_token(T_EOL, NULL) != EXIT_SUCCESS) return EXIT_FAILURE; }
95 {text} { if (parse_token(T_TEXT, yytext) != EXIT_SUCCESS) return EXIT_FAILURE; }
100 * Turn diagnostics back on, so we check the code that we've written.
109 ret = text2pcap_lex();
110 text2pcap_lex_destroy();