version 1.36, 2009/11/04 22:02:38 |
version 1.37, 2009/11/04 22:43:11 |
|
|
/* Global window list. */ |
/* Global window list. */ |
struct windows windows; |
struct windows windows; |
|
|
|
void window_pane_read_callback(struct bufferevent *, void *); |
|
void window_pane_error_callback(struct bufferevent *, short, void *); |
|
|
RB_GENERATE(winlinks, winlink, entry, winlink_cmp); |
RB_GENERATE(winlinks, winlink, entry, winlink_cmp); |
|
|
int |
int |
|
|
wp->cwd = NULL; |
wp->cwd = NULL; |
|
|
wp->fd = -1; |
wp->fd = -1; |
wp->in = buffer_create(BUFSIZ); |
wp->event = NULL; |
wp->out = buffer_create(BUFSIZ); |
|
|
|
wp->mode = NULL; |
wp->mode = NULL; |
|
|
|
|
void |
void |
window_pane_destroy(struct window_pane *wp) |
window_pane_destroy(struct window_pane *wp) |
{ |
{ |
if (wp->fd != -1) |
if (wp->fd != -1) { |
close(wp->fd); |
close(wp->fd); |
|
bufferevent_free(wp->event); |
|
} |
|
|
input_free(wp); |
input_free(wp); |
|
|
|
|
bufferevent_free(wp->pipe_event); |
bufferevent_free(wp->pipe_event); |
} |
} |
|
|
buffer_destroy(wp->in); |
|
buffer_destroy(wp->out); |
|
event_del(&wp->event); |
|
|
|
if (wp->cwd != NULL) |
if (wp->cwd != NULL) |
xfree(wp->cwd); |
xfree(wp->cwd); |
if (wp->shell != NULL) |
if (wp->shell != NULL) |
|
|
struct termios tio2; |
struct termios tio2; |
u_int i; |
u_int i; |
|
|
if (wp->fd != -1) |
if (wp->fd != -1) { |
close(wp->fd); |
close(wp->fd); |
|
bufferevent_free(wp->event); |
|
} |
if (cmd != NULL) { |
if (cmd != NULL) { |
if (wp->cmd != NULL) |
if (wp->cmd != NULL) |
xfree(wp->cmd); |
xfree(wp->cmd); |
|
|
fatal("fcntl failed"); |
fatal("fcntl failed"); |
if (fcntl(wp->fd, F_SETFD, FD_CLOEXEC) == -1) |
if (fcntl(wp->fd, F_SETFD, FD_CLOEXEC) == -1) |
fatal("fcntl failed"); |
fatal("fcntl failed"); |
|
wp->event = bufferevent_new(wp->fd, |
|
window_pane_read_callback, NULL, window_pane_error_callback, wp); |
|
bufferevent_enable(wp->event, EV_READ|EV_WRITE); |
|
|
return (0); |
return (0); |
} |
} |
|
|
void |
void |
|
window_pane_read_callback(unused struct bufferevent *bufev, void *data) |
|
{ |
|
struct window_pane *wp = data; |
|
|
|
window_pane_parse(wp); |
|
} |
|
|
|
void |
|
window_pane_error_callback( |
|
unused struct bufferevent *bufev, unused short what, void *data) |
|
{ |
|
struct window_pane *wp = data; |
|
|
|
close(wp->fd); |
|
bufferevent_free(wp->event); |
|
wp->fd = -1; |
|
} |
|
|
|
void |
window_pane_resize(struct window_pane *wp, u_int sx, u_int sy) |
window_pane_resize(struct window_pane *wp, u_int sx, u_int sy) |
{ |
{ |
struct winsize ws; |
struct winsize ws; |
|
|
void |
void |
window_pane_parse(struct window_pane *wp) |
window_pane_parse(struct window_pane *wp) |
{ |
{ |
|
char *data; |
size_t new_size; |
size_t new_size; |
|
|
if (wp->mode != NULL) |
if (wp->mode != NULL) |
return; |
return; |
|
|
new_size = BUFFER_USED(wp->in) - wp->pipe_off; |
new_size = EVBUFFER_LENGTH(wp->event->input) - wp->pipe_off; |
if (wp->pipe_fd != -1 && new_size > 0) |
if (wp->pipe_fd != -1 && new_size > 0) { |
bufferevent_write(wp->pipe_event, BUFFER_OUT(wp->in), new_size); |
data = EVBUFFER_DATA(wp->event->input); |
|
bufferevent_write(wp->pipe_event, data, new_size); |
|
} |
|
|
input_parse(wp); |
input_parse(wp); |
|
|
wp->pipe_off = BUFFER_USED(wp->in); |
wp->pipe_off = EVBUFFER_LENGTH(wp->event->input); |
} |
} |
|
|
void |
void |