Pull the stuff to read and write the list of filter expressions up into
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 28 Jan 2001 04:43:26 +0000 (04:43 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 28 Jan 2001 04:43:26 +0000 (04:43 +0000)
a file in the top-level directory.

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

Makefile.am
Makefile.nmake
filters.c [new file with mode: 0644]
filters.h [new file with mode: 0644]
gtk/filter_prefs.c

index be0542c3021a6d90bed989af54299e3ae175105e..0446014462da646ef05d210fff1225c0cd8e6050 100644 (file)
@@ -1,7 +1,7 @@
 # Makefile.am
 # Automake file for Ethereal
 #
-# $Id: Makefile.am,v 1.279 2001/01/27 20:33:00 guy Exp $
+# $Id: Makefile.am,v 1.280 2001/01/28 04:43:24 guy Exp $
 #
 # Ethereal - Network traffic analyzer
 # By Gerald Combs <gerald@zing.org>
@@ -352,6 +352,8 @@ ethereal_SOURCES = \
        capture.h      \
        file.c         \
        file.h         \
+       filters.c      \
+       filters.h      \
        globals.h      \
        menu.h         \
        simple_dialog.h \
index b980cd218a004bc3cae57e5d2650d1cc45577b1a..59534cc3cefef613b57a81e7712a146489292134 100644 (file)
@@ -1,7 +1,7 @@
 ## Makefile for building ethereal.exe with Microsoft C and nmake
 ## Use: nmake -f makefile.nmake
 #
-# $Id: Makefile.nmake,v 1.76 2001/01/27 20:33:00 guy Exp $
+# $Id: Makefile.nmake,v 1.77 2001/01/28 04:43:24 guy Exp $
 
 include config.nmake
 
@@ -198,6 +198,7 @@ ethereal_OBJECTS = \
        $(ETHEREAL_COMMON_OBJECTS) \
        capture.obj      \
        file.obj         \
+       filters.obj      \
        summary.obj      \
 
 tethereal_OBJECTS = \
diff --git a/filters.c b/filters.c
new file mode 100644 (file)
index 0000000..f59b44f
--- /dev/null
+++ b/filters.c
@@ -0,0 +1,144 @@
+/* filters.c
+ * Code for reading and writing the filters file.
+ *
+ * $Id: filters.c,v 1.1 2001/01/28 04:43:24 guy Exp $
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@zing.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+
+#ifdef HAVE_SYS_STAT_H
+#include <sys/stat.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#include <glib.h>
+
+#include <epan.h>
+
+#include "filters.h"
+#include "util.h"
+
+#define        FILTER_LINE_SIZE        2048
+
+/*
+ * List of filters.
+ */
+GList       *fl = NULL;
+
+void
+get_filter_list(void)
+{
+  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;
+  
+  /* 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);
+
+  if ((ff = fopen(ff_path, "r")) == NULL) {
+    g_free(ff_path);
+    return;
+  }
+
+  while (fgets(f_buf, FILTER_LINE_SIZE, ff)) {
+    line++;
+    len = strlen(f_buf);
+    if (f_buf[len - 1] == '\n') {
+      len--;
+      f_buf[len] = '\0';
+    }
+    name_begin = strchr(f_buf, '"');
+    /* Empty line */
+    if (name_begin == NULL)
+      continue;
+    name_end = strchr(name_begin + 1, '"');
+    /* No terminating quote */
+    if (name_end == NULL) {
+      g_warning("Malformed filter in '%s' line %d.", ff_path, line);
+      continue;
+    }
+    name_begin++;
+    name_end[0] = '\0';
+    filt_begin  = name_end + 1;
+    while(isspace((guchar)filt_begin[0])) filt_begin++;
+    /* No filter string */
+    if (filt_begin[0] == '\0') {
+      g_warning("Malformed filter in '%s' line %d.", ff_path, line);
+      continue;
+    }
+    filt         = (filter_def *) g_malloc(sizeof(filter_def));
+    filt->name   = g_strdup(name_begin);
+    filt->strval = g_strdup(filt_begin);
+    fl = g_list_append(fl, filt);
+  }
+  fclose(ff);
+  g_free(ff_path);
+}
+
+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;
+  
+  ff_path = (gchar *) g_malloc(strlen(get_home_dir()) + strlen(ff_dir) +  
+    strlen(ff_name) + 4);
+  sprintf(ff_path, "%s/%s", get_home_dir(), ff_dir);
+
+  if (stat(ff_path, &s_buf) != 0)
+#ifdef WIN32
+    mkdir(ff_path);
+#else
+    mkdir(ff_path, 0755);
+#endif
+    
+  sprintf(ff_path, "%s/%s/%s", get_home_dir(), ff_dir, ff_name);
+
+  if ((ff = fopen(ff_path, "w")) != NULL) {
+    flp = g_list_first(fl);
+    while (flp) {
+      filt = (filter_def *) flp->data;
+      fprintf(ff, "\"%s\" %s\n", filt->name, filt->strval);
+      flp = flp->next;
+    }
+    fclose(ff);
+  }
+
+  g_free(ff_path);
+}
diff --git a/filters.h b/filters.h
new file mode 100644 (file)
index 0000000..8839af7
--- /dev/null
+++ b/filters.h
@@ -0,0 +1,41 @@
+/* filters.c
+ * Declarations of routines for reading and writing the filters file.
+ *
+ * $Id: filters.h,v 1.1 2001/01/28 04:43:24 guy Exp $
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@zing.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * 
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+/*
+ * List of filters.
+ */
+extern GList       *fl;
+
+/*
+ * Item in a list of filters.
+ */
+typedef struct {
+  char *name;          /* filter name */
+  char *strval;                /* filter expression */
+} filter_def;
+
+void get_filter_list(void);
+
+void save_filter_list(void);
index 537d54247bca3cb7228b3e1c31b5897154d77112..8d387d720d8479fecc128edf38783633f37ccc2e 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.23 2001/01/21 03:30:24 guy Exp $
+ * $Id: filter_prefs.c,v 1.24 2001/01/28 04:43:26 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
 
 #include <gtk/gtk.h>
 
