From de459d1426cc27341dcf681cf5b35c27c9a5732a Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 22 Jul 1999 21:14:13 +0000 Subject: Revert to static sizing of columns. svn path=/trunk/; revision=377 --- column.c | 67 ++++++++++++++++++++++++++++++++- column.h | 3 +- ethereal.c | 16 ++++---- file.c | 123 +++++++++++++++++-------------------------------------------- packet.h | 4 +- 5 files changed, 109 insertions(+), 104 deletions(-) diff --git a/column.c b/column.c index 783ed1e8ab..77cfc7cc97 100644 --- a/column.c +++ b/column.c @@ -1,7 +1,7 @@ /* column.c * Routines for handling column preferences * - * $Id: column.c,v 1.17 1999/07/22 16:03:51 gram Exp $ + * $Id: column.c,v 1.18 1999/07/22 21:14:13 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -170,6 +170,71 @@ get_column_format_matches(gboolean *fmt_list, gint format) { } } +/* Returns the longest possible width for a particular column type */ +/* XXX - this is somewhat fragile; we should probably generate */ +/* the summary lines for all the packets first, and compute the */ +/* maximum column width as the maximum string width of all the */ +/* values in that column. */ +gint +get_column_width(gint format, GdkFont *font) { + switch (format) { + case COL_NUMBER: + return (gdk_string_width(font, "0") * 7); + break; + case COL_CLS_TIME: + if (timestamp_type == ABSOLUTE) + return (gdk_string_width(font, "00:00:00.000000")); + else + return (gdk_string_width(font, "0000.000000")); + break; + case COL_ABS_TIME: + return (gdk_string_width(font, "00:00:00.000000")); + break; + case COL_REL_TIME: + case COL_DELTA_TIME: + return (gdk_string_width(font, "0000.000000")); + break; + case COL_DEF_SRC: + case COL_RES_SRC: + case COL_UNRES_SRC: + case COL_DEF_DL_SRC: + case COL_RES_DL_SRC: + case COL_UNRES_DL_SRC: + case COL_DEF_NET_SRC: + case COL_RES_NET_SRC: + case COL_UNRES_NET_SRC: + case COL_DEF_DST: + case COL_RES_DST: + case COL_UNRES_DST: + case COL_DEF_DL_DST: + case COL_RES_DL_DST: + case COL_UNRES_DL_DST: + case COL_DEF_NET_DST: + case COL_RES_NET_DST: + case COL_UNRES_NET_DST: + return (gdk_string_width(font, "00000000.000000000000")); /* IPX-style */ + break; + case COL_DEF_SRC_PORT: + case COL_RES_SRC_PORT: + case COL_UNRES_SRC_PORT: + case COL_DEF_DST_PORT: + case COL_RES_DST_PORT: + case COL_UNRES_DST_PORT: + return (gdk_string_width(font, "0") * 6); + break; + case COL_PROTOCOL: + return (gdk_string_width(font, "NBNS (UDP)")); + break; + case COL_PACKET_LENGTH: + return (gdk_string_width(font, "0") * 6); + break; + default: /* COL_INFO */ + return (gdk_string_width(font, "Source port: kerberos-master " + "Destination port: kerberos-master")); + break; + } +} + #define TIME_DEF 0 #define TIME_REL 1 #define TIME_ABS 2 diff --git a/column.h b/column.h index 314b93ca25..9010d55716 100644 --- a/column.h +++ b/column.h @@ -1,7 +1,7 @@ /* column.h * Definitions for column handling routines * - * $Id: column.h,v 1.2 1999/06/19 03:14:31 guy Exp $ + * $Id: column.h,v 1.3 1999/07/22 21:14:13 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -35,6 +35,7 @@ gint get_column_format(gint); gchar *get_column_title(gint); gchar *col_format_to_pref_str(); void get_column_format_matches(gboolean *, gint); +gint get_column_width(gint format, GdkFont *font); GtkWidget *column_prefs_show(); void column_prefs_ok(GtkWidget *); void column_prefs_save(GtkWidget *); diff --git a/ethereal.c b/ethereal.c index fcc4324d79..1b080b534a 100644 --- a/ethereal.c +++ b/ethereal.c @@ -1,6 +1,6 @@ /* ethereal.c * - * $Id: ethereal.c,v 1.57 1999/07/15 15:32:39 gram Exp $ + * $Id: ethereal.c,v 1.58 1999/07/22 21:14:12 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -108,7 +108,6 @@ proto_tree *protocol_tree = NULL; GtkWidget *file_sel, *packet_list, *tree_view, *byte_view, *prog_bar, *info_bar; GdkFont *m_r_font, *m_b_font; -GtkStyle *pl_style; guint main_ctx, file_ctx; frame_data *fd; gint start_capture = 0; @@ -691,12 +690,14 @@ main(int argc, char *argv[]) GtkWidget *window, *main_vbox, *menubar, *u_pane, *l_pane, *bv_table, *bv_hscroll, *bv_vscroll, *stat_hbox, *tv_scrollw, *filter_bt, *filter_te; + GtkStyle *pl_style; GtkAccelGroup *accel; GtkWidget *packet_sw; gint pl_size = 280, tv_size = 95, bv_size = 75; gchar *rc_file, *cf_name = NULL; e_prefs *prefs; gint *col_fmt; + gchar **col_title; ethereal_path = argv[0]; @@ -727,10 +728,8 @@ main(int argc, char *argv[]) cf.snap = MAX_PACKET_SIZE; cf.count = 0; cf.cinfo.num_cols = prefs->num_cols; - cf.cinfo.col_title = (gchar **) g_malloc(sizeof(gchar *) * cf.cinfo.num_cols); cf.cinfo.fmt_matx = (gboolean **) g_malloc(sizeof(gboolean *) * cf.cinfo.num_cols); cf.cinfo.col_data = (gchar **) g_malloc(sizeof(gchar *) * cf.cinfo.num_cols); - cf.cinfo.col_width = (gint *) g_malloc(sizeof(gint) * cf.cinfo.num_cols); /* Assemble the compile-time options */ snprintf(comp_info_str, 256, @@ -861,15 +860,15 @@ main(int argc, char *argv[]) /* Build the column format array */ col_fmt = (gint *) g_malloc(sizeof(gint) * cf.cinfo.num_cols); + col_title = (gchar **) g_malloc(sizeof(gchar *) * cf.cinfo.num_cols); for (i = 0; i < cf.cinfo.num_cols; i++) { col_fmt[i] = get_column_format(i); - cf.cinfo.col_title[i] = g_strdup(get_column_title(i)); + col_title[i] = g_strdup(get_column_title(i)); cf.cinfo.fmt_matx[i] = (gboolean *) g_malloc0(sizeof(gboolean) * NUM_COL_FMTS); get_column_format_matches(cf.cinfo.fmt_matx[i], col_fmt[i]); cf.cinfo.col_data[i] = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN); - cf.cinfo.col_width[i] = 0; } if (cf.snap < 1) @@ -927,8 +926,7 @@ main(int argc, char *argv[]) gtk_widget_show(l_pane); /* Packet list */ - packet_list = gtk_clist_new_with_titles(cf.cinfo.num_cols, - cf.cinfo.col_title); + packet_list = gtk_clist_new_with_titles(cf.cinfo.num_cols, col_title); gtk_clist_column_titles_passive(GTK_CLIST(packet_list)); packet_sw = gtk_scrolled_window_new(NULL, NULL); gtk_widget_show(packet_sw); @@ -944,7 +942,7 @@ main(int argc, char *argv[]) GTK_SIGNAL_FUNC(packet_list_unselect_cb), NULL); for (i = 0; i < cf.cinfo.num_cols; i++) { gtk_clist_set_column_width(GTK_CLIST(packet_list), i, - gdk_string_width(pl_style->font, cf.cinfo.col_title[i])); + get_column_width(get_column_format(i), pl_style->font)); if (col_fmt[i] == COL_NUMBER) gtk_clist_set_column_justification(GTK_CLIST(packet_list), i, GTK_JUSTIFY_RIGHT); diff --git a/file.c b/file.c index 17212eae00..609514a736 100644 --- a/file.c +++ b/file.c @@ -1,7 +1,7 @@ /* file.c * File I/O routines * - * $Id: file.c,v 1.39 1999/07/20 05:13:24 guy Exp $ + * $Id: file.c,v 1.40 1999/07/22 21:14:11 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -78,7 +78,6 @@ #define TAIL_TIMEOUT 2000 /* msec */ extern GtkWidget *packet_list, *prog_bar, *info_bar, *byte_view, *tree_view; -extern GtkStyle *pl_style; extern guint file_ctx; extern int sync_mode; extern int sync_pipe[]; @@ -91,9 +90,6 @@ static guint32 lastsec, lastusec; static void wtap_dispatch_cb(u_char *, const struct wtap_pkthdr *, int, const u_char *); -static void init_col_widths(capture_file *); -static void set_col_widths(capture_file *); - #ifdef HAVE_LIBPCAP static gint tail_timeout_cb(gpointer); #endif @@ -210,13 +206,10 @@ load_cap_file(char *fname, capture_file *cf) { err = open_cap_file(fname, cf); if ((err == 0) && (cf->cd_t != WTAP_FILE_UNKNOWN)) { gtk_clist_freeze(GTK_CLIST(packet_list)); - init_col_widths(cf); wtap_loop(cf->wth, 0, wtap_dispatch_cb, (u_char *) cf); wtap_close(cf->wth); cf->wth = NULL; cf->fh = fopen(fname, "r"); - - set_col_widths(cf); gtk_clist_thaw(GTK_CLIST(packet_list)); } @@ -292,7 +285,6 @@ cap_file_input_cb (gpointer data, gint source, GdkInputCondition condition) { wtap_loop(cf->wth, 0, wtap_dispatch_cb, (u_char *) cf); - set_col_widths(cf); gtk_clist_thaw(GTK_CLIST(packet_list)); wtap_close(cf->wth); @@ -311,7 +303,6 @@ cap_file_input_cb (gpointer data, gint source, GdkInputCondition condition) { gtk_clist_freeze(GTK_CLIST(packet_list)); wtap_loop(cf->wth, 0, wtap_dispatch_cb, (u_char *) cf); - set_col_widths(cf); gtk_clist_thaw(GTK_CLIST(packet_list)); /* restore pipe handler */ @@ -338,7 +329,6 @@ tail_timeout_cb(gpointer data) { gtk_clist_freeze(GTK_CLIST(packet_list)); wtap_loop(cf->wth, 0, wtap_dispatch_cb, (u_char *) cf); - set_col_widths(cf); gtk_clist_thaw(GTK_CLIST(packet_list)); /* restore pipe handler */ @@ -363,7 +353,6 @@ tail_cap_file(char *fname, capture_file *cf) { err = open_cap_file(fname, cf); if ((err == 0) && (cf->cd_t != WTAP_FILE_UNKNOWN)) { - init_col_widths(cf); set_menu_sensitivity("/File/Open...", FALSE); set_menu_sensitivity("/File/Close", FALSE); @@ -435,46 +424,10 @@ compute_time_stamps(frame_data *fdata, capture_file *cf) lastusec = fdata->abs_usecs; } -static void -change_time_format_in_packet_list(frame_data *fdata, capture_file *cf) -{ - gint i, col_width; - - /* XXX - there really should be a way of checking "cf->cinfo" for this; - the answer isn't going to change from packet to packet, so we should - simply skip all the "change_time_formats()" work if we're not - changing anything. */ - fdata->cinfo = &cf->cinfo; - if (!check_col(fdata, COL_CLS_TIME)) { - /* There are no columns that show the time in the "command-line-specified" - format, so there's nothing we need to do. */ - return; - } - - compute_time_stamps(fdata, cf); - - for (i = 0; i < fdata->cinfo->num_cols; i++) { - fdata->cinfo->col_data[i][0] = '\0'; - } - col_add_cls_time(fdata); - for (i = 0; i < fdata->cinfo->num_cols; i++) { - if (fdata->cinfo->fmt_matx[i][COL_CLS_TIME]) { - /* This is one of the columns that shows the time in - "command-line-specified" format; update it. */ - col_width = gdk_string_width(pl_style->font, fdata->cinfo->col_data[i]); - if (col_width > fdata->cinfo->col_width[i]) - fdata->cinfo->col_width[i] = col_width; - gtk_clist_set_text(GTK_CLIST(packet_list), cf->count - 1, i, - fdata->cinfo->col_data[i]); - } - } - fdata->cinfo = NULL; -} - static void add_packet_to_packet_list(frame_data *fdata, capture_file *cf, const u_char *buf) { - gint i, col_width, row; + gint i, row; proto_tree *protocol_tree; compute_time_stamps(fdata, cf); @@ -495,11 +448,6 @@ add_packet_to_packet_list(frame_data *fdata, capture_file *cf, const u_char *buf dissect_packet(buf, fdata, NULL); fdata->passed_dfilter = TRUE; } - for (i = 0; i < fdata->cinfo->num_cols; i++) { - col_width = gdk_string_width(pl_style->font, fdata->cinfo->col_data[i]); - if (col_width > fdata->cinfo->col_width[i]) - fdata->cinfo->col_width[i] = col_width; - } if (fdata->passed_dfilter) { row = gtk_clist_append(GTK_CLIST(packet_list), fdata->cinfo->col_data); gtk_clist_set_row_data(GTK_CLIST(packet_list), row, fdata); @@ -591,11 +539,37 @@ change_time_formats_cb(gpointer data, gpointer user_data) { frame_data *fd = data; capture_file *cf = user_data; + gint i; cf->cur = fd; cf->count++; - change_time_format_in_packet_list(fd, cf); + /* XXX - there really should be a way of checking "cf->cinfo" for this; + the answer isn't going to change from packet to packet, so we should + simply skip all the "change_time_formats()" work if we're not + changing anything. */ + fd->cinfo = &cf->cinfo; + if (!check_col(fd, COL_CLS_TIME)) { + /* There are no columns that show the time in the "command-line-specified" + format, so there's nothing we need to do. */ + return; + } + + compute_time_stamps(fd, cf); + + for (i = 0; i < fd->cinfo->num_cols; i++) { + fd->cinfo->col_data[i][0] = '\0'; + } + col_add_cls_time(fd); + for (i = 0; i < fd->cinfo->num_cols; i++) { + if (fd->cinfo->fmt_matx[i][COL_CLS_TIME]) { + /* This is one of the columns that shows the time in + "command-line-specified" format; update it. */ + gtk_clist_set_text(GTK_CLIST(packet_list), cf->count - 1, i, + fd->cinfo->col_data[i]); + } + } + fd->cinfo = NULL; } /* Scan through the packet list and change all columns that use the @@ -605,14 +579,12 @@ void change_time_formats(capture_file *cf) { int i; + GtkStyle *pl_style; /* Freeze the packet list while we redo it, so we don't get any screen updates while it happens. */ gtk_clist_freeze(GTK_CLIST(packet_list)); - /* Zero out the column widths. */ - init_col_widths(cf); - /* * Iterate through the list of packets, calling a routine * to run the filter on the packet, see if it matches, and @@ -627,10 +599,11 @@ change_time_formats(capture_file *cf) /* Set the column widths of those columns that show the time in "command-line-specified" format. */ + pl_style = gtk_widget_get_style(packet_list); for (i = 0; i < cf->cinfo.num_cols; i++) { if (cf->cinfo.fmt_matx[i][COL_CLS_TIME]) { gtk_clist_set_column_width(GTK_CLIST(packet_list), i, - cf->cinfo.col_width[i]); + get_column_width(COL_CLS_TIME, pl_style->font)); } } @@ -638,37 +611,6 @@ change_time_formats(capture_file *cf) gtk_clist_thaw(GTK_CLIST(packet_list)); } -/* Initialize the maximum widths of the columns to the widths of their - titles. */ -static void -init_col_widths(capture_file *cf) -{ - int i; - - /* XXX - this should use the column *title* font, not the font for - the items in the list. - - Unfortunately, it's not clear how to get that font - it'd be - the font used for buttons; there doesn't seem to be a way to get - that from a clist, or to get one of the buttons in that clist from - the clist in order to get its font. */ - for (i = 0; i < cf->cinfo.num_cols; i++) - cf->cinfo.col_width[i] = gdk_string_width(pl_style->font, - cf->cinfo.col_title[i]); -} - -/* Set the widths of the columns to the maximum widths we found. */ -static void -set_col_widths(capture_file *cf) -{ - int i; - - for (i = 0; i < cf->cinfo.num_cols; i++) { - gtk_clist_set_column_width(GTK_CLIST(packet_list), i, - cf->cinfo.col_width[i]); - } -} - /* Tries to mv a file. If unsuccessful, tries to cp the file. * Returns 0 on failure to do either, 1 on success of either */ @@ -830,3 +772,4 @@ file_write_error_message(int err) } return errmsg; } + diff --git a/packet.h b/packet.h index 22fc4b3920..fa49250bbe 100644 --- a/packet.h +++ b/packet.h @@ -1,7 +1,7 @@ /* packet.h * Definitions for packet disassembly structures and routines * - * $Id: packet.h,v 1.72 1999/07/22 16:03:52 gram Exp $ + * $Id: packet.h,v 1.73 1999/07/22 21:14:12 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -84,10 +84,8 @@ typedef struct _column_info { gint num_cols; /* Number of columns */ - gchar **col_title;/* Column title */ gboolean **fmt_matx; /* Specifies which formats apply to a column */ gchar **col_data; /* Column data */ - gint *col_width; /* Column width */ } column_info; #define COL_MAX_LEN 256 -- cgit v1.2.3