aboutsummaryrefslogtreecommitdiffstats
path: root/dfilter.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>1999-10-07 21:47:20 +0000
committerGuy Harris <guy@alum.mit.edu>1999-10-07 21:47:20 +0000
commit361fcf26e9ffebce03d572a79edb00052e0b24a8 (patch)
tree14f29bc8ff7c75aeed1b89d23884cfdabc6f29e3 /dfilter.c
parent728ec33cb9ae4f76c54760911054966c7b873eff (diff)
Make "dfilter_error()" available to the lexical analyzer.
Get rid of the declaration of the non-existent "dfilter_yyerror()", and put in some #defines to work around the fact that the #defines to replace "yy" with "dfilter_" in the names of Flex-generated and Yacc-generated routines aren't put into a header file, they're put into ".c" files. Have it remember the error message it was handed (unless it's Yacc's boring "parse error" message). When generating the message to be shown to the user on a parse error, make it be the "Unable to parse filter string" message, and, if a non-boring error message was supplied to "dfilter_error()", take that error message onto the end. Don't panic if a field type we don't yet support in the parser is seen; generate an error, telling the user we don't support filter on that type yet. Don't assume that "global_df" has been set if we see an empty statement (if the first token was the end-marker, because, say, the first token the lexical analyzer found was a field of a type not yet supported in filter expressions, "global_df" won't have been set). svn path=/trunk/; revision=783
Diffstat (limited to 'dfilter.c')
-rw-r--r--dfilter.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/dfilter.c b/dfilter.c
index 5c6c933a77..6fa05ccbe8 100644
--- a/dfilter.c
+++ b/dfilter.c
@@ -1,7 +1,7 @@
/* dfilter.c
* Routines for display filters
*
- * $Id: dfilter.c,v 1.23 1999/10/04 18:53:26 gram Exp $
+ * $Id: dfilter.c,v 1.24 1999/10/07 21:47:18 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -167,15 +167,26 @@ dfilter_compile(dfilter *df, gchar *dfilter_text)
/* clean up lex */
dfilter_scanner_cleanup();
- /* If a parse error occurred, fill in a generic error message
- * if one was not created during parsing. */
+ /* Errors not found by the parser may not cause the parse to
+ * fail; if "dfilter_error_msg" is set, it means somebody
+ * else called "dfilter_error()", e.g. the lexical analyzer,
+ * so treat that as a parse error. */
+ if (dfilter_error_msg != NULL)
+ retval = 1;
+
if (retval != 0) {
if (dfilter_error_msg == NULL) {
- dfilter_error_msg = &dfilter_error_msg_buf[0];
- snprintf(dfilter_error_msg, sizeof(dfilter_error_msg_buf),
+ snprintf(dfilter_error_msg_buf, sizeof(dfilter_error_msg_buf),
"Unable to parse filter string \"%s\".",
dfilter_text);
+ } else {
+ /* An error message was supplied; use it in the
+ * error we display. */
+ snprintf(dfilter_error_msg_buf, sizeof(dfilter_error_msg_buf),
+ "Unable to parse filter string \"%s\": %s.",
+ dfilter_text, dfilter_error_msg);
}
+ dfilter_error_msg = &dfilter_error_msg_buf[0];
}
/* Clear the list of allocated nodes */
@@ -262,6 +273,12 @@ clear_byte_array(gpointer data, gpointer user_data)
void
dfilter_error(char *s)
{
+ /* Remember the error message we were handed, unless it's
+ * the boring "parse error" message used by YACC.
+ */
+ if (strcmp(s, "parse error") != 0)
+ dfilter_error_msg = s;
+
/* The only data we have to worry about freeing is the
* data used by any GNodes that were allocated during
* parsing. The data in those Gnodes will be cleared
@@ -745,4 +762,3 @@ gboolean check_relation_bytes(gint operand, GArray *a, GArray *b)
g_assert_not_reached();
return FALSE;
}
-