]>
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).
6 * This code is Copyright (c) 2002, by the authors of nmh. See the
7 * COPYRIGHT file in the root directory of the nmh distribution for
8 * complete copyright information.
14 * We want to perform the substitution
16 * \n(-.*)\n --> \n- \1\n
18 * This is equivalent to the sed substitution
20 * sed -e 's%^-%- -%' < ifile > ofile
22 * but the routine below is faster than the pipe, fork, and exec.
28 #define output(c) if (bp >= dp) {flush(); *bp++ = c;} else *bp++ = c
29 #define flush() if ((j = bp - outbuf) && write (out, outbuf, j) != j) \
30 adios (ofile, "error writing"); \
36 cpydgst (int in
, int out
, char *ifile
, char *ofile
)
41 char buffer
[BUFSIZ
], outbuf
[BUFSIZ
];
43 dp
= (bp
= outbuf
) + sizeof outbuf
;
44 for (state
= S1
; (i
= read (in
, buffer
, sizeof buffer
)) > 0;)
45 for (ep
= (cp
= buffer
) + i
; cp
< ep
; cp
++) {
54 state
= S2
; /* fall */
65 adios (ifile
, "error reading");