X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fwhatnowproc.c;h=765ed8ac354c49296a904903b70b00dd8bb8157b;hp=44146d7e27026d7880aeeb0e6d2e93fbb5500ce9;hb=6e9577f324bef90765a5edc02044eb111ec48072;hpb=a485ed478abbd599d8c9aab48934e7a26733ecb1 diff --git a/uip/whatnowproc.c b/uip/whatnowproc.c index 44146d7..765ed8a 100644 --- a/uip/whatnowproc.c +++ b/uip/whatnowproc.c @@ -1,71 +1,64 @@ /* - * whatnowproc.c -- exec the "whatnowproc" - * - * This code is Copyright (c) 2002, by the authors of nmh. See the - * COPYRIGHT file in the root directory of the nmh distribution for - * complete copyright information. - */ +** whatnowproc.c -- exec the "whatnowproc" +** +** This code is Copyright (c) 2002, by the authors of nmh. See the +** COPYRIGHT file in the root directory of the nmh distribution for +** complete copyright information. +*/ #include +#include /* - * This routine is used by comp, repl, forw, and dist to exec - * the "whatnowproc". It first sets up all the environment - * variables that the "whatnowproc" will need to check, and - * then execs the command. As an optimization, if the - * "whatnowproc" is the nmh command "whatnow" (typical case), - * it will call this routine directly without exec'ing it. - */ - -/* from whatnowsbr.c */ -int WhatNow (int, char **); - - +** This routine is used by comp, repl, forw, and dist to exec +** the "whatnowproc". It first sets up all the environment +** variables that the "whatnowproc" will need to check, and +** then execs the command. +*/ int -what_now (char *ed, int nedit, int use, char *file, char *altmsg, int dist, - struct msgs *mp, char *text, int inplace, char *cwd) +what_now(char *ed, int use, char *file, char *altmsg, int dist, + struct msgs *mp, char *text, char *cwd) { int found, k, msgnum, vecp; int len, buflen; - register char *bp; + char *bp; char buffer[BUFSIZ], *vec[MAXARGS]; vecp = 0; - vec[vecp++] = r1bindex (whatnowproc, '/'); + vec[vecp++] = mhbasename(whatnowproc); vec[vecp] = NULL; - m_putenv ("mhdraft", file); + m_putenv("mhdraft", file); if (mp) - m_putenv ("mhfolder", mp->foldpath); + m_putenv("mhfolder", mp->foldpath); else - unputenv ("mhfolder"); + unputenv("mhfolder"); if (altmsg) { if (mp == NULL || *altmsg == '/' || cwd == NULL) - m_putenv ("mhaltmsg", altmsg); + m_putenv("mhaltmsg", altmsg); else { - snprintf (buffer, sizeof(buffer), "%s/%s", mp->foldpath, altmsg); - m_putenv ("mhaltmsg", buffer); + snprintf(buffer, sizeof(buffer), "%s/%s", + mp->foldpath, altmsg); + m_putenv("mhaltmsg", buffer); } } else { - unputenv ("mhaltmsg"); + unputenv("mhaltmsg"); } - if ((bp = getenv ("mhaltmsg")))/* XXX */ - m_putenv ("editalt", bp); - snprintf (buffer, sizeof(buffer), "%d", dist); - m_putenv ("mhdist", buffer); - if (nedit) { - unputenv ("mheditor"); + snprintf(buffer, sizeof(buffer), "%d", dist); + m_putenv("mhdist", buffer); + if (!ed) { + m_putenv("mheditor", defaulteditor); + } else if (*ed) { + m_putenv("mheditor", ed); } else { - m_putenv ("mheditor", ed ? ed : (ed = context_find ("editor")) - ? ed : defaulteditor); + unputenv("mheditor"); } - snprintf (buffer, sizeof(buffer), "%d", use); - m_putenv ("mhuse", buffer); + snprintf(buffer, sizeof(buffer), "%d", use); + m_putenv("mhuse", buffer); - unputenv ("mhmessages"); - unputenv ("mhannotate"); - unputenv ("mhinplace"); + unputenv("mhmessages"); + unputenv("mhannotate"); if (text && mp && !is_readonly(mp)) { found = 0; @@ -73,15 +66,16 @@ what_now (char *ed, int nedit, int use, char *file, char *altmsg, int dist, buflen = sizeof(buffer); for (msgnum = mp->lowmsg; msgnum <= mp->hghmsg; msgnum++) { if (is_selected(mp, msgnum)) { - snprintf (bp, buflen, "%s%s", found ? " " : "", m_name (msgnum)); - len = strlen (bp); + snprintf(bp, buflen, "%s%s", found ? " " : "", + m_name(msgnum)); + len = strlen(bp); bp += len; buflen -= len; for (k = msgnum + 1; k <= mp->hghmsg && is_selected(mp, k); k++) continue; if (--k > msgnum) { - snprintf (bp, buflen, "-%s", m_name (k)); - len = strlen (bp); + snprintf(bp, buflen, "-%s", m_name(k)); + len = strlen(bp); bp += len; buflen -= len; } @@ -90,31 +84,20 @@ what_now (char *ed, int nedit, int use, char *file, char *altmsg, int dist, } } if (found) { - m_putenv ("mhmessages", buffer); - m_putenv ("mhannotate", text); - snprintf (buffer, sizeof(buffer), "%d", inplace); - m_putenv ("mhinplace", buffer); + m_putenv("mhmessages", buffer); + m_putenv("mhannotate", text); } } - context_save (); /* save the context file */ - fflush (stdout); + context_save(); /* save the context file */ + fflush(stdout); if (cwd) - chdir (cwd); - - /* - * If the "whatnowproc" is the nmh command "whatnow", - * we run it internally, rather than exec'ing it. - */ - if (strcmp (vec[0], "whatnow") == 0) { - WhatNow (vecp, vec); - done (0); - } + chdir(cwd); - execvp (whatnowproc, vec); - fprintf (stderr, "unable to exec "); - perror (whatnowproc); + execvp(whatnowproc, vec); + fprintf(stderr, "unable to exec "); + perror(whatnowproc); return 0; }