Move utility routines for capturing into a libcaputils static library.
[metze/wireshark/wip.git] / version_info.c
1 /* version_info.c
2  * Routines to report version information for stuff used by Wireshark
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include "config.h"
24
25 #include <glib.h>
26
27 #include <stdlib.h>
28 #include <string.h>
29
30 #ifdef HAVE_LIBZ
31 #include <zlib.h>       /* to get the libz version number */
32 #endif
33
34 #include "version_info.h"
35 #include <wsutil/glib_version_info.h>
36 #include <wsutil/os_version_info.h>
37 #include <wsutil/compiler_info.h>
38 #include <wsutil/cpu_info.h>
39 #include <wsutil/mem_info.h>
40
41 /*
42  * If the string doesn't end with a newline, append one.
43  * Then word-wrap it to 80 columns.
44  */
45 static void
46 end_string(GString *str)
47 {
48         size_t point;
49         char *p, *q;
50
51         point = str->len;
52         if (point == 0 || str->str[point - 1] != '\n')
53                 g_string_append(str, "\n");
54         p = str->str;
55         while (*p != '\0') {
56                 q = strchr(p, '\n');
57                 if (q - p > 80) {
58                         /*
59                          * Break at or before this point.
60                          */
61                         q = p + 80;
62                         while (q > p && *q != ' ')
63                                 q--;
64                         if (q != p)
65                                 *q = '\n';
66                 }
67                 p = q + 1;
68         }
69 }
70
71 /*
72  * Get various library compile-time versions and append them to
73  * the specified GString.
74  *
75  * "additional_info" is called at the end to append any additional
76  * information; this is required in order to, for example, put the
77  * Portaudio information at the end of the string, as we currently
78  * don't use Portaudio in TShark.
79  */
80 void
81 get_compiled_version_info(GString *str, void (*prepend_info)(GString *),
82                           void (*append_info)(GString *))
83 {
84         if (sizeof(str) == 4)
85                 g_string_append(str, "(32-bit) ");
86         else
87                 g_string_append(str, "(64-bit) ");
88
89         if (prepend_info) {
90                 (*prepend_info)(str);
91                 g_string_append(str, ", ");
92         }
93
94         get_glib_version_info(str);
95
96         /* Additional application-dependent information */
97         if (append_info)
98                 (*append_info)(str);
99         g_string_append(str, ".");
100
101         end_string(str);
102 }
103
104 /*
105  * Get various library run-time versions, and the OS version, and append
106  * them to the specified GString.
107  */
108 void
109 get_runtime_version_info(GString *str, void (*additional_info)(GString *))
110 {
111 #ifndef _WIN32
112         gchar *lang;
113 #endif
114
115         g_string_append(str, "on ");
116
117         get_os_version_info(str);
118
119 #ifndef _WIN32
120         /* Locale */
121         if ((lang = getenv ("LANG")) != NULL)
122                 g_string_append_printf(str, ", with locale %s", lang);
123         else
124                 g_string_append(str, ", without locale");
125 #endif
126
127         /* Additional application-dependent information */
128         if (additional_info)
129                 (*additional_info)(str);
130
131         g_string_append(str, ".");
132
133         /* CPU Info */
134         get_cpu_info(str);
135
136         /* Get info about installed memory Windows only */
137         get_mem_info(str);
138
139         /* Compiler info */
140         get_compiler_info(str);
141
142         end_string(str);
143 }
144
145 /*
146  * Editor modelines
147  *
148  * Local Variables:
149  * c-basic-offset: 8
150  * tab-width: 8
151  * indent-tabs-mode: t
152  * End:
153  *
154  * ex: set shiftwidth=8 tabstop=8 noexpandtab:
155  * :indentSize=8:tabSize=8:noTabs=false:
156  */