Merge branch 'master' of ssh://marmaro.de:443/var/git/mmh
authormarkus schnalke <meillo@marmaro.de>
Sat, 14 Feb 2015 16:44:14 +0000 (17:44 +0100)
committermarkus schnalke <meillo@marmaro.de>
Sat, 14 Feb 2015 16:44:14 +0000 (17:44 +0100)
Conflicts:
uip/mhl.c
uip/mhlist.c
uip/mhmail.c
uip/pick.c
uip/send.c

1  2 
uip/mhl.c
uip/mhmail.c
uip/mhparse.c
uip/mhstore.c
uip/pick.c
uip/prompter.c
uip/send.c

diff --combined uip/mhl.c
+++ b/uip/mhl.c
@@@ -175,17 -175,11 +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 +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 +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 == '-')
@@@ -573,10 -565,10 +565,9 @@@ process(char *fname, int ofilen, int of
        FILE *fp = NULL;
        struct mcomp *c1;
  
 -      switch (setjmp(env)) {
 -      case OK:
 +      if (setjmp(env) == 0) {
                if (fname) {
-                       fp = mhl_action ? (*mhl_action) (fname) :
-                                       fopen(fname, "r");
+                       fp = fopen(fname, "r");
                        if (fp == NULL) {
                                advise(fname, "unable to open");
                                exitstat++;
                }
                SIGNAL(SIGINT, intrser);
                mhlfile(fp, fname, ofilen, ofilec);
 -              /* FALL THROUGH! */
 -      default:
 -              SIGNAL(SIGINT, SIG_IGN);
 -              if (fp != stdin)
 -                      fclose(fp);
 -              if (holder.c_text) {
 -                      free(holder.c_text);
 -                      holder.c_text = NULL;
 -              }
 -              free_queue(&msghd, &msgtl);
 -              for (c1 = fmthd; c1; c1 = c1->c_next)
 -                      c1->c_flags &= ~HDROUTPUT;
 -              break;
        }
 +
 +      SIGNAL(SIGINT, SIG_IGN);
-       if (mhl_action == NULL && fp != stdin)
++      if (fp != stdin)
 +              fclose(fp);
 +      if (holder.c_text) {
 +              free(holder.c_text);
 +              holder.c_text = NULL;
 +      }
 +      free_queue(&msghd, &msgtl);
 +      for (c1 = fmthd; c1; c1 = c1->c_next)
 +              c1->c_flags &= ~HDROUTPUT;
  }
  
  
@@@ -1117,29 -1111,3 +1108,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 --combined uip/mhmail.c
@@@ -40,6 -40,7 +40,6 @@@ static void intrser(int)
  int
  main(int argc, char **argv)
  {
 -      pid_t child_id;
        int status, iscc = 0, nvec;
        char *cp, *tolist = NULL, *cclist = NULL, *subject = NULL;
        char *from = NULL, *body = NULL, **argp, **arguments;
@@@ -65,7 -66,8 +65,8 @@@
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               done(1);
+                               /* sysexits.h EX_USAGE */
+                               exit(1);
                        case UNKWNSW:
                                adios(NULL, "-%s unknown", cp);
  
                                                "%s addrs... [switches]",
                                                invo_name);
                                print_help(buf, switches, 0);
-                               done(1);
+                               exit(0);
                        case VERSIONSW:
                                print_version(invo_name);
-                               done(1);
+                               exit(0);
  
                        case FROMSW:
                                if (!(from = *argp++) || *from == '-')
        vec[nvec++] = tmpfil;
        vec[nvec] = NULL;
  
 -      if ((child_id = fork()) == NOTOK) {
 -              /* report failure and then send it */
 -              adios(NULL, "unable to fork");
 -
 -      } else if (child_id == 0) {
 -              /* child process */
 -              execvp(*vec, vec);
 -              fprintf(stderr, "unable to exec ");
 -              perror(*vec);
 -              _exit(-1);
 -
 -      } else {
 -              /* parent process */
 -              if ((status = pidXwait(child_id, *vec))) {
 -                      /* spost failed, save draft as dead.letter */
 -                      int in, out;
 -
 -                      in = open(tmpfil, O_RDONLY);
 -                      out = creat("dead.letter", 0600);
 -                      if (in == -1 || out == -1) {
 -                              fprintf(stderr, "Letter left at %s.\n",
 -                                              tmpfil);
 -                              /* sysexits.h exit-status from spost */
 -                              exit(status ? 1 : 0);
 -                      }
 -                      cpydata(in, out, tmpfil, "dead.letter");
 -                      close(in);
 -                      close(out);
 -                      fprintf(stderr, "Letter saved in dead.letter\n");
 +      if ((status = execprog(*vec, vec))) {
 +              /* spost failed, save draft as dead.letter */
 +              int in, out;
 +
 +              in = open(tmpfil, O_RDONLY);
 +              out = creat("dead.letter", 0600);
 +              if (in == -1 || out == -1) {
 +                      fprintf(stderr, "Letter left at %s.\n",
 +                                      tmpfil);
-                       done(status ? 1 : 0);
++                      /* sysexits.h exit-status from spost */
++                      exit(status ? 1 : 0);
                }
 -              unlink(tmpfil);
 -              /* sysexits.h exit status from spost */
 -              exit(status ? 1 : 0);
 +              cpydata(in, out, tmpfil, "dead.letter");
 +              close(in);
 +              close(out);
 +              fprintf(stderr, "Letter saved in dead.letter\n");
        }
 -
 -      return 0;  /* dead code to satisfy the compiler */
 +      unlink(tmpfil);
-       done(status ? 1 : 0);
-       return 0;  /* dead code to satisfy the compiler */
++      /* sysexits.h exit status from spost */
++      exit(status ? 1 : 0);
  }
  
  
@@@ -185,6 -204,6 +187,6 @@@ static voi
  intrser(int i)
  {
        unlink(tmpfil);
-       done(i != 0 ? 1 : 0);
+       exit(i != 0 ? 1 : 0);
  }
  
diff --combined uip/mhparse.c
@@@ -10,6 -10,7 +10,6 @@@
  #include <fcntl.h>
  #include <h/signals.h>
  #include <errno.h>
 -#include <setjmp.h>
  #include <signal.h>
  #include <h/tws.h>
  #include <h/mime.h>
@@@ -136,7 -137,7 +136,7 @@@ pidcheck(int status
  
        fflush(stdout);
        fflush(stderr);
-       done(1);
+       exit(1);
        return 1;
  }
  
diff --combined uip/mhstore.c
@@@ -10,6 -10,7 +10,6 @@@
  #include <fcntl.h>
  #include <h/signals.h>
  #include <errno.h>
 -#include <setjmp.h>
  #include <signal.h>
  #include <h/tws.h>
  #include <h/mime.h>
@@@ -63,7 -64,7 +63,7 @@@ void flush_errors(void)
  /* mhfree.c */
  void free_content(CT);
  extern CT *cts;  /* The list of top-level contents to display */
- void freects_done(int) NORETURN;
+ void freects_done();
  
  /*
  ** static prototypes
@@@ -129,7 -130,7 +129,7 @@@ main(int argc, char **argv
        CT ct, *ctp;
        FILE *fp;
  
-       done=freects_done;
+       atexit(freects_done);
  
        setlocale(LC_ALL, "");
        invo_name = mhbasename(argv[0]);
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               done(1);
+                               exit(1);
                        case UNKWNSW:
                                adios(NULL, "-%s unknown", cp);
  
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               done(1);
+                               exit(0);
                        case VERSIONSW:
                                print_version(invo_name);
-                               done(1);
+                               exit(0);
  
                        case AUTOSW:
                                autosw++;
                /* 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 */
  
                if (!(cts = (CT *) calloc((size_t) (mp->numsel + 1),
        }
  
        if (!*cts)
-               done(1);
+               exit(1);
  
        userrs = 1;
        SIGNAL(SIGQUIT, quitser);
                context_save();  /* save the context file  */
        }
  
-       done(0);
-       return 1;
+       return 0;
  }
  
  
@@@ -361,7 -361,7 +360,7 @@@ pipeser(int i
                fflush(stderr);
        }
  
-       done(1);
+       exit(1);
        /* NOTREACHED */
  }
  
diff --combined uip/pick.c
@@@ -76,7 -76,7 +76,7 @@@ static int pmatches(FILE *, int, 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 +91,7 @@@
        struct msgs *mp;
        register FILE *fp;
  
-       done=putzero_done;
+       atexit(putzero_done);
  
        setlocale(LC_ALL, "");
        invo_name = mhbasename(argv[0]);
                        case AMBIGSW:
                                ambigsw(cp, switches);
                                listsw = 0;  /* HACK */
-                               done(1);
+                               exit(1);
                        case UNKWNSW:
                                adios(NULL, "-%s unknown", cp);
  
                                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:
                                        adios(NULL, "too many sequences (more than %d) specified", NUMATTRS);
  
                                if (!seq_nameok(cp))
-                                       done(1);
 -                                exit(1);
++                                      exit(1);
  
                                seqs[seqp++] = cp;
                                continue;
        /* 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 */
  
        /*
                                folder);
  
        if (!pcompile(vec, NULL))
-               done(1);
+               exit(1);
  
        lo = mp->lowsel;
        hi = mp->hghsel;
        */
        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.
        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 --combined uip/prompter.c
@@@ -71,7 -71,7 +71,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", cp);
  
                                                "%s [switches] file",
                                                invo_name);
                                print_help(buffer, switches, 1);
-                               done(1);
+                               exit(0);
                        case VERSIONSW:
                                print_version(invo_name);
-                               done(1);
+                               exit(0);
  
                        case PREPSW:
                                prepend++;
                                if (i == -1) {
  abort:
                                        unlink(tmpfil);
-                                       done(1);
+                                       /* sysexits.h EX_DATAERR */
+                                       exit(1);
                                }
                                if (i || (field[0]!='\n' && field[0]!='\0')) {
                                        fprintf(out, "%s:", name);
@@@ -254,8 -255,7 +255,7 @@@ has_no_body
        unlink(tmpfil);
  
        context_save();  /* save the context file */
-       done(0);
-       return 1;
+       return 0;
  }
  
  
@@@ -269,7 -269,7 +269,7 @@@ getln(char *buffer, int n
        *cp = '\0';
  
        switch (setjmp(sigenv)) {
 -      case OK:
 +      case 0:
                wtuser = 1;
                break;
  
diff --combined uip/send.c
@@@ -11,7 -11,6 +11,6 @@@
  #include <errno.h>
  #include <signal.h>
  #include <h/signals.h>
- #include <setjmp.h>
  #include <h/mime.h>
  #include <h/tws.h>
  #include <h/utils.h>
@@@ -28,8 -27,6 +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 +41,6 @@@ static FILE *composition_file;  /* comp
  ** 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 +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);
  
                                                "%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++;
                /* 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);
        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:
        }
  
        context_save();
-       done(status);
-       return 1;
+       return status;
  }
  
  
@@@ -288,27 -283,26 +283,22 @@@ sendsbr(char **vec, int vecp, char *drf
                break;
        }
  
-       done=armed_done;
-       if (setjmp(env) == 0) {
-               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);
 -      switch (status = sendaux(vec, vecp, drft, st)) {
 -      case OK:
++      if ((status = sendaux(vec, vecp, drft, st)) == 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);
 -              break;
 -
 -      default:
 +      } else {
                status = DONE;
 -              break;
        }
  
-       done=exit;
        if (distfile) {
                unlink(distfile);
        }
@@@ -624,15 -618,15 +614,15 @@@ sendaux(char **vec, int vecp, char *drf
  
        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 */
        }
  
  
-       return status;
+       return status ? NOTOK : status;
  }
  
  
@@@ -745,12 -739,3 +735,3 @@@ strexit(int status
                return "message not delivered to anyone";
        }
  }
- static void
- armed_done(int status)
- {
-       longjmp(env, status ? status : NOTOK);
-       exit(status);
- }