From bce5ec919e2fd197e0042dfabf5186d0d6f6eb47 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 20 Apr 2017 00:19:01 -0700 Subject: Use the new cfile_XXX_failure_message() routines more broadly. Change-Id: I7814b3fd0353f4836ae61cbdbd4e13f659cbcb59 Reviewed-on: https://code.wireshark.org/review/21239 Reviewed-by: Guy Harris --- captype.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'captype.c') diff --git a/captype.c b/captype.c index a61ba4bc81..71fe572d93 100644 --- a/captype.c +++ b/captype.c @@ -40,6 +40,7 @@ #include +#include #include #include #include @@ -61,6 +62,8 @@ #include "wsutil/wsgetopt.h" #endif +#include "ui/failure_message.h" + static void print_usage(FILE *output) { @@ -68,7 +71,6 @@ print_usage(FILE *output) fprintf(output, "Usage: captype ...\n"); } -#ifdef HAVE_PLUGINS /* * General errors and warnings are reported with an console message * in captype. @@ -80,7 +82,16 @@ failure_warning_message(const char *msg_format, va_list ap) vfprintf(stderr, msg_format, ap); fprintf(stderr, "\n"); } -#endif + +/* + * Report additional information for an error in command-line arguments. + */ +static void +failure_message_cont(const char *msg_format, va_list ap) +{ + vfprintf(stderr, msg_format, ap); + fprintf(stderr, "\n"); +} int main(int argc, char *argv[]) @@ -103,6 +114,8 @@ main(int argc, char *argv[]) /* Set the C-language locale to the native environment. */ setlocale(LC_ALL, ""); + cmdarg_err_init(failure_warning_message, failure_message_cont); + /* Get the compile-time version information string */ comp_info_str = get_compiled_version_info(NULL, NULL); @@ -206,12 +219,8 @@ main(int argc, char *argv[]) if (err == WTAP_ERR_FILE_UNKNOWN_FORMAT) printf("%s: unknown\n", argv[i]); else { - fprintf(stderr, "captype: Can't open %s: %s\n", argv[i], - wtap_strerror(err)); - if (err_info != NULL) { - fprintf(stderr, "(%s)\n", err_info); - g_free(err_info); - } + cfile_open_failure_message("captype", argv[i], err, err_info, FALSE, + WTAP_TYPE_AUTO); overall_error_status = 2; /* remember that an error has occurred */ } } -- cgit v1.2.1