4 * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
6 * Support for candump log file format
7 * Copyright (c) 2019 by Maksim Salau <maksim.salau@gmail.com>
9 * SPDX-License-Identifier: GPL-2.0-or-later
13 /* Include this before everything else, for various large-file definitions */
15 #include <wireshark.h>
23 %option never-interactive
24 %option prefix="candump_"
25 %option extra-type="candump_state_t *"
29 %option noyy_scan_buffer
30 %option noyy_scan_bytes
31 %option noyy_scan_string
34 * We have to override the memory allocators so that we don't get
35 * "unused argument" warnings from the yyscanner argument (which
36 * we don't use, as we have a global memory allocator).
38 * We provide, as macros, our own versions of the routines generated by Flex,
39 * which just call malloc()/realloc()/free() (as the Flex versions do),
40 * discarding the extra argument.
48 #include <ws_diag_control.h>
49 #include <wiretap/file_wrappers.h>
50 #include "candump_parser.h"
51 #include "candump_priv.h"
54 #define YY_NO_UNISTD_H
57 static int candump_yyinput(void *buf, candump_state_t *state)
59 int c = file_getc(state->fh);
63 state->err = file_error(state->fh, &state->err_info);
72 #define YY_INPUT(buf, result, max_size) \
73 do { (result) = candump_yyinput((buf), yyextra); } while (0)
75 /* Count bytes read. This is required in order to rewind the file
76 * to the beginning of the next packet, since flex reads more bytes
77 * before executing the action that does yyterminate(). */
78 #define YY_USER_ACTION do { yyextra->file_bytes_read += yyleng; } while (0);
81 * Sleazy hack to suppress compiler warnings in yy_fatal_error().
83 #define YY_EXIT_FAILURE ((void)yyscanner, 2)
86 * Macros for the allocators, to discard the extra argument.
88 #define candump_alloc(size, yyscanner) (void *)malloc(size)
89 #define candump_realloc(ptr, size, yyscanner) (void *)realloc((char *)(ptr), (size))
90 #define candump_free(ptr, yyscanner) free((char *)(ptr))
101 [ \t] { return TOKEN_SPACE; };
102 [\r\n][ \t\r\n]* { yyterminate(); }
105 yyextra->token.v0 = strtoul(yytext + 1, NULL, 10);
106 yyextra->token.v1 = strtoul(strchr(yytext, '.') + 1, NULL, 10);
107 return TOKEN_TIMESTAMP;
111 yyextra->token.v0 = strtoul(yytext + 1, NULL, 10);
116 yyextra->token.v0 = 0;
121 yyextra->token.v0 = strtoul(yytext, NULL, 16);
126 yyextra->token.v0 = strtoul(yytext, NULL, 16);
131 yyextra->token.v0 = strtoul(yytext, NULL, 16);
136 yyextra->token.v0 = strtoul(yytext + 1, NULL, 16);
140 . { return TOKEN_UNKNOWN; }