From 1f8e6c08bec07688f19da62e4d0f3a5996ebd9fb Mon Sep 17 00:00:00 2001 From: Ulf Lamping Date: Sat, 12 Apr 2008 23:34:44 +0000 Subject: [PATCH] various code cleanup svn path=/trunk/; revision=24964 --- Makefile.common | 1 - epan/column.c | 47 +++++----- epan/column.h | 2 +- gtk/capture_if_dlg.c | 6 +- gtk/file_dlg.h | 2 +- gtk/main.c | 186 +++++++++++++++++-------------------- gtk/main_airpcap_toolbar.c | 1 - gtk/main_filter_toolbar.c | 2 + gtk/main_packet_list.c | 38 ++++---- gtk/main_statusbar.c | 9 +- main_window.h | 41 -------- 11 files changed, 138 insertions(+), 197 deletions(-) delete mode 100644 main_window.h diff --git a/Makefile.common b/Makefile.common index 68722cf051..d0266d4462 100644 --- a/Makefile.common +++ b/Makefile.common @@ -168,7 +168,6 @@ wireshark_INCLUDES = \ g711.h \ globals.h \ log.h \ - main_window.h \ merge.h \ progress_dlg.h \ proto_hier_stats.h \ diff --git a/epan/column.c b/epan/column.c index 58a346a09b..2f302ff96c 100644 --- a/epan/column.c +++ b/epan/column.c @@ -39,7 +39,6 @@ #include #include #include -#include "cfile.h" #include #include @@ -658,50 +657,50 @@ get_column_custom_field(gint col) { } void -build_column_format_array(capture_file *cfile, gboolean reset_fences) +build_column_format_array(column_info *cinfo, gboolean reset_fences) { int i, j; - col_setup(&cfile->cinfo, prefs.num_cols); + col_setup(cinfo, prefs.num_cols); - for (i = 0; i < cfile->cinfo.num_cols; i++) { - cfile->cinfo.col_fmt[i] = get_column_format(i); - cfile->cinfo.col_title[i] = g_strdup(get_column_title(i)); - if (cfile->cinfo.col_fmt[i] == COL_CUSTOM) { - cfile->cinfo.col_custom_field[i] = g_strdup(get_column_custom_field(i)); + for (i = 0; i < cinfo->num_cols; i++) { + cinfo->col_fmt[i] = get_column_format(i); + cinfo->col_title[i] = g_strdup(get_column_title(i)); + if (cinfo->col_fmt[i] == COL_CUSTOM) { + cinfo->col_custom_field[i] = g_strdup(get_column_custom_field(i)); } else { - cfile->cinfo.col_custom_field[i] = NULL; + cinfo->col_custom_field[i] = NULL; } - cfile->cinfo.fmt_matx[i] = (gboolean *) g_malloc0(sizeof(gboolean) * + cinfo->fmt_matx[i] = (gboolean *) g_malloc0(sizeof(gboolean) * NUM_COL_FMTS); - get_column_format_matches(cfile->cinfo.fmt_matx[i], - cfile->cinfo.col_fmt[i]); - cfile->cinfo.col_data[i] = NULL; + get_column_format_matches(cinfo->fmt_matx[i], + cinfo->col_fmt[i]); + cinfo->col_data[i] = NULL; - if (cfile->cinfo.col_fmt[i] == COL_INFO) - cfile->cinfo.col_buf[i] = (gchar *) g_malloc(sizeof(gchar) * + if (cinfo->col_fmt[i] == COL_INFO) + cinfo->col_buf[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_INFO_LEN); else - cfile->cinfo.col_buf[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN); + cinfo->col_buf[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN); if(reset_fences) - cfile->cinfo.col_fence[i] = 0; + cinfo->col_fence[i] = 0; - cfile->cinfo.col_expr.col_expr[i] = (gchar *) g_malloc(sizeof(gchar) * + cinfo->col_expr.col_expr[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN); - cfile->cinfo.col_expr.col_expr_val[i] = (gchar *) g_malloc(sizeof(gchar) * + cinfo->col_expr.col_expr_val[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN); } - for (i = 0; i < cfile->cinfo.num_cols; i++) { + for (i = 0; i < cinfo->num_cols; i++) { for (j = 0; j < NUM_COL_FMTS; j++) { - if (!cfile->cinfo.fmt_matx[i][j]) + if (!cinfo->fmt_matx[i][j]) continue; - if (cfile->cinfo.col_first[j] == -1) - cfile->cinfo.col_first[j] = i; + if (cinfo->col_first[j] == -1) + cinfo->col_first[j] = i; - cfile->cinfo.col_last[j] = i; + cinfo->col_last[j] = i; } } } diff --git a/epan/column.h b/epan/column.h index b5aff2d3fb..ec8238c0da 100644 --- a/epan/column.h +++ b/epan/column.h @@ -47,7 +47,7 @@ const char *get_column_longest_string(gint); gint get_column_char_width(gint format); void -build_column_format_array(capture_file *cfile, gboolean reset_fences); +build_column_format_array(column_info *cinfo, gboolean reset_fences); #ifdef __cplusplus } diff --git a/gtk/capture_if_dlg.c b/gtk/capture_if_dlg.c index 23916729ba..471d0f891d 100644 --- a/gtk/capture_if_dlg.c +++ b/gtk/capture_if_dlg.c @@ -26,15 +26,15 @@ # include "config.h" #endif -#ifdef HAVE_LIBPCAP - #ifdef HAVE_SYS_WAIT_H # include #endif - #include + +#ifdef HAVE_LIBPCAP + #include "globals.h" #include "capture-pcap-util.h" diff --git a/gtk/file_dlg.h b/gtk/file_dlg.h index 692d2856b9..fc9c039174 100644 --- a/gtk/file_dlg.h +++ b/gtk/file_dlg.h @@ -1,4 +1,4 @@ -/* file_utils.h +/* file_dlg.h * Declarations of utilities to use when constructing file selection dialogs * * $Id$ diff --git a/gtk/main.c b/gtk/main.c index 965f2473d7..faba7696fa 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -72,89 +72,84 @@ #include #include #include - -/* general (not GTK specific) */ -#include "file.h" -#include "summary.h" -#include "filters.h" -#include "disabled_protos.h" #include -#include "filter_dlg.h" -#include "layout_prefs.h" -#include "color.h" -#include "color_filters.h" -#include "print.h" -#include "simple_dialog.h" -#include "register.h" #include -#include "ringbuffer.h" -#include "../ui_util.h" #include #include -#include "util.h" -#include "clopts_common.h" -#include "cmdarg_err.h" -#include "version_info.h" -#include "merge.h" -#include "u3.h" -#include "uat_gui.h" -#include "epan/uat.h" +#include +#include +#include + +/* general (not GTK specific) */ +#include "../file.h" +#include "../summary.h" +#include "../filters.h" +#include "../disabled_protos.h" +#include "../color.h" +#include "../color_filters.h" +#include "../print.h" +#include "../simple_dialog.h" +#include "../register.h" +#include "../ringbuffer.h" +#include "../ui_util.h" +#include "../util.h" +#include "../clopts_common.h" +#include "../cmdarg_err.h" +#include "../version_info.h" +#include "../merge.h" +#include "../alert_box.h" +#include "../capture_ui_utils.h" +#include "../log.h" +#include "../wiretap/file_util.h" #ifdef HAVE_LIBPCAP -#include "capture-pcap-util.h" -#include "capture.h" -#include "capture_sync.h" +#include "../capture-pcap-util.h" +#include "../capture.h" +#include "../capture_sync.h" #endif #ifdef _WIN32 -#include "capture-wpcap.h" -#include "capture_wpcap_packet.h" +#include "../capture-wpcap.h" +#include "../capture_wpcap_packet.h" #include /* Needed for Unicode */ #include #endif /* _WIN32 */ /* GTK related */ -#include "alert_box.h" -#if 0 -#include "dlg_utils.h" -#endif -#include "file_dlg.h" -#include "gtkglobals.h" -#include "colors.h" -#include "gui_utils.h" -#include "color_dlg.h" - -#include "main.h" -#include "main_airpcap_toolbar.h" -#include "main_filter_toolbar.h" -#include "main_menu.h" -#include "main_packet_list.h" -#include "main_statusbar.h" -#include "main_toolbar.h" -#include "main_welcome.h" -#include "../main_window.h" -#include "drag_and_drop.h" -#include "capture_file_dlg.h" -#include -#include "main_proto_draw.h" -#include "keys.h" -#include "packet_win.h" -#include "stock_icons.h" -#include "find_dlg.h" -#include "recent.h" -#include "follow_tcp.h" -#include "font_utils.h" -#include "about_dlg.h" -#include "help_dlg.h" -#include "decode_as_dlg.h" -#include "webbrowser.h" -#include "capture_dlg.h" -#include "capture_ui_utils.h" -#include "log.h" -#include "../epan/emem.h" -#include "file_util.h" -#include "tap_dfilter_dlg.h" +#include "gtk/file_dlg.h" +#include "gtk/gtkglobals.h" +#include "gtk/colors.h" +#include "gtk/gui_utils.h" +#include "gtk/color_dlg.h" +#include "gtk/filter_dlg.h" +#include "gtk/uat_gui.h" +#include "gtk/layout_prefs.h" +#include "gtk/u3.h" +#include "gtk/main.h" +#include "gtk/main_airpcap_toolbar.h" +#include "gtk/main_filter_toolbar.h" +#include "gtk/main_menu.h" +#include "gtk/main_packet_list.h" +#include "gtk/main_statusbar.h" +#include "gtk/main_toolbar.h" +#include "gtk/main_welcome.h" +#include "gtk/drag_and_drop.h" +#include "gtk/capture_file_dlg.h" +#include "gtk/main_proto_draw.h" +#include "gtk/keys.h" +#include "gtk/packet_win.h" +#include "gtk/stock_icons.h" +#include "gtk/find_dlg.h" +#include "gtk/recent.h" +#include "gtk/follow_tcp.h" +#include "gtk/font_utils.h" +#include "gtk/about_dlg.h" +#include "gtk/help_dlg.h" +#include "gtk/decode_as_dlg.h" +#include "gtk/webbrowser.h" +#include "gtk/capture_dlg.h" +#include "gtk/tap_dfilter_dlg.h" #ifdef HAVE_LIBPCAP #include "../image/wsicon16.xpm" @@ -179,6 +174,7 @@ #include #endif + /* * Files under personal and global preferences directories in which * GTK settings for Wireshark are stored. @@ -186,23 +182,22 @@ #define RC_FILE "gtkrc" capture_file cfile; -GtkWidget *main_display_filter_widget=NULL; -GtkWidget *top_level = NULL, *tree_view, *byte_nb_ptr, *tv_scrollw; -GtkWidget *pkt_scrollw; -static GtkWidget *main_pane_v1, *main_pane_v2, *main_pane_h1, *main_pane_h2; -static GtkWidget *main_first_pane, *main_second_pane; -GtkWidget *statusbar; -static GtkWidget *menubar, *main_vbox, *main_tb, *filter_tb; -static GtkWidget *priv_warning_dialog; +/* "exported" main widgets */ +GtkWidget *top_level = NULL, *pkt_scrollw, *tree_view, *byte_nb_ptr; + +/* placement widgets (can be a bit confusing, because of the many layout possibilities */ +static GtkWidget *main_vbox, *main_pane_v1, *main_pane_v2, *main_pane_h1, *main_pane_h2; +static GtkWidget *main_first_pane, *main_second_pane; + +/* internally used widgets */ +static GtkWidget *menubar, *main_tb, *filter_tb, *tv_scrollw, *statusbar, *welcome_pane; #ifdef HAVE_AIRPCAP GtkWidget *airpcap_tb; int airpcap_dll_ret_val = -1; #endif -static GtkWidget *welcome_pane; - GString *comp_info_str, *runtime_info_str; gboolean have_capture_file = FALSE; /* XXX - is there an equivalent in cfile? */ @@ -214,16 +209,17 @@ static void console_log_handler(const char *log_domain, GLogLevelFlags log_level, const char *message, gpointer user_data); #ifdef HAVE_LIBPCAP -static gboolean list_link_layer_types; capture_options global_capture_opts; capture_options *capture_opts = &global_capture_opts; #endif + static void create_main_window(gint, gint, gint, e_prefs*); static void show_main_window(gboolean); static void file_quit_answered_cb(gpointer dialog, gint btn, gpointer data); static void main_save_window_geometry(GtkWidget *widget); + /* Match selected byte pattern */ static void match_selected_cb_do(gpointer data, int action, gchar *text) @@ -512,8 +508,6 @@ set_frame_reftime(gboolean set, frame_data *frame, gint row) { } -GtkWidget *reftime_dialog = NULL; - static void reftime_answered_cb(gpointer dialog _U_, gint btn, gpointer data _U_) { switch(btn) { @@ -540,6 +534,7 @@ static void reftime_answered_cb(gpointer dialog _U_, gint btn, gpointer data _U_ void reftime_frame_cb(GtkWidget *w _U_, gpointer data _U_, REFTIME_ACTION_E action) { + static GtkWidget *reftime_dialog = NULL; switch(action){ case REFTIME_TOGGLE: @@ -1394,7 +1389,7 @@ main_cf_cb_live_capture_fixed_finished(capture_file *cf _U_) } } -#endif +#endif /* HAVE_LIBPCAP */ static void main_cf_cb_packet_selected(gpointer data) @@ -1441,7 +1436,8 @@ main_cf_cb_file_safe_reload_finished(gpointer data _U_) set_menus_for_capture_file(&cfile); } -static void main_cf_callback(gint event, gpointer data, gpointer user_data _U_) +static void +main_cf_callback(gint event, gpointer data, gpointer user_data _U_) { switch(event) { case(cf_cb_file_closing): @@ -1547,11 +1543,7 @@ get_gui_compiled_info(GString *str) } static void -get_gui_runtime_info(GString *str -#ifndef HAVE_AIRPCAP - _U_ -#endif -) +get_gui_runtime_info(GString *str) { #ifdef HAVE_AIRPCAP g_string_append(str, ", "); @@ -1688,6 +1680,7 @@ main(int argc, char *argv[]) int err; #ifdef HAVE_LIBPCAP gboolean start_capture = FALSE; + gboolean list_link_layer_types = FALSE; #else gboolean capture_option_specified = FALSE; #endif @@ -1698,6 +1691,7 @@ main(int argc, char *argv[]) e_prefs *prefs; char badopt; GtkWidget *splash_win = NULL; + gpointer priv_warning_dialog; GLogLevelFlags log_flags; guint go_to_packet = 0; int optind_initial; @@ -1706,7 +1700,6 @@ main(int argc, char *argv[]) #ifdef HAVE_AIRPCAP char *err_str; - /*gchar *cant_get_if_list_errstr;*/ #endif #define OPTSTRING_INIT "a:b:c:C:Df:g:Hhi:klLm:nN:o:P:pQr:R:Ss:t:vw:X:y:z:" @@ -2341,7 +2334,7 @@ main(int argc, char *argv[]) set_disabled_protos_list(); } - build_column_format_array(&cfile, TRUE); + build_column_format_array(&cfile.cinfo, TRUE); /* read in rc file from global and personal configuration paths. */ rc_file = get_datafile_path(RC_FILE); @@ -2781,11 +2774,9 @@ void main_widgets_rearrange(void) { gtk_widget_ref(menubar); gtk_widget_ref(main_tb); gtk_widget_ref(filter_tb); - #ifdef HAVE_AIRPCAP gtk_widget_ref(airpcap_tb); #endif - gtk_widget_ref(pkt_scrollw); gtk_widget_ref(tv_scrollw); gtk_widget_ref(byte_nb_ptr); @@ -2918,13 +2909,6 @@ is_widget_visible(GtkWidget *widget, gpointer data) } - -/* - * XXX - this doesn't appear to work with the paned widgets in - * GTK+ 1.2[.x]; if you hide one of the panes, the splitter remains - * and the other pane doesn't grow to take up the rest of the pane. - * It does appear to work with GTK+ 2.x. - */ void main_widgets_show_or_hide(void) { @@ -3130,13 +3114,13 @@ create_main_window (gint pl_size, gint tv_size, gint bv_size, e_prefs *prefs) gtk_widget_show(main_pane_h1); main_pane_h2 = gtk_hpaned_new(); gtk_widget_show(main_pane_h2); - #ifdef HAVE_AIRPCAP airpcap_tb = airpcap_toolbar_new(); + gtk_widget_show(airpcap_tb); #endif - /* status bar */ statusbar = statusbar_new(); + gtk_widget_show(statusbar); /* Pane for the welcome screen */ welcome_pane = welcome_new(); diff --git a/gtk/main_airpcap_toolbar.c b/gtk/main_airpcap_toolbar.c index 5ee49829fd..fbf5e9e476 100644 --- a/gtk/main_airpcap_toolbar.c +++ b/gtk/main_airpcap_toolbar.c @@ -255,7 +255,6 @@ GtkWidget *airpcap_toolbar_new() airpcap_tb = gtk_toolbar_new(); gtk_toolbar_set_orientation(GTK_TOOLBAR(airpcap_tb), GTK_ORIENTATION_HORIZONTAL); - gtk_widget_show(airpcap_tb); /* Interface Label */ /*if(airpcap_if_active != NULL) { diff --git a/gtk/main_filter_toolbar.c b/gtk/main_filter_toolbar.c index 597c74b0dd..2192bdd946 100644 --- a/gtk/main_filter_toolbar.c +++ b/gtk/main_filter_toolbar.c @@ -47,6 +47,8 @@ #include "main_filter_toolbar.h" +GtkWidget *main_display_filter_widget=NULL; + /* Run the current display filter on the current packet set, and redisplay. */ static void diff --git a/gtk/main_packet_list.c b/gtk/main_packet_list.c index 0290847cc1..8f99c0ad4e 100644 --- a/gtk/main_packet_list.c +++ b/gtk/main_packet_list.c @@ -30,29 +30,29 @@ #include #include - -#include "globals.h" -#include "gtkglobals.h" -#include "color.h" -#include "color_filters.h" -#include "../ui_util.h" -#include "gui_utils.h" -#include "colors.h" #include #include #include #include -#include "capture_file_dlg.h" -#include "keys.h" -#include "font_utils.h" -#include "packet_history.h" -#include "progress_dlg.h" -#include "recent.h" -#include "main.h" -#include "main_menu.h" -#include "main_packet_list.h" -#include "main_statusbar.h" +#include "../globals.h" +#include "../color.h" +#include "../color_filters.h" +#include "../ui_util.h" +#include "../progress_dlg.h" + +#include "gtk/gtkglobals.h" +#include "gtk/gui_utils.h" +#include "gtk/colors.h" +#include "gtk/capture_file_dlg.h" +#include "gtk/keys.h" +#include "gtk/font_utils.h" +#include "gtk/packet_history.h" +#include "gtk/recent.h" +#include "gtk/main.h" +#include "gtk/main_menu.h" +#include "gtk/main_packet_list.h" +#include "gtk/main_statusbar.h" #include "image/clist_ascend.xpm" #include "image/clist_descend.xpm" @@ -541,7 +541,7 @@ packet_list_recreate(void) prefs.num_cols = g_list_length(prefs.col_list); - build_column_format_array(&cfile, FALSE); + build_column_format_array(&cfile.cinfo, FALSE); pkt_scrollw = packet_list_new(&prefs); gtk_widget_show(pkt_scrollw); diff --git a/gtk/main_statusbar.c b/gtk/main_statusbar.c index 513c388c41..45ce230415 100644 --- a/gtk/main_statusbar.c +++ b/gtk/main_statusbar.c @@ -187,6 +187,10 @@ statusbar_new(void) { GtkWidget *status_hbox; + /* Sstatus hbox */ + status_hbox = gtk_hbox_new(FALSE, 1); + gtk_container_border_width(GTK_CONTAINER(status_hbox), 0); + /* info (main) statusbar */ info_bar = info_bar_new(); gtk_widget_show(info_bar); @@ -202,11 +206,6 @@ statusbar_new(void) /* expert info indicator */ status_expert_new(); - /* Filter/status hbox */ - status_hbox = gtk_hbox_new(FALSE, 1); - gtk_container_border_width(GTK_CONTAINER(status_hbox), 0); - gtk_widget_show(status_hbox); - /* Pane for the statusbar */ status_pane_left = gtk_hpaned_new(); gtk_widget_show(status_pane_left); diff --git a/main_window.h b/main_window.h deleted file mode 100644 index e69c39bc40..0000000000 --- a/main_window.h +++ /dev/null @@ -1,41 +0,0 @@ -/* main_window.h - * Definitions for main window routines with toolkit-independent APIs but - * toolkit-dependent implementations. - * - * $Id$ - * - * Wireshark - Network traffic analyzer - * By Gerald Combs - * 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 __MAIN_WINDOW_H__ -#define __MAIN_WINDOW_H__ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/** Tell the main window that we have a capture file (or not) */ -extern void -main_set_for_capture_file(gboolean have_capture_file_in); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __MAIN_WINDOW_H__ */