Move the routines to parse numerical command-line arguments there.
Make cmdarg_err() and cmdarg_err_cont() routines in wsutil that just
call routines specified by a call to cmdarg_err_init(), and have
programs supply the appropriate routines to it.
Change-Id: Ic24fc758c0e647f4ff49eb91673529bcb9587b01
Reviewed-on: https://code.wireshark.org/review/2704
Reviewed-by: Evan Huus <eapache@gmail.com>
Reviewed-by: Guy Harris <guy@alum.mit.edu>
${PLATFORM_PCAP_SRC}
capture-pcap-util.c
cfile.c
- clopts_common.c
frame_tvbuff.c
version.h
sync_pipe_write.c
capture_opts.c
capture-pcap-util.c
capture_stop_conditions.c
- clopts_common.c
conditions.c
dumpcap.c
pcapio.c
$(PLATFORM_PCAP_SRC) \
capture-pcap-util.c \
cfile.c \
- clopts_common.c \
frame_tvbuff.c \
sync_pipe_write.c \
version_info.c
capture-pcap-util.h \
capture-pcap-util-int.h \
cfile.h \
- clopts_common.h \
- cmdarg_err.h \
color.h \
file.h \
fileset.h \
capture_opts.c \
capture-pcap-util.c \
capture_stop_conditions.c \
- clopts_common.c \
conditions.c \
dumpcap.c \
pcapio.c \
#include "capture_opts.h"
#include "ringbuffer.h"
-#include "clopts_common.h"
-#include "cmdarg_err.h"
#include <capchild/capture_ifinfo.h>
#include "capture-pcap-util.h"
+#include <wsutil/clopts_common.h>
+#include <wsutil/cmdarg_err.h>
#include <wsutil/file_util.h>
static gboolean capture_opts_output_to_pipe(const char *save_file, gboolean *is_pipe);
#include <zlib.h> /* to get the libz version number */
#endif
+#include <wsutil/cmdarg_err.h>
#include <wsutil/crash_info.h>
#include <wsutil/copyright_info.h>
#include <wsutil/ws_version_info.h>
#endif
#include "ringbuffer.h"
-#include "clopts_common.h"
-#include "cmdarg_err.h"
#include "version_info.h"
#include "capture-pcap-util.h"
# include "wsutil/inet_v6defs.h"
#endif
+#include <wsutil/clopts_common.h>
#include <wsutil/privileges.h>
#include "sync_pipe.h"
/*
* Report an error in command-line arguments.
+ * If we're a capture child, send a message back to the parent, otherwise
+ * just print it.
*/
-void
-cmdarg_err(const char *fmt, ...)
+static void
+dumpcap_cmdarg_err(const char *fmt, va_list ap)
{
- va_list ap;
-
if (capture_child) {
gchar *msg;
/* Generate a 'special format' message back to parent */
- va_start(ap, fmt);
msg = g_strdup_vprintf(fmt, ap);
sync_pipe_errmsg_to_parent(2, msg, "");
g_free(msg);
- va_end(ap);
} else {
- va_start(ap, fmt);
fprintf(stderr, "dumpcap: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
- va_end(ap);
}
}
/*
* Report additional information for an error in command-line arguments.
+ * If we're a capture child, send a message back to the parent, otherwise
+ * just print it.
*/
-void
-cmdarg_err_cont(const char *fmt, ...)
+static void
+dumpcap_cmdarg_err_cont(const char *fmt, va_list ap)
{
- va_list ap;
-
if (capture_child) {
gchar *msg;
- va_start(ap, fmt);
msg = g_strdup_vprintf(fmt, ap);
sync_pipe_errmsg_to_parent(2, msg, "");
g_free(msg);
- va_end(ap);
} else {
- va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
- va_end(ap);
}
}
#endif
GString *str;
+ cmdarg_err_init(dumpcap_cmdarg_err, dumpcap_cmdarg_err_cont);
+
/* Assemble the compile-time version information string */
comp_info_str = g_string_new("Compiled ");
get_compiled_version_info(comp_info_str, NULL, NULL);
#include <glib.h>
#include <epan/epan-int.h>
#include <epan/epan.h>
+
+#include <wsutil/cmdarg_err.h>
#include <wsutil/crash_info.h>
#include <wsutil/privileges.h>
#include <wsutil/file_util.h>
#include <epan/print.h>
#include <epan/addr_resolv.h>
#include "ui/util.h"
-#include "clopts_common.h"
-#include "cmdarg_err.h"
#include "version_info.h"
#include "register.h"
#include "conditions.h"
#include <wiretap/libpcap.h>
#include <wiretap/pcap-encap.h>
+#include <wsutil/clopts_common.h>
#include <wsutil/ws_version_info.h>
#ifdef HAVE_LIBPCAP
static void failure_message(const char *msg_format, va_list ap);
static void read_failure_message(const char *filename, int err);
static void write_failure_message(const char *filename, int err);
+static void rawshark_cmdarg_err(const char *fmt, va_list ap);
+static void rawshark_cmdarg_err_cont(const char *fmt, va_list ap);
static void protocolinfo_init(char *field);
static gboolean parse_field_string_format(char *format);
static const char optstring[] = OPTSTRING_INIT;
+ cmdarg_err_init(rawshark_cmdarg_err, rawshark_cmdarg_err_cont);
+
/* Assemble the compile-time version information string */
comp_info_str = g_string_new("Compiled ");
get_compiled_version_info(comp_info_str, NULL, epan_get_compiled_version_info);
/*
* Report an error in command-line arguments.
*/
-void
-cmdarg_err(const char *fmt, ...)
+static void
+rawshark_cmdarg_err(const char *fmt, va_list ap)
{
- va_list ap;
-
- va_start(ap, fmt);
fprintf(stderr, "rawshark: ");
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
- va_end(ap);
}
/*
* Report additional information for an error in command-line arguments.
*/
-void
-cmdarg_err_cont(const char *fmt, ...)
+static void
+rawshark_cmdarg_err_cont(const char *fmt, va_list ap)
{
- va_list ap;
-
- va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
- va_end(ap);
}
-
/*
* Editor modelines
*
#include <epan/exceptions.h>
#include <epan/epan-int.h>
#include <epan/epan.h>
+
+#include <wsutil/clopts_common.h>
+#include <wsutil/cmdarg_err.h>
#include <wsutil/crash_info.h>
#include <wsutil/privileges.h>
#include <wsutil/file_util.h>
#include <epan/print.h>
#include <epan/addr_resolv.h>
#include "ui/util.h"
-#include "clopts_common.h"
-#include "cmdarg_err.h"
#include "version_info.h"
#include "register.h"
#include <epan/epan_dissect.h>
static const char optstring[] = OPTSTRING;
+ cmdarg_err_init(failure_message, failure_message_cont);
+
/* Assemble the compile-time version information string */
comp_info_str = g_string_new("Compiled ");
get_compiled_version_info(comp_info_str, NULL, epan_get_compiled_version_info);
filename, g_strerror(err));
}
-/*
- * Report an error in command-line arguments.
- */
-void
-cmdarg_err(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- failure_message(fmt, ap);
- va_end(ap);
-}
-
/*
* Report additional information for an error in command-line arguments.
*/
-void
-cmdarg_err_cont(const char *fmt, ...)
+static void
+failure_message_cont(const char *msg_format, va_list ap)
{
- va_list ap;
-
- va_start(ap, fmt);
- vfprintf(stderr, fmt, ap);
+ vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
- va_end(ap);
}
-
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
#include <epan/exceptions.h>
#include <epan/epan-int.h>
#include <epan/epan.h>
+
+#include <wsutil/clopts_common.h>
+#include <wsutil/cmdarg_err.h>
#include <wsutil/crash_info.h>
#include <wsutil/privileges.h>
#include <wsutil/file_util.h>
#include <epan/addr_resolv.h>
#include "ui/util.h"
#include "ui/ui_util.h"
-#include "clopts_common.h"
-#include "cmdarg_err.h"
#include "version_info.h"
#include "register.h"
#include <epan/epan_dissect.h>
static void failure_message(const char *msg_format, va_list ap);
static void read_failure_message(const char *filename, int err);
static void write_failure_message(const char *filename, int err);
+static void failure_message_cont(const char *msg_format, va_list ap);
capture_file cfile;
}
#endif
+ cmdarg_err_init(failure_message, failure_message_cont);
+
/* Assemble the compile-time version information string */
comp_info_str = g_string_new("Compiled ");
get_compiled_version_info(comp_info_str, NULL, epan_get_compiled_version_info);
filename, g_strerror(err));
}
-/*
- * Report an error in command-line arguments.
- */
-void
-cmdarg_err(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- failure_message(fmt, ap);
- va_end(ap);
-}
-
/*
* Report additional information for an error in command-line arguments.
*/
-void
-cmdarg_err_cont(const char *fmt, ...)
+static void
+failure_message_cont(const char *msg_format, va_list ap)
{
- va_list ap;
-
- va_start(ap, fmt);
- vfprintf(stderr, fmt, ap);
+ vfprintf(stderr, msg_format, ap);
fprintf(stderr, "\n");
- va_end(ap);
}
-
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*
#include <portaudio.h>
#endif /* HAVE_LIBPORTAUDIO */
+#include <wsutil/clopts_common.h>
#include <wsutil/crash_info.h>
#include <wsutil/filesystem.h>
#include <wsutil/file_util.h>
#include <epan/print.h>
#include <epan/timestamp.h>
+#include <wsutil/cmdarg_err.h>
#include <wsutil/plugins.h>
/* general (not GTK specific) */
#include "../register.h"
#include "../ringbuffer.h"
#include "ui/util.h"
-#include "../clopts_common.h"
-#include "../cmdarg_err.h"
#include "../version_info.h"
#include "../log.h"
/*
* Report an error in command-line arguments.
* Creates a console on Windows.
+ * 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, ...)
+static void
+wireshark_cmdarg_err(const char *fmt, va_list ap)
{
- va_list ap;
-
#ifdef _WIN32
create_console();
#endif
fprintf(stderr, "wireshark: ");
- va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
- va_end(ap);
fprintf(stderr, "\n");
}
* 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_cont(const char *fmt, ...)
+static void
+wireshark_cmdarg_err_cont(const char *fmt, va_list ap)
{
- va_list ap;
-
#ifdef _WIN32
create_console();
#endif
- va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
- va_end(ap);
}
/*
static const char optstring[] = OPTSTRING;
+ cmdarg_err_init(wireshark_cmdarg_err, wireshark_cmdarg_err_cont);
/* Set the C-language locale to the native environment. */
setlocale(LC_ALL, "");
# include <getopt.h>
#endif
+#include <wsutil/clopts_common.h>
+#include <wsutil/cmdarg_err.h>
#include <wsutil/crash_info.h>
#include <wsutil/filesystem.h>
#include <wsutil/file_util.h>
#include "register.h"
#include "ringbuffer.h"
#include "ui/util.h"
-#include "clopts_common.h"
-#include "cmdarg_err.h"
#include "version_info.h"
#include "log.h"
* Creates a console on Windows.
*/
// xxx copied from ../gtk/main.c
-void
-cmdarg_err(const char *fmt, ...)
+static void
+wireshark_cmdarg_err(const char *fmt, va_list ap)
{
- va_list ap;
-
#ifdef _WIN32
create_console();
#endif
fprintf(stderr, "wireshark: ");
- va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
- va_end(ap);
fprintf(stderr, "\n");
}
* terminal isn't the standard error?
*/
// xxx copied from ../gtk/main.c
-void
-cmdarg_err_cont(const char *fmt, ...)
+static void
+wireshark_cmdarg_err_cont(const char *fmt, va_list ap)
{
- va_list ap;
-
#ifdef _WIN32
create_console();
#endif
- va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
- va_end(ap);
}
static void
e_prefs *prefs_p;
GLogLevelFlags log_flags;
+ cmdarg_err_init(wireshark_cmdarg_err, wireshark_cmdarg_err_cont);
+
#ifdef _WIN32
create_app_running_mutex();
#endif
base64.c
bitswap.c
cfutils.c
+ clopts_common.c
+ cmdarg_err.c
compiler_info.c
copyright_info.c
cpu_info.c
base64.c \
bitswap.c \
cfutils.c \
+ clopts_common.c \
+ cmdarg_err.c \
compiler_info.c \
copyright_info.c \
cpu_info.c \
base64.h \
bits_ctz.h \
bits_count_ones.h \
- bitswap.h \
+ bitswap.h \
cfutils.h \
+ clopts_common.h \
+ cmdarg_err.h \
compiler_info.h \
copyright_info.h \
cpu_info.h \
/* clopts_common.c
- * Handle command-line arguments common to Wireshark and TShark
+ * Handle command-line arguments common to various programs
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
#include <string.h>
#include <stdlib.h>
-#include "clopts_common.h"
-#include "cmdarg_err.h"
+#include <wsutil/cmdarg_err.h>
+
+#include <wsutil/clopts_common.h>
int
get_natural_int(const char *string, const char *name)
/* clopts_common.h
- * Handle command-line arguments common to Wireshark and TShark
+ * Handle command-line arguments common to various programs
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef __PROTO_DUMPOPTS_H__
-#define __PROTO_DUMPOPTS_H__
+#ifndef __WSUTIL_CLOPTS_COMMON_H__
+#define __WSUTIL_CLOPTS_COMMON_H__
+
+#include "ws_symbol_export.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
-int get_natural_int(const char *string, const char *name);
+WS_DLL_PUBLIC int
+get_natural_int(const char *string, const char *name);
-int get_positive_int(const char *string, const char *name);
+WS_DLL_PUBLIC int
+get_positive_int(const char *string, const char *name);
#ifdef __cplusplus
}
#endif /* __cplusplus */
-#endif /* __PROTO_DUMPOPTS_H__ */
+#endif /* __WSUTIL_CLOPTS_COMMON_H__ */
--- /dev/null
+/* cmdarg_err.c
+ * Routines to report command-line argument errors.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+
+#include <wsutil/cmdarg_err.h>
+
+static void (*print_err)(const char *, va_list ap);
+static void (*print_err_cont)(const char *, va_list ap);
+
+/*
+ * Set the reporting functions for error messages.
+ */
+void
+cmdarg_err_init(void (*err)(const char *, va_list),
+ void (*err_cont)(const char *, va_list))
+{
+ print_err = err;
+ print_err_cont = err_cont;
+}
+
+/*
+ * Report an error in command-line arguments.
+ */
+void
+cmdarg_err(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ print_err(fmt, ap);
+ va_end(ap);
+}
+
+/*
+ * Report additional information for an error in command-line arguments.
+ */
+void
+cmdarg_err_cont(const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ print_err_cont(fmt, ap);
+ va_end(ap);
+}
/* cmdarg_err.h
- * Declarations of routines to report command-line errors.
+ * Declarations of routines to report command-line argument errors.
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef __CMDARG_ERR_H__
-#define __CMDARG_ERR_H__
+#ifndef __WSUTIL_CMDARG_ERR_H__
+#define __WSUTIL_CMDARG_ERR_H__
+
+#include <stdarg.h>
#include <glib.h>
+#include "ws_symbol_export.h"
+
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
+/*
+ * Set the reporting functions for error messages.
+ */
+WS_DLL_PUBLIC void
+cmdarg_err_init(void (*err)(const char *, va_list),
+ void (*err_cont)(const char *, va_list));
+
/*
* Report an error in command-line arguments.
*/
-extern void cmdarg_err(const char *fmt, ...)
+WS_DLL_PUBLIC void
+cmdarg_err(const char *fmt, ...)
G_GNUC_PRINTF(1, 2);
/*
* Report additional information for an error in command-line arguments.
*/
-extern void cmdarg_err_cont(const char *fmt, ...)
+WS_DLL_PUBLIC void
+cmdarg_err_cont(const char *fmt, ...)
G_GNUC_PRINTF(1, 2);
#ifdef __cplusplus
}
#endif /* __cplusplus */
-#endif /* __CMDARG_ERR_H__ */
+#endif /* __WSUTIL_CMDARG_ERR_H__ */