]>
diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/sbr/cpydgst.c
1 /* cpydgst.c - copy from one fd to another in encapsulating mode */
3 static char ident
[] = "@(#)$Id: cpydgst.c,v 1.4 1992/12/15 00:20:22 jromine Exp $";
10 /* All we want to do is to perform the substitution
12 \n(-.*)\n --> \n- \1\n
16 sed -e 's%^-%- -%' < ifile > ofile
18 to do this, but the routine below is faster than the pipe, fork, and
25 #define output(c) if (bp >= dp) {flush(); *bp++ = c;} else *bp++ = c
26 #define flush() if ((j = bp - outbuf) && write (out, outbuf, j) != j) \
27 adios (ofile, "error writing"); \
33 void cpydgst (in
, out
, ifile
, ofile
)
49 dp
= (bp
= outbuf
) + sizeof outbuf
;
50 for (state
= S1
; (i
= read (in
, buffer
, sizeof buffer
)) > 0;)
51 for (ep
= (cp
= buffer
) + i
; cp
< ep
; cp
++) {
60 state
= S2
; /* fall */
71 adios (ifile
, "error reading");