diff options
author | Guy Harris <guy@alum.mit.edu> | 2001-01-28 04:43:26 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2001-01-28 04:43:26 +0000 |
commit | c8639c08ee832fc44651bb08091021e3579bf8ba (patch) | |
tree | 151d0daa7f8a84e486cb742c45ce5bdc3551e871 | |
parent | 7fc0d00b8a28d426096ea0c2bd9c092f225c9300 (diff) |
Pull the stuff to read and write the list of filter expressions up into
a file in the top-level directory.
svn path=/trunk/; revision=2946
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | Makefile.nmake | 3 | ||||
-rw-r--r-- | filters.c | 144 | ||||
-rw-r--r-- | filters.h | 41 | ||||
-rw-r--r-- | gtk/filter_prefs.c | 126 |
5 files changed, 194 insertions, 124 deletions
diff --git a/Makefile.am b/Makefile.am index be0542c302..0446014462 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 \ diff --git a/Makefile.nmake b/Makefile.nmake index b980cd218a..59534cc3ce 100644 --- a/Makefile.nmake +++ b/Makefile.nmake @@ -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 index 0000000000..f59b44fa02 --- /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 index 0000000000..8839af72d8 --- /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); diff --git a/gtk/filter_prefs.c b/gtk/filter_prefs.c index 537d54247b..8d387d720d 100644 --- a/gtk/filter_prefs.c +++ b/gtk/filter_prefs.c @@ -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> @@ -31,27 +31,11 @@ #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" @@ -70,20 +54,11 @@ #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); -} |