aboutsummaryrefslogtreecommitdiffstats
path: root/dfilter.c
diff options
context:
space:
mode:
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 */