From fe42762f236e23fefe47e67b6c248507d0ac5c8a Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sun, 29 Jun 2014 14:37:21 -0700 Subject: Move some more stuff into wsutil. 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 Reviewed-by: Guy Harris --- CMakeLists.txt | 2 -- Makefile.common | 4 --- capture_opts.c | 4 +-- clopts_common.c | 69 ------------------------------------------------- clopts_common.h | 38 --------------------------- cmdarg_err.h | 48 ---------------------------------- dumpcap.c | 30 +++++++++------------- rawshark.c | 26 ++++++++----------- tfshark.c | 31 ++++++---------------- tshark.c | 32 +++++++---------------- ui/gtk/main.c | 23 +++++++---------- ui/qt/main.cpp | 22 ++++++---------- wsutil/CMakeLists.txt | 2 ++ wsutil/Makefile.common | 6 ++++- wsutil/clopts_common.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++ wsutil/clopts_common.h | 42 ++++++++++++++++++++++++++++++ wsutil/cmdarg_err.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++ wsutil/cmdarg_err.h | 61 +++++++++++++++++++++++++++++++++++++++++++ 18 files changed, 306 insertions(+), 271 deletions(-) delete mode 100644 clopts_common.c delete mode 100644 clopts_common.h delete mode 100644 cmdarg_err.h create mode 100644 wsutil/clopts_common.c create mode 100644 wsutil/clopts_common.h create mode 100644 wsutil/cmdarg_err.c create mode 100644 wsutil/cmdarg_err.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 69aaa2c524..8e2cabf322 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -915,7 +915,6 @@ set(SHARK_COMMON_SRC ${PLATFORM_PCAP_SRC} capture-pcap-util.c cfile.c - clopts_common.c frame_tvbuff.c version.h sync_pipe_write.c @@ -1351,7 +1350,6 @@ if(BUILD_dumpcap AND PCAP_FOUND) capture_opts.c capture-pcap-util.c capture_stop_conditions.c - clopts_common.c conditions.c dumpcap.c pcapio.c diff --git a/Makefile.common b/Makefile.common index 34205d70c7..97e3cef31a 100644 --- a/Makefile.common +++ b/Makefile.common @@ -44,7 +44,6 @@ SHARK_COMMON_SRC = \ $(PLATFORM_PCAP_SRC) \ capture-pcap-util.c \ cfile.c \ - clopts_common.c \ frame_tvbuff.c \ sync_pipe_write.c \ version_info.c @@ -55,8 +54,6 @@ SHARK_COMMON_INCLUDES = \ capture-pcap-util.h \ capture-pcap-util-int.h \ cfile.h \ - clopts_common.h \ - cmdarg_err.h \ color.h \ file.h \ fileset.h \ @@ -172,7 +169,6 @@ dumpcap_SOURCES = \ capture_opts.c \ capture-pcap-util.c \ capture_stop_conditions.c \ - clopts_common.c \ conditions.c \ dumpcap.c \ pcapio.c \ diff --git a/capture_opts.c b/capture_opts.c index 6b17189e05..d9ec2d3e93 100644 --- a/capture_opts.c +++ b/capture_opts.c @@ -42,11 +42,11 @@ #include "capture_opts.h" #include "ringbuffer.h" -#include "clopts_common.h" -#include "cmdarg_err.h" #include #include "capture-pcap-util.h" +#include +#include #include static gboolean capture_opts_output_to_pipe(const char *save_file, gboolean *is_pipe); diff --git a/clopts_common.c b/clopts_common.c deleted file mode 100644 index 1ffcdedbc9..0000000000 --- a/clopts_common.c +++ /dev/null @@ -1,69 +0,0 @@ -/* clopts_common.c - * Handle command-line arguments common to Wireshark and TShark - * - * Wireshark - Network traffic analyzer - * By Gerald Combs - * 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 -#include -#include - -#include "clopts_common.h" -#include "cmdarg_err.h" - -int -get_natural_int(const char *string, const char *name) -{ - long number; - char *p; - - number = strtol(string, &p, 10); - if (p == string || *p != '\0') { - cmdarg_err("The specified %s \"%s\" isn't a decimal number", name, string); - exit(1); - } - if (number < 0) { - cmdarg_err("The specified %s \"%s\" is a negative number", name, string); - exit(1); - } - if (number > INT_MAX) { - cmdarg_err("The specified %s \"%s\" is too large (greater than %d)", - name, string, INT_MAX); - exit(1); - } - return (int)number; -} - - -int -get_positive_int(const char *string, const char *name) -{ - int number; - - number = get_natural_int(string, name); - - if (number == 0) { - cmdarg_err("The specified %s is zero", name); - exit(1); - } - - return number; -} diff --git a/clopts_common.h b/clopts_common.h deleted file mode 100644 index e98d7b4986..0000000000 --- a/clopts_common.h +++ /dev/null @@ -1,38 +0,0 @@ -/* clopts_common.h - * Handle command-line arguments common to Wireshark and TShark - * - * Wireshark - Network traffic analyzer - * By Gerald Combs - * 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. - */ - -#ifndef __PROTO_DUMPOPTS_H__ -#define __PROTO_DUMPOPTS_H__ - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -int get_natural_int(const char *string, const char *name); - -int get_positive_int(const char *string, const char *name); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __PROTO_DUMPOPTS_H__ */ diff --git a/cmdarg_err.h b/cmdarg_err.h deleted file mode 100644 index b4d639f8f1..0000000000 --- a/cmdarg_err.h +++ /dev/null @@ -1,48 +0,0 @@ -/* cmdarg_err.h - * Declarations of routines to report command-line errors. - * - * Wireshark - Network traffic analyzer - * By Gerald Combs - * 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. - */ - -#ifndef __CMDARG_ERR_H__ -#define __CMDARG_ERR_H__ - -#include - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -/* - * Report an error in command-line arguments. - */ -extern 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, ...) - G_GNUC_PRINTF(1, 2); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* __CMDARG_ERR_H__ */ diff --git a/dumpcap.c b/dumpcap.c index 90b12b1079..0c91b7341b 100644 --- a/dumpcap.c +++ b/dumpcap.c @@ -71,6 +71,7 @@ #include /* to get the libz version number */ #endif +#include #include #include #include @@ -89,8 +90,6 @@ #endif #include "ringbuffer.h" -#include "clopts_common.h" -#include "cmdarg_err.h" #include "version_info.h" #include "capture-pcap-util.h" @@ -113,6 +112,7 @@ # include "wsutil/inet_v6defs.h" #endif +#include #include #include "sync_pipe.h" @@ -580,49 +580,41 @@ show_version(GString *comp_info_str, GString *runtime_info_str) /* * 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); } } @@ -4232,6 +4224,8 @@ main(int argc, char *argv[]) #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); diff --git a/rawshark.c b/rawshark.c index 5e0e629e15..13d8d24b78 100644 --- a/rawshark.c +++ b/rawshark.c @@ -64,6 +64,8 @@ #include #include #include + +#include #include #include #include @@ -83,8 +85,6 @@ #include #include #include "ui/util.h" -#include "clopts_common.h" -#include "cmdarg_err.h" #include "version_info.h" #include "register.h" #include "conditions.h" @@ -102,6 +102,7 @@ #include #include +#include #include #ifdef HAVE_LIBPCAP @@ -158,6 +159,8 @@ static void open_failure_message(const char *filename, int err, 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); @@ -473,6 +476,8 @@ main(int argc, char *argv[]) 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); @@ -1732,33 +1737,24 @@ write_failure_message(const char *filename, int err) /* * 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 * diff --git a/tfshark.c b/tfshark.c index 8eb2565d83..2f71ee9256 100644 --- a/tfshark.c +++ b/tfshark.c @@ -59,6 +59,9 @@ #include #include #include + +#include +#include #include #include #include @@ -81,8 +84,6 @@ #include #include #include "ui/util.h" -#include "clopts_common.h" -#include "cmdarg_err.h" #include "version_info.h" #include "register.h" #include @@ -792,6 +793,8 @@ main(int argc, char *argv[]) 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); @@ -2767,34 +2770,16 @@ write_failure_message(const char *filename, int err) 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 * diff --git a/tshark.c b/tshark.c index 8d27037772..2be3e8b81b 100644 --- a/tshark.c +++ b/tshark.c @@ -64,6 +64,9 @@ #include #include #include + +#include +#include #include #include #include @@ -88,8 +91,6 @@ #include #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 @@ -212,6 +213,7 @@ static void open_failure_message(const char *filename, int err, 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; @@ -1009,6 +1011,8 @@ main(int argc, char *argv[]) } #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); @@ -4314,34 +4318,16 @@ write_failure_message(const char *filename, int err) 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 * diff --git a/ui/gtk/main.c b/ui/gtk/main.c index 5c54337cb6..ff5bf274b3 100644 --- a/ui/gtk/main.c +++ b/ui/gtk/main.c @@ -60,6 +60,7 @@ #include #endif /* HAVE_LIBPORTAUDIO */ +#include #include #include #include @@ -92,6 +93,7 @@ #include #include +#include #include /* general (not GTK specific) */ @@ -104,8 +106,6 @@ #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" @@ -1279,19 +1279,17 @@ show_version(void) /* * 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"); } @@ -1301,18 +1299,14 @@ cmdarg_err(const char *fmt, ...) * 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); } /* @@ -2184,6 +2178,7 @@ main(int argc, char *argv[]) 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, ""); diff --git a/ui/qt/main.cpp b/ui/qt/main.cpp index d14e6226f7..ef4704bc4f 100644 --- a/ui/qt/main.cpp +++ b/ui/qt/main.cpp @@ -41,6 +41,8 @@ # include #endif +#include +#include #include #include #include @@ -88,8 +90,6 @@ #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" @@ -317,18 +317,14 @@ show_version(void) * 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"); } @@ -339,18 +335,14 @@ cmdarg_err(const char *fmt, ...) * 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 @@ -493,6 +485,8 @@ int main(int argc, char *argv[]) e_prefs *prefs_p; GLogLevelFlags log_flags; + cmdarg_err_init(wireshark_cmdarg_err, wireshark_cmdarg_err_cont); + #ifdef _WIN32 create_app_running_mutex(); #endif diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt index 0157e74785..d8e2f04de1 100644 --- a/wsutil/CMakeLists.txt +++ b/wsutil/CMakeLists.txt @@ -45,6 +45,8 @@ set(WSUTIL_FILES base64.c bitswap.c cfutils.c + clopts_common.c + cmdarg_err.c compiler_info.c copyright_info.c cpu_info.c diff --git a/wsutil/Makefile.common b/wsutil/Makefile.common index 4bb8dea86b..2c0595c94e 100644 --- a/wsutil/Makefile.common +++ b/wsutil/Makefile.common @@ -33,6 +33,8 @@ LIBWSUTIL_SRC = \ base64.c \ bitswap.c \ cfutils.c \ + clopts_common.c \ + cmdarg_err.c \ compiler_info.c \ copyright_info.c \ cpu_info.c \ @@ -79,8 +81,10 @@ LIBWSUTIL_INCLUDES = \ 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 \ diff --git a/wsutil/clopts_common.c b/wsutil/clopts_common.c new file mode 100644 index 0000000000..8b1878758b --- /dev/null +++ b/wsutil/clopts_common.c @@ -0,0 +1,70 @@ +/* clopts_common.c + * Handle command-line arguments common to various programs + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * 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 +#include +#include + +#include + +#include + +int +get_natural_int(const char *string, const char *name) +{ + long number; + char *p; + + number = strtol(string, &p, 10); + if (p == string || *p != '\0') { + cmdarg_err("The specified %s \"%s\" isn't a decimal number", name, string); + exit(1); + } + if (number < 0) { + cmdarg_err("The specified %s \"%s\" is a negative number", name, string); + exit(1); + } + if (number > INT_MAX) { + cmdarg_err("The specified %s \"%s\" is too large (greater than %d)", + name, string, INT_MAX); + exit(1); + } + return (int)number; +} + + +int +get_positive_int(const char *string, const char *name) +{ + int number; + + number = get_natural_int(string, name); + + if (number == 0) { + cmdarg_err("The specified %s is zero", name); + exit(1); + } + + return number; +} diff --git a/wsutil/clopts_common.h b/wsutil/clopts_common.h new file mode 100644 index 0000000000..c409e8957a --- /dev/null +++ b/wsutil/clopts_common.h @@ -0,0 +1,42 @@ +/* clopts_common.h + * Handle command-line arguments common to various programs + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * 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. + */ + +#ifndef __WSUTIL_CLOPTS_COMMON_H__ +#define __WSUTIL_CLOPTS_COMMON_H__ + +#include "ws_symbol_export.h" + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +WS_DLL_PUBLIC int +get_natural_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 /* __WSUTIL_CLOPTS_COMMON_H__ */ diff --git a/wsutil/cmdarg_err.c b/wsutil/cmdarg_err.c new file mode 100644 index 0000000000..7dd2fa23c6 --- /dev/null +++ b/wsutil/cmdarg_err.c @@ -0,0 +1,67 @@ +/* cmdarg_err.c + * Routines to report command-line argument errors. + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * 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 + +#include + +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); +} diff --git a/wsutil/cmdarg_err.h b/wsutil/cmdarg_err.h new file mode 100644 index 0000000000..169c893b9f --- /dev/null +++ b/wsutil/cmdarg_err.h @@ -0,0 +1,61 @@ +/* cmdarg_err.h + * Declarations of routines to report command-line argument errors. + * + * Wireshark - Network traffic analyzer + * By Gerald Combs + * 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. + */ + +#ifndef __WSUTIL_CMDARG_ERR_H__ +#define __WSUTIL_CMDARG_ERR_H__ + +#include + +#include + +#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. + */ +WS_DLL_PUBLIC void +cmdarg_err(const char *fmt, ...) + G_GNUC_PRINTF(1, 2); + +/* + * Report additional information for an error in command-line arguments. + */ +WS_DLL_PUBLIC void +cmdarg_err_cont(const char *fmt, ...) + G_GNUC_PRINTF(1, 2); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* __WSUTIL_CMDARG_ERR_H__ */ -- cgit v1.2.3