9 date 92.12.15.00.20.22; author jromine; state Exp;
14 date 92.11.04.00.56.39; author jromine; state Exp;
19 date 92.02.05.07.26.30; author jromine; state Exp;
24 date 92.01.31.22.24.21; author jromine; state Exp;
29 date 90.11.05.13.50.14; author mh; state Exp;
34 date 90.11.05.11.38.50; author mh; state Exp;
39 date 90.04.05.14.59.35; author sources; state Exp;
44 date 90.02.06.13.28.19; author sources; state Exp;
49 date 90.01.30.10.42.40; author sources; state Exp;
54 date 90.01.30.10.41.00; author sources; state Exp;
68 @/* rcvdist.c - a rcvmail program to distribute messages */
70 static char ident[] = "@@(#)$Id: rcvdist.c,v 1.9 1992/11/04 00:56:39 jromine Exp jromine $";
74 #include "../h/formatsbr.h"
75 #include "../h/rcvmail.h"
76 #include "../zotnet/tws.h"
84 static struct swit switches[] = {
96 static char backup[BUFSIZ] = "";
97 static char drft[BUFSIZ] = "";
98 static char tmpfil[BUFSIZ] = "";
123 setlocale(LC_ALL, "");
125 invo_name = r1bindex (argv[0], '/');
126 mts_init (invo_name);
127 if ((cp = m_find (invo_name)) != NULL) {
128 ap = brkstring (cp = getcpy (cp), " ", "\n");
129 ap = copyip (ap, arguments);
133 (void) copyip (argv + 1, ap);
138 while (cp = *argp++) {
140 switch (smatch (++cp, switches)) {
142 ambigsw (cp, switches);
149 "%s [switches] [switches for postproc] address ...",
151 help (buf, switches);
155 if (!(form = *argp++) || *form == '-')
156 adios (NULLCP, "missing argument to %s", argp[-2]);
159 addrs = addrs ? add (cp, add (", ", addrs)) : getcpy (cp);
165 adios (NULLCP, "usage: %s [switches] [switches for postproc] address ...",
168 (void) umask (~m_gmprot ());
169 (void) strcpy (tmpfil, m_tmpfil (invo_name));
170 if ((fp = fopen (tmpfil, "w+")) == NULL)
171 adios (tmpfil, "unable to create");
172 (void) cpydata (fileno (stdin), fileno (fp), "message", tmpfil);
173 (void) fseek (fp, 0L, 0);
174 (void) strcpy (drft, m_tmpfil (invo_name));
175 rcvdistout (fp, form, addrs);
178 if (distout (drft, tmpfil, backup) == NOTOK)
181 vec[0] = r1bindex (postproc, '/');
182 vec[vecp++] = "-dist";
186 for (i = 0; (child_id = fork ()) == NOTOK && i < 5; i++)
190 admonish (NULLCP, "unable to fork");/* fall */
192 execvp (postproc, vec);
193 fprintf (stderr, "unable to exec ");
198 done (pidXwait (child_id, postproc));
205 /* very similar to routine in replsbr.c */
209 static int outputlinelen = OUTPUTLINELEN;
211 static struct format *fmt;
213 static int ncomps = 0;
214 static char **compbuffers = 0;
215 static struct comp **used_buf = 0;
219 static char *addrcomps[] = {
236 static rcvdistout (inb, form, addrs)
241 register int char_read = 0,
245 register char *tmpbuf,
251 register struct comp *cptr,
255 if ((out = fopen (drft, "w")) == NULL)
256 adios (drft, "unable to create");
258 cp = new_fs (form ? form : rcvdistcomps, NULLCP, NULLCP);
259 format_len = strlen (cp);
260 ncomps = fmt_compile (cp, &fmt) + 1;
261 if ((nxtbuf = compbuffers = (char **)
262 calloc ((unsigned) ncomps, sizeof (char *)))
264 adios (NULLCP, "unable to allocate component buffers");
265 if ((savecomp = used_buf = (struct comp **)
266 calloc ((unsigned) (ncomps + 1), sizeof (struct comp *)))
267 == (struct comp **) NULL)
268 adios (NULLCP, "unable to allocate component buffer stack");
269 savecomp += ncomps + 1;
272 for (i = ncomps; i--;)
273 if ((*nxtbuf++ = malloc (SBUFSIZ)) == NULL)
274 adios (NULLCP, "unable to allocate component buffer");
275 nxtbuf = compbuffers;
278 for (ap = addrcomps; *ap; ap++) {
279 FINDCOMP (cptr, *ap);
281 cptr -> c_type |= CT_ADDR;
284 FINDCOMP (cptr, "addresses");
286 cptr -> c_text = addrs;
288 for (state = FLD;;) {
289 switch (state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb)) {
292 if (cptr = wantcomp[CHASH (name)])
294 if (uleq (name, cptr -> c_name)) {
295 char_read += msg_count;
296 if (!cptr -> c_text) {
297 cptr -> c_text = tmpbuf;
302 i = strlen (cp = cptr -> c_text) - 1;
304 if (cptr -> c_type & CT_ADDR) {
306 cp = add (",\n\t", cp);
310 cptr -> c_text = add (tmpbuf, cp);
312 while (state == FLDPLUS) {
313 state = m_getfld (state, name, tmpbuf,
315 cptr -> c_text = add (tmpbuf, cptr -> c_text);
316 char_read += msg_count;
320 } while (cptr = cptr -> c_next);
322 while (state == FLDPLUS)
323 state = m_getfld (state, name, tmpbuf, SBUFSIZ, inb);
333 adios (NULLCP, "m_getfld() returned %d", state);
338 i = format_len + char_read + 256;
339 scanl = malloc ((unsigned) i + 2);
340 dat[0] = dat[1] = dat[2] = dat[4] = 0;
341 dat[3] = outputlinelen;
342 (void) fmtscan (fmt, scanl, i, dat);
346 adios (drft, "error writing");
350 for (nxtbuf = compbuffers, i = ncomps; cptr = *savecomp++; nxtbuf++, i--)
351 free (cptr -> c_text);
354 free ((char *) compbuffers);
355 free ((char *) used_buf);
364 (void) unlink (backup);
366 (void) unlink (drft);
368 (void) unlink (tmpfil);
370 exit (status ? RCV_MBX : RCV_MOK);
382 static char ident[] = "@@(#)$Id: rcvdist.c,v 1.8 1992/02/05 07:26:30 jromine Exp jromine $";
389 @put unseen sequence in mh-format
394 static char ident[] = "@@(#)$Id: rcvdist.c,v 1.7 1992/01/31 22:24:21 jromine Exp jromine $";
407 static char ident[] = "@@(#)$Id: rcvdist.c,v 1.6 1990/11/05 13:50:14 mh Exp jromine $";
413 dat[0] = dat[1] = dat[2] = 0;
424 static char ident[] = "@@(#)$Id: rcvdist.c,v 1.5 90/11/05 11:38:50 mh Exp Locker: mh $";
436 @fix freeing free buf problem
441 static char ident[] = "@@(#)$Id: rcvdist.c,v 1.4 90/04/05 14:59:35 sources Exp Locker: mh $";
444 free ((char *) used_buf_fp);
455 static char ident[] = "@@(#)$Id:$";
457 struct comp **used_buf_fp;
460 nxtbuf = compbuffers = (char **) calloc ((unsigned) ncomps,
465 used_buf = (struct comp **) calloc ((unsigned) (ncomps + 1),
466 sizeof (struct comp *));
467 if (used_buf == NULL)
470 used_buf_fp = used_buf;
471 used_buf += ncomps + 1;
479 while (cptr = *savecomp++)
482 for (nxtbuf = compbuffers, i = ncomps; i--; )
497 @freeing incremented pointer - bug fix.
513 free ((char *) used_buf);