From 43dfd45faa8af0b239a671b25ab6a398fa32f5c6 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Wed, 12 Dec 2018 18:16:15 -0800 Subject: Move more version-info-related stuff to version_info.c. Have a ws_init_version_info() routine that, given an application name string: constructs the app-name-and-version-information string, and saves it; adds the initial crash information on platforms that support it, and saves it. Have show_version() use the saved information and take no arguments. Add a show_help_header() routine to print the header for --help command-line options, given a description of the application; it prints the application name and version information, the description, and the "See {wireshark.org URL}" line. Use those routines in various places, including providing the "application name" string in pcapng SHBs. Change-Id: I0042a8fcc91aa919ad5c381a8b8674a007ce66df Reviewed-on: https://code.wireshark.org/review/31029 Petri-Dish: Guy Harris Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris --- tshark.c | 39 ++++++++------------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) (limited to 'tshark.c') diff --git a/tshark.c b/tshark.c index eb0304d058..00c28db781 100644 --- a/tshark.c +++ b/tshark.c @@ -47,7 +47,6 @@ #include #include -#include #include #include #include @@ -475,7 +474,7 @@ glossary_option_help(void) output = stdout; - fprintf(output, "TShark (Wireshark) %s\n", get_ws_vcs_version_info()); + fprintf(output, "%s\n", get_appname_and_version()); fprintf(output, "\n"); fprintf(output, "Usage: tshark -G [report]\n"); @@ -673,8 +672,6 @@ must_do_dissection(dfilter_t *rfcode, dfilter_t *dfcode, int real_main(int argc, char *argv[]) { - GString *comp_info_str; - GString *runtime_info_str; char *init_progfile_dir_error; int opt; static const struct option long_options[] = { @@ -799,22 +796,10 @@ real_main(int argc, char *argv[]) #endif /* HAVE_LIBPCAP */ #endif /* _WIN32 */ - /* Get the compile-time version information string */ - comp_info_str = get_compiled_version_info(get_tshark_compiled_version_info, - epan_get_compiled_version_info); - - /* Get the run-time version information string */ - runtime_info_str = get_runtime_version_info(get_tshark_runtime_version_info); - - /* Add it to the information to be reported on a crash. */ - ws_add_crash_info("TShark (Wireshark) %s\n" - "\n" - "%s" - "\n" - "%s", - get_ws_vcs_version_info(), comp_info_str->str, runtime_info_str->str); - g_string_free(comp_info_str, TRUE); - g_string_free(runtime_info_str, TRUE); + /* Initialize the version information. */ + ws_init_version_info("TShark (Wireshark)", get_tshark_compiled_version_info, + epan_get_compiled_version_info, + get_tshark_runtime_version_info); /* Fail sometimes. Useful for testing fuzz scripts. */ /* if (g_random_int_range(0, 100) < 5) abort(); */ @@ -1188,10 +1173,7 @@ real_main(int argc, char *argv[]) break; case 'h': /* Print help and exit */ - printf("TShark (Wireshark) %s\n" - "Dump and analyze network traffic.\n" - "See https://www.wireshark.org for more information.\n", - get_ws_vcs_version_info()); + show_help_header("Dump and analyze network traffic."); print_usage(stdout); exit_status = EXIT_SUCCESS; goto clean_exit; @@ -1370,12 +1352,7 @@ real_main(int argc, char *argv[]) break; } case 'v': /* Show version and exit */ - comp_info_str = get_compiled_version_info(get_tshark_compiled_version_info, - epan_get_compiled_version_info); - runtime_info_str = get_runtime_version_info(get_tshark_runtime_version_info); - show_version("TShark (Wireshark)", comp_info_str, runtime_info_str); - g_string_free(comp_info_str, TRUE); - g_string_free(runtime_info_str, TRUE); + show_version(); /* We don't really have to cleanup here, but it's a convenient way to test * start-up and shut-down of the epan library without any UI-specific * cruft getting in the way. Makes the results of running @@ -3089,7 +3066,7 @@ process_cap_file(capture_file *cf, char *save_file, int out_file_type, /* If we don't have an application name add Tshark */ if (wtap_block_get_string_option_value(g_array_index(params.shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, &shb_user_appl) != WTAP_OPTTYPE_SUCCESS) { /* this is free'd by wtap_block_free() later */ - wtap_block_add_string_option_format(g_array_index(params.shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, "TShark (Wireshark) %s", get_ws_vcs_version_info()); + wtap_block_add_string_option_format(g_array_index(params.shb_hdrs, wtap_block_t, 0), OPT_SHB_USERAPPL, "%s", get_appname_and_version()); } tshark_debug("tshark: writing format type %d, to %s", out_file_type, save_file); -- cgit v1.2.3