iconv: Bail out of the loop when an illegal sequence of bytes occurs.
[elinks/elinks-j605.git] / src / dialogs / info.c
blob4c4434ab4a84b3d76502f4a61c95ed2fea2229e4
1 /* Info dialogs */
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 "bfu/dialog.h"
17 #include "cache/cache.h"
18 #include "config/kbdbind.h"
19 #include "config/options.h"
20 #include "dialogs/info.h"
21 #include "document/renderer.h"
22 #include "ecmascript/ecmascript.h"
23 #include "intl/gettext/libintl.h"
24 #include "main/select.h"
25 #include "main/timer.h"
26 #include "main/version.h"
27 #include "network/connection.h"
28 #include "session/session.h"
29 #include "terminal/terminal.h"
30 #include "util/conv.h"
31 #ifdef DEBUG_MEMLEAK
32 #include "util/memdebug.h"
33 #endif
34 #include "util/memlist.h"
35 #include "util/memory.h"
36 #include "util/string.h"
38 void
39 menu_about(struct terminal *term, void *xxx, void *xxxx)
41 info_box(term, MSGBOX_FREE_TEXT,
42 N_("About"), ALIGN_CENTER,
43 get_dyn_full_version(term, 1));
46 struct keys_toggle_info {
47 struct terminal *term;
48 int toggle;
51 static void
52 push_toggle_keys_display_button(void *data)
54 struct keys_toggle_info *info = data;
56 menu_keys(info->term, (void *) (long) !info->toggle, NULL);
59 void
60 menu_keys(struct terminal *term, void *d_, void *xxx)
62 /* [gettext_accelerator_context(menu_keys)] */
63 int d = (long) d_;
65 /* We scale by main mapping because it has the most actions */
66 action_id_T action_ids[MAIN_ACTIONS] = {
67 ACT_MAIN_MENU,
68 ACT_MAIN_QUIT,
69 ACT_MAIN_MOVE_LINK_NEXT,
70 ACT_MAIN_MOVE_LINK_PREV,
71 ACT_MAIN_SCROLL_DOWN,
72 ACT_MAIN_SCROLL_UP,
73 ACT_MAIN_SCROLL_LEFT,
74 ACT_MAIN_SCROLL_RIGHT,
75 ACT_MAIN_HISTORY_MOVE_BACK,
76 ACT_MAIN_GOTO_URL,
77 ACT_MAIN_GOTO_URL_CURRENT,
78 ACT_MAIN_DOCUMENT_INFO,
79 ACT_MAIN_HEADER_INFO,
80 ACT_MAIN_SEARCH,
81 ACT_MAIN_SEARCH_BACK,
82 ACT_MAIN_FIND_NEXT,
83 ACT_MAIN_FIND_NEXT_BACK,
84 ACT_MAIN_LINK_FOLLOW,
85 ACT_MAIN_LINK_DOWNLOAD,
86 ACT_MAIN_TOGGLE_HTML_PLAIN,
88 ACT_MAIN_NONE,
90 struct string keys;
91 struct keys_toggle_info *info;
93 info = mem_calloc(1, sizeof(*info));
95 if (!info || !init_string(&keys)) {
96 mem_free_if(info);
97 return;
100 info->term = term;
101 info->toggle = d;
103 if (info->toggle) {
104 action_id_T action_id;
105 enum keymap_id keymap_id;
107 for (action_id = 0; action_id < MAIN_ACTIONS - 1; action_id++) {
108 action_ids[action_id] = action_id + 1;
111 for (keymap_id = 0; keymap_id < KEYMAP_MAX; keymap_id++) {
112 add_actions_to_string(&keys, action_ids, keymap_id, term);
113 if (keymap_id + 1 < KEYMAP_MAX)
114 add_to_string(&keys, "\n\n");
116 /* Just a little reminder that the following code takes
117 * the easy way. */
118 assert((int) MAIN_ACTIONS > (int) EDIT_ACTIONS);
119 assert((int) EDIT_ACTIONS > (int) MENU_ACTIONS);
121 if (keymap_id == KEYMAP_MAIN) {
122 action_ids[EDIT_ACTIONS] = ACT_EDIT_NONE;
123 } else if (keymap_id == KEYMAP_EDIT) {
124 action_ids[MENU_ACTIONS] = ACT_MENU_NONE;
127 } else {
128 add_actions_to_string(&keys, action_ids, KEYMAP_MAIN, term);
131 msg_box(term, getml(info, (void *) NULL), MSGBOX_FREE_TEXT | MSGBOX_SCROLLABLE,
132 N_("Keys"), ALIGN_LEFT,
133 keys.source,
134 info, 2,
135 MSG_BOX_BUTTON(N_("~OK"), NULL, B_ENTER | B_ESC),
136 MSG_BOX_BUTTON(N_("~Toggle display"), push_toggle_keys_display_button, B_ENTER));
139 void
140 menu_copying(struct terminal *term, void *xxx, void *xxxx)
142 info_box(term, MSGBOX_FREE_TEXT,
143 N_("Copying"), ALIGN_CENTER,
144 msg_text(term, N_("ELinks %s\n"
145 "\n"
146 "%s"
147 "et al.\n"
148 "\n"
149 "This program is free software; you can redistribute it "
150 "and/or modify it under the terms of the GNU General Public "
151 "License as published by the Free Software Foundation, "
152 "specifically version 2 of the License."),
153 VERSION_STRING, COPYRIGHT_STRING));
157 static unsigned char *
158 get_resource_info(struct terminal *term, void *data)
160 struct string info;
161 long val;
162 unsigned longlong bigval;
164 if (!init_string(&info))
165 return NULL;
167 #define val_add(text) \
168 add_format_to_string(&info, text, val);
170 add_to_string(&info, _("Resources", term));
171 add_to_string(&info, ": ");
173 val = get_file_handles_count();
174 val_add(n_("%ld handle", "%ld handles", val, term));
175 add_to_string(&info, ", ");
177 val = get_timers_count();
178 val_add(n_("%ld timer", "%ld timers", val, term));
179 add_to_string(&info, ".\n");
181 add_to_string(&info, _("Connections", term));
182 add_to_string(&info, ": ");
184 val = get_connections_count();
185 val_add(n_("%ld connection", "%ld connections", val, term));
186 add_to_string(&info, ", ");
188 val = get_connections_connecting_count();
189 val_add(n_("%ld connecting", "%ld connecting", val, term));
190 add_to_string(&info, ", ");
192 val = get_connections_transfering_count();
193 val_add(n_("%ld transferring", "%ld transferring", val, term));
194 add_to_string(&info, ", ");
196 val = get_keepalive_connections_count();
197 val_add(n_("%ld keepalive", "%ld keepalive", val, term));
198 add_to_string(&info, ".\n");
200 add_to_string(&info, _("Memory cache", term));
201 add_to_string(&info, ": ");
203 /* What about just using Kibi/Mebi representation here? --jonas */
204 bigval = get_cache_size();
205 add_format_to_string(&info, n_("%ld byte", "%ld bytes", bigval, term), bigval);
206 add_to_string(&info, ", ");
208 val = get_cache_entry_count();
209 val_add(n_("%ld file", "%ld files", val, term));
210 add_to_string(&info, ", ");
212 val = get_cache_entry_used_count();
213 val_add(n_("%ld in use", "%ld in use", val, term));
214 add_to_string(&info, ", ");
216 val = get_cache_entry_loading_count();
217 val_add(n_("%ld loading", "%ld loading", val, term));
218 add_to_string(&info, ".\n");
220 add_to_string(&info, _("Document cache", term));
221 add_to_string(&info, ": ");
223 val = get_format_cache_size();
224 val_add(n_("%ld formatted", "%ld formatted", val, term));
225 add_to_string(&info, ", ");
227 val = get_format_cache_used_count();
228 val_add(n_("%ld in use", "%ld in use", val, term));
229 add_to_string(&info, ", ");
231 val = get_format_cache_refresh_count();
232 val_add(n_("%ld refreshing", "%ld refreshing", val, term));
233 add_to_string(&info, ".\n");
235 #ifdef CONFIG_ECMASCRIPT
236 add_to_string(&info, _("ECMAScript", term));
237 add_to_string(&info, ": ");
239 val = ecmascript_get_interpreter_count();
240 val_add(n_("%ld interpreter", "%ld interpreters", val, term));
241 add_to_string(&info, ".\n");
242 #endif
244 add_to_string(&info, _("Interlinking", term));
245 add_to_string(&info, ": ");
246 if (term->master)
247 add_to_string(&info, _("master terminal", term));
248 else
249 add_to_string(&info, _("slave terminal", term));
250 add_to_string(&info, ", ");
252 val = list_size(&terminals);
253 val_add(n_("%ld terminal", "%ld terminals", val, term));
254 add_to_string(&info, ", ");
256 val = list_size(&sessions);
257 val_add(n_("%ld session", "%ld sessions", val, term));
258 add_char_to_string(&info, '.');
260 #ifdef DEBUG_MEMLEAK
261 add_char_to_string(&info, '\n');
262 add_to_string(&info, _("Memory allocated", term));
263 add_to_string(&info, ": ");
265 val = mem_stats.amount;
266 val_add(n_("%ld byte", "%ld bytes", val, term));
267 add_to_string(&info, ", ");
269 val = mem_stats.true_amount - mem_stats.amount;
270 val_add(n_("%ld byte overhead", "%ld bytes overhead", val, term));
272 add_format_to_string(&info, " (%0.2f%%).",
273 (double) (mem_stats.true_amount - mem_stats.amount) / (double) mem_stats.amount * 100);
274 #endif /* DEBUG_MEMLEAK */
276 #undef val_add
278 return info.source;
281 void
282 resource_info(struct terminal *term)
284 refreshed_msg_box(term, 0, N_("Resources"), ALIGN_LEFT,
285 get_resource_info, NULL);