aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-14 11:44:12 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-14 14:24:15 +0200
commit5d9b2527bc17daea3ec9eed74d80a76ec89e0f51 (patch)
tree8cfc67aad5d9ebced11f321adc0cc61fd501867e
parentf29e8f56535efd9aeb01764cfc8decb4b6027be4 (diff)
downloadrtty-5d9b2527bc17daea3ec9eed74d80a76ec89e0f51.tar.gz
rtty.c: Ignore repetition of typed command
-rw-r--r--rtty.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/rtty.c b/rtty.c
index 9118f79..42c9324 100644
--- a/rtty.c
+++ b/rtty.c
@@ -10,7 +10,7 @@
int
main()
{
- char bufin[MAXBUF], bufout[MAXBUF];
+ char bufin[MAXBUF], bufout[MAXBUF], *bi, *bo;
fd_set rfds0, rfds1;
int c, fdin, fdout, flags, i, nin, nout, state;
struct timeval tv;
@@ -31,15 +31,25 @@ main()
FD_SET(fdout, &rfds1);
if(select(fdout+1, &rfds1, NULL, NULL, &tv) > 0){
nout = read(fdout, bufout, MAXBUF);
+ if(!nout) continue;
bufout[nout] = 0;
/* Ignore repetition of typed command. */
- if(strcmp(bufout, bufin) == 0)
- bufin[0] = 0;
- else{
- printf("%s", bufout);
- fflush(stdout);
+ for(bi = bufin, bo = bufout;;){
+ if(*bo == '\n')
+ break;
+ if(*bo == 13){
+ bo++;
+ continue;
+ }
+ if(*bi != *bo){
+ printf("%s", bufout);
+ fflush(stdout);
+ break;
+ }
+ bi++; bo++;
}
+ bufin[0] = 0;
}
/* Read from standard in and print on named pipe (in). */