From: Ken Hornstein Date: Thu, 29 Nov 2012 20:28:12 +0000 (-0500) Subject: Merge branch 'master' of git.sv.nongnu.org:/srv/git/nmh X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=8353532c2c5bb170bf27a0354d83b842e0384c43;hp=d6c134e8c1182f9002ca7d8aa4059cbf7f1c6742;p=mmh Merge branch 'master' of git.sv.nongnu.org:/srv/git/nmh --- diff --git a/sbr/utils.c b/sbr/utils.c index cce7378..a279a32 100644 --- a/sbr/utils.c +++ b/sbr/utils.c @@ -213,14 +213,16 @@ num_digits (int n) /* * Append a message arg to an array of them, resizing it if necessary. - * The function is written to suit the arg parsing code it was extracted - * from, and will probably be changed when the other code is cleaned up. + * Really a simple vector-of-(char *) maintenance routine. */ void app_msgarg(struct msgs_array *msgs, char *cp) { - if(msgs->size >= msgs->max) - msgs->msgs = mh_xrealloc(msgs->msgs, (msgs->max+=MAXMSGS)*sizeof(*msgs->msgs)); + if(msgs->size >= msgs->max) { + msgs->max += MAXMSGS; + msgs->msgs = mh_xrealloc(msgs->msgs, + msgs->max * sizeof(*msgs->msgs)); + } msgs->msgs[msgs->size++] = cp; } diff --git a/uip/burst.c b/uip/burst.c index 6316e13..93fd5e0 100644 --- a/uip/burst.c +++ b/uip/burst.c @@ -8,6 +8,7 @@ */ #include +#include static struct swit switches[] = { #define INPLSW 0 @@ -56,9 +57,10 @@ int main (int argc, char **argv) { int inplace = 0, quietsw = 0, verbosw = 0; - int msgp = 0, hi, msgnum, numburst; + int hi, msgnum, numburst; char *cp, *maildir, *folder = NULL, buf[BUFSIZ]; - char **argp, **arguments, *msgs[MAXARGS]; + char **argp, **arguments; + struct msgs_array msgs = { 0, 0, NULL }; struct smsg *smsgs; struct msgs *mp; @@ -119,14 +121,14 @@ main (int argc, char **argv) else folder = pluspath (cp); } else { - msgs[msgp++] = cp; + app_msgarg(&msgs, cp); } } if (!context_find ("path")) free (path ("./", TFOLDER)); - if (!msgp) - msgs[msgp++] = "cur"; + if (!msgs.size) + app_msgarg(&msgs, "cur"); if (!folder) folder = getfolder (1); maildir = m_maildir (folder); @@ -143,8 +145,8 @@ main (int argc, char **argv) adios (NULL, "no messages in %s", folder); /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgp; msgnum++) - if (!m_convert (mp, msgs[msgnum])) + for (msgnum = 0; msgnum < msgs.size; msgnum++) + if (!m_convert (mp, msgs.msgs[msgnum])) done (1); seq_setprev (mp); /* set the previous-sequence */ diff --git a/uip/forw.c b/uip/forw.c index a04ebd6..2d6709e 100644 --- a/uip/forw.c +++ b/uip/forw.c @@ -127,7 +127,7 @@ static void copy_mime_draft (int); int main (int argc, char **argv) { - int msgp = 0, anot = 0, inplace = 1, mime = 0; + int anot = 0, inplace = 1, mime = 0; int issue = 0, volume = 0, dashstuff = 0; int nedit = 0, nwhat = 0, i, in; int out, isdf = 0, msgnum = 0; @@ -138,8 +138,9 @@ main (int argc, char **argv) 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 **argp, **arguments, *msgs[MAXARGS]; + char **argp, **arguments; struct stat st; + struct msgs_array msgs = { 0, 0, NULL }; int buildsw = 0; @@ -324,7 +325,7 @@ main (int argc, char **argv) else folder = pluspath (cp); } else { - msgs[msgp++] = cp; + app_msgarg(&msgs, cp); } } @@ -332,7 +333,7 @@ main (int argc, char **argv) if (!context_find ("path")) free (path ("./", TFOLDER)); - if (file && (msgp || folder)) + if (file && (msgs.size || folder)) adios (NULL, "can't mix files and folders/msgs"); try_it_again: @@ -377,8 +378,8 @@ try_it_again: /* * Forwarding a message. */ - if (!msgp) - msgs[msgp++] = "cur"; + if (!msgs.size) + app_msgarg(&msgs, "cur"); if (!folder) folder = getfolder (1); maildir = m_maildir (folder); @@ -395,9 +396,10 @@ try_it_again: adios (NULL, "no messages in %s", folder); /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgp; msgnum++) - if (!m_convert (mp, msgs[msgnum])) + for (msgnum = 0; msgnum < msgs.size; msgnum++) + if (!m_convert (mp, msgs.msgs[msgnum])) done (1); + seq_setprev (mp); /* set the previous sequence */ /* @@ -517,17 +519,18 @@ mhl_draft (int out, char *digest, int volume, int issue, { pid_t child_id; int i, msgnum, pd[2]; - char *vec[MAXARGS]; char buf1[BUFSIZ]; char buf2[BUFSIZ]; - + struct msgs_array vec = { 0, 0, NULL }; + if (pipe (pd) == NOTOK) adios ("pipe", "unable to create"); - vec[0] = r1bindex (mhlproc, '/'); + app_msgarg(&vec, r1bindex (mhlproc, '/')); for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++) sleep (5); + switch (child_id) { case NOTOK: adios ("fork", "unable to"); @@ -538,19 +541,19 @@ mhl_draft (int out, char *digest, int volume, int issue, close (pd[1]); i = 1; - vec[i++] = "-forwall"; - vec[i++] = "-form"; - vec[i++] = filter; + app_msgarg(&vec, "-forwall"); + app_msgarg(&vec, "-form"); + app_msgarg(&vec, filter); if (digest) { - vec[i++] = "-digest"; - vec[i++] = digest; - vec[i++] = "-issue"; + app_msgarg(&vec, "-digest"); + app_msgarg(&vec, digest); + app_msgarg(&vec, "-issue"); snprintf (buf1, sizeof(buf1), "%d", issue); - vec[i++] = buf1; - vec[i++] = "-volume"; + app_msgarg(&vec, buf1); + app_msgarg(&vec, "-volume"); snprintf (buf2, sizeof(buf2), "%d", volume); - vec[i++] = buf2; + app_msgarg(&vec, buf2); } /* @@ -559,34 +562,25 @@ mhl_draft (int out, char *digest, int volume, int issue, * unless the user has specified a specific flag. */ if (dashstuff > 0) - vec[i++] = "-dashstuffing"; + app_msgarg(&vec, "-dashstuffing"); else if (dashstuff < 0) - vec[i++] = "-nodashstuffing"; - - if (mp->numsel >= MAXARGS - i) - adios (NULL, "more than %d messages for %s exec", - MAXARGS - i, vec[0]); + app_msgarg(&vec, "-nodashstuffing"); - /* - * Now add the message names to filter. We can only - * handle about 995 messages (because vec is fixed size), - * but that should be plenty. - */ - for (msgnum = mp->lowsel; - msgnum <= mp->hghsel && i < (int) sizeof(vec) - 1; - msgnum++) + for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { if (is_selected (mp, msgnum)) - vec[i++] = getcpy (m_name (msgnum)); - vec[i] = NULL; + app_msgarg(&vec, getcpy (m_name (msgnum))); + } + + app_msgarg(&vec, NULL); - execvp (mhlproc, vec); + execvp (mhlproc, vec.msgs); fprintf (stderr, "unable to exec "); perror (mhlproc); _exit (-1); default: close (pd[1]); - cpydata (pd[0], out, vec[0], file); + cpydata (pd[0], out, vec.msgs[0], file); close (pd[0]); pidXwait(child_id, mhlproc); break; diff --git a/uip/show.c b/uip/show.c index 0b143fd..8494216 100644 --- a/uip/show.c +++ b/uip/show.c @@ -64,19 +64,22 @@ static int is_nontext(char *); int main (int argc, char **argv) { - int draftsw = 0, headersw = 1, msgp = 0; + int draftsw = 0, headersw = 1; int nshow = 0, checkmime = 1, mime; - int vecp = 1, procp = 1, isdf = 0, mode = SHOW, msgnum; + int isdf = 0, mode = SHOW, msgnum; char *cp, *maildir, *file = NULL, *folder = NULL, *proc; char buf[BUFSIZ], **argp, **arguments; - char *msgs[MAXARGS], *vec[MAXARGS]; struct msgs *mp = NULL; + struct msgs_array msgs = { 0, 0, NULL }; + struct msgs_array vec = { 0, 0, NULL }; #ifdef LOCALE setlocale(LC_ALL, ""); #endif invo_name = r1bindex (argv[0], '/'); + app_msgarg(&vec, NULL); /* placeholder, filled later with proc name */ + /* read user profile/context */ context_read(); @@ -97,7 +100,7 @@ main (int argc, char **argv) case UNKWNSW: case NPROGSW: case NFMTPROCSW: - vec[vecp++] = --cp; + app_msgarg(&vec, --cp); continue; case HELPSW: @@ -138,20 +141,20 @@ usage: continue; case FORMSW: - vec[vecp++] = --cp; + app_msgarg(&vec, --cp); if (!(cp = *argp++) || *cp == '-') adios (NULL, "missing argument to %s", argp[-2]); - vec[vecp++] = getcpy (etcpath(cp)); + app_msgarg(&vec, getcpy (etcpath(cp))); continue; case PROGSW: case LENSW: case WIDTHSW: case FMTPROCSW: - vec[vecp++] = --cp; + app_msgarg(&vec, --cp); if (!(cp = *argp++) || *cp == '-') adios (NULL, "missing argument to %s", argp[-2]); - vec[vecp++] = cp; + app_msgarg(&vec, cp); continue; case SHOWSW: @@ -185,41 +188,41 @@ usage: if (mode != SHOW) goto usage; else - msgs[msgp++] = cp; + app_msgarg(&msgs, cp); } } - procp = vecp; if (!context_find ("path")) free (path ("./", TFOLDER)); if (draftsw || file) { - if (msgp) + if (msgs.size) adios (NULL, "only one file at a time!"); - vec[vecp++] = draftsw - ? getcpy (m_draft (folder, msgp ? msgs[0] : NULL, 1, &isdf)) - : file; + if (draftsw) + app_msgarg(&vec, getcpy (m_draft (folder, NULL, 1, &isdf))); + else + app_msgarg(&vec, file); goto go_to_it; } #ifdef WHATNOW - if (!msgp && !folder && mode == SHOW && (cp = getenv ("mhdraft")) && *cp) { + if (!msgs.size && !folder && mode == SHOW && (cp = getenv ("mhdraft")) && *cp) { draftsw++; - vec[vecp++] = cp; + app_msgarg(&vec, cp); goto go_to_it; } #endif /* WHATNOW */ - if (!msgp) { + if (!msgs.size) { switch (mode) { case NEXT: - msgs[msgp++] = "next"; + app_msgarg(&msgs, "next"); break; case PREV: - msgs[msgp++] = "prev"; + app_msgarg(&msgs, "prev"); break; default: - msgs[msgp++] = "cur"; + app_msgarg(&msgs, "cur"); break; } } @@ -240,8 +243,8 @@ usage: adios (NULL, "no messages in %s", folder); /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgp; msgnum++) - if (!m_convert (mp, msgs[msgnum])) + for (msgnum = 0; msgnum < msgs.size; msgnum++) + if (!m_convert (mp, msgs.msgs[msgnum])) done (1); /* @@ -256,26 +259,21 @@ usage: seq_setprev (mp); /* set the Previous-Sequence */ seq_setunseen (mp, 1); /* unset the Unseen-Sequence */ - if (mp->numsel > MAXARGS - 2) - adios (NULL, "more than %d messages for show exec", MAXARGS - 2); - for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) if (is_selected(mp, msgnum)) - vec[vecp++] = getcpy (m_name (msgnum)); + app_msgarg(&vec, getcpy (m_name (msgnum))); seq_setcur (mp, mp->hghsel); /* update current message */ seq_save (mp); /* synchronize sequences */ context_replace (pfolder, folder); /* update current folder */ context_save (); /* save the context file */ - if (headersw && vecp == 2) - printf ("(Message %s:%s)\n", folder, vec[1]); + if (headersw && vec.size == 2) + printf ("(Message %s:%s)\n", folder, vec.msgs[1]); go_to_it: ; fflush (stdout); - vec[vecp] = NULL; - /* * Decide which "proc" to use */ @@ -294,7 +292,7 @@ go_to_it: ; } } else { /* check the file or draft for MIME */ - if (is_nontext (vec[vecp - 1])) + if (is_nontext (vec.msgs[vec.size - 1])) mime = 1; } } @@ -309,58 +307,31 @@ go_to_it: ; if (folder && !draftsw && !file) m_putenv ("mhfolder", folder); - /* - * For backward compatibility, if the "proc" is mhn, - * then add "-show" option. Add "-file" if showing - * file or draft. - */ if (strcmp (r1bindex (proc, '/'), "mhn") == 0) { + /* Add "-file" if showing file or draft, */ if (draftsw || file) { - vec[vecp] = vec[vecp - 1]; - vec[vecp - 1] = "-file"; - vecp++; + app_msgarg(&vec, vec.msgs[vec.size - 1]); + vec.msgs[vec.size - 2] = "-file"; } - vec[vecp++] = "-show"; - vec[vecp] = NULL; - } - - /* If the "proc" is "mhshow", add "-file" if showing file or draft. - */ - if (strcmp (r1bindex (proc, '/'), "mhshow") == 0 && (draftsw || file) ) { - vec[vecp] = vec[vecp - 1]; - vec[vecp - 1] = "-file"; - vec[++vecp] = NULL; - } - - /* - * If "proc" is mhl, then run it internally - * rather than exec'ing it. - */ - if (strcmp (r1bindex (proc, '/'), "mhl") == 0) { - vec[0] = "mhl"; - mhl (vecp, vec); + /* and add -show for backward compatibility */ + app_msgarg(&vec, "-show"); + } else if (strcmp (r1bindex (proc, '/'), "mhshow") == 0) { + /* If "mhshow", add "-file" if showing file or draft. */ + if (draftsw || file) { + app_msgarg(&vec, vec.msgs[vec.size - 1]); + vec.msgs[vec.size - 2] = "-file"; + } + } else if (strcmp (r1bindex (proc, '/'), "mhl") == 0) { + /* If "mhl", then run it internally */ + vec.msgs[0] = "mhl"; + app_msgarg(&vec, NULL); + mhl (vec.size, vec.msgs); done (0); } - /* - * If you are not using a nmh command as your "proc", then - * add the path to the message names. Currently, we are just - * checking for mhn here, since we've already taken care of mhl. - */ - if (!strcmp (r1bindex (proc, '/'), "mhl") - && !draftsw - && !file - && chdir (maildir = concat (m_maildir (""), "/", NULL)) != NOTOK) { - mp->foldpath = concat (mp->foldpath, "/", NULL); - cp = ssequal (maildir, mp->foldpath) - ? mp->foldpath + strlen (maildir) - : mp->foldpath; - for (msgnum = procp; msgnum < vecp; msgnum++) - vec[msgnum] = concat (cp, vec[msgnum], NULL); - } - - vec[0] = r1bindex (proc, '/'); - execvp (proc, vec); + vec.msgs[0] = r1bindex (proc, '/'); + app_msgarg(&vec, NULL); + execvp (proc, vec.msgs); adios (proc, "unable to exec"); return 0; /* dead code to satisfy the compiler */ }