TODO netlogon_user_flags_ntlmv2_enabled
[wireshark-sm.git] / ui / text_import_scanner.l
blob0595e9b7d00b803582144469f6f75f638049b355
1 /* -*-mode: flex-*- */
3 %top {
4 /* Include this before everything else, for various large-file definitions */
5 #include "config.h"
6 #include <wireshark.h>
9 /*
10  * We want a reentrant scanner.
11  */
12 %option reentrant
15  * We don't use input, so don't generate code for it.
16  */
17 %option noinput
20  * We don't use unput, so don't generate code for it.
21  */
22 %option nounput
25  * We don't read interactively from the terminal.
26  */
27 %option never-interactive
30  * We want to stop processing when we get to the end of the input.
31  */
32 %option noyywrap
35  * Prefix scanner routines with "text_import_" rather than "yy", so this scanner
36  * can coexist with other scanners.
37  */
38 %option prefix="text_import_"
41  * We have to override the memory allocators so that we don't get
42  * "unused argument" warnings from the yyscanner argument (which
43  * we don't use, as we have a global memory allocator).
44  *
45  * We provide, as macros, our own versions of the routines generated by Flex,
46  * which just call malloc()/realloc()/free() (as the Flex versions do),
47  * discarding the extra argument.
48  */
49 %option noyyalloc
50 %option noyyrealloc
51 %option noyyfree
55 /********************************************************************************
56  *
57  * text_import_scanner.l
58  * Scanner for text import
59  * November 2010, Jaap Keuter <jaap.keuter@xs4all.nl>
60  *
61  * Wireshark - Network traffic analyzer
62  * By Gerald Combs <gerald@wireshark.org>
63  * Copyright 1998 Gerald Combs
64  *
65  * Based on text2pcap-scanner.l by Ashok Narayanan <ashokn@cisco.com>
66  *
67  * SPDX-License-Identifier: GPL-2.0-or-later
68  *
69  *******************************************************************************/
71 #include <stdio.h>
72 #include <stdlib.h>
74 #include "text_import_scanner.h"
77  * Disable diagnostics in the code generated by Flex.
78  */
79 DIAG_OFF_FLEX()
82  * Flex (v 2.5.35) uses this symbol to "exclude" unistd.h
83  */
84 #ifdef _WIN32
85 #  define YY_NO_UNISTD_H
86 #endif
89  * Sleazy hack to suppress compiler warnings in yy_fatal_error().
90  */
91 #define YY_EXIT_FAILURE ((void)yyscanner, 2)
94  * Macros for the allocators, to discard the extra argument.
95  */
96 #define text_import_alloc(size, yyscanner)              (void *)malloc(size)
97 #define text_import_realloc(ptr, size, yyscanner)       (void *)realloc((char *)(ptr), (size))
98 #define text_import_free(ptr, yyscanner)                free((char *)ptr)
102 directive ^#TEXT2PCAP.*\r?\n
103 comment ^[\t ]*#.*\r?\n
104 byte [[:xdigit:]]{2}
105 offset (0[xX])?[[:xdigit:]]{3,8}:?
106 text [^ \r\n\t]+
107 mailfwd >
108 mailspace [> \t]
109 eol \r?\n\r?
113 {byte}            { if (parse_token(T_BYTE, yytext) != IMPORT_SUCCESS) return IMPORT_FAILURE; }
114 {byte}{2,4}       { if (parse_token(T_BYTES, yytext) != IMPORT_SUCCESS) return IMPORT_FAILURE; }
115 {offset}          { if (parse_token(T_OFFSET, yytext) != IMPORT_SUCCESS) return IMPORT_FAILURE; }
116 {mailfwd}+{offset} {
117         /* Handle the case where no blanks are between mailfwd and offset */
118         if (parse_token(T_OFFSET, yytext + strspn(yytext, ">")) != IMPORT_SUCCESS) return IMPORT_FAILURE;
120 {eol}             { if (parse_token(T_EOL, NULL) != IMPORT_SUCCESS) return IMPORT_FAILURE; }
121 ^{mailspace}+     ; /* ignore mailfwd characters (incl. separated by space) at line start */
122 [ \t]             ; /* ignore whitespace */
123 {directive}       { if (parse_token(T_DIRECTIVE, yytext) != IMPORT_SUCCESS) return IMPORT_FAILURE;
124         if (parse_token(T_EOL, NULL) != IMPORT_SUCCESS) return IMPORT_FAILURE; }
125 {comment}         { if (parse_token(T_EOL, NULL) != IMPORT_SUCCESS) return IMPORT_FAILURE; }
126 {text}            { if (parse_token(T_TEXT, yytext) != IMPORT_SUCCESS) return IMPORT_FAILURE; }
128 <<EOF>>           { if (parse_token(T_EOF, NULL) != IMPORT_SUCCESS) return IMPORT_FAILURE; yyterminate(); }
133  * Turn diagnostics back on, so we check the code that we've written.
134  */
135 DIAG_ON_FLEX()
137 import_status_t
138 text_import_scan(FILE *input_file)
140     yyscan_t scanner;
141     int ret;
143     if (text_import_lex_init(&scanner) != 0)
144         return IMPORT_INIT_FAILED;
146     text_import_set_in(input_file, scanner);
148     ret = text_import_lex(scanner);
150     text_import_lex_destroy(scanner);
152     return ret;