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

Explode exec_on_terminal() to new exec_on_master_terminal() and

exec_on_slave_terminal().
This commit is contained in:
Laurent MONIN 2006-01-07 01:47:36 +01:00 committed by Laurent MONIN
parent 450e44a598
commit a2b9d8bb78

View File

@ -197,91 +197,106 @@ unblock_terminal(struct terminal *term)
textarea_edit(1, NULL, NULL, NULL, NULL); textarea_edit(1, NULL, NULL, NULL, NULL);
} }
static void
exec_on_master_terminal(struct terminal *term,
unsigned char *path, int plen,
unsigned char *delete, int dlen,
int fg)
{
int blockh;
unsigned char *param;
int param_size;
if (is_blocked() && fg) {
unlink(delete);
return;
}
param_size = plen + dlen + 2 /* 2 null char */ + 1 /* fg */;
param = mem_alloc(param_size);
if (!param) return;
param[0] = fg;
memcpy(param + 1, path, plen + 1);
memcpy(param + 1 + plen + 1, delete, dlen + 1);
if (fg == 1) block_itrm(term->fdin);
blockh = start_thread((void (*)(void *, int)) exec_thread,
param, param_size);
if (blockh == -1) {
if (fg == 1) unblock_itrm(term->fdin);
mem_free(param);
return;
}
mem_free(param);
if (fg == 1) {
term->blocked = blockh;
set_handlers(blockh,
(select_handler_T) unblock_terminal,
NULL,
(select_handler_T) unblock_terminal,
term);
set_handlers(term->fdin, NULL, NULL,
(select_handler_T) destroy_terminal,
term);
/* block_itrm(term->fdin); */
} else {
set_handlers(blockh, close_handle, NULL,
close_handle, (void *) (long) blockh);
}
}
static void
exec_on_slave_terminal( struct terminal *term,
unsigned char *path, int plen,
unsigned char *delete, int dlen,
int fg)
{
int data_size = plen + dlen + 1 /* 0 */ + 1 /* fg */ + 2 /* 2 null char */;
unsigned char *data = mem_alloc(data_size);
if (data) {
data[0] = 0;
data[1] = fg;
memcpy(data + 2, path, plen + 1);
memcpy(data + 2 + plen + 1, delete, dlen + 1);
hard_write(term->fdout, data, data_size);
mem_free(data);
}
}
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, int fg)
{ {
int plen, dlen;
if (path) { if (path) {
if (!*path) return; if (!*path) return;
} else { } else {
path = ""; path = "";
} }
plen = strlen(path);
dlen = strlen(delete);
#ifdef NO_FG_EXEC #ifdef NO_FG_EXEC
fg = 0; fg = 0;
#endif #endif
if (term->master) { if (term->master) {
if (!*path) dispatch_special(delete); if (!*path) {
else { dispatch_special(delete);
int blockh; return;
unsigned char *param;
int param_size;
if (is_blocked() && fg) {
unlink(delete);
return;
}
param_size = plen + dlen + 2 /* 2 null char */ + 1 /* fg */;
param = mem_alloc(param_size);
if (!param) return;
param[0] = fg;
memcpy(param + 1, path, plen + 1);
memcpy(param + 1 + plen + 1, delete, dlen + 1);
if (fg == 1) block_itrm(term->fdin);
blockh = start_thread((void (*)(void *, int)) exec_thread,
param, param_size);
if (blockh == -1) {
if (fg == 1) unblock_itrm(term->fdin);
mem_free(param);
return;
}
mem_free(param);
if (fg == 1) {
term->blocked = blockh;
set_handlers(blockh,
(select_handler_T) unblock_terminal,
NULL,
(select_handler_T) unblock_terminal,
term);
set_handlers(term->fdin, NULL, NULL,
(select_handler_T) destroy_terminal,
term);
/* block_itrm(term->fdin); */
} else {
set_handlers(blockh, close_handle, NULL,
close_handle, (void *) (long) blockh);
}
} }
exec_on_master_terminal(term,
path, strlen(path),
delete, strlen(delete),
fg);
} else { } else {
int data_size = plen + dlen + 1 /* 0 */ + 1 /* fg */ + 2 /* 2 null char */; exec_on_slave_terminal( term,
unsigned char *data = mem_alloc(data_size); path, strlen(path),
delete, strlen(delete),
if (data) { fg);
data[0] = 0;
data[1] = fg;
memcpy(data + 2, path, plen + 1);
memcpy(data + 2 + plen + 1, delete, dlen + 1);
hard_write(term->fdout, data, data_size);
mem_free(data);
}
#if 0
char x = 0;
hard_write(term->fdout, &x, 1);
x = fg;
hard_write(term->fdout, &x, 1);
hard_write(term->fdout, path, strlen(path) + 1);
hard_write(term->fdout, delete, strlen(delete) + 1);
#endif
} }
} }