File: version.c

package info (click to toggle)
elinks 0.13~20190125-3
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 17,244 kB
  • sloc: ansic: 102,743; sh: 5,265; python: 3,940; perl: 2,175; makefile: 970; pascal: 930; yacc: 295; lisp: 125; ruby: 70; awk: 65
file content (192 lines) | stat: -rw-r--r-- 4,122 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/* Version information */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#include "elinks.h"

#include "intl/gettext/libintl.h"
#include "main/module.h"
#include "main/version.h"
#include "terminal/terminal.h"
#include "util/error.h"
#include "util/memory.h"
#include "util/string.h"
#include "vernum.h"

#if defined(CONFIG_LIBEV) || defined(CONFIG_LIBEVENT)
extern int event_enabled;
#endif 

static void
add_module_to_string(struct string *string, struct module *module,
		     struct terminal *term)
{
	struct module *submodule;
	int i;

	if (module->name) add_to_string(string, _(module->name, term));

	if (!module->submodules) return;

	add_to_string(string, " (");

	foreach_module (submodule, module->submodules, i) {
		if (i > 0) add_to_string(string, ", ");
		add_module_to_string(string, submodule, term);
	}

	add_to_string(string, ")");
}

static void
add_modules_to_string(struct string *string, struct terminal *term)
{
	struct module *module;
	int i;

	foreach_module (module, builtin_modules, i) {
		if (i > 0) add_to_string(string, ", ");
		add_module_to_string(string, module, term);
	}
}

/* Wrap string on spaces starting at position @start_at, trying
 * to keep lines undex @maxlen length */
static void
wrap_string(struct string *string, int start_at, int maxlen)
{
	unsigned char *pos, *start_pos;
	unsigned char *last_pos = NULL;

	assert(string && string->source && start_at < string->length);
	if_assert_failed return;

	if (maxlen <= 0) return;

	pos = start_pos = &string->source[start_at];
	while ((pos = strchr((const char *)pos, ' '))) {
		int len = pos - start_pos;

		if (len < maxlen) {
			last_pos = pos;
			pos++;
		} else {
			if (last_pos) *last_pos = '\n';
			pos = start_pos = last_pos + 1;
		}
		if (!*pos) break;
	}
}

/* @more will add more information especially for info box. */
unsigned char *
get_dyn_full_version(struct terminal *term, int more)
{
	static const unsigned char comma[] = ", ";
	struct string string;

	if (!init_string(&string)) return NULL;

	add_format_to_string(&string, "ELinks %s", VERSION_STRING);
	if (*build_id) {
		add_char_to_string(&string, more ? '\n' : ' ');
		add_format_to_string(&string, "%s", build_id);
	}

	add_char_to_string(&string, '\n');

	if (more) {
		add_to_string(&string, "\n\n");
		add_to_string(&string, _("Text WWW browser", term));
	}

	string_concat(&string,
		"\n\n",
		_("Features:", term), "\n",
#ifndef CONFIG_DEBUG
		_("Standard", term),
#else
		_("Debug", term),
#endif
#ifdef CONFIG_FASTMEM
		comma, _("Fastmem", term),
#endif
#ifdef CONFIG_OWN_LIBC
		comma, _("Own Libc Routines", term),
#endif
#ifndef CONFIG_BACKTRACE
		comma, _("No Backtrace", term),
#endif
#ifdef CONFIG_IPV6
		comma, "IPv6",
#endif
#ifdef CONFIG_BROTLI
		comma, "brotli",
#endif
#ifdef CONFIG_GZIP
		comma, "gzip",
#endif
#ifdef CONFIG_BZIP2
		comma, "bzip2",
#endif
#ifdef CONFIG_LZMA
		comma, "lzma",
#endif
#ifndef CONFIG_MOUSE
		comma, _("No mouse", term),
#endif
#ifdef CONFIG_UTF8
		comma, "UTF-8",
#endif
#ifdef CONFIG_COMBINE
		comma, _("Combining characters", term),
#endif
#ifdef CONFIG_LIBEV
		comma, (event_enabled ? _("libev", term) : _("libev (disabled)", term)),
#endif
#ifdef CONFIG_LIBEVENT
		comma, (event_enabled ? _("libevent", term) : _("libevent (disabled)", term)),
#endif
#ifdef CONFIG_TERMINFO
		comma, (get_cmd_opt_bool("terminfo") ? _("terminfo", term) : _("terminfo (disabled)", term)),
#endif
		comma,
		(unsigned char *) NULL
	);

	add_modules_to_string(&string, term);

	if (!more) {
		int start_at = 0;
		unsigned char *last_newline = strrchr((const char *)string.source, '\n');

		if (last_newline) {
			start_at = last_newline - string.source + 1;
		}

		wrap_string(&string, start_at, 72);
	}

	return string.source;
}

/* This one is used to prevent usage of straconcat() at backtrace time. */
void
init_static_version(void)
{
	unsigned char *s = get_dyn_full_version((struct terminal *) NULL, 0);

	if (s) {
		safe_strncpy(full_static_version, s, sizeof(full_static_version));
		mem_free(s);
	}
}