]> diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/sbr/RCS/cpydgst.c,v
sbr/mts.c: Delete mmdlm2; use same-valued mmdlm1 instead.
[nmh] / docs / historical / mh-6.8.5 / sbr / RCS / cpydgst.c,v
1 head 1.4;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.4
9 date 92.12.15.00.20.22; author jromine; state Exp;
10 branches;
11 next 1.3;
12
13 1.3
14 date 92.01.31.21.48.21; author jromine; state Exp;
15 branches;
16 next 1.2;
17
18 1.2
19 date 92.01.31.21.47.47; author jromine; state Exp;
20 branches;
21 next 1.1;
22
23 1.1
24 date 92.01.31.21.47.44; author jromine; state Exp;
25 branches;
26 next ;
27
28
29 desc
30 @@
31
32
33 1.4
34 log
35 @endif sugar
36 @
37 text
38 @/* cpydgst.c - copy from one fd to another in encapsulating mode */
39 #ifndef lint
40 static char ident[] = "@@(#)$Id: cpydgst.c,v 1.3 1992/01/31 21:48:21 jromine Exp jromine $";
41 #endif /* lint */
42
43 #include "../h/mh.h"
44 #include <stdio.h>
45
46
47 /* All we want to do is to perform the substitution
48
49 \n(-.*)\n --> \n- \1\n
50
51 we could use
52
53 sed -e 's%^-%- -%' < ifile > ofile
54
55 to do this, but the routine below is faster than the pipe, fork, and
56 exec.
57 */
58
59 #define S1 0
60 #define S2 1
61
62 #define output(c) if (bp >= dp) {flush(); *bp++ = c;} else *bp++ = c
63 #define flush() if ((j = bp - outbuf) && write (out, outbuf, j) != j) \
64 adios (ofile, "error writing"); \
65 else \
66 bp = outbuf
67
68 /* \f */
69
70 void cpydgst (in, out, ifile, ofile)
71 register int in,
72 out;
73 register char *ifile,
74 *ofile;
75 {
76 register int i,
77 state;
78 register char *cp,
79 *ep;
80 char buffer[BUFSIZ];
81 register int j;
82 register char *bp,
83 *dp;
84 char outbuf[BUFSIZ];
85
86 dp = (bp = outbuf) + sizeof outbuf;
87 for (state = S1; (i = read (in, buffer, sizeof buffer)) > 0;)
88 for (ep = (cp = buffer) + i; cp < ep; cp++) {
89 if (*cp == '\0')
90 continue;
91 switch (state) {
92 case S1:
93 if (*cp == '-') {
94 output ('-');
95 output (' ');
96 }
97 state = S2; /* fall */
98
99 case S2:
100 output (*cp);
101 if (*cp == '\n')
102 state = S1;
103 break;
104 }
105 }
106
107 if (i == NOTOK)
108 adios (ifile, "error reading");
109 flush ();
110 }
111 @
112
113
114 1.3
115 log
116 @add id
117 @
118 text
119 @d3 2
120 a4 2
121 static char ident[] = "@@(#)$Id: m_getfld.c,v 1.9 1992/01/24 18:03:41 jromine Exp $";
122 #endif lint
123 @
124
125
126 1.2
127 log
128 @kerberos
129 @
130 text
131 @d2 3
132 @
133
134
135 1.1
136 log
137 @Initial revision
138 @
139 text
140 @d49 1
141 a49 1
142 if (*cp == NULL)
143 @