2012-09-14 20:23:18 +00:00
|
|
|
/* -*-mode: flex-*- */
|
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
/*
|
|
|
|
* We want a reentrant scanner.
|
|
|
|
*/
|
|
|
|
%option reentrant
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We don't use input, so don't generate code for it.
|
|
|
|
*/
|
|
|
|
%option noinput
|
|
|
|
|
2012-09-14 20:23:18 +00:00
|
|
|
/*
|
|
|
|
* We don't use unput, so don't generate code for it.
|
|
|
|
*/
|
2016-03-31 01:44:01 +00:00
|
|
|
%option nounput
|
2012-09-14 20:23:18 +00:00
|
|
|
|
|
|
|
/*
|
2015-11-05 23:35:04 +00:00
|
|
|
* We don't read interactively from the terminal.
|
2012-09-14 20:23:18 +00:00
|
|
|
*/
|
|
|
|
%option never-interactive
|
|
|
|
|
2015-12-05 03:52:51 +00:00
|
|
|
/*
|
|
|
|
* We want to stop processing when we get to the end of the input.
|
|
|
|
*/
|
|
|
|
%option noyywrap
|
|
|
|
|
2012-09-14 20:23:18 +00:00
|
|
|
/*
|
2016-03-31 01:44:01 +00:00
|
|
|
* Prefix scanner routines with "text_import_" rather than "yy", so this scanner
|
2012-09-14 20:23:18 +00:00
|
|
|
* can coexist with other scanners.
|
|
|
|
*/
|
2016-03-31 01:44:01 +00:00
|
|
|
%option prefix="text_import_"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We have to override the memory allocators so that we don't get
|
|
|
|
* "unused argument" warnings from the yyscanner argument (which
|
|
|
|
* we don't use, as we have a global memory allocator).
|
|
|
|
*
|
|
|
|
* We provide, as macros, our own versions of the routines generated by Flex,
|
|
|
|
* which just call malloc()/realloc()/free() (as the Flex versions do),
|
|
|
|
* discarding the extra argument.
|
|
|
|
*/
|
|
|
|
%option noyyalloc
|
|
|
|
%option noyyrealloc
|
|
|
|
%option noyyfree
|
2012-09-14 20:23:18 +00:00
|
|
|
|
|
|
|
%{
|
|
|
|
|
|
|
|
/********************************************************************************
|
|
|
|
*
|
|
|
|
* text_import_scanner.l
|
|
|
|
* Scanner for text import
|
|
|
|
* November 2010, Jaap Keuter <jaap.keuter@xs4all.nl>
|
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* Based on text2pcap-scanner.l by Ashok Narayanan <ashokn@cisco.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2013-12-04 07:39:37 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-09-14 20:23:18 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "text_import_scanner.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Flex (v 2.5.35) uses this symbol to "exclude" unistd.h
|
|
|
|
*/
|
|
|
|
#ifdef _WIN32
|
2013-12-04 07:39:37 +00:00
|
|
|
# define YY_NO_UNISTD_H
|
2012-09-14 20:23:18 +00:00
|
|
|
|
2013-12-04 07:39:37 +00:00
|
|
|
/* disable Windows VC compiler warning "signed/unsigned mismatch" associated */
|
|
|
|
/* with YY_INPUT code generated by flex versions such as 2.5.35. */
|
|
|
|
# pragma warning (disable:4018)
|
2012-09-14 20:23:18 +00:00
|
|
|
#endif
|
|
|
|
|
2016-03-31 01:44:01 +00:00
|
|
|
/*
|
|
|
|
* Sleazy hack to suppress compiler warnings in yy_fatal_error().
|
|
|
|
*/
|
|
|
|
#define YY_EXIT_FAILURE ((void)yyscanner, 2)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Macros for the allocators, to discard the extra argument.
|
|
|
|
*/
|
|
|
|
#define text_import_alloc(size, yyscanner) (void *)malloc(size)
|
|
|
|
#define text_import_realloc(ptr, size, yyscanner) (void *)realloc((char *)(ptr), (size))
|
|
|
|
#define text_import_free(ptr, yyscanner) free((char *)ptr)
|
|
|
|
|
2012-09-14 20:23:18 +00:00
|
|
|
%}
|
|
|
|
|
|
|
|
hexdigit [0-9A-Fa-f]
|
2016-01-14 15:55:51 +00:00
|
|
|
directive ^#TEXT2PCAP.*\r?\n
|
|
|
|
comment ^[\t ]*#.*\r?\n
|
2012-09-14 20:23:18 +00:00
|
|
|
byte [0-9A-Fa-f][0-9A-Fa-f][ \t]
|
|
|
|
byte_eol [0-9A-Fa-f][0-9A-Fa-f]\r?\n
|
|
|
|
offset [0-9A-Fa-f]+[: \t]
|
|
|
|
offset_eol [0-9A-Fa-f]+\r?\n
|
|
|
|
text [^ \n\t]+
|
|
|
|
mailfwd >
|
|
|
|
eol \r?\n\r?
|
|
|
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
{byte} { parse_token(T_BYTE, yytext); }
|
|
|
|
{byte_eol} { parse_token(T_BYTE, yytext); parse_token(T_EOL, NULL); }
|
|
|
|
{offset} { parse_token(T_OFFSET, yytext); }
|
|
|
|
{offset_eol} { parse_token(T_OFFSET, yytext); parse_token(T_EOL, NULL); }
|
|
|
|
{mailfwd}{offset} { parse_token(T_OFFSET, yytext+1); }
|
|
|
|
{eol} { parse_token(T_EOL, NULL); }
|
|
|
|
[ \t] ; /* ignore whitespace */
|
2016-01-14 15:55:51 +00:00
|
|
|
{directive} { parse_token(T_DIRECTIVE, yytext); parse_token(T_EOL, NULL); }
|
|
|
|
{comment} { parse_token(T_EOL, NULL); }
|
2012-09-14 20:23:18 +00:00
|
|
|
{text} { parse_token(T_TEXT, yytext); }
|
|
|
|
|
|
|
|
<<EOF>> { write_current_packet(); yyterminate(); }
|