iconv: Bail out of the loop when an illegal sequence of bytes occurs.
[elinks/elinks-j605.git] / src / osdep / newwin.c
blob8c92300d36f8bbe75874fbdaba62ec28ab45a8e7
1 /* Open in new window handling */
3 #ifdef HAVE_CONFIG_H
4 #include "config.h"
5 #endif
7 #include <stdlib.h>
8 #include <string.h>
10 #include "elinks.h"
12 #include "intl/gettext/libintl.h"
13 #include "osdep/newwin.h"
14 #include "osdep/osdep.h"
15 #include "terminal/terminal.h"
16 #include "util/memory.h"
17 #include "util/string.h"
19 #ifdef XTERM
20 #define XTERM_CMD XTERM
21 #else
22 #define XTERM_CMD DEFAULT_XTERM_CMD
23 #endif
25 const struct open_in_new open_in_new[] = {
26 /* [gettext_accelerator_context(open_in_new.os2, open_in_new.win32, open_in_new.beos)] */
27 { ENV_XWIN, XTERM_CMD, N_("~Xterm") },
28 { ENV_TWIN, DEFAULT_TWTERM_CMD, N_("T~wterm") },
29 { ENV_SCREEN, DEFAULT_SCREEN_CMD, N_("~Screen") },
30 /* [gettext_accelerator_context()] */
31 #ifdef CONFIG_OS_OS2
32 /* [gettext_accelerator_context(open_in_new.os2)] */
33 { ENV_OS2VIO, DEFAULT_OS2_WINDOW_CMD, N_("~Window") },
34 { ENV_OS2VIO, DEFAULT_OS2_FULLSCREEN_CMD, N_("~Full screen") },
35 /* [gettext_accelerator_context()] */
36 #endif
37 #ifdef CONFIG_OS_WIN32
38 /* [gettext_accelerator_context(open_in_new.win32)] */
39 { ENV_WIN32, "", N_("~Window") },
40 /* [gettext_accelerator_context()] */
41 #endif
42 #ifdef CONFIG_OS_BEOS
43 /* [gettext_accelerator_context(open_in_new.beos)] */
44 { ENV_BE, DEFAULT_BEOS_TERM_CMD, N_("~BeOS terminal") },
45 /* [gettext_accelerator_context()] */
46 #endif
47 { 0, NULL, NULL }
50 int
51 can_open_in_new(struct terminal *term)
53 int i, possibilities = 0;
55 foreach_open_in_new (i, term->environment) {
56 possibilities++;
59 return possibilities;
62 void
63 open_new_window(struct terminal *term, unsigned char *exe_name,
64 enum term_env_type environment, unsigned char *param)
66 unsigned char *command = NULL;
67 int i;
69 foreach_open_in_new (i, environment) {
70 command = open_in_new[i].command;
71 break;
74 assert(command);
76 if (environment & ENV_XWIN) {
77 unsigned char *xterm = getenv("ELINKS_XTERM");
79 if (!xterm) xterm = getenv("LINKS_XTERM");
80 if (xterm) command = xterm;
82 } else if (environment & ENV_TWIN) {
83 unsigned char *twterm = getenv("ELINKS_TWTERM");
85 if (!twterm) twterm = getenv("LINKS_TWTERM");
86 if (twterm) command = twterm;
89 command = straconcat(command, " ", exe_name, " ", param,
90 (unsigned char *) NULL);
91 if (!command) return;
93 exec_on_terminal(term, command, "", TERM_EXEC_NEWWIN);
94 mem_free(command);