]> diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/uip/RCS/annosbr.c,v
sbr/mts.c: Delete mmdlm2; use same-valued mmdlm1 instead.
[nmh] / docs / historical / mh-6.8.5 / uip / RCS / annosbr.c,v
1 head 2.6;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 2.6
9 date 93.08.25.17.24.39; author jromine; state Exp;
10 branches;
11 next 2.5;
12
13 2.5
14 date 92.12.15.00.20.22; author jromine; state Exp;
15 branches;
16 next 2.4;
17
18 2.4
19 date 90.04.05.15.35.09; author sources; state Exp;
20 branches;
21 next 2.3;
22
23 2.3
24 date 90.04.05.14.54.53; author sources; state Exp;
25 branches;
26 next 2.2;
27
28 2.2
29 date 90.03.27.12.51.49; author sources; state Exp;
30 branches;
31 next 2.1;
32
33 2.1
34 date 90.02.06.13.15.57; author sources; state Exp;
35 branches;
36 next 2.0;
37
38 2.0
39 date 89.11.17.15.57.50; author sources; state Exp;
40 branches;
41 next 1.2;
42
43 1.2
44 date 88.06.30.08.28.41; author sources; state Exp;
45 branches;
46 next 1.1;
47
48 1.1
49 date 88.06.30.08.27.15; author sources; state Exp;
50 branches;
51 next ;
52
53
54 desc
55 @Original with no mods.
56 @
57
58
59 2.6
60 log
61 @off_t fixes for BSD44
62 @
63 text
64 @/* annosbr.c - prepend annotation to messages */
65 #ifndef lint
66 static char ident[] = "@@(#)$Id: annosbr.c,v 2.5 1992/12/15 00:20:22 jromine Exp jromine $";
67 #endif /* lint */
68
69 #include "../h/mh.h"
70 #include "../zotnet/tws.h"
71 #include <errno.h>
72 #include <stdio.h>
73 #include <sys/types.h>
74 #include <sys/stat.h>
75
76
77 extern int errno;
78 off_t lseek ();
79 static annosbr();
80
81 /* \f */
82
83 annotate (file, comp, text, inplace, datesw)
84 register char *file,
85 *comp,
86 *text;
87 int inplace,
88 datesw;
89 {
90 int i,
91 fd;
92
93 if ((fd = lkopen (file, 2)) == NOTOK) {
94 switch (errno) {
95 case ENOENT:
96 break;
97
98 default:
99 admonish (file, "unable to lock and open");
100 break;
101 }
102 return 1;
103 }
104
105 i = annosbr (fd, file, comp, text, inplace, datesw);
106
107 (void) lkclose (fd, file);
108
109 return i;
110 }
111
112 /* \f */
113
114 static annosbr (src, file, comp, text, inplace, datesw)
115 register char *file,
116 *comp,
117 *text;
118 int src,
119 inplace,
120 datesw;
121 {
122 int mode,
123 fd;
124 register char *cp,
125 *sp;
126 char buffer[BUFSIZ],
127 tmpfil[BUFSIZ];
128 struct stat st;
129 register FILE *tmp;
130
131 mode = fstat (src, &st) != NOTOK ? (st.st_mode & 0777) : m_gmprot ();
132
133 (void) strcpy (tmpfil, m_scratch (file, "annotate"));
134
135 if ((tmp = fopen (tmpfil, "w")) == NULL) {
136 admonish (tmpfil, "unable to create");
137 return 1;
138 }
139 (void) chmod (tmpfil, mode);
140
141 if (datesw)
142 fprintf (tmp, "%s: %s\n", comp, dtimenow ());
143 if (cp = text) {
144 do {
145 while (*cp == ' ' || *cp == '\t')
146 cp++;
147 sp = cp;
148 while (*cp && *cp++ != '\n')
149 continue;
150 if (cp - sp)
151 fprintf (tmp, "%s: %*.*s", comp, cp - sp, cp - sp, sp);
152 } while (*cp);
153 if (cp[-1] != '\n' && cp != text)
154 (void) putc ('\n', tmp);
155 }
156 (void) fflush (tmp);
157 cpydata (src, fileno (tmp), file, tmpfil);
158 (void) fclose (tmp);
159
160 if (inplace) {
161 if ((fd = open (tmpfil, 0)) == NOTOK)
162 adios (tmpfil, "unable to open for re-reading");
163 (void) lseek (src, (off_t)0, 0);
164 cpydata (fd, src, tmpfil, file);
165 (void) close (fd);
166 (void) unlink (tmpfil);
167 }
168 else {
169 (void) strcpy (buffer, m_backup (file));
170 if (rename (file, buffer) == NOTOK) {
171 switch (errno) {
172 case ENOENT: /* unlinked early - no annotations */
173 (void) unlink (tmpfil);
174 break;
175
176 default:
177 admonish (buffer, "unable to rename %s to", file);
178 break;
179 }
180 return 1;
181 }
182 if (rename (tmpfil, file) == NOTOK) {
183 admonish (file, "unable to rename %s to", tmpfil);
184 return 1;
185 }
186 }
187
188 return 0;
189 }
190 @
191
192
193 2.5
194 log
195 @endif sugar
196 @
197 text
198 @d3 1
199 a3 1
200 static char ident[] = "@@(#)$Id: annosbr.c,v 2.4 1990/04/05 15:35:09 sources Exp jromine $";
201 d15 1
202 a15 1
203 long lseek ();
204 d100 1
205 a100 1
206 (void) lseek (src, 0L, 0);
207 @
208
209
210 2.4
211 log
212 @add ID
213 @
214 text
215 @d3 2
216 a4 2
217 static char ident[] = "@@(#)$Id:$";
218 #endif lint
219 @
220
221
222 2.3
223 log
224 @add ID
225 @
226 text
227 @d3 1
228 a3 1
229 static char ident[] = "@@(#)$Id:";
230 @
231
232
233 2.2
234 log
235 @race condition. don't complain if target file is unlinked before
236 annotations finish.
237 @
238 text
239 @d2 3
240 @
241
242
243 2.1
244 log
245 @ANSI Compilance
246 @
247 text
248 @d105 9
249 a113 1
250 admonish (buffer, "unable to rename %s to", file);
251 @
252
253
254 2.0
255 log
256 @changes for SUN40 shared libraries and NNTP under bbc
257 @
258 text
259 @d13 1
260 @
261
262
263 1.2
264 log
265 @Added the code for fanno.
266 Gary <erickson>
267 @
268 text
269 @a11 4
270 #ifdef UCI
271 int fanno = 0;
272 #endif UCI
273
274 d16 1
275 a16 1
276 annotate (file, comp, text, inplace)
277 d20 2
278 a21 1
279 int inplace;
280 d38 1
281 a38 1
282 i = annosbr (fd, file, comp, text, inplace);
283 d47 1
284 a47 1
285 static annosbr (src, file, comp, text, inplace)
286 d52 2
287 a53 1
288 inplace;
289 d74 2
290 a75 4
291 #ifdef UCI
292 if (!fanno)
293 #endif UCI
294 fprintf (tmp, "%s: %s\n", comp, dtimenow ());
295 @
296
297
298 1.1
299 log
300 @Initial revision
301 @
302 text
303 @d12 3
304 d76 3
305 @