X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/8bb0f8000b86df9270f2410de3fb6f41fa63e88b..a514b8a78c447c8abc69386bee9f2c463b1c9362:/uip/rcvdist.c?ds=inline diff --git a/uip/rcvdist.c b/uip/rcvdist.c index 0052b07b..85baf33d 100644 --- a/uip/rcvdist.c +++ b/uip/rcvdist.c @@ -14,15 +14,18 @@ #include #include -static struct swit switches[] = { -#define FORMSW 0 - { "form formfile", 4 }, -#define VERSIONSW 1 - { "version", 0 }, -#define HELPSW 2 - { "help", 0 }, - { NULL, 0 } -}; +#define RCVDIST_SWITCHES \ + X("form formfile", 4, FORMSW) \ + X("version", 0, VERSIONSW) \ + X("help", 0, HELPSW) \ + +#define X(sw, minchars, id) id, +DEFINE_SWITCH_ENUM(RCVDIST); +#undef X + +#define X(sw, minchars, id) { sw, minchars, id }, +DEFINE_SWITCH_ARRAY(RCVDIST, switches); +#undef X static char backup[BUFSIZ] = ""; static char drft[BUFSIZ] = ""; @@ -39,21 +42,22 @@ int main (int argc, char **argv) { pid_t child_id; - int i, vecp = 1; - char *addrs = NULL, *cp, *form = NULL, buf[BUFSIZ]; - char **argp, **arguments, *vec[MAXARGS]; + int i, vecp; + char *addrs = NULL, *cp, *form = NULL, buf[BUFSIZ], *program; + char **argp, **arguments, **vec; FILE *fp; char *tfile = NULL; + if (nmh_init(argv[0], 1)) { return 1; } + done=unlink_done; -#ifdef LOCALE - setlocale(LC_ALL, ""); -#endif - invo_name = r1bindex (argv[0], '/'); + /* + * Configure this now, since any unknown switches to rcvdist get + * sent to postproc + */ - /* read user profile/context */ - context_read(); + vec = argsplit(postproc, &program, &vecp); mts_init (invo_name); arguments = getarguments (invo_name, argc, argv, 1); @@ -94,15 +98,17 @@ main (int argc, char **argv) umask (~m_gmprot ()); - tfile = m_mktemp2(NULL, invo_name, NULL, &fp); - if (tfile == NULL) adios("rcvdist", "unable to create temporary file"); + if ((tfile = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) { + adios(NULL, "unable to create temporary file in %s", get_temp_dir()); + } strncpy (tmpfil, tfile, sizeof(tmpfil)); cpydata (fileno (stdin), fileno (fp), "message", tmpfil); fseek (fp, 0L, SEEK_SET); - tfile = m_mktemp2(NULL, invo_name, NULL, NULL); - if (tfile == NULL) adios("forw", "unable to create temporary file"); + if ((tfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) { + adios(NULL, "unable to create temporary file in %s", get_temp_dir()); + } strncpy (drft, tfile, sizeof(tmpfil)); rcvdistout (fp, form, addrs); @@ -111,7 +117,6 @@ main (int argc, char **argv) if (distout (drft, tmpfil, backup) == NOTOK) done (1); - vec[0] = r1bindex (postproc, '/'); vec[vecp++] = "-dist"; vec[vecp++] = drft; if ((cp = context_find ("mhlproc"))) { @@ -126,7 +131,7 @@ main (int argc, char **argv) case NOTOK: admonish (NULL, "unable to fork");/* fall */ case OK: - execvp (postproc, vec); + execvp (program, vec); fprintf (stderr, "unable to exec "); perror (postproc); _exit (1); @@ -232,7 +237,7 @@ finished: ; scanl = mh_xmalloc ((size_t) i + 2); dat[0] = dat[1] = dat[2] = dat[4] = 0; dat[3] = outputlinelen; - fmt_scan (fmt, scanl, i + 1, i, dat); + fmt_scan (fmt, scanl, i + 1, i, dat, NULL); fputs (scanl, out); if (ferror (out)) @@ -248,11 +253,11 @@ static void unlink_done (int status) { if (backup[0]) - unlink (backup); + (void) m_unlink (backup); if (drft[0]) - unlink (drft); + (void) m_unlink (drft); if (tmpfil[0]) - unlink (tmpfil); + (void) m_unlink (tmpfil); exit (status ? RCV_MBX : RCV_MOK); }