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