Do the full string in get_{compiled,runtime}_version_info().
[metze/wireshark/wip.git] / wsutil / ws_version_info.c
1 /* ws_version_info.c
2  * Routines to report version information for Wireshark programs
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 <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 #include <glib.h>
30
31 #include <wsutil/ws_version_info.h>
32
33 #include <wsutil/copyright_info.h>
34 #include <wsutil/glib_version_info.h>
35 #include <wsutil/os_version_info.h>
36 #include <wsutil/compiler_info.h>
37 #include <wsutil/cpu_info.h>
38 #include <wsutil/mem_info.h>
39
40 /*
41  * If the string doesn't end with a newline, append one.
42  * Then word-wrap it to 80 columns.
43  */
44 static void
45 end_string(GString *str)
46 {
47         size_t point;
48         char *p, *q;
49
50         point = str->len;
51         if (point == 0 || str->str[point - 1] != '\n')
52                 g_string_append(str, "\n");
53         p = str->str;
54         while (*p != '\0') {
55                 q = strchr(p, '\n');
56                 if (q - p > 80) {
57                         /*
58                          * Break at or before this point.
59                          */
60                         q = p + 80;
61                         while (q > p && *q != ' ')
62                                 q--;
63                         if (q != p)
64                                 *q = '\n';
65                 }
66                 p = q + 1;
67         }
68 }
69
70 /*
71  * Get various library compile-time versions, put them in a GString,
72  * and return the GString.
73  *
74  * "prepend_info" is called at the start to prepend any additional
75  * information before the standard library information.
76  *
77  * "append_info" is called at the end to append any additional
78  * information after the standard library information.  This is
79  * required in order to, for example, put the Portaudio information
80  * at the end of the string, as we currently don't use Portaudio in
81  * TShark.
82  */
83 GString *
84 get_compiled_version_info(void (*prepend_info)(GString *),
85                           void (*append_info)(GString *))
86 {
87         GString *str;
88
89         str = g_string_new("Compiled ");
90
91         if (sizeof(str) == 4)
92                 g_string_append(str, "(32-bit) ");
93         else
94                 g_string_append(str, "(64-bit) ");
95
96         if (prepend_info) {
97                 (*prepend_info)(str);
98                 g_string_append(str, ", ");
99         }
100
101         get_glib_version_info(str);
102
103         /* Additional application-dependent information */
104         if (append_info)
105                 (*append_info)(str);
106         g_string_append(str, ".");
107
108         end_string(str);
109
110         return str;
111 }
112
113 /*
114  * Get various library run-time versions, and the OS version, and append
115  * them to the specified GString.
116  *
117  * "additional_info" is called at the end to append any additional
118  * information; this is required in order to, for example, put the
119  * Portaudio information at the end of the string, as we currently
120  * don't use Portaudio in TShark.
121  */
122 GString *
123 get_runtime_version_info(void (*additional_info)(GString *))
124 {
125         GString *str;
126 #ifndef _WIN32
127         gchar *lang;
128 #endif
129
130         str = g_string_new("Running on ");
131
132         get_os_version_info(str);
133
134 #ifndef _WIN32
135         /* Locale */
136         if ((lang = getenv ("LANG")) != NULL)
137                 g_string_append_printf(str, ", with locale %s", lang);
138         else
139                 g_string_append(str, ", with default locale");
140 #endif
141
142         /* Additional application-dependent information */
143         if (additional_info)
144                 (*additional_info)(str);
145
146         g_string_append(str, ".");
147
148         /* CPU Info */
149         get_cpu_info(str);
150
151         /* Get info about installed memory Windows only */
152         get_mem_info(str);
153
154         /* Compiler info */
155         get_compiler_info(str);
156
157         end_string(str);
158
159         return str;
160 }
161
162 void
163 show_version(const gchar *prog_name_str, GString *comp_info_str,
164              GString *runtime_info_str)
165 {
166         printf("%s %s\n"
167                "\n"
168                "%s"
169                "\n"
170                "%s"
171                "\n"
172                "%s",
173                prog_name_str, get_ws_vcs_version_info(), get_copyright_info(),
174                comp_info_str->str, runtime_info_str->str);
175 }
176
177 /*
178  * Return a version number string for Wireshark, including, for builds
179  * from a tree checked out from Wireshark's version control system,
180  * something identifying what version was checked out.
181  */
182 const char *
183 get_ws_vcs_version_info(void)
184 {
185 #ifdef GITVERSION
186         return VERSION " (" GITVERSION " from " GITBRANCH ")";
187 #else
188         return VERSION;
189 #endif
190 }
191
192 /*
193  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
194  *
195  * Local variables:
196  * c-basic-offset: 8
197  * tab-width: 8
198  * indent-tabs-mode: t
199  * End:
200  *
201  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
202  * :indentSize=8:tabSize=8:noTabs=false:
203  */