- Include config.h
[metze/wireshark/wip.git] / ui / text_import_scanner.l
1 /* -*-mode: flex-*- */
2
3 /*
4  * We don't use unput, so don't generate code for it.
5  */
6 %option nounput noinput
7
8 /*
9  * We don't read from the terminal.
10  */
11 %option never-interactive
12
13 /*
14  * Prefix scanner routines with "text_import" rather than "yy", so this scanner
15  * can coexist with other scanners.
16  */
17 %option prefix="text_import"
18
19 %{
20
21 /********************************************************************************
22  *
23  * text_import_scanner.l
24  * Scanner for text import
25  * November 2010, Jaap Keuter <jaap.keuter@xs4all.nl>
26  *
27  * $Id$
28  *
29  * Wireshark - Network traffic analyzer
30  * By Gerald Combs <gerald@wireshark.org>
31  * Copyright 1998 Gerald Combs
32  *
33  * Based on text2pcap-scanner.l by Ashok Narayanan <ashokn@cisco.com>
34  *
35  * This program is free software; you can redistribute it and/or
36  * modify it under the terms of the GNU General Public License
37  * as published by the Free Software Foundation; either version 2
38  * of the License, or (at your option) any later version.
39  *
40  * This program is distributed in the hope that it will be useful,
41  * but WITHOUT ANY WARRANTY; without even the implied warranty of
42  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
43  * GNU General Public License for more details.
44  *
45  * You should have received a copy of the GNU General Public License
46  * along with this program; if not, write to the Free Software
47  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
48  *
49  *******************************************************************************/
50
51 #include "config.h"
52
53 #include <stdio.h>
54 #include <stdlib.h>
55
56 #include "text_import_scanner.h"
57 #include "text_import_scanner_lex.h"
58
59 /*
60  * Flex (v 2.5.35) uses this symbol to "exclude" unistd.h
61  */
62 #ifdef _WIN32
63 #  define YY_NO_UNISTD_H
64
65    /* disable Windows VC compiler warning "signed/unsigned mismatch" associated  */
66    /* with YY_INPUT code generated by flex versions such as 2.5.35.              */
67 #  pragma warning (disable:4018)
68 #endif
69
70 %}
71
72 hexdigit [0-9A-Fa-f]
73 directive #TEXT2PCAP.*
74 comment #[^W].*
75 byte [0-9A-Fa-f][0-9A-Fa-f][ \t]
76 byte_eol [0-9A-Fa-f][0-9A-Fa-f]\r?\n
77 offset [0-9A-Fa-f]+[: \t]
78 offset_eol [0-9A-Fa-f]+\r?\n
79 text [^ \n\t]+
80 mailfwd >
81 eol \r?\n\r?
82
83 %%
84
85 {byte}            { parse_token(T_BYTE, yytext); }
86 {byte_eol}        { parse_token(T_BYTE, yytext); parse_token(T_EOL, NULL); }
87 {offset}          { parse_token(T_OFFSET, yytext); }
88 {offset_eol}      { parse_token(T_OFFSET, yytext); parse_token(T_EOL, NULL); }
89 {mailfwd}{offset} { parse_token(T_OFFSET, yytext+1); }
90 {eol}             { parse_token(T_EOL, NULL); }
91 [ \t]             ; /* ignore whitespace */
92 {directive}       { parse_token(T_DIRECTIVE, yytext); }
93 {comment}         ; /* ignore comments */
94 {text}            { parse_token(T_TEXT, yytext); }
95
96 <<EOF>>           { write_current_packet(); yyterminate(); }
97
98 %%
99 int yywrap(void)
100 {
101     return 1;
102 }