Cast to (const char *) in strrchr calls
[elinks.git] / src / main / version.c
blob79fe6c52fbaa1dffb38780163b390919e34de57d
1 /* Version information */
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10 #ifdef HAVE_UNISTD_H
11 #include <unistd.h>
12 #endif
14 #include "elinks.h"
16 #include "intl/gettext/libintl.h"
17 #include "main/module.h"
18 #include "main/version.h"
19 #include "terminal/terminal.h"
20 #include "util/error.h"
21 #include "util/memory.h"
22 #include "util/string.h"
23 #include "vernum.h"
26 static void
27 add_module_to_string(struct string *string, struct module *module,
28 struct terminal *term)
30 struct module *submodule;
31 int i;
33 if (module->name) add_to_string(string, _(module->name, term));
35 if (!module->submodules) return;
37 add_to_string(string, " (");
39 foreach_module (submodule, module->submodules, i) {
40 if (i > 0) add_to_string(string, ", ");
41 add_module_to_string(string, submodule, term);
44 add_to_string(string, ")");
47 static void
48 add_modules_to_string(struct string *string, struct terminal *term)
50 struct module *module;
51 int i;
53 foreach_module (module, builtin_modules, i) {
54 if (i > 0) add_to_string(string, ", ");
55 add_module_to_string(string, module, term);
59 /* Wrap string on spaces starting at position @start_at, trying
60 * to keep lines undex @maxlen length */
61 static void
62 wrap_string(struct string *string, int start_at, int maxlen)
64 unsigned char *pos, *start_pos;
65 unsigned char *last_pos = NULL;
67 assert(string && string->source && start_at < string->length);
68 if_assert_failed return;
70 if (maxlen <= 0) return;
72 pos = start_pos = &string->source[start_at];
73 while ((pos = strchr((const char *)pos, ' '))) {
74 int len = pos - start_pos;
76 if (len < maxlen) {
77 last_pos = pos;
78 pos++;
79 } else {
80 if (last_pos) *last_pos = '\n';
81 pos = start_pos = last_pos + 1;
83 if (!*pos) break;
87 /* @more will add more information especially for info box. */
88 unsigned char *
89 get_dyn_full_version(struct terminal *term, int more)
91 static const unsigned char comma[] = ", ";
92 struct string string;
94 if (!init_string(&string)) return NULL;
96 add_format_to_string(&string, "ELinks %s", VERSION_STRING);
97 if (*build_id) {
98 add_char_to_string(&string, more ? '\n' : ' ');
99 add_format_to_string(&string, "%s", build_id);
102 add_char_to_string(&string, '\n');
103 add_format_to_string(&string, _("Built on %s %s", term),
104 build_date, build_time);
106 if (more) {
107 add_to_string(&string, "\n\n");
108 add_to_string(&string, _("Text WWW browser", term));
111 string_concat(&string,
112 "\n\n",
113 _("Features:", term), "\n",
114 #ifndef CONFIG_DEBUG
115 _("Standard", term),
116 #else
117 _("Debug", term),
118 #endif
119 #ifdef CONFIG_FASTMEM
120 comma, _("Fastmem", term),
121 #endif
122 #ifdef CONFIG_OWN_LIBC
123 comma, _("Own Libc Routines", term),
124 #endif
125 #ifndef CONFIG_BACKTRACE
126 comma, _("No Backtrace", term),
127 #endif
128 #ifdef CONFIG_IPV6
129 comma, "IPv6",
130 #endif
131 #ifdef CONFIG_GZIP
132 comma, "gzip",
133 #endif
134 #ifdef CONFIG_BZIP2
135 comma, "bzip2",
136 #endif
137 #ifdef CONFIG_LZMA
138 comma, "lzma",
139 #endif
140 #ifndef CONFIG_MOUSE
141 comma, _("No mouse", term),
142 #endif
143 #ifdef CONFIG_UTF8
144 comma, "UTF-8",
145 #endif
146 #ifdef CONFIG_COMBINE
147 comma, _("Combining characters", term),
148 #endif
149 comma,
150 (unsigned char *) NULL
153 add_modules_to_string(&string, term);
155 if (!more) {
156 int start_at = 0;
157 unsigned char *last_newline = strrchr((const char *)string.source, '\n');
159 if (last_newline) {
160 start_at = last_newline - string.source + 1;
163 wrap_string(&string, start_at, 72);
166 return string.source;
169 /* This one is used to prevent usage of straconcat() at backtrace time. */
170 void
171 init_static_version(void)
173 unsigned char *s = get_dyn_full_version((struct terminal *) NULL, 0);
175 if (s) {
176 safe_strncpy(full_static_version, s, sizeof(full_static_version));
177 mem_free(s);