X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=madtty%2Fmadtty.c;h=959204d9f0a5d17e52ba5354812cef062ef7ba04;hb=880886ae6dca338d2d57e4b85cf984f4022ec520;hp=13f6026f9b4dceaeb86f80182ab1aac4a58343fe;hpb=95d605c6b6281c9faae8bf6db465fe7920fa12fb;p=apps%2Fmadtty.git diff --git a/madtty/madtty.c b/madtty/madtty.c index 13f6026..959204d 100644 --- a/madtty/madtty.c +++ b/madtty/madtty.c @@ -22,16 +22,12 @@ #include #include #include -#ifdef USE_PTY -#include -#endif #include #include +#include #include "madtty.h" -#include "roteprivate.h" - -#define ROTE_VT_UPDATE_ITERATIONS 5 +#include "madtty_priv.h" RoteTerm *rote_vt_create(int rows, int cols) { @@ -75,7 +71,7 @@ RoteTerm *rote_vt_create(int rows, int cols) /* allocate private data */ rt->pd = (RoteTermPrivate*)calloc(sizeof(RoteTermPrivate), 1); - rt->pd->pty = -1; /* no pty for now */ + rt->pty = -1; /* no pty for now */ /* initial scrolling area is the whole window */ rt->pd->scrolltop = 0; @@ -120,9 +116,10 @@ void rote_vt_draw(RoteTerm *rt, WINDOW *win, int srow, int scol, void (*cur_set_attr)(WINDOW*,unsigned char)) { int i, j; - rote_vt_update(rt); - if (!cur_set_attr) cur_set_attr = default_cur_set_attr; + if (!cur_set_attr) + cur_set_attr = default_cur_set_attr; + for (i = 0; i < rt->rows; i++) { wmove(win, srow + i, scol); for (j = 0; j < rt->cols; j++) { @@ -213,9 +210,6 @@ run_process(const char *path, const char **argv, int *fd_ptr, int *pid_ptr) return 0; } - -#ifdef USE_PTY - pid_t rote_vt_forkpty(RoteTerm *rt, const char *path, const char *argv[]) { struct winsize ws; @@ -224,60 +218,35 @@ pid_t rote_vt_forkpty(RoteTerm *rt, const char *path, const char *argv[]) ws.ws_col = rt->cols; ws.ws_xpixel = ws.ws_ypixel = 0; - if (run_process(path, argv, &rt->pd->pty, &rt->childpid)) { + if (run_process(path, argv, &rt->pty, &rt->childpid)) { return -1; } - ioctl(rt->pd->pty, TIOCSWINSZ, &ws); + ioctl(rt->pty, TIOCSWINSZ, &ws); return rt->childpid; } void rote_vt_forsake_child(RoteTerm *rt) { - if (rt->pd->pty >= 0) - close(rt->pd->pty); - rt->pd->pty = -1; + if (rt->pty >= 0) + close(rt->pty); + rt->pty = -1; rt->childpid = 0; } -#endif - -void rote_vt_update(RoteTerm *rt) -{ - char buf[512]; - int nbread; - int n = ROTE_VT_UPDATE_ITERATIONS; - - while (n--) { /* iterate at most ROVE_VT_UPDATE_ITERATIONS times. - * As Phil Endecott pointed out, if we don't restrict this, - * a program that floods the terminal with output - * could cause this loop to iterate forever, never - * being able to catch up. So we'll rely on the client - * calling rote_vt_update often, as the documentation - * recommends :-) */ - - nbread = rote_vt_read(rt, buf, sizeof(buf)); - if (nbread <= 0) - return; - - /* inject the data into the terminal */ - rote_vt_inject(rt, buf, nbread); - } -} - int rote_vt_read(RoteTerm *rt, char *buf, int buflen) { - if (rt->pd->pty < 0) { + if (rt->pty < 0) { errno = EINVAL; return -1; } - return read(rt->pd->pty, buf, buflen); + return read(rt->pty, buf, buflen); } void rote_vt_write(RoteTerm *rt, const char *data, int len) { - if (rt->pd->pty < 0) { + if (rt->pty < 0) { /* no pty, so just inject the data plain and simple */ rote_vt_inject(rt, data, len); return; @@ -286,7 +255,7 @@ void rote_vt_write(RoteTerm *rt, const char *data, int len) /* write data to pty. Keep calling write() until we have written * everything. */ while (len > 0) { - int byteswritten = write(rt->pd->pty, data, len); + int byteswritten = write(rt->pty, data, len); if (byteswritten < 0) { /* very ugly way to inform the error. Improvements welcome! */ static char errormsg[] = "\n(ROTE: pty write() error)\n"; @@ -324,11 +293,6 @@ void rote_vt_restore_snapshot(RoteTerm *rt, void *snapbuf) } } -int rote_vt_get_pty_fd(RoteTerm *rt) -{ - return rt->pd->pty; -} - static const char *keytable[KEY_MAX+1]; static void keytable_init()