3 * distsbr.c -- routines to do additional "dist-style" processing
11 static int hdrfd = NOTOK;
12 static int txtfd = NOTOK;
14 #define BADHDR "please re-edit %s to remove the ``%s'' header!"
15 #define BADTXT "please re-edit %s to consist of headers only!"
16 #define BADMSG "please re-edit %s to include a ``Resent-To:''!"
17 #define BADRFT "please re-edit %s and fix that header!"
22 static void ready_msg(char *);
25 distout (char *drft, char *msgnam, char *backup)
28 register char *dp, *resent;
29 char name[NAMESZ], buffer[BUFSIZ];
30 register FILE *ifp, *ofp;
32 if (rename (drft, strcpy (backup, m_backup (drft))) == NOTOK)
33 adios (backup, "unable to rename %s to",drft);
34 if ((ifp = fopen (backup, "r")) == NULL)
35 adios (backup, "unable to read");
37 if ((ofp = fopen (drft, "w")) == NULL)
38 adios (drft, "unable to create temporary file");
39 chmod (drft, m_gmprot ());
42 lseek (hdrfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */
43 cpydata (hdrfd, fileno (ofp), msgnam, drft);
45 for (state = FLD, resent = NULL;;)
47 m_getfld (state, name, buffer, sizeof buffer, ifp)) {
51 if (uprf (name, "distribute-"))
52 snprintf (name, sizeof(name), "%s%s", "Resent", &name[10]);
53 if (uprf (name, "distribution-"))
54 snprintf (name, sizeof(name), "%s%s", "Resent", &name[12]);
55 if (!uprf (name, "resent")) {
56 advise (NULL, BADHDR, "draft", name);
60 resent = add (":", add (name, resent));
61 resent = add (buffer, resent);
62 fprintf (ofp, "%s: %s", name, buffer);
63 while (state == FLDPLUS) {
64 state = m_getfld (state, name,
65 buffer, sizeof buffer, ifp);
66 resent = add (buffer, resent);
75 for (dp = buffer; *dp; dp++)
77 advise (NULL, BADTXT, "draft");
86 advise (NULL, BADRFT, "draft");
91 if (rename (backup, drft) == NOTOK)
92 adios (drft, "unable to rename %s to", backup);
96 adios (NULL, "getfld() returned %d", state);
103 advise (NULL, BADMSG, "draft");
106 if (rename (backup, drft) == NOTOK)
107 adios (drft, "unable to rename %s to", backup);
112 if (txtfd != NOTOK) {
113 lseek (txtfd, (off_t) 0, SEEK_SET); /* msgnam not accurate */
114 cpydata (txtfd, fileno (ofp), msgnam, drft);
124 ready_msg (char *msgnam)
127 char name[NAMESZ], buffer[BUFSIZ], tmpfil[BUFSIZ];
128 register FILE *ifp, *ofp;
131 close (hdrfd), hdrfd = NOTOK;
133 close (txtfd), txtfd = NOTOK;
135 if ((ifp = fopen (msgnam, "r")) == NULL)
136 adios (msgnam, "unable to open message");
138 strncpy (tmpfil, m_tmpfil ("dist"), sizeof(tmpfil));
139 if ((hdrfd = open (tmpfil, O_RDWR | O_CREAT | O_TRUNC, 0600)) == NOTOK)
140 adios (tmpfil, "unable to re-open temporary file");
141 if ((out = dup (hdrfd)) == NOTOK
142 || (ofp = fdopen (out, "w")) == NULL)
143 adios (NULL, "no file descriptors -- you lose big");
148 m_getfld (state, name, buffer, sizeof buffer, ifp)) {
152 if (uprf (name, "resent"))
153 fprintf (ofp, "Prev-");
154 fprintf (ofp, "%s: %s", name, buffer);
155 while (state == FLDPLUS) {
156 state = m_getfld (state, name,
157 buffer, sizeof buffer, ifp);
168 strncpy (tmpfil, m_tmpfil ("dist"), sizeof(tmpfil));
169 if ((txtfd = open (tmpfil, O_RDWR | O_CREAT | O_TRUNC, 0600)) == NOTOK)
170 adios (tmpfil, "unable to open temporary file");
171 if ((out = dup (txtfd)) == NOTOK
172 || (ofp = fdopen (out, "w")) == NULL)
173 adios (NULL, "no file descriptors -- you lose big");
175 fprintf (ofp, "\n%s", buffer);
176 while (state == BODY) {
177 state = m_getfld (state, name,
178 buffer, sizeof buffer, ifp);
186 adios (NULL, "format error in message %s", msgnam);
189 adios (NULL, "getfld() returned %d", state);