diff options
-rw-r--r-- | Makefile.common | 1 | ||||
-rw-r--r-- | capture_opts.c | 11 | ||||
-rw-r--r-- | console_io.h | 51 | ||||
-rw-r--r-- | dumpcap.c | 21 | ||||
-rw-r--r-- | gtk/main.c | 44 | ||||
-rw-r--r-- | tshark.c | 21 |
6 files changed, 131 insertions, 18 deletions
diff --git a/Makefile.common b/Makefile.common index 1a13fc5101..e3d1a7e7dc 100644 --- a/Makefile.common +++ b/Makefile.common @@ -69,6 +69,7 @@ WIRESHARK_COMMON_INCLUDES = \ cfile.h \ clopts_common.h \ cmdarg_err.h \ + console_io.h \ color.h \ disabled_protos.h \ file.h \ diff --git a/capture_opts.c b/capture_opts.c index 67d4237a80..f69f791f08 100644 --- a/capture_opts.c +++ b/capture_opts.c @@ -66,6 +66,7 @@ #include "capture_opts.h" #include "ringbuffer.h" #include "clopts_common.h" +#include "console_io.h" #include "cmdarg_err.h" #include "capture_ifinfo.h" @@ -577,16 +578,16 @@ capture_opts_print_link_layer_types(GList *lt_list) GList *lt_entry; data_link_info_t *data_link_info; - cmdarg_err_cont("Data link types (use option -y to set):"); + fprintf_stderr("Data link types (use option -y to set):\n"); for (lt_entry = lt_list; lt_entry != NULL; lt_entry = g_list_next(lt_entry)) { data_link_info = (data_link_info_t *)lt_entry->data; - cmdarg_err_cont(" %s", data_link_info->name); + fprintf_stderr(" %s", data_link_info->name); if (data_link_info->description != NULL) - cmdarg_err_cont(" (%s)", data_link_info->description); + fprintf_stderr(" (%s)", data_link_info->description); else - cmdarg_err_cont(" (not supported)"); - putchar('\n'); + fprintf_stderr(" (not supported)"); + fprintf_stderr("\n"); } } diff --git a/console_io.h b/console_io.h new file mode 100644 index 0000000000..bfcbf3e132 --- /dev/null +++ b/console_io.h @@ -0,0 +1,51 @@ +/* console_io.h + * Declarations of routines to print to the standard error, and, in + * GUI programs on Windows, to create a console in which to display + * the standard error. + * + * $Id$ + * + * Wireshark - Network traffic analyzer + * By Gerald Combs <gerald@wireshark.org> + * 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 __CONSOLE_IO_H__ +#define __CONSOLE_IO_H__ + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/* + * Print to the standard error. On Windows, create a console for the + * standard error to show up on, if necessary. + * XXX - pop this up in a window of some sort on UNIX+X11 if the controlling + * terminal isn't the standard error? + */ +extern void +vfprintf_stderr(const char *fmt, va_list ap); + +extern void +fprintf_stderr(const char *fmt, ...) + G_GNUC_PRINTF(1, 2); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __CMDARG_ERR_H__ */ @@ -72,6 +72,7 @@ #include "ringbuffer.h" #include "clopts_common.h" +#include "console_io.h" #include "cmdarg_err.h" #include "version_info.h" @@ -383,6 +384,26 @@ show_version(GString *comp_info_str, GString *runtime_info_str) } /* + * Print to the standard error. This is a command-line tool, so there's + * no need to pop up a console. + */ +void +vfprintf_stderr(const char *fmt, va_list ap) +{ + vfprintf(stderr, fmt, ap); +} + +void +fprintf_stderr(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf_stderr(fmt, ap); + va_end(ap); +} + +/* * Report an error in command-line arguments. */ void diff --git a/gtk/main.c b/gtk/main.c index 83046dd19a..e230d3b5c6 100644 --- a/gtk/main.c +++ b/gtk/main.c @@ -97,6 +97,7 @@ #include "../ui_util.h" #include "../util.h" #include "../clopts_common.h" +#include "../console_io.h" #include "../cmdarg_err.h" #include "../version_info.h" #include "../merge.h" @@ -1247,24 +1248,44 @@ show_version(void) } /* - * Report an error in command-line arguments. - * Creates a console on Windows. + * Print to the standard error. On Windows, create a console for the + * standard error to show up on, if necessary. * XXX - pop this up in a window of some sort on UNIX+X11 if the controlling * terminal isn't the standard error? */ void -cmdarg_err(const char *fmt, ...) +vfprintf_stderr(const char *fmt, va_list ap) { - va_list ap; - #ifdef _WIN32 create_console(); #endif - va_start(ap, fmt); - fprintf(stderr, "wireshark: "); vfprintf(stderr, fmt, ap); - fprintf(stderr, "\n"); +} + +void +fprintf_stderr(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf_stderr(fmt, ap); + va_end(ap); +} + +/* + * Report an error in command-line arguments. + * Creates a console on Windows. + */ +void +cmdarg_err(const char *fmt, ...) +{ + va_list ap; + + fprintf_stderr("wireshark: "); + va_start(ap, fmt); + vfprintf_stderr(fmt, ap); va_end(ap); + fprintf_stderr("\n"); } /* @@ -1278,12 +1299,9 @@ cmdarg_err_cont(const char *fmt, ...) { va_list ap; -#ifdef _WIN32 - create_console(); -#endif va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - fprintf(stderr, "\n"); + vfprintf_stderr(fmt, ap); + fprintf_stderr("\n"); va_end(ap); } @@ -77,6 +77,7 @@ #include <epan/addr_resolv.h> #include "util.h" #include "clopts_common.h" +#include "console_io.h" #include "cmdarg_err.h" #include "version_info.h" #include <epan/plugins.h> @@ -3398,6 +3399,26 @@ write_failure_message(const char *filename, int err) } /* + * Print to the standard error. This is a command-line tool, so there's + * no need to pop up a console. + */ +void +vfprintf_stderr(const char *fmt, va_list ap) +{ + vfprintf(stderr, fmt, ap); +} + +void +fprintf_stderr(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vfprintf_stderr(fmt, ap); + va_end(ap); +} + +/* * Report an error in command-line arguments. */ void |