epan: use SPDX indentifiers.
[metze/wireshark/wip.git] / text2pcap-scanner.l
1 /* -*-mode: flex-*- */
2
3 %top {
4 /* Include this before everything else, for various large-file definitions */
5 #include "config.h"
6 }
7
8 /*
9  * We don't use input, so don't generate code for it.
10  */
11 %option noinput
12
13 /*
14  * We don't use unput, so don't generate code for it.
15  */
16 %option nounput
17
18 /*
19  * We don't read interactively from the terminal.
20  */
21 %option never-interactive
22
23 /*
24  * We want to stop processing when we get to the end of the input.
25  */
26 %option noyywrap
27
28 /*
29  * Prefix scanner routines with "text2pcap_" rather than "yy" to avoid a
30  * "redefined macro" warning with flex 2.6.3.
31  */
32 %option prefix="text2pcap_"
33
34 %{
35
36 /********************************************************************************
37  *
38  * text2pcap-scanner.l
39  *
40  * Utility to convert an ASCII hexdump into a libpcap-format capture file
41  *
42  * (c) Copyright 2001 Ashok Narayanan <ashokn@cisco.com>
43  *
44  * Wireshark - Network traffic analyzer
45  * By Gerald Combs <gerald@wireshark.org>
46  * Copyright 1998 Gerald Combs
47  *
48  * This program is free software; you can redistribute it and/or
49  * modify it under the terms of the GNU General Public License
50  * as published by the Free Software Foundation; either version 2
51  * of the License, or (at your option) any later version.
52  *
53  * This program is distributed in the hope that it will be useful,
54  * but WITHOUT ANY WARRANTY; without even the implied warranty of
55  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
56  * GNU General Public License for more details.
57  *
58  * You should have received a copy of the GNU General Public License
59  * along with this program; if not, write to the Free Software
60  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
61  *
62  *******************************************************************************/
63
64 #include <stdio.h>
65 #include <stdlib.h>
66
67 #include "text2pcap.h"
68
69 DIAG_OFF(sign-compare)
70
71 /*
72  * Flex (v 2.5.35) uses this symbol to "exclude" unistd.h
73  */
74 #ifdef _WIN32
75 #define YY_NO_UNISTD_H
76 #endif
77
78 #ifdef _WIN32
79 /* disable Windows VC compiler warning "signed/unsigned mismatch" associated  */
80 /* with YY_INPUT code generated by flex versions such as 2.5.35.              */
81 #pragma warning (disable:4018)
82 #endif
83
84 %}
85
86 hexdigit [0-9A-Fa-f]
87 directive ^#TEXT2PCAP.*\r?\n
88 comment ^[\t ]*#.*\r?\n
89 byte [0-9A-Fa-f][0-9A-Fa-f][ \t]
90 byte_eol [0-9A-Fa-f][0-9A-Fa-f]\r?\n
91 offset [0-9A-Fa-f]+[: \t]
92 offset_eol [0-9A-Fa-f]+\r?\n
93 text [^ \n\t]+
94 mailfwd >
95 eol \r?\n\r?
96
97 %%
98
99 {byte}            { if (parse_token(T_BYTE, yytext) != EXIT_SUCCESS) return EXIT_FAILURE; }
100 {byte_eol}        { if (parse_token(T_BYTE, yytext) != EXIT_SUCCESS) return EXIT_FAILURE;
101         if (parse_token(T_EOL, NULL) != EXIT_SUCCESS) return EXIT_FAILURE; }
102 {offset}          { if (parse_token(T_OFFSET, yytext) != EXIT_SUCCESS) return EXIT_FAILURE; }
103 {offset_eol}      { if (parse_token(T_OFFSET, yytext) != EXIT_SUCCESS) return EXIT_FAILURE;
104         if (parse_token(T_EOL, NULL) != EXIT_SUCCESS) return EXIT_FAILURE; }
105 {mailfwd}{offset} { if (parse_token(T_OFFSET, yytext+1) != EXIT_SUCCESS) return EXIT_FAILURE; }
106 {eol}             { if (parse_token(T_EOL, NULL) != EXIT_SUCCESS) return EXIT_FAILURE; }
107 [ \t]             ; /* ignore whitespace */
108 {directive}       { if (parse_token(T_DIRECTIVE, yytext) != EXIT_SUCCESS) return EXIT_FAILURE;
109         if (parse_token(T_EOL, NULL) != EXIT_SUCCESS) return EXIT_FAILURE; }
110 {comment}         { if (parse_token(T_EOL, NULL) != EXIT_SUCCESS) return EXIT_FAILURE; }
111 {text}            { if (parse_token(T_TEXT, yytext) != EXIT_SUCCESS) return EXIT_FAILURE; }