diff options
-rw-r--r-- | gtk/Makefile.am | 10 | ||||
-rw-r--r-- | gtk/Makefile.nmake | 5 | ||||
-rw-r--r-- | gtk/color_dlg.c | 4 | ||||
-rw-r--r-- | gtk/color_filters.c | 245 | ||||
-rw-r--r-- | gtk/color_filters.h | 41 | ||||
-rw-r--r-- | gtk/colors.c | 241 | ||||
-rw-r--r-- | gtk/colors.h | 21 | ||||
-rw-r--r-- | gtk/main.c | 4 |
8 files changed, 324 insertions, 247 deletions
diff --git a/gtk/Makefile.am b/gtk/Makefile.am index 3e58477395..ab79d81244 100644 --- a/gtk/Makefile.am +++ b/gtk/Makefile.am @@ -1,7 +1,7 @@ # Makefile.am # Automake file for the GTK interface routines for Ethereal # -# $Id: Makefile.am,v 1.50 2002/12/03 01:26:31 jmayer Exp $ +# $Id: Makefile.am,v 1.51 2003/01/08 01:59:41 guy Exp $ # # Ethereal - Network traffic analyzer # By Gerald Combs <gerald@ethereal.com> @@ -50,10 +50,12 @@ libui_a_SOURCES = \ capture_prefs.h \ color_dlg.c \ color_dlg.h \ - colors.c \ - colors.h \ + color_filters.c \ + color_filters.h \ color_utils.c \ color_utils.h \ + colors.c \ + colors.h \ column_prefs.c \ column_prefs.h \ compat_macros.h \ @@ -122,6 +124,8 @@ libui_a_SOURCES = \ capture_prefs.h \ color_dlg.c \ color_dlg.h \ + color_filters.c \ + color_filters.h \ colors.c \ colors.h \ color_utils.c \ diff --git a/gtk/Makefile.nmake b/gtk/Makefile.nmake index e4ea923092..0bb714241c 100644 --- a/gtk/Makefile.nmake +++ b/gtk/Makefile.nmake @@ -1,7 +1,7 @@ ## Makefile for building ethereal.exe with Microsoft C and nmake ## Use: $(MAKE) /$(MAKEFLAGS) -f makefile.nmake # -# $Id: Makefile.nmake,v 1.37 2002/11/14 10:32:22 sahlberg Exp $ +# $Id: Makefile.nmake,v 1.38 2003/01/08 01:59:41 guy Exp $ include ..\config.nmake @@ -36,9 +36,10 @@ ETHEREAL_TAP_OBJECTS = $(ETHEREAL_TAP_SRC:.c=.obj) OBJECTS=capture_dlg.obj \ capture_prefs.obj \ color_dlg.obj \ + color_filters.obj \ + column_prefs.obj \ colors.obj \ color_utils.obj \ - column_prefs.obj \ decode_as_dlg.obj \ dfilter_expr_dlg.obj \ display_opts.obj \ diff --git a/gtk/color_dlg.c b/gtk/color_dlg.c index 01ad8f8f2d..3406b5562e 100644 --- a/gtk/color_dlg.c +++ b/gtk/color_dlg.c @@ -1,7 +1,7 @@ /* color_dlg.c * Definitions for dialog boxes for color filters * - * $Id: color_dlg.c,v 1.21 2002/11/09 20:00:35 oabad Exp $ + * $Id: color_dlg.c,v 1.22 2003/01/08 01:59:41 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -32,7 +32,9 @@ #include "gtk/main.h" #include <epan/packet.h> +#include "color.h" #include "colors.h" +#include "color_filters.h" #include "color_dlg.h" #include "color_utils.h" #include "file.h" diff --git a/gtk/color_filters.c b/gtk/color_filters.c new file mode 100644 index 0000000000..89b635f248 --- /dev/null +++ b/gtk/color_filters.c @@ -0,0 +1,245 @@ +/* color_filters.c + * Routines for color filters + * + * $Id: color_filters.c,v 1.1 2003/01/08 01:59:42 guy Exp $ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@ethereal.com> + * 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. + */ +/* + * Updated 1 Dec 10 jjm + */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <gtk/gtk.h> + +#include <string.h> + +#include <epan/filesystem.h> + +#include <epan/packet.h> +#include "color.h" +#include "colors.h" +#include "color_filters.h" +#include "color_utils.h" +#include "file.h" +#include <epan/dfilter/dfilter.h> +#include "simple_dialog.h" +#include "gtkglobals.h" + +static gboolean read_filters(void); + +GSList *filter_list; + +/* Initialize the filter structures (reading from file) */ +void +colfilter_init(void) +{ + read_filters(); +} + +/* Create a new filter */ +color_filter_t * +new_color_filter(gchar *name, /* The name of the filter to create */ + gchar *filter_string) /* The string representing the filter */ +{ + color_filter_t *colorf; + GtkStyle *style; + + colorf = (color_filter_t *)g_malloc(sizeof (color_filter_t)); + colorf->filter_name = g_strdup(name); + colorf->filter_text = g_strdup(filter_string); + style = gtk_widget_get_style(packet_list); + gdkcolor_to_color_t(&colorf->bg_color, &style->base[GTK_STATE_NORMAL]); + gdkcolor_to_color_t(&colorf->fg_color, &style->text[GTK_STATE_NORMAL]); + colorf->c_colorfilter = NULL; + colorf->edit_dialog = NULL; + filter_list = g_slist_append(filter_list, colorf); + return colorf; +} + +/* delete the specified filter */ +void +delete_color_filter(color_filter_t *colorf) +{ + if (colorf->filter_name != NULL) + g_free(colorf->filter_name); + if (colorf->filter_text != NULL) + g_free(colorf->filter_text); + if (colorf->c_colorfilter != NULL) + dfilter_free(colorf->c_colorfilter); + filter_list = g_slist_remove(filter_list, colorf); + g_free(colorf); +} + +static void +prime_edt(gpointer data, gpointer user_data) +{ + color_filter_t *colorf = data; + epan_dissect_t *edt = user_data; + + if (colorf->c_colorfilter != NULL) + epan_dissect_prime_dfilter(edt, colorf->c_colorfilter); +} + +/* Prime the epan_dissect_t with all the compiler + * color filters in 'filter_list'. */ +void +filter_list_prime_edt(epan_dissect_t *edt) +{ + g_slist_foreach(filter_list, prime_edt, edt); +} + + +/* read filters from the file */ +static gboolean +read_filters(void) +{ + /* TODO: Lots more syntax checking on the file */ + /* I hate these fixed length names! TODO: make more dynamic */ + /* XXX - buffer overflow possibility here + * sscanf blocks max size of name and filter_exp; buf is used for + * reading only */ + gchar name[256],filter_exp[256], buf[1024]; + guint16 fg_r, fg_g, fg_b, bg_r, bg_g, bg_b; + GdkColor fg_color, bg_color; + color_filter_t *colorf; + gchar *path; + FILE *f; + dfilter_t *temp_dfilter; + + /* decide what file to open (from dfilter code) */ + path = get_persconffile_path("colorfilters", FALSE); + if ((f = fopen(path, "r")) == NULL) { + if (errno != ENOENT) { + simple_dialog(ESD_TYPE_CRIT, NULL, + "Could not open filter file\n\"%s\": %s.", path, + strerror(errno)); + } + g_free((gchar *)path); + return FALSE; + } + g_free((gchar *)path); + path = NULL; + + do { + if (fgets(buf,sizeof buf, f) == NULL) + break; + + if (strspn(buf," \t") == (size_t)((strchr(buf,'*') - buf))) { + /* leading # comment */ + continue; + } + + /* we get the @ delimiter. It is not in any strings + * Format is: + * @name@filter expression@[background r,g,b][foreground r,g,b] + */ + if (sscanf(buf," @%256[^@]@%256[^@]@[%hu,%hu,%hu][%hu,%hu,%hu]", + name, filter_exp, &bg_r, &bg_g, &bg_b, &fg_r, &fg_g, &fg_b) + == 8) { + /* we got a filter */ + + if (!dfilter_compile(filter_exp, &temp_dfilter)) { + simple_dialog(ESD_TYPE_CRIT, NULL, + "Could not compile color filter %s from saved filters.\n%s", + name, dfilter_error_msg); + continue; + } + if (!get_color(&fg_color)) { + /* oops */ + simple_dialog(ESD_TYPE_CRIT, NULL, + "Could not allocate foreground color " + "specified in input file for %s.", name); + dfilter_free(temp_dfilter); + continue; + } + if (!get_color(&bg_color)) { + /* oops */ + simple_dialog(ESD_TYPE_CRIT, NULL, + "Could not allocate background color " + "specified in input file for %s.", name); + dfilter_free(temp_dfilter); + continue; + } + + colorf = new_color_filter(name, filter_exp); + colorf->c_colorfilter = temp_dfilter; + fg_color.red = fg_r; + fg_color.green = fg_g; + fg_color.blue = fg_b; + bg_color.red = bg_r; + bg_color.green = bg_g; + bg_color.blue = bg_b; + + gdkcolor_to_color_t(&colorf->bg_color, &bg_color); + gdkcolor_to_color_t(&colorf->fg_color, &fg_color); + } /* if sscanf */ + } while(!feof(f)); + return TRUE; +} + +static void +write_filter(gpointer filter_arg, gpointer file_arg) +{ + color_filter_t *colorf = filter_arg; + FILE *f = file_arg; + + fprintf(f,"@%s@%s@[%d,%d,%d][%d,%d,%d]\n", + colorf->filter_name, + colorf->filter_text, + colorf->bg_color.red, + colorf->bg_color.green, + colorf->bg_color.blue, + colorf->fg_color.red, + colorf->fg_color.green, + colorf->fg_color.blue); +} + +/* save filters in filter file */ +gboolean +write_filters(void) +{ + gchar *pf_dir_path; + const gchar *path; + FILE *f; + + /* Create the directory that holds personal configuration files, + if necessary. */ + if (create_persconffile_dir(&pf_dir_path) == -1) { + simple_dialog(ESD_TYPE_WARN, NULL, + "Can't create directory\n\"%s\"\nfor color files: %s.", + pf_dir_path, strerror(errno)); + g_free(pf_dir_path); + return FALSE; + } + + path = get_persconffile_path("colorfilters", TRUE); + if ((f = fopen(path, "w+")) == NULL) { + simple_dialog(ESD_TYPE_CRIT, NULL, + "Could not open\n%s\nfor writing: %s.", + path, strerror(errno)); + return FALSE; + } + fprintf(f,"# DO NOT EDIT THIS FILE! It was created by Ethereal\n"); + g_slist_foreach(filter_list, write_filter, f); + fclose(f); + return TRUE; +} diff --git a/gtk/color_filters.h b/gtk/color_filters.h new file mode 100644 index 0000000000..046a672031 --- /dev/null +++ b/gtk/color_filters.h @@ -0,0 +1,41 @@ +/* color_filters.h + * Definitions for color filters + * + * $Id: color_filters.h,v 1.1 2003/01/08 01:59:42 guy Exp $ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@ethereal.com> + * 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. + */ +#ifndef __COLOR_FILTERS_H__ +#define __COLOR_FILTERS_H__ + +#define MAXCOLORS 255 +#define MAX_COLOR_FILTER_NAME_LEN 33 +#define MAX_COLOR_FILTER_STRING_LEN 256 + +#define CFILTERS_CONTAINS_FILTER(filter) \ + ((filter)->num_of_filters != 0) + +void colfilter_init(void); + +gboolean write_filters(void); + +color_filter_t *new_color_filter(gchar *name, gchar *filter_string); +void delete_color_filter(color_filter_t *colorf); + +#endif diff --git a/gtk/colors.c b/gtk/colors.c index fe4f5661c5..37cfc1f157 100644 --- a/gtk/colors.c +++ b/gtk/colors.c @@ -1,7 +1,7 @@ /* colors.c - * Definitions for color structures and routines + * Routines for colors * - * $Id: colors.c,v 1.26 2002/11/03 17:38:32 oabad Exp $ + * $Id: colors.c,v 1.27 2003/01/08 01:59:42 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -21,9 +21,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -/* - * Updated 1 Dec 10 jjm - */ #ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -32,31 +29,19 @@ #include <string.h> -#include <epan/filesystem.h> - -#include <epan/packet.h> #include "colors.h" -#include "color_utils.h" -#include "file.h" -#include <epan/dfilter/dfilter.h> #include "simple_dialog.h" #include "gtkglobals.h" -extern capture_file cf; - -static gboolean read_filters(void); - -GSList *filter_list; - static GdkColormap* sys_cmap; static GdkColormap* our_cmap = NULL; GdkColor WHITE = { 0, 65535, 65535, 65535 }; GdkColor BLACK = { 0, 0, 0, 0 }; -/* Initialize the filter structures (reading from file) */ +/* Initialize the colors */ void -colfilter_init(void) +colors_init(void) { gboolean got_white, got_black; @@ -79,212 +64,24 @@ colfilter_init(void) simple_dialog(ESD_TYPE_WARN, NULL, "Could not allocate color black."); } - - read_filters(); -} - -/* Create a new filter */ -color_filter_t * -new_color_filter(gchar *name, /* The name of the filter to create */ - gchar *filter_string) /* The string representing the filter */ -{ - color_filter_t *colorf; - GtkStyle *style; - - colorf = (color_filter_t *)g_malloc(sizeof (color_filter_t)); - colorf->filter_name = g_strdup(name); - colorf->filter_text = g_strdup(filter_string); - style = gtk_widget_get_style(packet_list); - gdkcolor_to_color_t(&colorf->bg_color, &style->base[GTK_STATE_NORMAL]); - gdkcolor_to_color_t(&colorf->fg_color, &style->text[GTK_STATE_NORMAL]); - colorf->c_colorfilter = NULL; - colorf->edit_dialog = NULL; - filter_list = g_slist_append(filter_list, colorf); - return colorf; -} - -/* delete the specified filter */ -void -delete_color_filter(color_filter_t *colorf) -{ - if (colorf->filter_name != NULL) - g_free(colorf->filter_name); - if (colorf->filter_text != NULL) - g_free(colorf->filter_text); - if (colorf->c_colorfilter != NULL) - dfilter_free(colorf->c_colorfilter); - filter_list = g_slist_remove(filter_list, colorf); - g_free(colorf); -} - -static void -prime_edt(gpointer data, gpointer user_data) -{ - color_filter_t *colorf = data; - epan_dissect_t *edt = user_data; - - if (colorf->c_colorfilter != NULL) - epan_dissect_prime_dfilter(edt, colorf->c_colorfilter); -} - -/* Prime the epan_dissect_t with all the compiler - * color filters in 'filter_list'. */ -void -filter_list_prime_edt(epan_dissect_t *edt) -{ - g_slist_foreach(filter_list, prime_edt, edt); -} - - -/* read filters from the file */ -static gboolean -read_filters(void) -{ - /* TODO: Lots more syntax checking on the file */ - /* I hate these fixed length names! TODO: make more dynamic */ - /* XXX - buffer overflow possibility here - * sscanf blocks max size of name and filter_exp; buf is used for - * reading only */ - gchar name[256],filter_exp[256], buf[1024]; - guint16 fg_r, fg_g, fg_b, bg_r, bg_g, bg_b; - GdkColor fg_color, bg_color; - color_filter_t *colorf; - gchar *path; - FILE *f; - dfilter_t *temp_dfilter; - - /* decide what file to open (from dfilter code) */ - path = get_persconffile_path("colorfilters", FALSE); - if ((f = fopen(path, "r")) == NULL) { - if (errno != ENOENT) { - simple_dialog(ESD_TYPE_CRIT, NULL, - "Could not open filter file\n\"%s\": %s.", path, - strerror(errno)); - } - g_free((gchar *)path); - return FALSE; - } - g_free((gchar *)path); - path = NULL; - - do { - if (fgets(buf,sizeof buf, f) == NULL) - break; - - if (strspn(buf," \t") == (size_t)((strchr(buf,'*') - buf))) { - /* leading # comment */ - continue; - } - - /* we get the @ delimiter. It is not in any strings - * Format is: - * @name@filter expression@[background r,g,b][foreground r,g,b] - */ - if (sscanf(buf," @%256[^@]@%256[^@]@[%hu,%hu,%hu][%hu,%hu,%hu]", - name, filter_exp, &bg_r, &bg_g, &bg_b, &fg_r, &fg_g, &fg_b) - == 8) { - /* we got a filter */ - - if (!dfilter_compile(filter_exp, &temp_dfilter)) { - simple_dialog(ESD_TYPE_CRIT, NULL, - "Could not compile color filter %s from saved filters.\n%s", - name, dfilter_error_msg); - continue; - } - if (!get_color(&fg_color)) { - /* oops */ - simple_dialog(ESD_TYPE_CRIT, NULL, - "Could not allocate foreground color " - "specified in input file for %s.", name); - dfilter_free(temp_dfilter); - continue; - } - if (!get_color(&bg_color)) { - /* oops */ - simple_dialog(ESD_TYPE_CRIT, NULL, - "Could not allocate background color " - "specified in input file for %s.", name); - dfilter_free(temp_dfilter); - continue; - } - - colorf = new_color_filter(name, filter_exp); - colorf->c_colorfilter = temp_dfilter; - fg_color.red = fg_r; - fg_color.green = fg_g; - fg_color.blue = fg_b; - bg_color.red = bg_r; - bg_color.green = bg_g; - bg_color.blue = bg_b; - - gdkcolor_to_color_t(&colorf->bg_color, &bg_color); - gdkcolor_to_color_t(&colorf->fg_color, &fg_color); - } /* if sscanf */ - } while(!feof(f)); - return TRUE; -} - -static void -write_filter(gpointer filter_arg, gpointer file_arg) -{ - color_filter_t *colorf = filter_arg; - FILE *f = file_arg; - - fprintf(f,"@%s@%s@[%d,%d,%d][%d,%d,%d]\n", - colorf->filter_name, - colorf->filter_text, - colorf->bg_color.red, - colorf->bg_color.green, - colorf->bg_color.blue, - colorf->fg_color.red, - colorf->fg_color.green, - colorf->fg_color.blue); -} - -/* save filters in filter file */ -gboolean -write_filters(void) -{ - gchar *pf_dir_path; - const gchar *path; - FILE *f; - - /* Create the directory that holds personal configuration files, - if necessary. */ - if (create_persconffile_dir(&pf_dir_path) == -1) { - simple_dialog(ESD_TYPE_WARN, NULL, - "Can't create directory\n\"%s\"\nfor color files: %s.", - pf_dir_path, strerror(errno)); - g_free(pf_dir_path); - return FALSE; - } - - path = get_persconffile_path("colorfilters", TRUE); - if ((f = fopen(path, "w+")) == NULL) { - simple_dialog(ESD_TYPE_CRIT, NULL, - "Could not open\n%s\nfor writing: %s.", - path, strerror(errno)); - return FALSE; - } - fprintf(f,"# DO NOT EDIT THIS FILE! It was created by Ethereal\n"); - g_slist_foreach(filter_list, write_filter, f); - fclose(f); - return TRUE; } /* allocate a color from the color map */ gboolean -get_color (GdkColor *new_color) +get_color(GdkColor *new_color) { - GdkVisual *pv; - - if (!our_cmap) { - if ( !gdk_colormap_alloc_color (sys_cmap, new_color, FALSE, TRUE)) { - pv = gdk_visual_get_best(); - if ( !(our_cmap = gdk_colormap_new(pv, TRUE))) - simple_dialog(ESD_TYPE_WARN, NULL, "Could not create new colormap"); - } else - return (TRUE); - } - return ( gdk_colormap_alloc_color ( our_cmap, new_color, FALSE, TRUE) ); + GdkVisual *pv; + + if (!our_cmap) { + if (!gdk_colormap_alloc_color (sys_cmap, new_color, FALSE, + TRUE)) { + pv = gdk_visual_get_best(); + if (!(our_cmap = gdk_colormap_new(pv, TRUE))) { + simple_dialog(ESD_TYPE_WARN, NULL, + "Could not create new colormap"); + } + } else + return (TRUE); + } + return (gdk_colormap_alloc_color(our_cmap, new_color, FALSE, TRUE)); } diff --git a/gtk/colors.h b/gtk/colors.h index 6c56739018..de7e117c30 100644 --- a/gtk/colors.h +++ b/gtk/colors.h @@ -1,7 +1,7 @@ /* colors.h * Definitions for color structures and routines * - * $Id: colors.h,v 1.10 2002/09/23 19:09:49 oabad Exp $ + * $Id: colors.h,v 1.11 2003/01/08 01:59:42 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -24,25 +24,10 @@ #ifndef __COLORS_H__ #define __COLORS_H__ -#include "../color.h" - -#define MAXCOLORS 255 -#define MAX_COLOR_FILTER_NAME_LEN 33 -#define MAX_COLOR_FILTER_STRING_LEN 256 - -#define CFILTERS_CONTAINS_FILTER(filter) \ - ((filter)->num_of_filters != 0) - extern GdkColor WHITE; extern GdkColor BLACK; -void colfilter_init(void); - -gboolean write_filters(void); - -color_filter_t *new_color_filter(gchar *name, gchar *filter_string); -void delete_color_filter(color_filter_t *colorf); - -gboolean get_color (GdkColor *new_color); +void colors_init(void); +gboolean get_color(GdkColor *new_color); #endif diff --git a/gtk/main.c b/gtk/main.c index d472919398..dcb16dad8d 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -1,6 +1,6 @@ /* main.c * - * $Id: main.c,v 1.279 2002/12/19 02:58:53 guy Exp $ + * $Id: main.c,v 1.280 2003/01/08 01:59:42 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@ethereal.com> @@ -104,6 +104,7 @@ #include "menu.h" #include "../menu.h" #include "color.h" +#include "color_filters.h" #include "color_utils.h" #include "filter_prefs.h" #include "file_dlg.h" @@ -2141,6 +2142,7 @@ main(int argc, char *argv[]) g_free(tap_opt); } + colors_init(); colfilter_init(); /* If we were given the name of a capture file, read it in now; |