aboutsummaryrefslogtreecommitdiffstats
path: root/dfilter.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>1999-10-12 05:01:07 +0000
committerGuy Harris <guy@alum.mit.edu>1999-10-12 05:01:07 +0000
commitf3da72ef2fd7486be06c6bb69418d4416fdaf3e6 (patch)
tree745d48db7c24775225b32326c4721af356973484 /dfilter.c
parent1efcb7b2cfc60043e672d5cc4c78aabbe50f5416 (diff)
Have "dfilter_compile()" return 0 on success and 1 on failure, and
return the pointer to the compiled filter through a pointer argument. Have it check whether the filter is a null filter and, if so, free up the filter and supply a filter pointer, rather than obliging its callers to check whether the filter actually has any code. (Well, they may want to check if the filter is null, so that they don't save a pointer to the filter text, e.g. so that the display filter displays as "none" rather than as a blank string in the summary box.) In the process, fix the check in "gtk/file_dlg.c" that tests whether the read filter compiled successfully. svn path=/trunk/; revision=812
Diffstat (limited to 'dfilter.c')
-rw-r--r--dfilter.c35
1 files changed, 25 insertions, 10 deletions
diff --git a/dfilter.c b/dfilter.c
index 4f0486239a..444fc9f888 100644
--- a/dfilter.c
+++ b/dfilter.c
@@ -1,7 +1,7 @@
/* dfilter.c
* Routines for display filters
*
- * $Id: dfilter.c,v 1.29 1999/10/12 04:21:10 gram Exp $
+ * $Id: dfilter.c,v 1.30 1999/10/12 05:00:50 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -133,15 +133,20 @@ dfilter_cleanup(void)
* display filter each time, without having to clear any memory used, since
* dfilter_compile will take care of that automatically.
*
- * Returns a pointer to a newly-allocated dfilter strucutre on success,
- * NULL on failure.
- * If a failure, dfilter_error_msg points to an appropriate error message.
+ * Returns 0 on success, non-zero on failure.
+ *
+ * On success, sets the "dfilter *" pointed to by its second argument
+ * either to a null pointer (if the filter is a null filter, as
+ * generated by an all-blank string) or to a pointer to a newly-allocated
+ * dfilter structure (if the filter isn't null).
+ *
+ * On failure, "dfilter_error_msg" points to an appropriate error message.
* This error message is a global string, so another invocation of
* dfilter_compile will clear it. If the caller needs is stored, he
* needs to g_strdup it himself.
*/
-dfilter*
-dfilter_compile(gchar *dfilter_text)
+int
+dfilter_compile(gchar *dfilter_text, dfilter **dfp)
{
dfilter *df;
int retval;
@@ -184,12 +189,22 @@ dfilter_compile(gchar *dfilter_text)
/* Set global_df to NULL just to be tidy. */
global_df = NULL;
- if (retval == 0)
- return df;
- else {
+ if (retval == 0) {
+ /* Success. Check if the filter is empty; if so, discard
+ * it and set "*dfp" to NULL, otherwise set "*dfp" to
+ * point to the filter. */
+ if (df->dftree == NULL) {
+ /* The filter is empty. */
+ dfilter_destroy(df);
+ df = NULL;
+ }
+ *dfp = df;
+ } else {
+ /* Failure. Destroy the filter. */
dfilter_destroy(df);
- return NULL;
+ df = NULL;
}
+ return retval;
}
/* Allocates new dfilter, initializes values, and returns pointer to dfilter */