diff options
author | John Ankarström <john@ankarstrom.se> | 2021-07-14 10:31:43 +0200 |
---|---|---|
committer | John Ankarström <john@ankarstrom.se> | 2021-07-14 10:31:43 +0200 |
commit | 7aca3e73faeb306b62edfb41e8459cdcdfe619dd (patch) | |
tree | c775a8d401c6a2831e7ed0f4af31ac6ebdd813b5 | |
parent | 99334c581349f27551f30082de9b0b8a7b9274af (diff) | |
download | rtty-7aca3e73faeb306b62edfb41e8459cdcdfe619dd.tar.gz |
rin.c: Send input line by line
-rw-r--r-- | rin.c | 27 |
1 files changed, 18 insertions, 9 deletions
@@ -4,11 +4,13 @@ #include <unistd.h> #include <sys/select.h> +#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); } } |