aboutsummaryrefslogtreecommitdiffstats
path: root/capinfos.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2014-07-03 01:45:32 -0700
committerGuy Harris <guy@alum.mit.edu>2014-07-03 08:46:01 +0000
commitb4ce352539ec1e88a8002c65a38cc3029860c0e0 (patch)
treef2c702b2722c20464477e5f85cb5c80abab31915 /capinfos.c
parentd70e56a733a1d432dedc0dce7fbd992ef225d0c5 (diff)
Make --help and --version information a bit more uniform.
Have --version print the version number, the copyright information, the "compiled with" information, the "running on/with" information, and the compiler information. Have --help print the version number, a one-line summary of what the program does, a reference to http://www.wireshark.org for more information, a Usage: line, and a list of command-line options. This means programs doing that don't need to include version.h; that's left up to get_ws_vcs_version_info() to do. Change-Id: Idac641bc10e4dfd04c9914d379b3a3e0cc5ca8cb Reviewed-on: https://code.wireshark.org/review/2794 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'capinfos.c')
-rw-r--r--capinfos.c100
1 files changed, 74 insertions, 26 deletions
diff --git a/capinfos.c b/capinfos.c
index b8e74e91bd..aec23f94a7 100644
--- a/capinfos.c
+++ b/capinfos.c
@@ -77,8 +77,16 @@
#include <glib.h>
+#ifdef HAVE_LIBZ
+#include <zlib.h> /* to get the libz version number */
+#endif
+
#include <wsutil/privileges.h>
#include <wsutil/filesystem.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>
@@ -86,7 +94,6 @@
#include "wtap.h"
#include <wsutil/report_err.h>
-#include <wsutil/privileges.h>
#include <wsutil/str_util.h>
#include <wsutil/file_util.h>
@@ -102,7 +109,7 @@
#include <wsutil/unicode-utils.h>
#endif /* _WIN32 */
-#include "version.h"
+#include "version_info.h"
/*
* By default capinfos now continues processing
@@ -996,31 +1003,22 @@ process_cap_file(wtap *wth, const char *filename)
}
static void
-print_version(FILE *output)
+show_version(GString *comp_info_str, GString *runtime_info_str)
{
- fprintf(output, "Capinfos %s"
-#ifdef GITVERSION
- " (" GITVERSION " from " GITBRANCH ")"
-#endif
- "\n", VERSION);
+ printf("Capinfos (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
-usage(gboolean is_error)
+print_usage(FILE *output)
{
- FILE *output;
-
- if (!is_error) {
- output = stdout;
- /* XXX - add capinfos header info here */
- }
- else {
- output = stderr;
- }
-
- print_version(output);
- fprintf(output, "Prints various information (infos) about capture files.\n");
- fprintf(output, "See http://www.wireshark.org for more information.\n");
fprintf(output, "\n");
fprintf(output, "Usage: capinfos [options] <infile> ...\n");
fprintf(output, "\n");
@@ -1107,9 +1105,37 @@ hash_to_str(const unsigned char *hash, size_t length, char *str) {
}
#endif /* HAVE_LIBGCRYPT */
+static void
+get_capinfos_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_capinfos_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;
@@ -1132,6 +1158,22 @@ main(int argc, char *argv[])
size_t hash_bytes;
#endif
+ /* Assemble the compile-time version information string */
+ comp_info_str = g_string_new("Compiled ");
+ get_compiled_version_info(comp_info_str, NULL, get_capinfos_compiled_info);
+
+ /* Assemble the run-time version information string */
+ runtime_info_str = g_string_new("Running ");
+ get_runtime_version_info(runtime_info_str, get_capinfos_runtime_info);
+
+ /* Add it to the information to be reported on a crash. */
+ ws_add_crash_info("Capinfos (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();
@@ -1363,17 +1405,23 @@ main(int argc, char *argv[])
break;
case 'h':
- usage(FALSE);
+ printf("Capinfos (Wireshark) %s\n"
+ "Print various information (infos) about 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':
- print_version(stdout);
+ 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 */
- usage(TRUE);
+ print_usage(stderr);
exit(1);
break;
}
@@ -1383,7 +1431,7 @@ main(int argc, char *argv[])
setlocale(LC_ALL, "");
if ((argc - optind) < 1) {
- usage(TRUE);
+ print_usage(stderr);
exit(1);
}