From: markus schnalke Date: Wed, 8 Feb 2012 13:24:08 +0000 (+0100) Subject: Separated send from whatnow, similar to the previous commit. X-Git-Tag: mmh-thesis-end~362 X-Git-Url: http://git.marmaro.de/?a=commitdiff_plain;h=3df5ab3c116e6d4a2fb4bb5cc9dfc5f781825815;p=mmh Separated send from whatnow, similar to the previous commit. Again, I traded execution speed for less (doubled) code, clearer interfaces, and modularization. Oh what an improvement! --- diff --git a/uip/Makefile.in b/uip/Makefile.in index 63f71e2..88b9bd7 100644 --- a/uip/Makefile.in +++ b/uip/Makefile.in @@ -225,8 +225,8 @@ spost: spost.o aliasbr.o $(LOCALLIBS) viamail: viamail.o mhmisc.o mhoutsbr.o sendsbr.o annosbr.o distsbr.o $(LOCALLIBS) $(LINK) viamail.o mhmisc.o mhoutsbr.o sendsbr.o annosbr.o distsbr.o $(LINKLIBS) $(TERMLIB) -whatnow: whatnow.o sendsbr.o annosbr.o distsbr.o $(LOCALLIBS) - $(LINK) whatnow.o sendsbr.o annosbr.o distsbr.o $(LINKLIBS) +whatnow: whatnow.o annosbr.o distsbr.o $(LOCALLIBS) + $(LINK) whatnow.o annosbr.o distsbr.o $(LINKLIBS) # ========== DEPENDENCIES FOR INSTALLING ========== diff --git a/uip/send.c b/uip/send.c index da5f23b..bdcd83b 100644 --- a/uip/send.c +++ b/uip/send.c @@ -62,11 +62,12 @@ extern char *distfile; int main(int argc, char **argv) { - int msgp = 0, distsw = 0, vecp = 1; + int msgp = 0, msgp2 = 0, distsw = 0, vecp = 1; int msgnum, status; char *cp, *maildir = NULL; char buf[BUFSIZ], **ap, **argp, **arguments; char *msgs[MAXARGS], *vec[MAXARGS]; + char *msgs2[MAXARGS]; struct msgs *mp; struct stat st; @@ -180,14 +181,22 @@ main(int argc, char **argv) adios(NULL, "no messages in draft folder %s", draftfolder); /* parse all the message ranges/sequences and set SELECTED */ - for (msgnum = 0; msgnum < msgp; msgnum++) - if (!m_convert(mp, msgs[msgnum])) + msgp2 = 0; + for (msgnum = 0; msgnum < msgp; msgnum++) { + if (*msgs[msgnum] == '/') { + /* absolute path */ + msgs2[msgp2++] = msgs[msgnum]; + continue; + } + if (!m_convert(mp, msgs[msgnum])) { done(1); + } + } seq_setprev(mp); /* set the previous-sequence */ for (msgp = 0, msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) { if (is_selected(mp, msgnum)) { - msgs[msgp++] = getcpy(m_name(msgnum)); + msgs2[msgp2++] = getcpy(m_name(msgnum)); unset_exists(mp, msgnum); } } @@ -199,9 +208,9 @@ main(int argc, char **argv) if ((cp = context_find("signature")) && *cp) m_putenv("SIGNATURE", cp); - for (msgnum = 0; msgnum < msgp; msgnum++) - if (stat(msgs[msgnum], &st) == NOTOK) - adios(msgs[msgnum], "unable to stat draft file"); + for (msgnum = 0; msgnum < msgp2; msgnum++) + if (stat(msgs2[msgnum], &st) == NOTOK) + adios(msgs2[msgnum], "unable to stat draft file"); if ((annotext = getenv("mhannotate")) == NULL || *annotext == 0) annotext = NULL; @@ -252,8 +261,8 @@ main(int argc, char **argv) vec[0] = mhbasename(postproc); closefds(3); - for (msgnum = 0; msgnum < msgp; msgnum++) { - switch (sendsbr(vec, vecp, msgs[msgnum], &st, 1)) { + for (msgnum = 0; msgnum < msgp2; msgnum++) { + switch (sendsbr(vec, vecp, msgs2[msgnum], &st, 1)) { case DONE: done(++status); case NOTOK: diff --git a/uip/whatnow.c b/uip/whatnow.c index 0ec8e41..7033cdf 100644 --- a/uip/whatnow.c +++ b/uip/whatnow.c @@ -100,7 +100,6 @@ static char *myprompt = "\nWhat now? "; static int editfile(char **, char **, char *, int, struct msgs *, char *, char *, int); static int sendfile(char **, char *, int); -static void sendit(char *, char **, char *, int); static int removefile(char *); static void writelscmd(char *, int, char **); static void writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp); @@ -775,20 +774,7 @@ sendfile(char **arg, char *file, int pushsw) { pid_t child_id; int i, vecp; - char *cp, *sp, *vec[MAXARGS]; - - /* - ** If the sendproc is the nmh command `send', then we call - ** those routines directly rather than exec'ing the command. - */ - if (strcmp(sp = mhbasename(sendproc), "send") == 0) { - cp = invo_name; - sendit(invo_name = sp, arg, file, pushsw); - invo_name = cp; - return 1; - } - - /* some different sendproc */ + char *vec[MAXARGS]; context_save(); /* save the context file */ fflush(stdout); @@ -823,234 +809,6 @@ sendfile(char **arg, char *file, int pushsw) } -static struct swit sendswitches[] = { -#define ALIASW 0 - { "alias aliasfile", 0 }, -#define DEBUGSW 1 - { "debug", -5 }, -#define FILTSW 2 - { "filter filterfile", 0 }, -#define NFILTSW 3 - { "nofilter", 0 }, -#define FRMTSW 4 - { "format", 0 }, -#define NFRMTSW 5 - { "noformat", 0 }, -#define FORWSW 6 - { "forward", 0 }, -#define NFORWSW 7 - { "noforward", 0 }, -#define SPSHSW 8 - { "push", 0 }, -#define NSPSHSW 9 - { "nopush", 0 }, -#define VERBSW 10 - { "verbose", 0 }, -#define NVERBSW 11 - { "noverbose", 0 }, -#define WATCSW 12 - { "watch", 0 }, -#define NWATCSW 13 - { "nowatch", 0 }, -#define WIDTHSW 14 - { "width columns", 0 }, -#define SVERSIONSW 15 - { "version", 0 }, -#define SHELPSW 16 - { "help", 0 }, - { NULL, 0 } -}; - - -extern int debugsw; /* from sendsbr.c */ -extern int forwsw; -extern int inplace; -extern int pushsw; -extern int verbsw; - -extern char *altmsg; /* .. */ -extern char *annotext; -extern char *distfile; - - -static void -sendit(char *sp, char **arg, char *file, int pushed) -{ - int vecp, n = 1; - char *cp, buf[BUFSIZ], **argp; - char **arguments, *vec[MAXARGS]; - struct stat st; - -#ifndef lint - int distsw = 0; -#endif - - /* - ** Make sure these are defined. In particular, we need - ** vec[1] to be NULL, in case "arg" is NULL below. It - ** doesn't matter what is the value of vec[0], but we - ** set it to NULL, to help catch "off-by-one" errors. - */ - vec[0] = NULL; - vec[1] = NULL; - - /* - ** Temporarily copy arg to vec, since the brkstring() call in - ** getarguments() will wipe it out before it is merged in. - ** Also, we skip the first element of vec, since getarguments() - ** skips it. Then we count the number of arguments - ** copied. The value of "n" will be one greater than - ** this in order to simulate the standard argc/argv. - */ - if (arg) { - char **bp; - - copyip(arg, vec+1, MAXARGS-1); - bp = vec+1; - while (*bp++) - n++; - } - - /* - ** Merge any arguments from command line (now in vec) - ** and arguments from profile. - */ - arguments = getarguments(sp, n, vec, 1); - argp = arguments; - - debugsw = 0; - forwsw = 1; - inplace = 1; - - altmsg = NULL; - annotext = NULL; - distfile = NULL; - - vecp = 1; /* we'll get the zero'th element later */ - vec[vecp++] = "-library"; - vec[vecp++] = getcpy(toabsdir("+")); - - while ((cp = *argp++)) { - if (*cp == '-') { - switch (smatch(++cp, sendswitches)) { - case AMBIGSW: - ambigsw(cp, sendswitches); - return; - case UNKWNSW: - advise(NULL, "-%s unknown\n", cp); - return; - - case SHELPSW: - snprintf(buf, sizeof(buf), - "%s [switches]", sp); - print_help(buf, sendswitches, 1); - return; - case SVERSIONSW: - print_version(invo_name); - return; - - case SPSHSW: - pushed++; - continue; - case NSPSHSW: - pushed = 0; - continue; - - case FORWSW: - forwsw++; - continue; - case NFORWSW: - forwsw = 0; - continue; - - case VERBSW: - verbsw++; - vec[vecp++] = --cp; - continue; - case NVERBSW: - verbsw = 0; - vec[vecp++] = --cp; - continue; - - case DEBUGSW: - debugsw++; /* fall */ - case NFILTSW: - case FRMTSW: - case NFRMTSW: - case WATCSW: - case NWATCSW: - vec[vecp++] = --cp; - continue; - - case ALIASW: - case FILTSW: - case WIDTHSW: - vec[vecp++] = --cp; - if (!(cp = *argp++) || *cp == '-') { - advise(NULL, "missing argument to %s", - argp[-2]); - return; - } - vec[vecp++] = cp; - continue; - - } - } - advise(NULL, "usage: %s [switches]", sp); - return; - } - - /* allow Aliasfile: profile entry */ - if ((cp = context_find("Aliasfile"))) { - char **ap, *dp; - - dp = getcpy(cp); - for (ap = brkstring(dp, " ", "\n"); ap && *ap; ap++) { - vec[vecp++] = "-alias"; - vec[vecp++] = getcpy(etcpath(*ap)); - } - } - - if (!(cp = getenv("SIGNATURE")) || !*cp) - if ((cp = context_find("signature")) && *cp) - m_putenv("SIGNATURE", cp); - - if ((annotext = getenv("mhannotate")) == NULL || *annotext == 0) - annotext = NULL; - if ((altmsg = getenv("mhaltmsg")) == NULL || *altmsg == 0) - altmsg = NULL; - if (annotext && ((cp = getenv("mhinplace")) != NULL && *cp != 0)) - inplace = atoi(cp); - - if ((cp = getenv("mhdist")) && *cp -#ifndef lint - && (distsw = atoi (cp)) -#endif /* not lint */ - && altmsg) { - vec[vecp++] = "-dist"; - distfile = getcpy(m_mktemp2(altmsg, invo_name, NULL, NULL)); - if (link(altmsg, distfile) == NOTOK) - adios(distfile, "unable to link %s to", altmsg); - } else { - distfile = NULL; - } - - if (altmsg == NULL || stat(altmsg, &st) == NOTOK) { - st.st_mtime = 0; - st.st_dev = 0; - st.st_ino = 0; - } - if ((pushsw = pushed)) - push(); - - vec[0] = mhbasename(postproc); - closefds(3); - - if (sendsbr(vec, vecp, file, &st, 1) == OK) - done(0); -} - - /* ** Remove the draft file */