From b4ce352539ec1e88a8002c65a38cc3029860c0e0 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Thu, 3 Jul 2014 01:45:32 -0700 Subject: 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 --- mergecap.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 73 insertions(+), 23 deletions(-) (limited to 'mergecap.c') diff --git a/mergecap.c b/mergecap.c index 44c8c71b43..49dcfe6c83 100644 --- a/mergecap.c +++ b/mergecap.c @@ -42,6 +42,10 @@ #include #endif +#ifdef HAVE_LIBZ +#include /* to get the libz version number */ +#endif + #include #include "wtap.h" @@ -51,10 +55,14 @@ #include #include +#include +#include +#include +#include #include -#include "version.h" +#include "version_info.h" #ifdef HAVE_FCNTL_H #include @@ -104,33 +112,25 @@ get_positive_int(const char *string, const char *name) } static void -print_version(FILE *output) +show_version(GString *comp_info_str, GString *runtime_info_str) { - fprintf(output, "Mergecap %s" -#ifdef GITVERSION - " (" GITVERSION " from " GITBRANCH ")" -#endif - "\n", VERSION); + printf("Mergecap (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); } /* * Show the usage */ static void -usage(gboolean is_error) +print_usage(FILE *output) { - FILE *output; - - if (!is_error) { - output = stdout; - } - else { - output = stderr; - } - - print_version(output); - fprintf(output, "Merge two or more capture files into one.\n"); - fprintf(output, "See http://www.wireshark.org for more information.\n"); fprintf(output, "\n"); fprintf(output, "Usage: mergecap [options] -w |- [ ...]\n"); fprintf(output, "\n"); @@ -217,9 +217,37 @@ list_encap_types(void) { g_free(encaps); } +static void +get_mergecap_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_mergecap_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; int opt; static const struct option long_options[] = { {(char *)"help", no_argument, NULL, 'h'}, @@ -253,6 +281,22 @@ main(int argc, char *argv[]) create_app_running_mutex(); #endif /* _WIN32 */ + /* Assemble the compile-time version information string */ + comp_info_str = g_string_new("Compiled "); + get_compiled_version_info(comp_info_str, NULL, get_mergecap_compiled_info); + + /* Assemble the run-time version information string */ + runtime_info_str = g_string_new("Running "); + get_runtime_version_info(runtime_info_str, get_mergecap_runtime_info); + + /* Add it to the information to be reported on a crash. */ + ws_add_crash_info("Mergecap (Wireshark) %s\n" + "\n" + "%s" + "\n" + "%s", + get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str); + /* Process the options first */ while ((opt = getopt_long(argc, argv, "aF:hs:T:vVw:", long_options, NULL)) != -1) { @@ -272,7 +316,11 @@ main(int argc, char *argv[]) break; case 'h': - usage(FALSE); + printf("Mergecap (Wireshark) %s\n" + "Merge two or more capture files into one.\n" + "See http://www.wireshark.org for more information.\n", + get_ws_vcs_version_info()); + print_usage(stdout); exit(0); break; @@ -295,7 +343,9 @@ main(int argc, char *argv[]) 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; @@ -312,7 +362,7 @@ main(int argc, char *argv[]) list_encap_types(); break; default: - usage(TRUE); + print_usage(stderr); } exit(1); break; -- cgit v1.2.1