Call "get_filter_list()" when Ethereal starts up.
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 28 Jan 2001 04:52:29 +0000 (04:52 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 28 Jan 2001 04:52:29 +0000 (04:52 +0000)
Have it free up any list of filters we already have before reading in
new filters.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@2947 f5534014-38df-0310-8fa8-9805f1628bb7

filters.c
gtk/filter_prefs.c
gtk/main.c

index f59b44fa02b0b00d7bc20e73c94ed54339804585..682a37c9c7b4a001fc52b1f74cb86f53e91de526 100644 (file)
--- a/filters.c
+++ b/filters.c
@@ -1,7 +1,7 @@
 /* filters.c
  * Code for reading and writing the filters file.
  *
- * $Id: filters.c,v 1.1 2001/01/28 04:43:24 guy Exp $
+ * $Id: filters.c,v 1.2 2001/01/28 04:52:28 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -56,14 +56,27 @@ GList       *fl = NULL;
 void
 get_filter_list(void)
 {
+  GList      *flp;
   filter_def *filt;
   FILE       *ff;
   gchar      *ff_path, *ff_name = PF_DIR "/filters", f_buf[FILTER_LINE_SIZE];
   gchar      *name_begin, *name_end, *filt_begin;
   int         len, line = 0;
 
-  if (fl) return;
-  
+  /* If we already have a list of filters, discard it. */
+  if (fl != NULL) {
+    flp = g_list_first(fl);
+    while (flp) {
+      filt = (filter_def *) flp->data;
+      g_free(filt->name);
+      g_free(filt->strval);
+      g_free(filt);
+      flp = flp->next;
+    }
+    g_list_free(fl);
+    fl = NULL;
+  }
+
   /* To do: generalize this */
   ff_path = (gchar *) g_malloc(strlen(get_home_dir()) + strlen(ff_name) +  4);
   sprintf(ff_path, "%s/%s", get_home_dir(), ff_name);
@@ -111,11 +124,11 @@ get_filter_list(void)
 void
 save_filter_list(void)
 {
-  GList       *flp;
-  filter_def  *filt;
-  gchar       *ff_path, *ff_dir = PF_DIR, *ff_name = "filters";
-  FILE        *ff;
-  struct stat  s_buf;
+  GList      *flp;
+  filter_def *filt;
+  gchar      *ff_path, *ff_dir = PF_DIR, *ff_name = "filters";
+  FILE       *ff;
+  struct stat s_buf;
   
   ff_path = (gchar *) g_malloc(strlen(get_home_dir()) + strlen(ff_dir) +  
     strlen(ff_name) + 4);
index 8d387d720d8479fecc128edf38783633f37ccc2e..6a78c809cb27ef07f5d1013391d0d13a33a694a1 100644 (file)
@@ -3,7 +3,7 @@
  * (This used to be a notebook page under "Preferences", hence the
  * "prefs" in the file name.)
  *
- * $Id: filter_prefs.c,v 1.24 2001/01/28 04:43:26 guy Exp $
+ * $Id: filter_prefs.c,v 1.25 2001/01/28 04:52:29 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -296,7 +296,6 @@ filter_dialog_new(GtkWidget *caller, GtkWidget *parent_filter_te,
        gtk_widget_show(main_vb);
 
        /* Make sure everything is set up */  
-       get_filter_list();
        if (parent_filter_te)
                filter_te_str = gtk_entry_get_text(GTK_ENTRY(parent_filter_te));
 
index 6c5529ebbe0143c26a872cfdd3be291ad8877b39..67a6c348bf38112c686eb57083c8ec8d7a096d58 100644 (file)
@@ -1,6 +1,6 @@
 /* main.c
  *
- * $Id: main.c,v 1.173 2001/01/21 02:27:24 guy Exp $
+ * $Id: main.c,v 1.174 2001/01/28 04:52:29 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
 #include "capture.h"
 #include "summary.h"
 #include "file.h"
+#include "filters.h"
 #include "menu.h"
 #include "../menu.h"
 #include "color.h"
@@ -924,8 +925,12 @@ main(int argc, char *argv[])
   /* Let GTK get its args */
   gtk_init (&argc, &argv);
   
+  /* Read the preference files. */
   prefs = read_prefs(&gpf_open_errno, &gpf_path, &pf_open_errno, &pf_path);
 
+  /* Read the filter file. */
+  get_filter_list();
+
   /* Initialize the capture file struct */
   cfile.plist          = NULL;
   cfile.plist_end      = NULL;