epan/dissectors/packet-xml.c try to decrypt data, but the data doesn't look correct yet
[metze/wireshark/wip.git] / ui / text_import_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 want a reentrant scanner.
10  */
11 %option reentrant
12
13 /*
14  * We don't use input, so don't generate code for it.
15  */
16 %option noinput
17
18 /*
19  * We don't use unput, so don't generate code for it.
20  */
21 %option nounput
22
23 /*
24  * We don't read interactively from the terminal.
25  */
26 %option never-interactive
27
28 /*
29  * We want to stop processing when we get to the end of the input.
30  */
31 %option noyywrap
32
33 /*
34  * Prefix scanner routines with "text_import_" rather than "yy", so this scanner
35  * can coexist with other scanners.
36  */
37 %option prefix="text_import_"
38
39 /*
40  * We have to override the memory allocators so that we don't get
41  * "unused argument" warnings from the yyscanner argument (which
42  * we don't use, as we have a global memory allocator).
43  *
44  * We provide, as macros, our own versions of the routines generated by Flex,
45  * which just call malloc()/realloc()/free() (as the Flex versions do),
46  * discarding the extra argument.
47  */
48 %option noyyalloc
49 %option noyyrealloc
50 %option noyyfree
51
52 %{
53
54 /********************************************************************************
55  *
56  * text_import_scanner.l
57  * Scanner for text import
58  * November 2010, Jaap Keuter <jaap.keuter@xs4all.nl>
59  *
60  * Wireshark - Network traffic analyzer
61  * By Gerald Combs <gerald@wireshark.org>
62  * Copyright 1998 Gerald Combs
63  *
64  * Based on text2pcap-scanner.l by Ashok Narayanan <ashokn@cisco.com>
65  *
66  * SPDX-License-Identifier: GPL-2.0-or-later
67  *
68  *******************************************************************************/
69
70 #include <stdio.h>
71 #include <stdlib.h>
72
73 #include "text_import_scanner.h"
74
75 /*
76  * Disable diagnostics in the code generated by Flex.
77  */
78 DIAG_OFF_FLEX
79
80 /*
81  * Flex (v 2.5.35) uses this symbol to "exclude" unistd.h
82  */
83 #ifdef _WIN32
84 #  define YY_NO_UNISTD_H
85 #endif
86
87 /*
88  * Sleazy hack to suppress compiler warnings in yy_fatal_error().
89  */
90 #define YY_EXIT_FAILURE ((void)yyscanner, 2)
91
92 /*
93  * Macros for the allocators, to discard the extra argument.
94  */
95 #define text_import_alloc(size, yyscanner)              (void *)malloc(size)
96 #define text_import_realloc(ptr, size, yyscanner)       (void *)realloc((char *)(ptr), (size))
97 #define text_import_free(ptr, yyscanner)                free((char *)ptr)
98
99 %}
100
101 hexdigit [0-9A-Fa-f]
102 directive ^#TEXT2PCAP.*\r?\n
103 comment ^[\t ]*#.*\r?\n
104 byte [0-9A-Fa-f][0-9A-Fa-f][ \t]
105 byte_eol [0-9A-Fa-f][0-9A-Fa-f]\r?\n
106 offset [0-9A-Fa-f]+[: \t]
107 offset_eol [0-9A-Fa-f]+\r?\n
108 text [^ \n\t]+
109 mailfwd >
110 eol \r?\n\r?
111
112 %%
113
114 {byte}            { parse_token(T_BYTE, yytext); }
115 {byte_eol}        { parse_token(T_BYTE, yytext); parse_token(T_EOL, NULL); }
116 {offset}          { parse_token(T_OFFSET, yytext); }
117 {offset_eol}      { parse_token(T_OFFSET, yytext); parse_token(T_EOL, NULL); }
118 {mailfwd}{offset} { parse_token(T_OFFSET, yytext+1); }
119 {eol}             { parse_token(T_EOL, NULL); }
120 [ \t]             ; /* ignore whitespace */
121 {directive}       { parse_token(T_DIRECTIVE, yytext); parse_token(T_EOL, NULL); }
122 {comment}         { parse_token(T_EOL, NULL); }
123 {text}            { parse_token(T_TEXT, yytext); }
124
125 <<EOF>>           { write_current_packet(); yyterminate(); }
126
127 %%
128
129 /*
130  * Turn diagnostics back on, so we check the code that we've written.
131  */
132 DIAG_ON_FLEX
133
134 int
135 text_import_scan(FILE *input_file)
136 {
137     yyscan_t scanner;
138
139     if (text_import_lex_init(&scanner) != 0)
140         return errno;
141
142     text_import_set_in(input_file, scanner);
143
144     text_import_lex(scanner);
145
146     text_import_lex_destroy(scanner);
147
148     return 0;
149 }