From f3da72ef2fd7486be06c6bb69418d4416fdaf3e6 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 12 Oct 1999 05:01:07 +0000 Subject: 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 --- dfilter.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'dfilter.c') 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 @@ -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 */ -- cgit v1.2.3