X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Fcpydgst.c;h=5e5ef87f2ea306bdad881a8c05843d5fb2ea144b;hp=068fb6e89190282d9a0b1193fece05648c3214f0;hb=c29e62470a481bcd4d54760b0578ca4bc1201681;hpb=1691e80890e5d8ba258c51c214a3e91880e1db2b diff --git a/sbr/cpydgst.c b/sbr/cpydgst.c index 068fb6e..5e5ef87 100644 --- a/sbr/cpydgst.c +++ b/sbr/cpydgst.c @@ -1,65 +1,68 @@ - /* - * cpydgst.c -- copy from one fd to another in encapsulating mode - * -- (do dashstuffing of input data). - * - * $Id$ - */ +** cpydgst.c -- copy from one fd to another in encapsulating mode +** -- (do dashstuffing of input data). +** +** This code is Copyright (c) 2002, by the authors of nmh. See the +** COPYRIGHT file in the root directory of the nmh distribution for +** complete copyright information. +*/ +#include +#include #include /* - * We want to perform the substitution - * - * \n(-.*)\n --> \n- \1\n - * - * This is equivalent to the sed substitution - * - * sed -e 's%^-%- -%' < ifile > ofile - * - * but the routine below is faster than the pipe, fork, and exec. - */ +** We want to perform the substitution +** +** \n(-.*)\n --> \n- \1\n +** +** This is equivalent to the sed substitution +** +** sed -e 's%^-%- -%' < ifile > ofile +** +** 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(EX_IOERR, ofile, "error writing"); \ + else \ + bp = outbuf void -cpydgst (int in, int out, char *ifile, char *ofile) +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]; + int i, j, state; + char *cp, *ep; + 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(EX_IOERR, ifile, "error reading"); + flush(); }