Add routines vfprintf_stderr() and fprintf_stderr() to print to the
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 7 May 2010 08:40:02 +0000 (08:40 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 7 May 2010 08:40:02 +0000 (08:40 +0000)
standard error and, in Wireshark on Windows, create a console if
necessary.  Have the cmdarg_err routines use them.

Use *fprintf_stderr() to print the output of -L, rather than using
cmdarg_err_cont(), so that we don't get extra newlines in the output (it
should look similar to the output of tcpdump).

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@32711 f5534014-38df-0310-8fa8-9805f1628bb7

Makefile.common
capture_opts.c
console_io.h [new file with mode: 0644]
dumpcap.c
gtk/main.c
tshark.c

index 1a13fc5101c251b96bc18b31e370f0b8c8a4a762..e3d1a7e7dc36d735d725094822094af4e90adc12 100644 (file)
@@ -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  \
index 67d4237a80d0080eebcb96d8ceed07ad68b96b13..f69f791f088d4ef15c7ae090116b3b4340023943 100644 (file)
@@ -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 (file)
index 0000000..bfcbf3e
--- /dev/null
@@ -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__ */
index 944e5606e19a6003b4c305dfc846181c27cf440a..e6de0d1fac635de8307644fc2d40e536738ba43b 100644 (file)
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -72,6 +72,7 @@
 
 #include "ringbuffer.h"
 #include "clopts_common.h"
+#include "console_io.h"
 #include "cmdarg_err.h"
 #include "version_info.h"
 
@@ -382,6 +383,26 @@ show_version(GString *comp_info_str, GString *runtime_info_str)
         wireshark_svnversion, get_copyright_info() ,comp_info_str->str, runtime_info_str->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.
  */
index 83046dd19a2c89c4f4fa15fe91f9c62532c214a3..e230d3b5c613e064111e770952f9ace78f6cf54d 100644 (file)
@@ -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);
 }
 
index 33cbb103d147090f8d35e84d46a29fc6ec316463..3ed559c92d0e2e9508490cf10796c8c1b70a6765 100644 (file)
--- a/tshark.c
+++ b/tshark.c
@@ -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>
@@ -3397,6 +3398,26 @@ write_failure_message(const char *filename, int err)
           filename, strerror(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.
  */