]>
diplodocus.org Git - nmh/blob - sbr/cpydgst.c
3 * cpydgst.c -- copy from one fd to another in encapsulating mode
4 * -- (do dashstuffing of input data).
12 * We want to perform the substitution
14 * \n(-.*)\n --> \n- \1\n
16 * This is equivalent to the sed substitution
18 * sed -e 's%^-%- -%' < ifile > ofile
20 * but the routine below is faster than the pipe, fork, and exec.
26 #define output(c) if (bp >= dp) {flush(); *bp++ = c;} else *bp++ = c
27 #define flush() if ((j = bp - outbuf) && write (out, outbuf, j) != j) \
28 adios (ofile, "error writing"); \
34 cpydgst (int in
, int out
, char *ifile
, char *ofile
)
36 register int i
, j
, state
;
37 register char *cp
, *ep
;
38 register char *bp
, *dp
;
39 char buffer
[BUFSIZ
], outbuf
[BUFSIZ
];
41 dp
= (bp
= outbuf
) + sizeof outbuf
;
42 for (state
= S1
; (i
= read (in
, buffer
, sizeof buffer
)) > 0;)
43 for (ep
= (cp
= buffer
) + i
; cp
< ep
; cp
++) {
52 state
= S2
; /* fall */
63 adios (ifile
, "error reading");