6b0b716f4555389c8f39551d46cd99cd361350aa
[obnox/wireshark/wip.git] / text2pcap-scanner.l
1 /* -*-mode: flex-*- */
2
3 /*
4  * We don't use unput, so don't generate code for it.
5  */
6 %option nounput
7
8 %{
9     
10 /********************************************************************************
11  *
12  * text2pcap-scanner.l
13  *
14  * Utility to convert an ASCII hexdump into a libpcap-format capture file
15  *
16  * (c) Copyright 2001 Ashok Narayanan <ashokn@cisco.com>
17  *
18  * $Id$
19  * 
20  * Wireshark - Network traffic analyzer
21  * By Gerald Combs <gerald@wireshark.org>
22  * Copyright 1998 Gerald Combs
23  * 
24  * This program is free software; you can redistribute it and/or
25  * modify it under the terms of the GNU General Public License
26  * as published by the Free Software Foundation; either version 2
27  * of the License, or (at your option) any later version.
28  * 
29  * This program is distributed in the hope that it will be useful,
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32  * GNU General Public License for more details.
33  * 
34  * You should have received a copy of the GNU General Public License
35  * along with this program; if not, write to the Free Software
36  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
37  *
38  *******************************************************************************/
39     
40 #include <stdio.h>
41 #include <stdlib.h>
42
43 #include "text2pcap.h"
44     
45 %}
46
47 hexdigit [0-9A-Fa-f]
48 directive #TEXT2PCAP.*
49 comment #[^W].*
50 byte [0-9A-Fa-f][0-9A-Fa-f][ \t]
51 byte_eol [0-9A-Fa-f][0-9A-Fa-f]\n
52 offset [0-9A-Fa-f]+[: \t]
53 offset_eol [0-9A-Fa-f]+\n
54 text [^ \n\t]+
55 mailfwd >
56 eol \r?\n\r?
57
58 %%
59
60 {byte}            { parse_token(T_BYTE, yytext); }
61 {byte_eol}        { parse_token(T_BYTE, yytext); parse_token(T_EOL, NULL); }
62 {offset}          { parse_token(T_OFFSET, yytext); }
63 {offset_eol}      { parse_token(T_OFFSET, yytext); parse_token(T_EOL, NULL); }
64 {mailfwd}{offset} { parse_token(T_OFFSET, yytext+1); }
65 {eol}             { parse_token(T_EOL, NULL); }
66 [ \t]             ; /* ignore whitespace */
67 {directive}       { parse_token(T_DIRECTIVE, yytext); }
68 {comment}         ; /* ignore comments */
69 {text}            { parse_token(T_TEXT, yytext); }
70
71 %%
72
73 int yywrap()
74 {
75     return 1;
76 }