aboutsummaryrefslogtreecommitdiffstats
path: root/captype.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2014-07-03 02:08:48 -0700
committerGuy Harris <guy@alum.mit.edu>2014-07-03 09:09:14 +0000
commitedc67362936f6e23ca0a630e6321563395a91e35 (patch)
tree4a84e03e467f27f932a3e99ab668e63b6aa5693a /captype.c
parentf0ed0e69fa5ab097ddb7cbfa4bb6b54f4c183f0c (diff)
Add --help and --version support.
Make the output for them resemble the output for other programs. Change-Id: I45dbee32ad403b8fedc2350ac9096ac1a5820cbe Reviewed-on: https://code.wireshark.org/review/2799 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'captype.c')
-rw-r--r--captype.c121
1 files changed, 109 insertions, 12 deletions
diff --git a/captype.c b/captype.c
index 3062fb1122..708038fdb7 100644
--- a/captype.c
+++ b/captype.c
@@ -36,15 +36,27 @@
#include <unistd.h>
#endif
+#ifdef HAVE_GETOPT_H
+#include <getopt.h>
+#endif
+
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
+#ifdef HAVE_LIBZ
+#include <zlib.h> /* to get the libz version number */
+#endif
+
#include <glib.h>
#include <wsutil/privileges.h>
#include <wsutil/filesystem.h>
#include <wsutil/file_util.h>
+#include <wsutil/crash_info.h>
+#include <wsutil/copyright_info.h>
+#include <wsutil/os_version_info.h>
+#include <wsutil/ws_version_info.h>
#ifdef HAVE_PLUGINS
#include <wsutil/plugins.h>
@@ -59,20 +71,27 @@
#include <wsutil/unicode-utils.h>
#endif /* _WIN32 */
-#include "version.h"
+#include "version_info.h"
static void
-usage(void)
+show_version(GString *comp_info_str, GString *runtime_info_str)
{
- fprintf(stderr, "Captype %s"
-#ifdef GITVERSION
- " (" GITVERSION " from " GITBRANCH ")"
-#endif
- "\n", VERSION);
- fprintf(stderr, "Prints the file types of capture files.\n");
- fprintf(stderr, "See http://www.wireshark.org for more information.\n");
- fprintf(stderr, "\n");
- fprintf(stderr, "Usage: captype <infile> ...\n");
+ printf("Captype (Wireshark) %s\n"
+ "\n"
+ "%s"
+ "\n"
+ "%s"
+ "\n"
+ "%s",
+ get_ws_vcs_version_info(), get_copyright_info(),
+ comp_info_str->str, runtime_info_str->str);
+}
+
+static void
+print_usage(FILE *output)
+{
+ fprintf(output, "\n");
+ fprintf(output, "Usage: captype <infile> ...\n");
}
#ifdef HAVE_PLUGINS
@@ -88,19 +107,69 @@ failure_message(const char *msg_format _U_, va_list ap _U_)
}
#endif
+static void
+get_captype_compiled_info(GString *str)
+{
+ /* LIBZ */
+ g_string_append(str, ", ");
+#ifdef HAVE_LIBZ
+ g_string_append(str, "with libz ");
+#ifdef ZLIB_VERSION
+ g_string_append(str, ZLIB_VERSION);
+#else /* ZLIB_VERSION */
+ g_string_append(str, "(version unknown)");
+#endif /* ZLIB_VERSION */
+#else /* HAVE_LIBZ */
+ g_string_append(str, "without libz");
+#endif /* HAVE_LIBZ */
+}
+
+static void
+get_captype_runtime_info(GString *str)
+{
+ /* zlib */
+#if defined(HAVE_LIBZ) && !defined(_WIN32)
+ g_string_append_printf(str, ", with libz %s", zlibVersion());
+#endif
+}
+
int
main(int argc, char *argv[])
{
+ GString *comp_info_str;
+ GString *runtime_info_str;
wtap *wth;
int err;
gchar *err_info;
int i;
+ int opt;
int overall_error_status;
+ static const struct option long_options[] = {
+ {(char *)"help", no_argument, NULL, 'h'},
+ {(char *)"version", no_argument, NULL, 'v'},
+ {0, 0, 0, 0 }
+ };
#ifdef HAVE_PLUGINS
char *init_progfile_dir_error;
#endif
+ /* Assemble the compile-time version information string */
+ comp_info_str = g_string_new("Compiled ");
+ get_compiled_version_info(comp_info_str, NULL, get_captype_compiled_info);
+
+ /* Assemble the run-time version information string */
+ runtime_info_str = g_string_new("Running ");
+ get_runtime_version_info(runtime_info_str, get_captype_runtime_info);
+
+ /* Add it to the information to be reported on a crash. */
+ ws_add_crash_info("Captype (Wireshark) %s\n"
+ "\n"
+ "%s"
+ "\n"
+ "%s",
+ get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str);
+
#ifdef _WIN32
arg_list_utf_16to8(argc, argv);
create_app_running_mutex();
@@ -131,11 +200,39 @@ main(int argc, char *argv[])
}
#endif
+ /* Process the options */
+ while ((opt = getopt_long(argc, argv, "hv", long_options, NULL)) !=-1) {
+
+ switch (opt) {
+
+ case 'h':
+ printf("Captype (Wireshark) %s\n"
+ "Print the file types of capture files.\n"
+ "See http://www.wireshark.org for more information.\n",
+ get_ws_vcs_version_info());
+ print_usage(stdout);
+ exit(0);
+ break;
+
+ case 'v':
+ show_version(comp_info_str, runtime_info_str);
+ g_string_free(comp_info_str, TRUE);
+ g_string_free(runtime_info_str, TRUE);
+ exit(0);
+ break;
+
+ case '?': /* Bad flag - print usage message */
+ print_usage(stderr);
+ exit(1);
+ break;
+ }
+ }
+
/* Set the C-language locale to the native environment. */
setlocale(LC_ALL, "");
if (argc < 2) {
- usage();
+ print_usage(stderr);
return 1;
}