From c1f30471caebea3e7954cc4fbf876b2eae1045e4 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Tue, 30 Dec 2014 19:36:26 -0800 Subject: Move the version_info.c stuff to wsutil/ws_version_info.c. Change-Id: I3a5c7e219974bfb924819b43b4d445eaf00e5bde Reviewed-on: https://code.wireshark.org/review/6153 Reviewed-by: Guy Harris --- wsutil/ws_version_info.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 112 insertions(+), 1 deletion(-) (limited to 'wsutil/ws_version_info.c') diff --git a/wsutil/ws_version_info.c b/wsutil/ws_version_info.c index 49af7acfad..c0e83ae467 100644 --- a/wsutil/ws_version_info.c +++ b/wsutil/ws_version_info.c @@ -23,12 +23,123 @@ #include "config.h" #include +#include +#include #include - #include + #include +#include +#include +#include +#include +#include + +/* + * If the string doesn't end with a newline, append one. + * Then word-wrap it to 80 columns. + */ +static void +end_string(GString *str) +{ + size_t point; + char *p, *q; + + point = str->len; + if (point == 0 || str->str[point - 1] != '\n') + g_string_append(str, "\n"); + p = str->str; + while (*p != '\0') { + q = strchr(p, '\n'); + if (q - p > 80) { + /* + * Break at or before this point. + */ + q = p + 80; + while (q > p && *q != ' ') + q--; + if (q != p) + *q = '\n'; + } + p = q + 1; + } +} + +/* + * Get various library compile-time versions and append them to + * the specified GString. + * + * "additional_info" is called at the end to append any additional + * information; this is required in order to, for example, put the + * Portaudio information at the end of the string, as we currently + * don't use Portaudio in TShark. + */ +void +get_compiled_version_info(GString *str, void (*prepend_info)(GString *), + void (*append_info)(GString *)) +{ + if (sizeof(str) == 4) + g_string_append(str, "(32-bit) "); + else + g_string_append(str, "(64-bit) "); + + if (prepend_info) { + (*prepend_info)(str); + g_string_append(str, ", "); + } + + get_glib_version_info(str); + + /* Additional application-dependent information */ + if (append_info) + (*append_info)(str); + g_string_append(str, "."); + + end_string(str); +} + +/* + * Get various library run-time versions, and the OS version, and append + * them to the specified GString. + */ +void +get_runtime_version_info(GString *str, void (*additional_info)(GString *)) +{ +#ifndef _WIN32 + gchar *lang; +#endif + + g_string_append(str, "on "); + + get_os_version_info(str); + +#ifndef _WIN32 + /* Locale */ + if ((lang = getenv ("LANG")) != NULL) + g_string_append_printf(str, ", with locale %s", lang); + else + g_string_append(str, ", with default locale"); +#endif + + /* Additional application-dependent information */ + if (additional_info) + (*additional_info)(str); + + g_string_append(str, "."); + + /* CPU Info */ + get_cpu_info(str); + + /* Get info about installed memory Windows only */ + get_mem_info(str); + + /* Compiler info */ + get_compiler_info(str); + + end_string(str); +} void show_version(const gchar *prog_name_str, GString *comp_info_str, -- cgit v1.2.1