summaryrefslogtreecommitdiff
path: root/epan/uat_load.l
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2008-02-15 22:36:24 +0000
committerGerald Combs <gerald@wireshark.org>2008-02-15 22:36:24 +0000
commit6537c76fb62d583eb5f98308c15ae31c1712a31a (patch)
tree8865e9d95e6828e9a2ca528a96d3c7d08ff80943 /epan/uat_load.l
parenteba80d5c38f495d1943355f8f5a439c1ab3d99d0 (diff)
downloadwireshark-6537c76fb62d583eb5f98308c15ae31c1712a31a.tar.gz
Extend the UAT and preferences code so that you can use the "-o" flag
to override UAT entries from the command line, e.g. -o "uat:user_dlts:\"User 0 (DLT=147)\",\"http\",\"0\",\"\",\"0\",\"\"" Fix up white space. svn path=/trunk/; revision=24338
Diffstat (limited to 'epan/uat_load.l')
-rw-r--r--epan/uat_load.l66
1 files changed, 66 insertions, 0 deletions
diff --git a/epan/uat_load.l b/epan/uat_load.l
index f5422e4cec..42593998d9 100644
--- a/epan/uat_load.l
+++ b/epan/uat_load.l
@@ -73,6 +73,8 @@
static gchar* error;
static void* record;
static guint linenum;
+ static gchar *parse_str;
+ static guint parse_str_pos;
#define ERROR(fmtd) do { error = ep_strdup_printf("%s:%d: %s",uat->filename,linenum,ep_strdup_printf fmtd); yyterminate(); } while(0)
@@ -97,6 +99,37 @@
#define DUMP_FIELD(s)
#define DUMP(s)
#endif
+
+/* Modified version of YY_INPUT generated by Flex 2.91 */
+#define YY_INPUT(buf,result,max_size) \
+ if ( parse_str ) \
+ { \
+ int n = 0; \
+ guint pslen = strlen(parse_str); \
+ if (parse_str_pos < pslen) \
+ { \
+ n = pslen - parse_str_pos; \
+ if (n > max_size) n = max_size; \
+ memcpy(buf, parse_str + parse_str_pos, n); \
+ parse_str_pos += n; \
+ } \
+ result = n; \
+ } \
+ else \
+ { \
+ errno=0; \
+ while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \
+ { \
+ if( errno != EINTR) \
+ { \
+ YY_FATAL_ERROR( "input in flex scanner failed" ); \
+ break; \
+ } \
+ errno=0; \
+ clearerr(yyin); \
+ } \
+ }
+
/*
* XXX
* quoted_string below fails badly on "...\\"
@@ -246,6 +279,7 @@ gboolean uat_load(uat_t* uat_in, char** err) {
gchar* fname = uat_get_actual_filename(uat_in, FALSE);
uat = uat_in;
+ parse_str = NULL;
if (!fname) {
UAT_UPDATE(uat);
@@ -281,3 +315,35 @@ gboolean uat_load(uat_t* uat_in, char** err) {
return TRUE;
}
}
+
+gboolean uat_load_str(uat_t* uat_in, char* entry, char** err) {
+ uat = uat_in;
+ parse_str = g_strdup_printf("%s\n", entry); /* Records must end with a newline */
+ parse_str_pos = 0;
+ yyin = NULL;
+
+ error = NULL;
+ colnum = 0;
+ record = g_malloc0(uat->record_size);
+ linenum = 1;
+
+ BEGIN START_OF_LINE;
+ DUMP(entry);
+
+ yylex();
+ yyrestart(NULL);
+ g_free(parse_str);
+ parse_str = NULL;
+
+ uat->changed = TRUE;
+ uat->loaded = TRUE;
+ if (error) {
+ UAT_UPDATE(uat);
+ *err = ep_strdup(error);
+ return FALSE;
+ } else {
+ UAT_UPDATE(uat);
+ *err = NULL;
+ return TRUE;
+ }
+}