From 727b913bbd2b41c6ece202f240f69e2f621833ac Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Wed, 11 Feb 2004 01:23:25 +0000 Subject: Add an "open_failure_alert_box()" routine to pop up an alert box for a failed attempt to open/create a file. Fix one call to pass the right value for the "for_writing" flag. svn path=/trunk/; revision=10026 --- alert_box.c | 22 +++++++++++++++++++++- alert_box.h | 11 ++++++++++- capture.c | 7 +++---- file.c | 11 ++++------- gtk/follow_dlg.c | 13 ++++++------- gtk/print_dlg.c | 6 +++--- gtk/proto_draw.c | 6 +++--- gtk/rtp_analysis.c | 14 +++++--------- gtk/rtp_stream.c | 6 +++--- 9 files changed, 58 insertions(+), 38 deletions(-) diff --git a/alert_box.c b/alert_box.c index c2f8784acc..ecd0f734d7 100644 --- a/alert_box.c +++ b/alert_box.c @@ -2,7 +2,7 @@ * Routines to put up various "standard" alert boxes used in multiple * places * - * $Id: alert_box.c,v 1.1 2004/02/11 00:55:26 guy Exp $ + * $Id: alert_box.c,v 1.2 2004/02/11 01:23:23 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -29,12 +29,32 @@ #include +#include #include #include "alert_box.h" #include "simple_dialog.h" +/* + * Alert box for a failed attempt to open or create a file. + * "err" is assumed to be a UNIX-style errno; "for_writing" is TRUE if + * the file is being opened for writing and FALSE if it's being opened + * for reading. + * + * XXX - add explanatory secondary text for at least some of the errors; + * various HIGs suggest that you should, for example, suggest that the + * user remove files if the file system is full. Perhaps that's because + * they're providing guidelines for people less sophisticated than the + * typical Ethereal user is, but.... + */ +void +open_failure_alert_box(const char *filename, int err, gboolean for_writing) +{ + simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, + file_open_error_message(err, for_writing), filename); +} + /* * Alert box for an invalid display filter expression. * Assumes "dfilter_error_msg" has been set by "dfilter_compile()" to the diff --git a/alert_box.h b/alert_box.h index 5c35d1896a..249d6aaafa 100644 --- a/alert_box.h +++ b/alert_box.h @@ -2,7 +2,7 @@ * Routines to put up various "standard" alert boxes used in multiple * places * - * $Id: alert_box.h,v 1.1 2004/02/11 00:55:27 guy Exp $ + * $Id: alert_box.h,v 1.2 2004/02/11 01:23:23 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -30,6 +30,15 @@ extern "C" { #endif /* __cplusplus */ +/* + * Alert box for a failed attempt to open or create a file. + * "err" is assumed to be a UNIX-style errno; "for_writing" is TRUE if + * the file is being opened for writing and FALSE if it's being opened + * for reading. + */ +extern void open_failure_alert_box(const char *filename, int err, + gboolean for_writing); + /* * Alert box for an invalid display filter expression. * Assumes "dfilter_error_msg" has been set by "dfilter_compile()" to the diff --git a/capture.c b/capture.c index 7bd3a8d714..6221a77252 100644 --- a/capture.c +++ b/capture.c @@ -1,7 +1,7 @@ /* capture.c * Routines for packet capture windows * - * $Id: capture.c,v 1.237 2004/02/09 19:19:19 ulfl Exp $ + * $Id: capture.c,v 1.238 2004/02/11 01:23:23 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -130,11 +130,11 @@ #include #include -#include #include "file.h" #include "capture.h" #include "util.h" #include "pcap-util.h" +#include "alert_box.h" #include "simple_dialog.h" #include "prefs.h" #include "globals.h" @@ -322,8 +322,7 @@ do_capture(const char *save_file) if (capture_opts.ringbuffer_on) { ringbuf_error_cleanup(); } - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - file_open_error_message(errno, TRUE), capfile_name); + open_failure_alert_box(capfile_name, errno, TRUE); } g_free(capfile_name); return FALSE; diff --git a/file.c b/file.c index 23c47cb805..d91bdb599a 100644 --- a/file.c +++ b/file.c @@ -1,7 +1,7 @@ /* file.c * File I/O routines * - * $Id: file.c,v 1.358 2004/02/11 00:55:27 guy Exp $ + * $Id: file.c,v 1.359 2004/02/11 01:23:24 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -70,6 +70,7 @@ #include "file.h" #include "menu.h" #include "util.h" +#include "alert_box.h" #include "simple_dialog.h" #include "progress_dlg.h" #include "ui_util.h" @@ -2979,9 +2980,7 @@ copy_binary_file(char *from_filename, char *to_filename) /* Copy the raw bytes of the file. */ from_fd = open(from_filename, O_RDONLY | O_BINARY); if (from_fd < 0) { - err = errno; - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - file_open_error_message(err, TRUE), from_filename); + open_failure_alert_box(from_filename, errno, FALSE); goto done; } @@ -2992,9 +2991,7 @@ copy_binary_file(char *from_filename, char *to_filename) to be open in binary mode. */ to_fd = open(to_filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0644); if (to_fd < 0) { - err = errno; - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - file_open_error_message(err, TRUE), to_filename); + open_failure_alert_box(to_filename, errno, TRUE); close(from_fd); goto done; } diff --git a/gtk/follow_dlg.c b/gtk/follow_dlg.c index ed99c97e54..e31218f70a 100644 --- a/gtk/follow_dlg.c +++ b/gtk/follow_dlg.c @@ -1,6 +1,6 @@ /* follow_dlg.c * - * $Id: follow_dlg.c,v 1.43 2004/02/06 19:19:10 ulfl Exp $ + * $Id: follow_dlg.c,v 1.44 2004/02/11 01:23:24 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -54,6 +54,7 @@ #include "globals.h" #include "gtkglobals.h" #include "main.h" +#include "alert_box.h" #include "simple_dialog.h" #include "packet-ipv6.h" #include "prefs.h" @@ -765,10 +766,9 @@ follow_print_stream(GtkWidget * w _U_, gpointer data) fh = open_print_dest(to_file, print_dest); if (fh == NULL) { - if (to_file) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - file_open_error_message(errno, TRUE), prefs.pr_file); - } else { + if (to_file) + open_failure_alert_box(prefs.pr_file, errno, TRUE); + else { simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Couldn't run print command %s.", prefs.pr_cmd); } @@ -977,8 +977,7 @@ follow_save_as_ok_cb(GtkWidget * w _U_, GtkFileSelection * fs) fh = fopen(to_name, "wb"); if (fh == NULL) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - file_open_error_message(errno, TRUE), to_name); + open_failure_alert_box(to_name, errno, TRUE); g_free(to_name); return; } diff --git a/gtk/print_dlg.c b/gtk/print_dlg.c index 5d9c6b58df..5955a36c82 100644 --- a/gtk/print_dlg.c +++ b/gtk/print_dlg.c @@ -1,7 +1,7 @@ /* print_dlg.c * Dialog boxes for printing * - * $Id: print_dlg.c,v 1.60 2004/01/31 20:31:20 ulfl Exp $ + * $Id: print_dlg.c,v 1.61 2004/02/11 01:23:24 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -34,6 +34,7 @@ #include "keys.h" #include "print.h" #include "prefs.h" +#include "alert_box.h" #include "simple_dialog.h" #include "file_dlg.h" #include "ui_util.h" @@ -846,8 +847,7 @@ print_ok_cb(GtkWidget *ok_bt, gpointer parent_w) case PP_OPEN_ERROR: if (print_args.to_file) - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - file_open_error_message(errno, TRUE), print_args.dest); + open_failure_alert_box(print_args.dest, errno, TRUE); else simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, "Couldn't run print command %s.", print_args.dest); diff --git a/gtk/proto_draw.c b/gtk/proto_draw.c index 506eb6941a..ea5b52b340 100644 --- a/gtk/proto_draw.c +++ b/gtk/proto_draw.c @@ -1,7 +1,7 @@ /* proto_draw.c * Routines for GTK+ packet display * - * $Id: proto_draw.c,v 1.86 2004/02/06 19:19:10 ulfl Exp $ + * $Id: proto_draw.c,v 1.87 2004/02/11 01:23:24 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs @@ -62,6 +62,7 @@ #include "gtkglobals.h" #include "compat_macros.h" #include +#include "alert_box.h" #include "simple_dialog.h" #define BYTE_VIEW_WIDTH 16 @@ -918,8 +919,7 @@ savehex_save_clicked_cb(GtkWidget * w _U_, gpointer data _U_) fd = open(file, O_WRONLY|O_CREAT|O_TRUNC, 0666); if (fd == -1) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - file_open_error_message(errno, TRUE), file); + open_failure_alert_box(file, errno, TRUE); return; } if (write(fd, data_p + start, end - start) < 0) { diff --git a/gtk/rtp_analysis.c b/gtk/rtp_analysis.c index c878f1c908..1d85416720 100644 --- a/gtk/rtp_analysis.c +++ b/gtk/rtp_analysis.c @@ -1,7 +1,7 @@ /* rtp_analysis.c * RTP analysis addition for ethereal * - * $Id: rtp_analysis.c,v 1.32 2004/02/06 19:19:10 ulfl Exp $ + * $Id: rtp_analysis.c,v 1.33 2004/02/11 01:23:25 guy Exp $ * * Copyright 2003, Alcatel Business Systems * By Lars Ruoff @@ -60,6 +60,7 @@ /* in /gtk ... */ #include "dlg_utils.h" #include "ui_util.h" +#include "alert_box.h" #include "simple_dialog.h" #include "menu.h" #include "main.h" @@ -986,8 +987,7 @@ static void save_csv_as_ok_cb(GtkWidget *bt _U_, gpointer fs /*user_data_t *user if (GTK_TOGGLE_BUTTON(forw)->active || GTK_TOGGLE_BUTTON(both)->active) { fp = fopen(g_dest, "w"); if (fp == NULL) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - file_open_error_message(errno, TRUE), g_dest); + open_failure_alert_box(g_dest, errno, TRUE); return; } @@ -1045,9 +1045,7 @@ static void save_csv_as_ok_cb(GtkWidget *bt _U_, gpointer fs /*user_data_t *user if (GTK_TOGGLE_BUTTON(both)->active) { fp = fopen(g_dest, "a"); if (fp == NULL) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - file_open_error_message(errno, TRUE), - g_dest); + open_failure_alert_box(g_dest, errno, TRUE); return; } fprintf(fp, "\nReverse\n"); @@ -1060,9 +1058,7 @@ static void save_csv_as_ok_cb(GtkWidget *bt _U_, gpointer fs /*user_data_t *user } else { fp = fopen(g_dest, "w"); if (fp == NULL) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - file_open_error_message(errno, TRUE), - g_dest); + open_failure_alert_box(g_dest, errno, TRUE); return; } } diff --git a/gtk/rtp_stream.c b/gtk/rtp_stream.c index df73005518..029ed1c1ac 100644 --- a/gtk/rtp_stream.c +++ b/gtk/rtp_stream.c @@ -1,7 +1,7 @@ /* rtp_stream.c * RTP streams summary addition for ethereal * - * $Id: rtp_stream.c,v 1.11 2004/01/31 09:48:26 guy Exp $ + * $Id: rtp_stream.c,v 1.12 2004/02/11 01:23:25 guy Exp $ * * Copyright 2003, Alcatel Business Systems * By Lars Ruoff @@ -40,6 +40,7 @@ #include +#include "alert_box.h" #include "simple_dialog.h" #ifdef HAVE_SYS_TYPES_H @@ -285,8 +286,7 @@ gboolean rtpstream_save(rtp_stream_info_t* stream, const gchar *filename) /* open file for saving */ the_tapinfo_struct.save_file = fopen(filename, "wb"); if (the_tapinfo_struct.save_file==NULL) { - simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, - file_open_error_message(errno, TRUE), filename); + open_failure_alert_box(filename, errno, TRUE); return FALSE; } -- cgit v1.2.3