-#include <stdlib.h>
-#include <string.h>
-
-#ifdef HAVE_SYS_STAT_H
-#include <sys/stat.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#include <ctype.h>
-#ifdef HAVE_DIRECT_H
-#include <direct.h>
-#endif
-
 #include <epan.h>
+
+#include "filters.h"
 #include "gtk/main.h"
 #include "filter_prefs.h"
-#include "packet.h"
-#include "file.h"
-#include "util.h"
 #include "dlg_utils.h"
 #include "ui_util.h"
 #include "prefs_dlg.h"
 #define E_FILT_DBLFUNC_KEY          "filter_dblfunc"
 #define E_FILT_DBLARG_KEY           "filter_dblarg"
 
-typedef struct _filter_def {
-  char *name;
-  char *strval;
-} filter_def;
-
 typedef struct _filter_cb_data {
   GList     *fl;
   GtkWidget *win;
 } filter_cb_data;
 
-
-static GList       *fl = NULL;
-
-static void get_filter_list(void);
 static GtkWidget *filter_dialog_new(GtkWidget *caller, GtkWidget *filter_te,
     construct_args_t *construct_args, gboolean wants_add_expression_button);
 static void filter_dlg_dclick(GtkWidget *dummy, gpointer main_w_arg);
@@ -108,64 +83,6 @@ static void       filter_del_bt_destroy_cb(GtkWidget *, gpointer);
 static void       filter_expr_cb(GtkWidget *, gpointer);
 static void       filter_name_te_destroy_cb(GtkWidget *, gpointer);
 static void       filter_filter_te_destroy_cb(GtkWidget *, gpointer);
-static void       filter_prefs_save(void);
-
-#define        FILTER_LINE_SIZE        2048
-
-static void
-get_filter_list(void)
-{
-  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;
-  
-  /* 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);
-
-  if ((ff = fopen(ff_path, "r")) == NULL) {
-    g_free(ff_path);
-    return;
-  }
-
-  while (fgets(f_buf, FILTER_LINE_SIZE, ff)) {
-    line++;
-    len = strlen(f_buf);
-    if (f_buf[len - 1] == '\n') {
-      len--;
-      f_buf[len] = '\0';
-    }
-    name_begin = strchr(f_buf, '"');
-    /* Empty line */
-    if (name_begin == NULL)
-      continue;
-    name_end = strchr(name_begin + 1, '"');
-    /* No terminating quote */
-    if (name_end == NULL) {
-      g_warning("Malformed filter in '%s' line %d.", ff_path, line);
-      continue;
-    }
-    name_begin++;
-    name_end[0] = '\0';
-    filt_begin  = name_end + 1;
-    while(isspace((guchar)filt_begin[0])) filt_begin++;
-    /* No filter string */
-    if (filt_begin[0] == '\0') {
-      g_warning("Malformed filter in '%s' line %d.", ff_path, line);
-      continue;
-    }
-    filt         = (filter_def *) g_malloc(sizeof(filter_def));
-    filt->name   = g_strdup(name_begin);
-    filt->strval = g_strdup(filt_begin);
-    fl = g_list_append(fl, filt);
-  }
-  fclose(ff);
-  g_free(ff_path);
-}
 
 /* XXX - we can have one global dialog box for editing, and a bunch
    of dialog boxes associated with browse buttons; we want the dialog
@@ -671,7 +588,7 @@ filter_apply(GtkWidget *main_w)
 static void
 filter_dlg_save_cb(GtkWidget *save_bt, gpointer parent_w)
 {
-       filter_prefs_save();
+       save_filter_list();
 }
 
 static void
@@ -1051,38 +968,3 @@ filter_filter_te_destroy_cb(GtkWidget *filter_te, gpointer data)
 
   gtk_object_set_data(GTK_OBJECT(main_w), E_FILT_FILTER_TE_KEY, NULL);
 }
-
-static void
-filter_prefs_save(void)
-{
-  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);
-  sprintf(ff_path, "%s/%s", get_home_dir(), ff_dir);
-
-  if (stat(ff_path, &s_buf) != 0)
-#ifdef WIN32
-    mkdir(ff_path);
-#else
-    mkdir(ff_path, 0755);
-#endif
-    
-  sprintf(ff_path, "%s/%s/%s", get_home_dir(), ff_dir, ff_name);
-
-  if ((ff = fopen(ff_path, "w")) != NULL) {
-    flp = g_list_first(fl);
-    while (flp) {
-      filt = (filter_def *) flp->data;
-      fprintf(ff, "\"%s\" %s\n", filt->name, filt->strval);
-      flp = flp->next;
-    }
-    fclose(ff);
-  }
-
-  g_free(ff_path);
-}