1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

Name the exec_on_terminal() fg values.

This commit is contained in:
Kalle Olavi Niemitalo 2007-07-14 12:26:45 +03:00 committed by Kalle Olavi Niemitalo
parent a0d7c3e7f6
commit 6117f8a164
10 changed files with 46 additions and 26 deletions

View File

@ -759,7 +759,7 @@ do_pass_uri_to_command(struct terminal *term, void *command_, void *xxx)
{ {
unsigned char *command = command_; unsigned char *command = command_;
exec_on_terminal(term, command, "", 0); exec_on_terminal(term, command, "", TERM_EXEC_BG);
mem_free(command); mem_free(command);
} }

View File

@ -90,6 +90,6 @@ open_new_window(struct terminal *term, unsigned char *exe_name,
(unsigned char *) NULL); (unsigned char *) NULL);
if (!command) return; if (!command) return;
exec_on_terminal(term, command, "", 2); exec_on_terminal(term, command, "", TERM_EXEC_NEWWIN);
mem_free(command); mem_free(command);
} }

View File

@ -300,7 +300,7 @@ user_protocol_handler(struct session *ses, struct uri *uri)
if (prog) { if (prog) {
unsigned char *delete = empty_string_or_(filename); unsigned char *delete = empty_string_or_(filename);
exec_on_terminal(ses->tab->term, prog, delete, 1); exec_on_terminal(ses->tab->term, prog, delete, TERM_EXEC_FG);
mem_free(prog); mem_free(prog);
} else if (filename) { } else if (filename) {

View File

@ -231,7 +231,8 @@ static int
l_execute(LS) l_execute(LS)
{ {
if (lua_isstring(S, 1)) { if (lua_isstring(S, 1)) {
exec_on_terminal(lua_ses->tab->term, (unsigned char *) lua_tostring(S, 1), "", 0); exec_on_terminal(lua_ses->tab->term, (unsigned char *) lua_tostring(S, 1), "",
TERM_EXEC_BG);
lua_pushnumber(S, 0); lua_pushnumber(S, 0);
return 1; return 1;
} }
@ -795,7 +796,7 @@ handle_ret_run(struct session *ses)
unsigned char *cmd = (unsigned char *) lua_tostring(L, -1); unsigned char *cmd = (unsigned char *) lua_tostring(L, -1);
if (cmd) { if (cmd) {
exec_on_terminal(ses->tab->term, cmd, "", 1); exec_on_terminal(ses->tab->term, cmd, "", TERM_EXEC_FG);
return; return;
} }

View File

@ -103,7 +103,7 @@ elinks_execute(JSContext *ctx, JSObject *obj, uintN argc, jsval *argv, jsval *rv
if (!*string) if (!*string)
return JS_TRUE; return JS_TRUE;
exec_on_terminal(smjs_ses->tab->term, string, "", 0); exec_on_terminal(smjs_ses->tab->term, string, "", TERM_EXEC_BG);
undef_to_jsval(ctx, rval); undef_to_jsval(ctx, rval);
return JS_TRUE; return JS_TRUE;

View File

@ -376,7 +376,7 @@ download_data_store(struct download *download, struct file_download *file_downlo
} else { } else {
exec_on_terminal(term, file_download->external_handler, exec_on_terminal(term, file_download->external_handler,
file_download->file, file_download->file,
!!file_download->block); file_download->block ? TERM_EXEC_FG : TERM_EXEC_BG);
file_download->delete = 0; file_download->delete = 0;
abort_download_and_beep(file_download, term); abort_download_and_beep(file_download, term);
} }
@ -1100,7 +1100,8 @@ tp_open(struct type_query *type_query)
read_from_popen(type_query->ses, handler, NULL); read_from_popen(type_query->ses, handler, NULL);
else else
exec_on_terminal(type_query->ses->tab->term, exec_on_terminal(type_query->ses->tab->term,
handler, "", !!type_query->block); handler, "",
type_query->block ? TERM_EXEC_FG : TERM_EXEC_BG);
mem_free(handler); mem_free(handler);
} }

View File

@ -510,7 +510,7 @@ in_sock(struct itrm *itrm)
struct string path; struct string path;
struct string delete; struct string delete;
char ch; char ch;
int fg; int fg; /* enum term_exec */
ssize_t bytes_read, i, p; ssize_t bytes_read, i, p;
unsigned char buf[ITRM_OUT_QUEUE_SIZE]; unsigned char buf[ITRM_OUT_QUEUE_SIZE];
@ -575,7 +575,7 @@ has_nul_byte:
unsigned char *param; unsigned char *param;
int path_len, del_len, param_len; int path_len, del_len, param_len;
if (is_blocked() && fg) { if (is_blocked() && fg != TERM_EXEC_BG) {
if (*delete.source) unlink(delete.source); if (*delete.source) unlink(delete.source);
goto nasty_thing; goto nasty_thing;
} }
@ -591,20 +591,20 @@ has_nul_byte:
memcpy(param + 1, path.source, path_len + 1); memcpy(param + 1, path.source, path_len + 1);
memcpy(param + 1 + path_len + 1, delete.source, del_len + 1); memcpy(param + 1 + path_len + 1, delete.source, del_len + 1);
if (fg == 1) block_itrm(); if (fg == TERM_EXEC_FG) block_itrm();
blockh = start_thread((void (*)(void *, int)) exec_thread, blockh = start_thread((void (*)(void *, int)) exec_thread,
param, param_len); param, param_len);
mem_free(param); mem_free(param);
if (blockh == -1) { if (blockh == -1) {
if (fg == 1) if (fg == TERM_EXEC_FG)
unblock_itrm(); unblock_itrm();
goto nasty_thing; goto nasty_thing;
} }
if (fg == 1) { if (fg == TERM_EXEC_FG) {
set_handlers(blockh, (select_handler_T) unblock_itrm_x, set_handlers(blockh, (select_handler_T) unblock_itrm_x,
NULL, (select_handler_T) unblock_itrm_x, NULL, (select_handler_T) unblock_itrm_x,
(void *) (long) blockh); (void *) (long) blockh);

View File

@ -179,7 +179,7 @@ exec_thread(unsigned char *path, int p)
int plen = strlen(path + 1) + 2; int plen = strlen(path + 1) + 2;
#if defined(HAVE_SETPGID) && !defined(CONFIG_OS_BEOS) && !defined(HAVE_BEGINTHREAD) #if defined(HAVE_SETPGID) && !defined(CONFIG_OS_BEOS) && !defined(HAVE_BEGINTHREAD)
if (path[0] == 2) setpgid(0, 0); if (path[0] == TERM_EXEC_NEWWIN) setpgid(0, 0);
#endif #endif
exe(path + 1); exe(path + 1);
if (path[plen]) unlink(path + plen); if (path[plen]) unlink(path + plen);
@ -210,7 +210,7 @@ static void
exec_on_master_terminal(struct terminal *term, exec_on_master_terminal(struct terminal *term,
unsigned char *path, int plen, unsigned char *path, int plen,
unsigned char *delete, int dlen, unsigned char *delete, int dlen,
int fg) enum term_exec fg)
{ {
int blockh; int blockh;
int param_size = plen + dlen + 2 /* 2 null char */ + 1 /* fg */; int param_size = plen + dlen + 2 /* 2 null char */ + 1 /* fg */;
@ -222,17 +222,17 @@ exec_on_master_terminal(struct terminal *term,
memcpy(param + 1, path, plen + 1); memcpy(param + 1, path, plen + 1);
memcpy(param + 1 + plen + 1, delete, dlen + 1); memcpy(param + 1 + plen + 1, delete, dlen + 1);
if (fg == 1) block_itrm(); if (fg == TERM_EXEC_FG) block_itrm();
blockh = start_thread((void (*)(void *, int)) exec_thread, blockh = start_thread((void (*)(void *, int)) exec_thread,
param, param_size); param, param_size);
fmem_free(param); fmem_free(param);
if (blockh == -1) { if (blockh == -1) {
if (fg == 1) unblock_itrm(); if (fg == TERM_EXEC_FG) unblock_itrm();
return; return;
} }
if (fg == 1) { if (fg == TERM_EXEC_FG) {
term->blocked = blockh; term->blocked = blockh;
set_handlers(blockh, set_handlers(blockh,
(select_handler_T) unblock_terminal, (select_handler_T) unblock_terminal,
@ -253,7 +253,7 @@ static void
exec_on_slave_terminal( struct terminal *term, exec_on_slave_terminal( struct terminal *term,
unsigned char *path, int plen, unsigned char *path, int plen,
unsigned char *delete, int dlen, unsigned char *delete, int dlen,
int fg) enum term_exec fg)
{ {
int data_size = plen + dlen + 1 /* 0 */ + 1 /* fg */ + 2 /* 2 null char */; int data_size = plen + dlen + 1 /* 0 */ + 1 /* fg */ + 2 /* 2 null char */;
unsigned char *data = fmem_alloc(data_size); unsigned char *data = fmem_alloc(data_size);
@ -270,7 +270,7 @@ exec_on_slave_terminal( struct terminal *term,
void void
exec_on_terminal(struct terminal *term, unsigned char *path, exec_on_terminal(struct terminal *term, unsigned char *path,
unsigned char *delete, int fg) unsigned char *delete, enum term_exec fg)
{ {
if (path) { if (path) {
if (!*path) return; if (!*path) return;
@ -279,7 +279,7 @@ exec_on_terminal(struct terminal *term, unsigned char *path,
} }
#ifdef NO_FG_EXEC #ifdef NO_FG_EXEC
fg = 0; fg = TERM_EXEC_BG;
#endif #endif
if (term->master) { if (term->master) {
@ -288,7 +288,7 @@ exec_on_terminal(struct terminal *term, unsigned char *path,
return; return;
} }
if (fg && is_blocked()) { if (fg != TERM_EXEC_BG && is_blocked()) {
unlink(delete); unlink(delete);
return; return;
} }
@ -314,7 +314,7 @@ exec_shell(struct terminal *term)
sh = get_shell(); sh = get_shell();
if (sh && *sh) if (sh && *sh)
exec_on_terminal(term, sh, "", 1); exec_on_terminal(term, sh, "", TERM_EXEC_FG);
} }
@ -328,7 +328,7 @@ do_terminal_function(struct terminal *term, unsigned char code,
if (!x_data) return; if (!x_data) return;
x_data[0] = code; x_data[0] = code;
memcpy(x_data + 1, data, data_len + 1); memcpy(x_data + 1, data, data_len + 1);
exec_on_terminal(term, NULL, x_data, 0); exec_on_terminal(term, NULL, x_data, TERM_EXEC_BG);
fmem_free(x_data); fmem_free(x_data);
} }

View File

@ -175,10 +175,28 @@ void destroy_all_terminals(void);
void exec_thread(unsigned char *, int); void exec_thread(unsigned char *, int);
void close_handle(void *); void close_handle(void *);
/* Operations that can be requested with do_terminal_function().
* The interlink protocol passes these values as one byte in a
* null-terminated string, so zero cannot be used. */
#define TERM_FN_TITLE 1 #define TERM_FN_TITLE 1
#define TERM_FN_RESIZE 2 #define TERM_FN_RESIZE 2
void exec_on_terminal(struct terminal *, unsigned char *, unsigned char *, int); /* How to execute a program in a terminal. These values are used in
* the interlink protocol and must fit in one byte. */
enum term_exec {
/* Execute in the background. ELinks keeps using the terminal
* and the program should not use it. */
TERM_EXEC_BG = 0,
/* Execute in the foreground. The program may use the terminal.
* ELinks will redraw when the program exits. */
TERM_EXEC_FG = 1,
/* Execute in the background and in a new process group. */
TERM_EXEC_NEWWIN = 2
};
void exec_on_terminal(struct terminal *, unsigned char *, unsigned char *, enum term_exec);
void exec_shell(struct terminal *term); void exec_shell(struct terminal *term);
void set_terminal_title(struct terminal *, unsigned char *); void set_terminal_title(struct terminal *, unsigned char *);

View File

@ -625,7 +625,7 @@ textarea_edit(int op, struct terminal *term_, struct form_state *fs_,
} }
if (term_) term = term_; if (term_) term = term_;
exec_on_terminal(term, ex, "", 1); exec_on_terminal(term, ex, "", TERM_EXEC_FG);
mem_free(ex); mem_free(ex);
textarea_editor = 1; textarea_editor = 1;