X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/0509728c8a506f287fa3483d8e8ffaf8fb66d41d..0b7286788a95dd854d1826b8493eda431d8e8aac:/uip/forw.c diff --git a/uip/forw.c b/uip/forw.c index 8ee8da9b..e0c5423d 100644 --- a/uip/forw.c +++ b/uip/forw.c @@ -5,11 +5,24 @@ * complete copyright information. */ -#include +#include "h/mh.h" +#include "sbr/folder_read.h" +#include "sbr/context_save.h" +#include "sbr/context_replace.h" +#include "sbr/context_find.h" +#include "sbr/ambigsw.h" +#include "sbr/pidstatus.h" +#include "sbr/path.h" +#include "sbr/print_version.h" +#include "sbr/print_help.h" +#include "sbr/arglist.h" +#include "sbr/error.h" #include -#include -#include -#include "../sbr/m_maildir.h" +#include "h/tws.h" +#include "h/done.h" +#include "h/utils.h" +#include "sbr/m_maildir.h" +#include "forwsbr.h" #define IFORMAT "digest-issue-%s" @@ -40,7 +53,7 @@ X("nodashstuffing", 0, NBITSTUFFSW) \ X("version", 0, VERSIONSW) \ X("help", 0, HELPSW) \ - X("file file", 4, FILESW) /* interface from msh */ \ + X("file file", 4, FILESW) \ X("build", 5, BILDSW) /* interface from mhe */ \ X("from address", 0, FROMSW) \ X("to address", 0, TOSW) \ @@ -101,9 +114,13 @@ static void copy_mime_draft (int); int main (int argc, char **argv) { - int anot = 0, inplace = 1, mime = 0; + bool anot = false; + bool inplace = true; + bool mime = false; int issue = 0, volume = 0, dashstuff = 0; - int nedit = 0, nwhat = 0, i, in; + bool nedit = false; + bool nwhat = false; + int i, in; int out, isdf = 0, msgnum = 0; int outputlinelen = OUTPUTLINELEN; int dat[5]; @@ -111,13 +128,13 @@ main (int argc, char **argv) char *dmsg = NULL, *digest = NULL, *ed = NULL; char *file = NULL, *filter = NULL, *folder = NULL, *fwdmsg = NULL; char *from = NULL, *to = NULL, *cc = NULL, *subject = NULL, *fcc = NULL; - char *form = NULL, buf[BUFSIZ], value[10]; + char *form = NULL, buf[BUFSIZ]; char **argp, **arguments; struct stat st; struct msgs_array msgs = { 0, 0, NULL }; - int buildsw = 0; + bool buildsw = false; - if (nmh_init(argv[0], 1)) { return 1; } + if (nmh_init(argv[0], true, true)) { return 1; } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; @@ -129,7 +146,7 @@ main (int argc, char **argv) ambigsw (cp, switches); done (1); case UNKWNSW: - adios (NULL, "-%s unknown", cp); + die("-%s unknown", cp); case HELPSW: snprintf (buf, sizeof(buf), "%s [+folder] [msgs] [switches]", @@ -141,105 +158,105 @@ main (int argc, char **argv) done (0); case ANNOSW: - anot++; + anot = true; continue; case NANNOSW: - anot = 0; + anot = false; continue; case EDITRSW: if (!(ed = *argp++) || *ed == '-') - adios (NULL, "missing argument to %s", argp[-2]); - nedit = 0; + die("missing argument to %s", argp[-2]); + nedit = false; continue; case NEDITSW: - nedit++; + nedit = true; continue; case WHATSW: if (!(whatnowproc = *argp++) || *whatnowproc == '-') - adios (NULL, "missing argument to %s", argp[-2]); - nwhat = 0; + die("missing argument to %s", argp[-2]); + nwhat = false; continue; case BILDSW: - buildsw++; + buildsw = true; /* FALLTHRU */ case NWHATSW: - nwhat++; + nwhat = true; continue; case FILESW: if (file) - adios (NULL, "only one file at a time!"); + die("only one file at a time!"); if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); file = path (cp, TFILE); continue; case FILTSW: if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); - filter = getcpy (etcpath (cp)); - mime = 0; + die("missing argument to %s", argp[-2]); + filter = mh_xstrdup(etcpath(cp)); + mime = false; continue; case FORMSW: if (!(form = *argp++) || *form == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); continue; case FRMTSW: - filter = getcpy (etcpath (mhlforward)); + filter = mh_xstrdup(etcpath(mhlforward)); continue; case NFRMTSW: filter = NULL; continue; case INPLSW: - inplace++; + inplace = true; continue; case NINPLSW: - inplace = 0; + inplace = false; continue; case MIMESW: - mime++; + mime = true; filter = NULL; continue; case NMIMESW: - mime = 0; + mime = false; continue; case DGSTSW: if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); digest = mh_xstrdup(cp); - mime = 0; + mime = false; continue; case ISSUESW: if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); if ((issue = atoi (cp)) < 1) - adios (NULL, "bad argument %s %s", argp[-2], cp); + die("bad argument %s %s", argp[-2], cp); continue; case VOLUMSW: if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); if ((volume = atoi (cp)) < 1) - adios (NULL, "bad argument %s %s", argp[-2], cp); + die("bad argument %s %s", argp[-2], cp); continue; case DFOLDSW: if (dfolder) - adios (NULL, "only one draft folder at a time!"); + die("only one draft folder at a time!"); if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp, *cp != '@' ? TFOLDER : TSUBCWF); continue; case DMSGSW: if (dmsg) - adios (NULL, "only one draft message at a time!"); + die("only one draft message at a time!"); if (!(dmsg = *argp++) || *dmsg == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); continue; case NDFLDSW: dfolder = NULL; @@ -255,43 +272,42 @@ main (int argc, char **argv) case FROMSW: if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); from = addlist(from, cp); continue; case TOSW: if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); to = addlist(to, cp); continue; case CCSW: if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); cc = addlist(cc, cp); continue; case FCCSW: if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); fcc = addlist(fcc, cp); continue; case SUBJECTSW: if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); subject = mh_xstrdup(cp); continue; case WIDTHSW: if (!(cp = *argp++) || *cp == '-') - adios (NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); if ((outputlinelen = atoi(cp)) < 10) - adios (NULL, "impossible width %d", outputlinelen); + die("impossible width %d", outputlinelen); continue; } } if (*cp == '+' || *cp == '@') { if (folder) - adios (NULL, "only one folder at a time!"); - else - folder = pluspath (cp); + die("only one folder at a time!"); + folder = pluspath (cp); } else { app_msgarg(&msgs, cp); } @@ -302,7 +318,7 @@ main (int argc, char **argv) if (!context_find ("path")) free (path ("./", TFOLDER)); if (file && (msgs.size || folder)) - adios (NULL, "can't mix files and folders/msgs"); + die("can't mix files and folders/msgs"); try_it_again: @@ -342,7 +358,7 @@ try_it_again: /* * Forwarding a file. */ - anot = 0; /* don't want to annotate a file */ + anot = false; /* don't want to annotate a file */ } else { /* * Forwarding a message. @@ -358,11 +374,11 @@ try_it_again: /* read folder and create message structure */ if (!(mp = folder_read (folder, 1))) - adios (NULL, "unable to read folder %s", folder); + die("unable to read folder %s", folder); /* check for empty folder */ if (mp->nummsg == 0) - adios (NULL, "no messages in %s", folder); + die("no messages in %s", folder); /* parse all the message ranges/sequences and set SELECTED */ for (msgnum = 0; msgnum < msgs.size; msgnum++) @@ -383,7 +399,7 @@ try_it_again: } if (! fwdmsg) - adios (NULL, "Unable to find input message"); + die("Unable to find input message"); } if (filter && access (filter, R_OK) == NOTOK) @@ -454,11 +470,9 @@ try_it_again: if (digest) { snprintf (buf, sizeof(buf), IFORMAT, digest); - snprintf (value, sizeof(value), "%d", issue); - context_replace (buf, mh_xstrdup(value)); + context_replace (buf, mh_xstrdup(m_str(issue))); snprintf (buf, sizeof(buf), VFORMAT, digest); - snprintf (value, sizeof(value), "%d", volume); - context_replace (buf, mh_xstrdup(value)); + context_replace (buf, mh_xstrdup(m_str(volume))); } context_replace (pfolder, folder); /* update current folder */ @@ -487,7 +501,7 @@ mhl_draft (int out, char *digest, int volume, int issue, char *file, char *filter, int dashstuff) { pid_t child_id; - int i, msgnum, pd[2]; + int msgnum, pd[2]; char buf1[BUFSIZ]; char buf2[BUFSIZ]; char *program; @@ -498,9 +512,7 @@ mhl_draft (int out, char *digest, int volume, int issue, argsplit_msgarg(&vec, mhlproc, &program); - for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) - sleep (5); - + child_id = fork(); switch (child_id) { case NOTOK: adios ("fork", "unable to"); @@ -545,7 +557,7 @@ mhl_draft (int out, char *digest, int volume, int issue, execvp (program, vec.msgs); fprintf (stderr, "unable to exec "); perror (mhlproc); - _exit (-1); + _exit(1); default: close (pd[1]);