From 96d10c193324201ef8acb622ed13e9a5ecb59827 Mon Sep 17 00:00:00 2001 From: Philipp Takacs Date: Fri, 16 Jan 2015 22:31:04 +0100 Subject: [PATCH] Remove done from mhl pick and send Second part of removing done, to make the code better to read. This tools needed some refactoring before done could removed. Next step is removing done from sbr. --- uip/mhl.c | 45 +++++--------------------------------------- uip/pick.c | 27 +++++++++++++-------------- uip/send.c | 61 +++++++++++++++++++++--------------------------------------- 3 files changed, 39 insertions(+), 94 deletions(-) diff --git a/uip/mhl.c b/uip/mhl.c index fedf78f..45113f3 100644 --- a/uip/mhl.c +++ b/uip/mhl.c @@ -175,17 +175,11 @@ static int num_ignores = 0; static char *ignores[MAXARGS]; static jmp_buf env; -static jmp_buf mhlenv; - -static FILE *(*mhl_action) () = (FILE *(*) ()) 0; - /* ** Redefine a couple of functions. ** These are undefined later in the code. */ -#define adios mhladios -#define done mhldone /* ** prototypes @@ -208,8 +202,6 @@ static char *oneline(char *, long); static void putstr(char *); static void putch(char); static void intrser(int); -static void mhladios(char *, char *, ...); -static void mhldone(int); int sc_width(void); /* from termsbr.c */ @@ -239,17 +231,17 @@ main(int argc, char **argv) switch (smatch(++cp, switches)) { case AMBIGSW: ambigsw(cp, switches); - done(1); + exit(1); case UNKWNSW: adios(NULL, "-%s unknown\n", cp); case HELPSW: snprintf(buf, sizeof(buf), "%s [switches] [files ...]", invo_name); print_help(buf, switches, 1); - done(1); + exit(0); case VERSIONSW: print_version(invo_name); - done(1); + exit(0); case FORMSW: if (!(form = *argp++) || *form == '-') @@ -576,8 +568,7 @@ process(char *fname, int ofilen, int ofilec) switch (setjmp(env)) { case OK: if (fname) { - fp = mhl_action ? (*mhl_action) (fname) : - fopen(fname, "r"); + fp = fopen(fname, "r"); if (fp == NULL) { advise(fname, "unable to open"); exitstat++; @@ -592,7 +583,7 @@ process(char *fname, int ofilen, int ofilec) /* FALL THROUGH! */ default: SIGNAL(SIGINT, SIG_IGN); - if (mhl_action == NULL && fp != stdin) + if (fp != stdin) fclose(fp); if (holder.c_text) { free(holder.c_text); @@ -1120,29 +1111,3 @@ intrser(int i) putchar('\n'); longjmp(env, DONE); } - - -#undef adios -#undef done - -static void -mhladios(char *what, char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - advertise(what, NULL, fmt, ap); - va_end(ap); - mhldone(1); -} - - -static void -mhldone(int status) -{ - exitstat = status; - if (mhl_action) - longjmp(mhlenv, DONE); - else - done(exitstat); -} diff --git a/uip/pick.c b/uip/pick.c index e94c259..ae1fa03 100644 --- a/uip/pick.c +++ b/uip/pick.c @@ -76,7 +76,7 @@ static int pmatches(FILE *, int, long, long); static int listsw = -1; -static void putzero_done(int) NORETURN; +static void putzero_done(); int main(int argc, char **argv) @@ -91,7 +91,7 @@ main(int argc, char **argv) struct msgs *mp; register FILE *fp; - done=putzero_done; + atexit(putzero_done); setlocale(LC_ALL, ""); invo_name = mhbasename(argv[0]); @@ -112,7 +112,7 @@ main(int argc, char **argv) case AMBIGSW: ambigsw(cp, switches); listsw = 0; /* HACK */ - done(1); + exit(1); case UNKWNSW: adios(NULL, "-%s unknown", cp); @@ -120,11 +120,11 @@ main(int argc, char **argv) snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name); print_help(buf, switches, 1); listsw = 0; /* HACK */ - done(1); + exit(0); case VERSIONSW: print_version(invo_name); listsw = 0; /* HACK */ - done(1); + exit(0); case CCSW: case DATESW: @@ -163,7 +163,7 @@ main(int argc, char **argv) adios(NULL, "too many sequences (more than %d) specified", NUMATTRS); if (!seq_nameok(cp)) - done(1); + exit(1); seqs[seqp++] = cp; continue; @@ -223,7 +223,7 @@ main(int argc, char **argv) /* parse all the message ranges/sequences and set SELECTED */ for (msgnum = 0; msgnum < msgs.size; msgnum++) if (!m_convert(mp, msgs.msgs[msgnum])) - done(1); + exit(1); seq_setprev(mp); /* set the previous-sequence */ /* @@ -238,7 +238,7 @@ main(int argc, char **argv) folder); if (!pcompile(vec, NULL)) - done(1); + exit(1); lo = mp->lowsel; hi = mp->hghsel; @@ -289,7 +289,7 @@ main(int argc, char **argv) */ for (seqp = 0; seqs[seqp]; seqp++) if (!seq_addsel(mp, seqs[seqp], publicsw, zerosw)) - done(1); + exit(1); /* ** Print total matched if not printing each matched message number. @@ -302,17 +302,16 @@ main(int argc, char **argv) seq_save(mp); /* synchronize message sequences */ context_save(); /* save the context file */ folder_free(mp); /* free folder/message structure */ - done(0); - return 1; + listsw = 0; /* HACK */ + return 0; } static void -putzero_done(int status) +putzero_done() { - if (listsw && status && !isatty(fileno(stdout))) + if (listsw && !isatty(fileno(stdout))) printf("0\n"); - exit(status); } diff --git a/uip/send.c b/uip/send.c index ed6b08d..07f2545 100644 --- a/uip/send.c +++ b/uip/send.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include #include @@ -28,8 +27,6 @@ char *altmsg = NULL; char *annotext = NULL; char *distfile = NULL; -static jmp_buf env; - /* name of temp file for body content */ static char body_file_name[MAXPATHLEN + 1]; /* name of mhbuild composition temporary file */ @@ -44,7 +41,6 @@ static FILE *composition_file; /* composition file pointer */ ** static prototypes */ static int sendsbr(char **, int, char *, struct stat *); -static void armed_done(int) NORETURN; static void anno(struct stat *); static int sendaux(char **, int, char *, struct stat *); static int attach(char *); @@ -99,7 +95,7 @@ main(int argc, char **argv) switch (smatch(++cp, switches)) { case AMBIGSW: ambigsw(cp, switches); - done(1); + exit(1); case UNKWNSW: adios(NULL, "-%s unknown\n", cp); @@ -108,10 +104,10 @@ main(int argc, char **argv) "%s [file] [switches]", invo_name); print_help(buf, switches, 1); - done(1); + exit(0); case VERSIONSW: print_version(invo_name); - done(1); + exit(0); case DEBUGSW: debugsw++; @@ -150,7 +146,7 @@ main(int argc, char **argv) /* parse all the msgranges/sequences and set SELECTED */ for (msgnum = 0; msgnum < nmsgs; msgnum++) { if (!m_convert(mp, msgs[msgnum])) { - done(1); + exit(1); } } seq_setprev(mp); @@ -217,7 +213,7 @@ main(int argc, char **argv) for (n = 0; n < nfiles; n++) { switch (sendsbr(vec, vecp, files[n], &st)) { case DONE: - done(++status); + exit(++status); case NOTOK: status++; /* fall */ case OK: @@ -226,8 +222,7 @@ main(int argc, char **argv) } context_save(); - done(status); - return 1; + return status; } @@ -288,23 +283,19 @@ sendsbr(char **vec, int vecp, char *drft, struct stat *st) break; } - done=armed_done; - switch (setjmp(env)) { + switch (sendaux(vec, vecp, drft, st)) { case OK: - status = sendaux(vec, vecp, drft, st) ? NOTOK : OK; - if (status == OK) { - /* move original draft to +trash folder */ - /* temporary close stdin, for refile not to ask */ - dupfd = dup(0); - close(0); - if (execprogl("refile", "refile", "-file", - original_draft, "+trash", - (char *)NULL) != 0) { - advise(NULL, "unable to trash the draft"); - } - dup2(dupfd, 0); - close(dupfd); + /* move original draft to +trash folder */ + /* temporary close stdin, for refile not to ask */ + dupfd = dup(0); + close(0); + if (execprogl("refile", "refile", "-file", + original_draft, "+trash", + (char *)NULL) != 0) { + advise(NULL, "unable to trash the draft"); } + dup2(dupfd, 0); + close(dupfd); break; default: @@ -312,7 +303,6 @@ sendsbr(char **vec, int vecp, char *drft, struct stat *st) break; } - done=exit; if (distfile) { unlink(distfile); } @@ -628,15 +618,15 @@ sendaux(char **vec, int vecp, char *drft, struct stat *st) vec[vecp++] = drft; if (distfile && distout(drft, distfile, backup) == NOTOK) { - done(1); + return DONE; } vec[vecp] = NULL; switch (child_id = fork()) { case -1: /* oops -- fork error */ - adios("fork", "unable to"); - break; /* NOT REACHED */ + advise("fork", "unable to"); + return DONE; case 0: /* child process -- send it */ @@ -667,7 +657,7 @@ sendaux(char **vec, int vecp, char *drft, struct stat *st) } - return status; + return status ? NOTOK : status; } @@ -749,12 +739,3 @@ strexit(int status) return "message not delivered to anyone"; } } - - -static void -armed_done(int status) -{ - longjmp(env, status ? status : NOTOK); - - exit(status); -} -- 1.7.10.4