aboutsummaryrefslogtreecommitdiff
path: root/rtty.c
diff options
context:
space:
mode:
Diffstat (limited to 'rtty.c')
-rw-r--r--rtty.c51
1 files changed, 37 insertions, 14 deletions
diff --git a/rtty.c b/rtty.c
index 42c9324..88ef214 100644
--- a/rtty.c
+++ b/rtty.c
@@ -27,38 +27,61 @@ main()
tv.tv_usec = 1;
for(;;){
- /* Read from named pipe (out) and print on standard in. */
+ /*
+ * User input is read from standard in and copied the
+ * input pipe. It is saved in bufin for later use.
+ */
+ FD_SET(0, &rfds0);
+ if(select(0+1, &rfds0, NULL, NULL, &tv) > 0){
+ nout = read(0, bufin, MAXBUF);
+ bufin[nout] = 0;
+ dprintf(fdin, "%s", bufin);
+ fflush(stdout);
+ }
+
+ /*
+ * System output is read from the output pipe and copied
+ * to standard out for the user to see.
+ */
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. */
- for(bi = bufin, bo = bufout;;){
- if(*bo == '\n')
+ /*
+ * Bufin and bufout are copied to the temporary
+ * pointers bi and bo. Bo is incremented in order
+ * to skip any potential repetition of the command
+ * given by the user on standard in. (It is assumed
+ * that the typed command fits in bufin, i.e. is
+ * not larger than MAXBUF.)
+ */
+ bi = bufin;
+ bo = bufout;
+ for(;;){
+ if(*bo == '\n'){
+ bo++;
break;
+ }
if(*bo == 13){
bo++;
continue;
}
if(*bi != *bo){
- printf("%s", bufout);
- fflush(stdout);
+ bo = bufout;
break;
}
bi++; bo++;
}
- bufin[0] = 0;
- }
- /* Read from standard in and print on named pipe (in). */
- FD_SET(0, &rfds0);
- if(select(0+1, &rfds0, NULL, NULL, &tv) > 0){
- nout = read(0, bufin, MAXBUF);
- bufin[nout] = 0;
- dprintf(fdin, "%s", bufin);
+ /*
+ * Bo is printed and bufin is cleared, so as not
+ * to perform the skip again, incorrectly.
+ */
+ printf("%s", bo);
fflush(stdout);
+ bufin[0] = 0;
}
}