aboutsummaryrefslogtreecommitdiffstats
path: root/file.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2003-09-15 20:37:37 +0000
committerGuy Harris <guy@alum.mit.edu>2003-09-15 20:37:37 +0000
commit673e47d4a9a1a79170bc93b8df23c6ac328bb531 (patch)
treed1a536772bd6167431c28ecb60a637804f762b3b /file.c
parent4339a40c036664a30485c50692a9d9dba5419bbe (diff)
downloadwireshark-673e47d4a9a1a79170bc93b8df23c6ac328bb531.tar.gz
wireshark-673e47d4a9a1a79170bc93b8df23c6ac328bb531.tar.bz2
wireshark-673e47d4a9a1a79170bc93b8df23c6ac328bb531.zip
Keep a "display name" as part of a capture_file structure; for live
capture temporary files, it's "<capture", and for saved capture files, it's the last component of the pathname of the file. Use that in various places when displaying the file name. svn path=/trunk/; revision=8474
Diffstat (limited to 'file.c')
-rw-r--r--file.c55
1 files changed, 29 insertions, 26 deletions
diff --git a/file.c b/file.c
index 6777138d62..b2607d65e8 100644
--- a/file.c
+++ b/file.c
@@ -1,7 +1,7 @@
/* file.c
* File I/O routines
*
- * $Id: file.c,v 1.310 2003/09/12 02:48:20 sahlberg Exp $
+ * $Id: file.c,v 1.311 2003/09/15 20:37:36 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -151,6 +151,7 @@ open_cap_file(char *fname, gboolean is_tempfile, capture_file *cf)
int err;
int fd;
struct stat cf_stat;
+ gchar *displayname;
wth = wtap_open_offline(fname, &err, TRUE);
if (wth == NULL)
@@ -189,6 +190,17 @@ open_cap_file(char *fname, gboolean is_tempfile, capture_file *cf)
/* If it's a temporary capture buffer file, mark it as not saved. */
cf->user_saved = !is_tempfile;
+ /* Set the name we use in various displays */
+ if (!cf->is_tempfile) {
+ /* Get the last component of the file name, and use that. */
+ displayname = get_basename(cf->filename);
+ } else {
+ /* The file we read is a temporary file from a live capture;
+ we don't mention its name. */
+ displayname = "<capture>";
+ }
+ cf->displayname = g_strdup(displayname);
+
cf->cd_t = wtap_file_type(cf->wth);
cf->count = 0;
cf->marked_count = 0;
@@ -245,6 +257,10 @@ close_cap_file(capture_file *cf)
g_free(cf->filename);
cf->filename = NULL;
}
+ if (cf->displayname != NULL) {
+ g_free(cf->displayname);
+ cf->displayname = NULL;
+ }
/* ...which means we have nothing to save. */
cf->user_saved = FALSE;
@@ -292,7 +308,6 @@ close_cap_file(capture_file *cf)
static void
set_display_filename(capture_file *cf)
{
- gchar *name_ptr;
size_t msg_len;
static const gchar done_fmt_nodrops[] = " File: %s";
static const gchar done_fmt_drops[] = " File: %s Drops: %u";
@@ -300,31 +315,21 @@ set_display_filename(capture_file *cf)
gchar *win_name_fmt = "%s - Ethereal";
gchar *win_name;
- if (!cf->is_tempfile) {
- /* Get the last component of the file name, and put that in the
- status bar. */
- name_ptr = get_basename(cf->filename);
- } else {
- /* The file we read is a temporary file from a live capture;
- we don't mention its name in the status bar. */
- name_ptr = "<capture>";
- }
-
if (cf->drops_known) {
- msg_len = strlen(name_ptr) + strlen(done_fmt_drops) + 64;
+ msg_len = strlen(cf->displayname) + strlen(done_fmt_drops) + 64;
done_msg = g_malloc(msg_len);
- snprintf(done_msg, msg_len, done_fmt_drops, name_ptr, cf->drops);
+ snprintf(done_msg, msg_len, done_fmt_drops, cf->displayname, cf->drops);
} else {
- msg_len = strlen(name_ptr) + strlen(done_fmt_nodrops);
+ msg_len = strlen(cf->displayname) + strlen(done_fmt_nodrops);
done_msg = g_malloc(msg_len);
- snprintf(done_msg, msg_len, done_fmt_nodrops, name_ptr);
+ snprintf(done_msg, msg_len, done_fmt_nodrops, cf->displayname);
}
statusbar_push_file_msg(done_msg);
g_free(done_msg);
- msg_len = strlen(name_ptr) + strlen(win_name_fmt) + 1;
+ msg_len = strlen(cf->displayname) + strlen(win_name_fmt) + 1;
win_name = g_malloc(msg_len);
- snprintf(win_name, msg_len, win_name_fmt, name_ptr);
+ snprintf(win_name, msg_len, win_name_fmt, cf->displayname);
set_main_window_name(win_name);
g_free(win_name);
}
@@ -332,7 +337,7 @@ set_display_filename(capture_file *cf)
read_status_t
read_cap_file(capture_file *cf, int *err)
{
- gchar *name_ptr, *load_msg, *load_fmt = "%s";
+ gchar *load_msg, *load_fmt = "%s";
size_t msg_len;
char *errmsg;
char errmsg_errno[1024+1];
@@ -354,11 +359,10 @@ read_cap_file(capture_file *cf, int *err)
cul_bytes=0;
reset_tap_listeners();
- name_ptr = get_basename(cf->filename);
- msg_len = strlen(name_ptr) + strlen(load_fmt) + 2;
+ msg_len = strlen(cf->displayname) + strlen(load_fmt) + 2;
load_msg = g_malloc(msg_len);
- snprintf(load_msg, msg_len, load_fmt, name_ptr);
+ snprintf(load_msg, msg_len, load_fmt, cf->displayname);
statusbar_push_file_msg(load_msg);
/* Update the progress bar when it gets to this value. */
@@ -2151,7 +2155,7 @@ save_cap_file(char *fname, capture_file *cf, gboolean save_filtered,
gboolean save_marked, guint save_format)
{
gchar *from_filename;
- gchar *name_ptr, *save_msg, *save_fmt = " Saving: %s...";
+ gchar *save_msg, *save_fmt = " Saving: %s...";
size_t msg_len;
int err;
gboolean do_copy;
@@ -2162,10 +2166,9 @@ save_cap_file(char *fname, capture_file *cf, gboolean save_filtered,
guint8 pd[65536];
struct stat infile, outfile;
- name_ptr = get_basename(fname);
- msg_len = strlen(name_ptr) + strlen(save_fmt) + 2;
+ msg_len = strlen(cf->displayname) + strlen(save_fmt) + 2;
save_msg = g_malloc(msg_len);
- snprintf(save_msg, msg_len, save_fmt, name_ptr);
+ snprintf(save_msg, msg_len, save_fmt, cf->displayname);
statusbar_push_file_msg(save_msg);
g_free(save_msg);