9 date 93.08.25.22.26.24; author jromine; state Exp;
14 date 93.08.25.17.24.48; author jromine; state Exp;
19 date 92.12.15.00.20.22; author jromine; state Exp;
24 date 90.04.05.15.00.50; author sources; state Exp;
29 date 90.02.06.13.17.31; author sources; state Exp;
34 date 90.02.06.13.17.06; author sources; state Exp;
48 @/* distsbr.c - routines to do additional "dist-style" processing */
50 static char ident[] = "@@(#)$Id: distsbr.c,v 1.5 1993/08/25 17:24:48 jromine Exp jromine $";
56 #include <sys/types.h> /* for off_t */
60 static int hdrfd = NOTOK;
61 static int txtfd = NOTOK;
68 #define BADHDR "please re-edit %s to remove the ``%s'' header!"
69 #define BADTXT "please re-edit %s to consist of headers only!"
70 #define BADMSG "please re-edit %s to include a ``Resent-To:''!"
71 #define BADRFT "please re-edit %s and fix that header!"
73 int distout (drft, msgnam, backup)
86 if (rename (drft, strcpy (backup, m_backup (drft))) == NOTOK)
87 adios (backup, "unable to rename %s to",drft);
88 if ((ifp = fopen (backup, "r")) == NULL)
89 adios (backup, "unable to read");
91 if ((ofp = fopen (drft, "w")) == NULL)
92 adios (drft, "unable to create temporary file");
93 (void) chmod (drft, m_gmprot ());
96 (void) lseek (hdrfd, (off_t)0, 0); /* msgnam not accurate */
97 cpydata (hdrfd, fileno (ofp), msgnam, drft);
101 for (state = FLD, resent = NULL;;)
103 m_getfld (state, name, buffer, sizeof buffer, ifp)) {
107 if (uprf (name, "distribute-"))
108 (void) sprintf (name, "%s%s", "Resent", &name[10]);
109 if (uprf (name, "distribution-"))
110 (void) sprintf (name, "%s%s", "Resent", &name[12]);
111 if (!uprf (name, "resent")) {
112 advise (NULLCP, BADHDR, "draft", name);
116 resent = add (":", add (name, resent));
117 resent = add (buffer, resent);
118 fprintf (ofp, "%s: %s", name, buffer);
119 while (state == FLDPLUS) {
120 state = m_getfld (state, name,
121 buffer, sizeof buffer, ifp);
122 resent = add (buffer, resent);
131 for (dp = buffer; *dp; dp++)
132 if (!isspace (*dp)) {
133 advise (NULLCP, BADTXT, "draft");
142 advise (NULLCP, BADRFT, "draft");
146 (void) unlink (drft);
147 if (rename (backup, drft) == NOTOK)
148 adios (drft, "unable to rename %s to", backup);
152 adios (NULLCP, "getfld() returned %d", state);
161 advise (NULLCP, BADMSG, "draft");
163 (void) unlink (drft);
164 if (rename (backup, drft) == NOTOK)
165 adios (drft, "unable to rename %s to", backup);
170 if (txtfd != NOTOK) {
171 (void) lseek (txtfd, (off_t)0, 0); /* msgnam not accurate */
172 cpydata (txtfd, fileno (ofp), msgnam, drft);
182 static ready_msg (msgnam)
183 register char *msgnam;
194 (void) close (hdrfd), hdrfd = NOTOK;
196 (void) close (txtfd), txtfd = NOTOK;
198 if ((ifp = fopen (msgnam, "r")) == NULL)
199 adios (msgnam, "unable to open message");
201 (void) strcpy (tmpfil, m_tmpfil ("dist"));
202 if ((hdrfd = creat (tmpfil, 0600)) == NOTOK)
203 adios (tmpfil, "unable to create temporary file");
204 (void) close (hdrfd);
205 if ((hdrfd = open (tmpfil, 2)) == NOTOK)
206 adios (tmpfil, "unable to re-open temporary file");
207 if ((out = dup (hdrfd)) == NOTOK
208 || (ofp = fdopen (out, "w")) == NULL)
209 adios (NULLCP, "no file descriptors -- you lose big");
210 (void) unlink (tmpfil);
216 m_getfld (state, name, buffer, sizeof buffer, ifp)) {
220 if (uprf (name, "resent"))
221 fprintf (ofp, "Prev-");
222 fprintf (ofp, "%s: %s", name, buffer);
223 while (state == FLDPLUS) {
224 state = m_getfld (state, name,
225 buffer, sizeof buffer, ifp);
236 (void) strcpy (tmpfil, m_tmpfil ("dist"));
237 if ((txtfd = creat (tmpfil, 0600)) == NOTOK)
238 adios (tmpfil, "unable to create temporary file");
239 (void) close (txtfd);
240 if ((txtfd = open (tmpfil, 2)) == NOTOK)
241 adios (tmpfil, "unable to re-open temporary file");
242 if ((out = dup (txtfd)) == NOTOK
243 || (ofp = fdopen (out, "w")) == NULL)
244 adios (NULLCP, "no file descriptors -- you lose big");
245 (void) unlink (tmpfil);
246 fprintf (ofp, "\n%s", buffer);
247 while (state == BODY) {
248 state = m_getfld (state, name,
249 buffer, sizeof buffer, ifp);
257 adios (NULLCP, "format error in message %s", msgnam);
260 adios (NULLCP, "getfld() returned %d", state);
271 @off_t fixes for BSD44
276 static char ident[] = "@@(#)$Id: distsbr.c,v 1.4 1992/12/15 00:20:22 jromine Exp jromine $";
288 static char ident[] = "@@(#)$Id: distsbr.c,v 1.3 1990/04/05 15:00:50 sources Exp jromine $";
294 (void) lseek (hdrfd, 0L, 0); /* msgnam not accurate */
297 (void) lseek (txtfd, 0L, 0); /* msgnam not accurate */
308 static char ident[] = "@@(#)$Id:$";