3 * cpydgst.c -- copy from one fd to another in encapsulating mode
4 * -- (do dashstuffing of input data).
8 * This code is Copyright (c) 2002, by the authors of nmh. See the
9 * COPYRIGHT file in the root directory of the nmh distribution for
10 * complete copyright information.
16 * We want to perform the substitution
18 * \n(-.*)\n --> \n- \1\n
20 * This is equivalent to the sed substitution
22 * sed -e 's%^-%- -%' < ifile > ofile
24 * but the routine below is faster than the pipe, fork, and exec.
30 #define output(c) if (bp >= dp) {flush(); *bp++ = c;} else *bp++ = c
31 #define flush() if ((j = bp - outbuf) && write (out, outbuf, j) != j) \
32 adios (ofile, "error writing"); \
38 cpydgst (int in, int out, char *ifile, char *ofile)
40 register int i, j, state;
41 register char *cp, *ep;
42 register char *bp, *dp;
43 char buffer[BUFSIZ], outbuf[BUFSIZ];
45 dp = (bp = outbuf) + sizeof outbuf;
46 for (state = S1; (i = read (in, buffer, sizeof buffer)) > 0;)
47 for (ep = (cp = buffer) + i; cp < ep; cp++) {
56 state = S2; /* fall */
67 adios (ifile, "error reading");