X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Fcpydgst.c;h=7195cd152d90173c630fc6b352a933ad1dbbf988;hp=12829f1312b83f405b87adfceaca6ce792bff8b7;hb=a485ed478abbd599d8c9aab48934e7a26733ecb1;hpb=f480c03187724e54e5391ee61b810827da319a6c diff --git a/sbr/cpydgst.c b/sbr/cpydgst.c index 12829f1..7195cd1 100644 --- a/sbr/cpydgst.c +++ b/sbr/cpydgst.c @@ -1,4 +1,3 @@ - /* * cpydgst.c -- copy from one fd to another in encapsulating mode * -- (do dashstuffing of input data). @@ -13,7 +12,7 @@ /* * We want to perform the substitution * - * \n(-.*)\n --> \n- \1\n + * \n(-.*)\n --> \n- \1\n * * This is equivalent to the sed substitution * @@ -22,46 +21,46 @@ * but the routine below is faster than the pipe, fork, and exec. */ -#define S1 0 -#define S2 1 +#define S1 0 +#define S2 1 -#define output(c) if (bp >= dp) {flush(); *bp++ = c;} else *bp++ = c -#define flush() if ((j = bp - outbuf) && write (out, outbuf, j) != j) \ - adios (ofile, "error writing"); \ - else \ - bp = outbuf +#define output(c) if (bp >= dp) {flush(); *bp++ = c;} else *bp++ = c +#define flush() if ((j = bp - outbuf) && write (out, outbuf, j) != j) \ + adios (ofile, "error writing"); \ + else \ + bp = outbuf void cpydgst (int in, int out, char *ifile, char *ofile) { - register int i, j, state; - register char *cp, *ep; - register char *bp, *dp; - char buffer[BUFSIZ], outbuf[BUFSIZ]; + register int i, j, state; + register char *cp, *ep; + register char *bp, *dp; + char buffer[BUFSIZ], outbuf[BUFSIZ]; - dp = (bp = outbuf) + sizeof outbuf; - for (state = S1; (i = read (in, buffer, sizeof buffer)) > 0;) - for (ep = (cp = buffer) + i; cp < ep; cp++) { - if (*cp == '\0') - continue; - switch (state) { - case S1: - if (*cp == '-') { - output ('-'); - output (' '); - } - state = S2; /* fall */ + dp = (bp = outbuf) + sizeof outbuf; + for (state = S1; (i = read (in, buffer, sizeof buffer)) > 0;) + for (ep = (cp = buffer) + i; cp < ep; cp++) { + if (*cp == '\0') + continue; + switch (state) { + case S1: + if (*cp == '-') { + output ('-'); + output (' '); + } + state = S2; /* fall */ - case S2: - output (*cp); - if (*cp == '\n') - state = S1; - break; - } - } + case S2: + output (*cp); + if (*cp == '\n') + state = S1; + break; + } + } - if (i == -1) - adios (ifile, "error reading"); - flush(); + if (i == -1) + adios (ifile, "error reading"); + flush(); }