From 7aca3e73faeb306b62edfb41e8459cdcdfe619dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Ankarstr=C3=B6m?= Date: Wed, 14 Jul 2021 10:31:43 +0200 Subject: rin.c: Send input line by line --- rin.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'rin.c') diff --git a/rin.c b/rin.c index 8d89bc6..fe32cdb 100644 --- a/rin.c +++ b/rin.c @@ -4,11 +4,13 @@ #include #include +#define MAXBUF 1024 + int main() { fd_set rfds; - int c, in, n, out, startx, y; + int bufin[MAXBUF], bufout[MAXBUF], c, in, nin, nout, out, startx, y; struct timeval tv; WINDOW *w; @@ -23,16 +25,18 @@ main() err(1, "/var/tmp/r.out"); tv.tv_sec = 0; - tv.tv_usec = 1; + tv.tv_usec = 0; FD_ZERO(&rfds); startx = 0; + nin = 0; for(;;){ FD_SET(out, &rfds); if(select(out+1, &rfds, NULL, NULL, &tv) > 0){ - read(out, &c, 1); - printw("%c", c); + nout = read(out, bufout, MAXBUF); + bufout[nout+1] = 0; + printw("%s", bufout); startx = -1; } @@ -42,15 +46,20 @@ main() if(c == 26) /* ^Z */ break; if(c == 21){ /* ^U */ -move: y = getcury(w); +reset: bufin[0] = nin = 0; + y = getcury(w); move(y, startx); continue; } - if(c == '\n') - goto move; - else + + bufin[nin++] = c; + + if(c == '\n'){ + bufin[nin] = 0; + dprintf(in, "%s", bufin); + goto reset; + }else printw("%c", c); - write(in, &c, 1); } } -- cgit v1.2.3