2 * We want to stop processing when we get to the end of the input.
7 * We don't use unput, so don't generate code for it.
12 * We don't read from the terminal.
14 %option never-interactive
17 * Prefix scanner routines with "uat_load_" rather than "yy", so this scanner
18 * can coexist with other scanners.
20 %option prefix="uat_load_"
28 * User Accessible Tables
29 * Mantain an array of user accessible data strucures
30 * One parser to fit them all
32 * (c) 2007, Luis E. Garcia Ontanon <luis.ontanon@gmail.com>
34 * Wireshark - Network traffic analyzer
35 * By Gerald Combs <gerald@wireshark.org>
36 * Copyright 2001 Gerald Combs
38 * This program is free software; you can redistribute it and/or
39 * modify it under the terms of the GNU General Public License
40 * as published by the Free Software Foundation; either version 2
41 * of the License, or (at your option) any later version.
43 * This program is distributed in the hope that it will be useful,
44 * but WITHOUT ANY WARRANTY; without even the implied warranty of
45 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46 * GNU General Public License for more details.
48 * You should have received a copy of the GNU General Public License
49 * along with this program; if not, write to the Free Software
50 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
64 #include <epan/emem.h>
75 #define ERROR(fmtd) do { error = ep_strdup_printf("%s:%d: %s",uat->filename,linenum,ep_strdup_printf fmtd); yyterminate(); } while(0)
79 if (uat->fields[colnum].cb.chk) { \
80 if ( ! uat->fields[colnum].cb.chk(record, ptr, len, uat->fields[colnum].cbdata.chk, uat->fields[colnum].fld_data, &err) ) { \
84 uat->fields[colnum].cb.set(record, ptr, len, uat->fields[colnum].cbdata.chk, uat->fields[colnum].fld_data);\
90 #define DUMP_FIELD(str) \
91 { guint i; printf("%s: %s='",str,uat->fields[colnum].name); for(i=0;i<len;i++) if (uat->fields[colnum].mode == PT_TXTMOD_HEXBYTES) { printf("%.2x ",((guint8*)ptr)[i]); } else putc(ptr[i],stdout); printf("'[%d]\n",len); }
93 #define DUMP(str) printf("%s\n",str)
100 * quoted_string below fails badly on "...\\"
101 * workarround in uat_save(), using /x5c and /x22
105 quoted_string \042([^\042]|\134\042)*\042
106 binstring ([0-9a-zA-Z][0-9a-zA-Z])*
108 newline [ \t]*[\r]?\n
112 %x START_OF_LINE NEXT_FIELD SEPARATOR END_OF_RECORD ERRORED
114 <START_OF_LINE,NEXT_FIELD>{ws} ;
115 <START_OF_LINE>{newline} linenum++;
116 <START_OF_LINE>{comment} linenum++;
118 <START_OF_LINE,NEXT_FIELD>{separator} {
122 DUMP_FIELD("empty->next");
126 if ( colnum >= uat->ncols ) {
127 ERROR(("more fields than required"));
133 <START_OF_LINE,NEXT_FIELD>{newline} {
142 <START_OF_LINE,NEXT_FIELD>{quoted_string} {
143 ptr = uat_undquote(yytext,yyleng,&len);
146 if (colnum < uat->ncols - 1) {
147 DUMP("quoted_str->s");
150 DUMP("quoted_str->eor");
155 <START_OF_LINE,NEXT_FIELD>{binstring} {
156 ptr = uat_unbinstring(yytext,yyleng,&len);
159 ERROR(("uneven hexstring for field %s",uat->fields[colnum].name));
162 if ( colnum < uat->ncols - 1 ) {
163 DUMP("binstring->s");
166 DUMP("binstring->eor");
171 <SEPARATOR>{separator} {
173 DUMP_FIELD("separator->next");
177 if ( colnum >= uat->ncols ) {
178 ERROR(("more fields than required"));
184 <SEPARATOR>{newline} {
186 ERROR(("expecting field %s in previuos line",uat->fields[colnum].name));
191 ERROR(("unexpected char '%s' while looking for field %s",yytext,uat->fields[colnum].name));
195 <END_OF_RECORD>{separator} {
196 ERROR(("more fields than required"));
200 <END_OF_RECORD>{newline} {
202 const gchar* err = NULL;
206 DUMP_FIELD("newline->start");
210 rec = uat_add_record(uat, record);
213 uat->update_cb(rec,&err);
222 memset(record,0,uat->record_size);
228 ERROR(("unexpected char while looking for end of line"));
232 <ERRORED>{newline} { linenum++; BEGIN START_OF_LINE; }
235 {newline} { linenum++; ERROR(("incomplete record")); BEGIN START_OF_LINE; }
236 . { ERROR(("unexpected input")); }
243 gboolean uat_load(uat_t* uat_in, char** err) {
244 gchar* fname = uat_get_actual_filename(uat_in, FALSE);
254 if (!(yyin = fopen(fname,"r"))) {
255 *err = strerror(errno);
261 record = g_malloc0(uat->record_size);
270 uat->changed = FALSE;
274 *err = ep_strdup(error);