Use sysexits.h for better exit-codes
authorPhilipp Takacs <philipp@bureaucracy.de>
Tue, 14 Apr 2015 13:29:56 +0000 (15:29 +0200)
committerPhilipp Takacs <philipp@bureaucracy.de>
Sun, 19 Apr 2015 12:15:21 +0000 (14:15 +0200)
The sysexits header describe some standard exit-codes, which should
be used. adios has now a status argument so sysexits.h can be used.

67 files changed:
docs/TODO
h/prototypes.h
sbr/addrsbr.c
sbr/brkstring.c
sbr/context_read.c
sbr/context_save.c
sbr/cpydata.c
sbr/cpydgst.c
sbr/error.c
sbr/execprog.c
sbr/fmt_compile.c
sbr/fmt_new.c
sbr/fmt_scan.c
sbr/folder_delmsgs.c
sbr/folder_realloc.c
sbr/m_draft.c
sbr/m_getfld.c
sbr/path.c
sbr/readconfig.c
sbr/seq_msgstats.c
sbr/seq_read.c
sbr/utils.c
sbr/vfgets.c
uip/ali.c
uip/anno.c
uip/ap.c
uip/burst.c
uip/comp.c
uip/dist.c
uip/dp.c
uip/flist.c
uip/fmtdump.c
uip/folder.c
uip/forw.c
uip/inc.c
uip/mark.c
uip/mhbuild.c
uip/mhl.c
uip/mhlist.c
uip/mhlistsbr.c
uip/mhmail.c
uip/mhparam.c
uip/mhparse.c
uip/mhpath.c
uip/mhshow.c
uip/mhshowsbr.c
uip/mhstore.c
uip/mhtest.c
uip/new.c
uip/packf.c
uip/pick.c
uip/prompter.c
uip/rcvdist.c
uip/rcvpack.c
uip/rcvstore.c
uip/refile.c
uip/repl.c
uip/rmf.c
uip/rmm.c
uip/scan.c
uip/scansbr.c
uip/send.c
uip/slocal.c
uip/sortm.c
uip/spost.c
uip/whatnow.c
uip/whom.c

index cfc0dc5..8ea5ab5 100644 (file)
--- a/docs/TODO
+++ b/docs/TODO
@@ -102,7 +102,6 @@ MHBUILD
 
 MHL
 ---
-* remove naming hack in mhlsbr.c for adios and done.
 * add ability to filter parts of the message by calling
   an external filtering program.
 * fix internal pager for mhl?
@@ -206,7 +205,6 @@ GENERAL
 * Maybe should move etcpath to sbr and add to libmh.
 * collect winsize, struct termio, etc... together into a ttyinfo
   structure.
-* change adios to take exit code argument.
 * use wait3 if not waitpid (maybe)
 * some of the calls to setjmp/longjmp should be replaced with
   sigsetjmp/siglongjmp.
index f162ef5..3512ef7 100644 (file)
@@ -22,7 +22,7 @@ char *etcpath(char *);
 /*
 ** prototypes from the nmh subroutine library
 */
-void adios(char *, char *, ...) NORETURN;
+void adios(int, char *, char *, ...) NORETURN;
 void admonish(char *, char *, ...);
 void advertise(char *, char *, char *, va_list);
 void advise(char *, char *, ...);
index e759088..d7894c5 100644 (file)
@@ -6,6 +6,7 @@
 ** complete copyright information.
 */
 
+#include <sysexits.h>
 #include <h/mh.h>
 #include <h/addrsbr.h>
 #include <h/mf.h>
@@ -107,7 +108,7 @@ getm(char *str, char *dfhost, int dftype, int wanthost, char *eresult)
                if (eresult)
                        strcpy(eresult, "insufficient memory to represent address");
                else if (wanthost == AD_HOST)
-                       adios(NULL, "insufficient memory to represent address");
+                       adios(EX_OSERR, NULL, "insufficient memory to represent address");
                return NULL;
        }
 
index 32dd37f..205c8c9 100644 (file)
@@ -7,6 +7,7 @@
 ** complete copyright information.
 */
 
+#include <sysexits.h>
 #include <h/mh.h>
 #include <h/utils.h>
 
@@ -71,5 +72,5 @@ brkstring(char *str, char *brksep, char *brkterm)
                        }
                }
        }
-       adios("brkstring()", "reached unreachable point");
+       adios(EX_SOFTWARE, "brkstring()", "reached unreachable point");
 }
index 166fe59..5886c5e 100644 (file)
@@ -29,6 +29,7 @@
 #include <pwd.h>     /* structure for getpwuid() results */
 #include <unistd.h>
 #include <sys/stat.h>
+#include <sysexits.h>
 
 void
 context_read(void)
@@ -54,7 +55,7 @@ context_read(void)
        */
        if (!(mypath = getenv("HOME"))) {
                if (!(pw = getpwuid(getuid())) || !*pw->pw_dir) {
-                       adios(NULL, "cannot determine your home directory");
+                       adios(EX_OSERR, NULL, "cannot determine your home directory");
                }
                mypath = pw->pw_dir;
        }
@@ -65,12 +66,12 @@ context_read(void)
        if ((cp = getenv("MMH")) && *cp) {
                mmhpath = getcpy(expanddir(cp));  /* rel to cwd */
                if (stat(mmhpath, &st) != -1 && (st.st_mode & S_IFDIR) == 0) {
-                       adios(NULL, "`%s' specified by your MMH environment variable is not a directory", cp);
+                       adios(EX_CONFIG, NULL, "`%s' specified by your MMH environment variable is not a directory", cp);
                }
        } else {
                mmhpath = concat(mypath, "/", mmhdir, NULL);
                if (stat(mmhpath, &st) == -1 || (st.st_mode & S_IFDIR) == 0) {
-                       adios(NULL, "Doesn't look like mmh is set up for your account.  Run `mmh' to do so.");
+                       adios(EX_CONFIG, NULL, "Doesn't look like mmh is set up for your account.  Run `mmh' to do so.");
                }
        }
 
@@ -86,15 +87,15 @@ context_read(void)
                        defpath = concat(mmhpath, "/", cp, NULL);
                }
                if (stat(defpath, &st) != -1 && (st.st_mode & S_IFREG) == 0) {
-                       adios(NULL, "Your profile `%s', specified by the MMHP environment variable, is not a normal file", cp);
+                       adios(EX_CONFIG, NULL, "Your profile `%s', specified by the MMHP environment variable, is not a normal file", cp);
                }
                if ((ib = fopen(defpath, "r")) == (FILE *)0) {
-                       adios(NULL, "Unable to read your profile `%s', specified by the MMHP environment variable", defpath);
+                       adios(EX_IOERR, NULL, "Unable to read your profile `%s', specified by the MMHP environment variable", defpath);
                }
        } else {
                defpath = concat(mmhpath, "/", profile, NULL);
                if ((ib = fopen(defpath, "r")) == (FILE *)0) {
-                       adios(NULL, "No profile found. Please create `%s' first.", defpath);
+                       adios(EX_CONFIG, NULL, "No profile found. Please create `%s' first.", defpath);
                }
                cp = profile;
        }
@@ -107,10 +108,10 @@ context_read(void)
        ** to an absolute one rooted in the home directory.
        */
        if ((cp = context_find("path")) == NULL) {
-               adios(NULL, "Your profile `%s' does not contain the required path entry.", defpath);
+               adios(EX_CONFIG, NULL, "Your profile `%s' does not contain the required path entry.", defpath);
        }
        if (!*cp) {
-               adios(NULL, "The Path entry of your profile `%s' must be non-empty.", defpath);
+               adios(EX_CONFIG, NULL, "The Path entry of your profile `%s' must be non-empty.", defpath);
        }
        if (*cp == '/') {
                nd = cp;
@@ -119,18 +120,18 @@ context_read(void)
        }
        if (stat(nd, &st) == -1) {
                if (errno != ENOENT) {
-                       adios(nd, "error opening");
+                       adios(EX_IOERR, nd, "error opening");
                }
                cp = concat("Your mail storage directory `", nd, "' doesn't exist; Create it? ", NULL);
                if (!getanswer(cp)) {
-                       adios(NULL, "Unable to access the mail storage directory `%s'", nd);
+                       adios(EX_NOPERM, NULL, "Unable to access the mail storage directory `%s'", nd);
                }
                free(cp);
                if (!makedir(nd)) {
-                       adios(nd, "unable to create");
+                       adios(EX_CANTCREAT, nd, "unable to create");
                }
        } else if ((st.st_mode & S_IFDIR) == 0) {
-               adios(NULL, "Your mail storage `%s' is not a directory", nd);
+               adios(EX_DATAERR, NULL, "Your mail storage `%s' is not a directory", nd);
        }
        /*
        ** Create the default folder (inbox)
@@ -138,10 +139,10 @@ context_read(void)
        cp = toabsdir(defaultfolder);
        if (stat(cp, &st) == -1) {
                if (!makedir(cp)) {
-                       adios(cp, "Unable to create the default folder");
+                       adios(EX_CANTCREAT, cp, "Unable to create the default folder");
                }
        } else if ((st.st_mode & S_IFDIR) == 0) {
-               adios(NULL, "The default folder `%s' is not a directory", cp);
+               adios(EX_DATAERR, NULL, "The default folder `%s' is not a directory", cp);
        }
 
        /*
index ac0dbfd..10d4d42 100644 (file)
@@ -12,6 +12,7 @@
  * because there no longer are setuid/setgid programs in nmh.
  */
 
+#include <sysexits.h>
 #include <h/mh.h>
 #include <h/signals.h>
 
@@ -39,7 +40,7 @@ context_save(void)
        sigprocmask(SIG_BLOCK, &set, &oset);
 
        if (!(out = lkfopen(ctxpath, "w")))
-               adios(ctxpath, "unable to write");
+               adios(EX_IOERR, ctxpath, "unable to write");
        for (np = m_defs; np; np = np->n_next)
                if (np->n_context)
                        fprintf(out, "%s: %s\n", np->n_name, np->n_field);
index 6fa21f7..9cd8d38 100644 (file)
@@ -6,6 +6,7 @@
 ** complete copyright information.
 */
 
+#include <sysexits.h>
 #include <unistd.h>
 #include <h/mh.h>
 
@@ -17,9 +18,9 @@ cpydata(int in, int out, char *ifile, char *ofile)
 
        while ((i = read(in, buffer, sizeof(buffer))) > 0) {
                if (write(out, buffer, i) != i)
-                       adios(ofile, "error writing");
+                       adios(EX_IOERR, ofile, "error writing");
        }
 
        if (i == -1)
-               adios(ifile, "error reading");
+               adios(EX_IOERR, ifile, "error reading");
 }
index a9e5bc6..090cd71 100644 (file)
@@ -7,6 +7,7 @@
 ** complete copyright information.
 */
 
+#include <sysexits.h>
 #include <unistd.h>
 #include <h/mh.h>
 
@@ -27,7 +28,7 @@
 
 #define output(c)  if (bp >= dp) {flush(); *bp++ = c;} else *bp++ = c
 #define flush()  if ((j = bp - outbuf) && write(out, outbuf, j) != j) \
-               adios(ofile, "error writing"); \
+               adios(EX_IOERR, ofile, "error writing"); \
        else \
                bp = outbuf
 
@@ -62,6 +63,6 @@ cpydgst(int in, int out, char *ifile, char *ofile)
                }
 
        if (i == -1)
-               adios(ifile, "error reading");
+               adios(EX_IOERR, ifile, "error reading");
        flush();
 }
index 28f3255..1841ce4 100644 (file)
@@ -29,14 +29,14 @@ advise(char *what, char *fmt, ...)
 ** print out error message and exit
 */
 void
-adios(char *what, char *fmt, ...)
+adios(int status, char *what, char *fmt, ...)
 {
        va_list ap;
 
        va_start(ap, fmt);
        advertise(what, NULL, fmt, ap);
        va_end(ap);
-       exit(1);
+       exit(status);
 }
 
 
index 28ef810..c10421d 100644 (file)
@@ -6,6 +6,7 @@
 #include <h/mh.h>
 #include <unistd.h>
 #include <stdarg.h>
+#include <sysexits.h>
 
 
 int
@@ -25,7 +26,7 @@ execprog(char *cmd, char **arg)
                execvp(cmd, arg);
                fprintf(stderr, "unable to exec ");
                perror(cmd);
-               _exit(-1);
+               _exit(EX_OSERR);
 
        default:
                /* parent */
index d299efc..ce35de9 100644 (file)
@@ -44,6 +44,7 @@
 #include <h/fmt_scan.h>
 #include <h/fmt_compile.h>
 #include <ctype.h>
+#include <sysexits.h>
 
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
@@ -291,7 +292,7 @@ compile_error(char *str, char *cp)
 
        advise(NULL, "\"%s\": format compile error - %s",
                        &usr_fstring[errpos-errctx], str);
-       adios(NULL, "%*s", errctx+1, "^");
+       adios(EX_SOFTWARE, NULL, "%*s", errctx+1, "^");
 }
 
 /*
@@ -329,7 +330,7 @@ fmt_compile(char *fstring, struct format **fmt)
        next_fp = formatvec = (struct format *)calloc((size_t) i,
                sizeof(struct format));
        if (next_fp == NULL)
-               adios(NULL, "unable to allocate format storage");
+               adios(EX_OSERR, NULL, "unable to allocate format storage");
 
        ncomp = 0;
        infunction = 0;
index e71b8d0..8ddd3c1 100644 (file)
@@ -10,6 +10,7 @@
 #include <h/utils.h>
 #include <unistd.h>
 #include <sys/stat.h>
+#include <sysexits.h>
 
 static char *formats = NULL;
 
@@ -37,14 +38,14 @@ new_fs(char *form, char *def_form)
                        formats = getcpy(form+1);
                } else {
                        if ((fp = fopen(etcpath(form), "r")) == NULL) {
-                               adios(form, "unable to open format file");
+                               adios(EX_IOERR, form, "unable to open format file");
                        }
                        if (fstat(fileno(fp), &st) == -1) {
-                               adios(form, "unable to stat format file");
+                               adios(EX_IOERR, form, "unable to stat format file");
                        }
                        formats = mh_xmalloc((size_t) st.st_size + 1);
                        if (read(fileno(fp), formats, (int)st.st_size) != st.st_size) {
-                               adios(form, "error reading format file");
+                               adios(EX_IOERR, form, "error reading format file");
                        }
                        formats[st.st_size] = '\0';
                        fclose(fp);
@@ -54,14 +55,14 @@ new_fs(char *form, char *def_form)
                        formats = getcpy(def_form+1);
                } else {
                        if ((fp = fopen(etcpath(def_form), "r")) == NULL) {
-                               adios(def_form, "unable to open format file");
+                               adios(EX_IOERR, def_form, "unable to open format file");
                        }
                        if (fstat(fileno(fp), &st) == -1) {
-                               adios(def_form, "unable to stat format file");
+                               adios(EX_IOERR, def_form, "unable to stat format file");
                        }
                        formats = mh_xmalloc((size_t) st.st_size + 1);
                        if (read(fileno(fp), formats, (int)st.st_size) != st.st_size) {
-                               adios(def_form, "error reading format file");
+                               adios(EX_IOERR, def_form, "error reading format file");
                        }
                        formats[st.st_size] = '\0';
                        fclose(fp);
index 0616d17..a8e773a 100644 (file)
@@ -15,6 +15,7 @@
 #include <h/tws.h>
 #include <h/fmt_compile.h>
 #include <ctype.h>
+#include <sysexits.h>
 
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
@@ -323,7 +324,7 @@ fmt_scan(struct format *format, char *scanl, int width, int *dat)
                        cptrimmed(&cp, str, fmt->f_width, fmt->f_fill, ep - cp);
                        break;
                case FT_STRFW:
-                       adios(NULL, "internal error (FT_STRFW)");
+                       adios(EX_SOFTWARE, NULL, "internal error (FT_STRFW)");
 
                case FT_NUM:
                        n = snprintf(cp, ep - cp + 1, "%d", value);
@@ -775,7 +776,7 @@ fmt_scan(struct format *format, char *scanl, int width, int *dat)
                        indent = strlen(sp);
                        wid -= indent;
                        if (wid <= 0) {
-                               adios(NULL, "putaddr -- num register (%d) "
+                               adios(EX_SOFTWARE, NULL, "putaddr -- num register (%d) "
                                                "must be greater than label "
                                                "width (%d)", value, indent);
                        }
index 0ecf382..8e5fd0a 100644 (file)
@@ -6,6 +6,7 @@
 ** complete copyright information.
 */
 
+#include <sysexits.h>
 #include <unistd.h>
 #include <h/mh.h>
 
@@ -51,7 +52,7 @@ folder_delmsgs(struct msgs *mp, int hook)
 
        /* Sanity check */
        if (mp->numsel != 0)
-               adios(NULL, "oops, mp->numsel should be 0");
+               adios(EX_SOFTWARE, NULL, "oops, mp->numsel should be 0");
 
        /* Mark that the sequence information has changed */
        mp->msgflags |= SEQMOD;
index 8b0d67d..47b9281 100644 (file)
@@ -6,6 +6,7 @@
 ** complete copyright information.
 */
 
+#include <sysexits.h>
 #include <h/mh.h>
 #include <h/utils.h>
 
@@ -24,14 +25,14 @@ folder_realloc(struct msgs *mp, int lo, int hi)
 
        /* sanity checks */
        if (lo < 1)
-               adios(NULL, "BUG: called folder_realloc with lo (%d) < 1", lo);
+               adios(EX_SOFTWARE, NULL, "BUG: called folder_realloc with lo (%d) < 1", lo);
        if (hi < 1)
-               adios(NULL, "BUG: called folder_realloc with hi (%d) < 1", hi);
+               adios(EX_SOFTWARE, NULL, "BUG: called folder_realloc with hi (%d) < 1", hi);
        if (mp->nummsg > 0 && lo > mp->lowmsg)
-               adios(NULL, "BUG: called folder_realloc with lo (%d) > mp->lowmsg (%d)",
+               adios(EX_SOFTWARE, NULL, "BUG: called folder_realloc with lo (%d) > mp->lowmsg (%d)",
                                lo, mp->lowmsg);
        if (mp->nummsg > 0 && hi < mp->hghmsg)
-               adios(NULL, "BUG: called folder_realloc with hi (%d) < mp->hghmsg (%d)",
+               adios(EX_SOFTWARE, NULL, "BUG: called folder_realloc with hi (%d) < mp->hghmsg (%d)",
                                hi, mp->hghmsg);
 
        /* Check if we really need to reallocate anything */
index e97dd1e..b3659f9 100644 (file)
@@ -9,6 +9,7 @@
 #include <h/mh.h>
 #include <h/utils.h>
 #include <errno.h>
+#include <sysexits.h>
 
 
 /*
@@ -25,7 +26,7 @@ m_draft(char *which)
        folder = getcpy(toabsdir(draftfolder));
        create_folder(folder, 0, exit);
        if (!(mp = folder_read(folder))) {
-               adios(NULL, "unable to read folder %s", folder);
+               adios(EX_IOERR, NULL, "unable to read folder %s", folder);
        }
        free(folder);
 
@@ -37,10 +38,10 @@ m_draft(char *which)
        */
        if (mp->hghmsg >= mp->hghoff) {
                if (!(mp = folder_realloc(mp, 1, mp->hghmsg + 10)))
-                       adios(NULL, "unable to allocate folder storage");
+                       adios(EX_OSERR, NULL, "unable to allocate folder storage");
        } else if (mp->lowoff > 1) {
                if (!(mp = folder_realloc(mp, 1, mp->hghoff)))
-                       adios(NULL, "unable to allocate folder storage");
+                       adios(EX_OSERR, NULL, "unable to allocate folder storage");
        }
 
        mp->msgflags |= ALLOW_BEYOND;  /* allow the beyond sequence */
@@ -51,7 +52,7 @@ m_draft(char *which)
        ** (to start a new draft).
        */
        if (!m_convert(mp, which))
-               exit(1);
+               exit(EX_SOFTWARE);
        seq_setprev(mp);
 
        snprintf(buffer, sizeof(buffer), "%s/%s", mp->foldpath,
index a3852fe..12d05b9 100644 (file)
@@ -9,6 +9,7 @@
 #include <h/mh.h>
 #include <h/utils.h>
 #include <ctype.h>
+#include <sysexits.h>
 
 /*
 ** This module has a long and checkered history.
@@ -563,7 +564,7 @@ m_getfld(int state, unsigned char *name, unsigned char *buf,
                break;
 
        default:
-               adios(NULL, "m_getfld() called with bogus state of %d", state);
+               adios(EX_SOFTWARE, NULL, "m_getfld() called with bogus state of %d", state);
        }
 finish:
        *cp = 0;
@@ -599,10 +600,10 @@ thisisanmbox(FILE *iob)
        */
 
        if (fread(text, sizeof(*text), 5, iob) != 5) {
-               adios(NULL, "Read error");
+               adios(EX_IOERR, NULL, "Read error");
        }
        if (strncmp(text, "From ", 5)!=0) {
-               adios(NULL, "No Unix style (mbox) maildrop.");
+               adios(EX_USAGE, NULL, "No Unix style (mbox) maildrop.");
        }
        ismbox = TRUE;
        delimstr = "\nFrom ";
@@ -620,7 +621,7 @@ thisisanmbox(FILE *iob)
        strcpy(msg_delim, delimstr);
        delimend = (unsigned char *)msg_delim + edelimlen;
        if (edelimlen <= 1)
-               adios(NULL, "maildrop delimiter must be at least 2 bytes");
+               adios(EX_DATAERR, NULL, "maildrop delimiter must be at least 2 bytes");
        /*
        ** build a Boyer-Moore end-position map for the matcher in m_getfld.
        ** N.B. - we don't match just the first char (since it's the newline
index 90d3a27..f95a758 100644 (file)
@@ -6,6 +6,7 @@
 ** complete copyright information.
 */
 
+#include <sysexits.h>
 #include <h/mh.h>
 #include <pwd.h>
 #include <unistd.h>
@@ -285,7 +286,7 @@ toabsdir(char *path)
                char *cp=buf, *pp;
 
                if (!(pp = context_find("path")) || !*pp) {
-                       adios(NULL, "Non-empty profile entry `Path' required");
+                       adios(EX_CONFIG, NULL, "Non-empty profile entry `Path' required");
                }
                if (*pp != '/') {
                        /* Path is relative to $HOME */
index d93d04b..171ecf8 100644 (file)
@@ -7,6 +7,7 @@
 ** complete copyright information.
 */
 
+#include <sysexits.h>
 #include <h/mh.h>
 #include <h/utils.h>
 
@@ -86,14 +87,14 @@ readconfig(struct node **npp, FILE *ib, char *file, int ctx)
 
                case BODY:
                case BODYEOF:
-                       adios(NULL, "no blank lines are permitted in %s",
+                       adios(EX_CONFIG, NULL, "no blank lines are permitted in %s",
                                        file);
 
                case FILEEOF:
                        break;
 
                default:
-                       adios(NULL, "%s is poorly formatted", file);
+                       adios(EX_CONFIG, NULL, "%s is poorly formatted", file);
                }
                break;
        }
index 40b8474..eb483b7 100644 (file)
@@ -4,13 +4,14 @@
 ** (These functions had once been macros in h/mh.h)
 */
 
+#include <sysexits.h>
 #include <h/mh.h>
 
 static void
 assert_msg_range(struct msgs *mp, int msgnum)
 {
        if (msgnum < mp->lowoff || msgnum > mp->hghoff) {
-               adios(NULL, "Bug: message out of bounds");
+               adios(EX_SOFTWARE, NULL, "Bug: message out of bounds");
        }
 }
 
index bfecaf0..ff01c42 100644 (file)
@@ -7,6 +7,7 @@
 ** complete copyright information.
 */
 
+#include <sysexits.h>
 #include <h/mh.h>
 #include <h/utils.h>
 
@@ -97,7 +98,7 @@ seq_public(struct msgs *mp)
 
                case BODY:
                case BODYEOF:
-                       adios(NULL, "no blank lines are permitted in %s",
+                       adios(EX_CONFIG, NULL, "no blank lines are permitted in %s",
                                        seqfile);
                        /* fall */
 
@@ -105,7 +106,7 @@ seq_public(struct msgs *mp)
                        break;
 
                default:
-                       adios(NULL, "%s is poorly formatted", seqfile);
+                       adios(EX_CONFIG, NULL, "%s is poorly formatted", seqfile);
                }
                break;  /* break from for loop */
        }
index 1a9093d..f23e1d0 100644 (file)
@@ -13,6 +13,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <sys/stat.h>
+#include <sysexits.h>
 
 /*
 ** We allocate space for messages (msgs array)
@@ -29,11 +30,11 @@ mh_xmalloc(size_t size)
        void *memory;
 
        if (size == 0)
-               adios(NULL, "Tried to malloc 0 bytes");
+               adios(EX_SOFTWARE, NULL, "Tried to malloc 0 bytes");
 
        memory = malloc(size);
        if (!memory)
-               adios(NULL, "Malloc failed");
+               adios(EX_OSERR, NULL, "Malloc failed");
 
        return memory;
 }
@@ -52,11 +53,11 @@ mh_xrealloc(void *ptr, size_t size)
        }
 
        if (size == 0)
-               adios(NULL, "Tried to realloc 0 bytes");
+               adios(EX_SOFTWARE, NULL, "Tried to realloc 0 bytes");
 
        memory = realloc(ptr, size);
        if (!memory)
-               adios(NULL, "Realloc failed");
+               adios(EX_OSERR, NULL, "Realloc failed");
 
        return memory;
 }
@@ -141,19 +142,19 @@ create_folder(char *folder, int autocreate, void (*done_callback)(int))
 
        if (stat(folder, &st) == -1) {
                if (errno != ENOENT)
-                       adios(folder, "error on folder");
+                       adios(EX_IOERR, folder, "error on folder");
                if (autocreate == 0) {
                        /* ask before creating folder */
                        cp = concat("Create folder \"", folder, "\"? ", NULL);
                        if (!getanswer(cp))
-                               done_callback(1);
+                               done_callback(EX_CANTCREAT);
                        free(cp);
                } else if (autocreate == -1) {
                        /* do not create, so exit */
-                       done_callback(1);
+                       done_callback(EX_CANTCREAT);
                }
                if (!makedir(folder))
-                       adios(NULL, "unable to create folder %s", folder);
+                       adios(EX_CANTCREAT, NULL, "unable to create folder %s", folder);
        }
 }
 
@@ -168,7 +169,7 @@ num_digits(int n)
 
        /* Sanity check */
        if (n < 0)
-               adios(NULL, "oops, num_digits called with negative value");
+               adios(EX_SOFTWARE, NULL, "oops, num_digits called with negative value");
 
        if (n == 0)
                return 1;
index bd01a2c..3e71ad0 100644 (file)
@@ -6,6 +6,7 @@
 ** complete copyright information.
 */
 
+#include <sysexits.h>
 #include <h/mh.h>
 #include <h/utils.h>
 
@@ -35,7 +36,7 @@ vfgets(FILE *in, char **bp)
                if ((dp = cp + strlen(cp) - 2) < cp || *dp != QUOTE) {
 wrong_guess:
                        if (cp > ++dp)
-                               adios(NULL, "vfgets() botch -- you lose big");
+                               adios(EX_SOFTWARE, NULL, "vfgets() botch -- you lose big");
                        if (*dp == '\n') {
                                *bp = pp;
                                return 0;
index e7bc90f..c6b028c 100644 (file)
--- a/uip/ali.c
+++ b/uip/ali.c
@@ -11,6 +11,7 @@
 #include <h/aliasbr.h>
 #include <h/utils.h>
 #include <locale.h>
+#include <sysexits.h>
 
 /*
 ** maximum number of names
@@ -73,25 +74,25 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               /* sysexits.h EX_USAGE */
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [switches] aliases ...",
                                        invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case FILESW:
-                               if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s", argp[-2]);
+                               if (!(cp = *argp++) || *cp == '-') {
+                                       adios(EX_USAGE, NULL, "missing argument to %s", argp[-2]);
+                               }
                                if ((i = alias(cp)) != AK_OK)
-                                       adios(NULL, "aliasing error in %s: %s", cp, akerror(i));
+                                       adios(EX_USAGE, NULL, "aliasing error in %s: %s", cp, akerror(i));
                                deffiles = 0;
                                continue;
 
@@ -127,7 +128,7 @@ main(int argc, char **argv)
                for (ap = brkstring(dp=getcpy(cp), " ", "\n");
                                ap && *ap; ap++) {
                        if ((i = alias(etcpath(*ap))) != AK_OK) {
-                               adios(NULL, "aliasing error in %s: %s",
+                               adios(EX_DATAERR, NULL, "aliasing error in %s: %s",
                                                *ap, akerror(i));
                        }
                }
@@ -141,13 +142,13 @@ main(int argc, char **argv)
        */
        if (inverted) {
                if (vecp == 0)
-                       adios(NULL, "usage: %s -user addresses ...  (you forgot the addresses)",
+                       adios(EX_USAGE, NULL, "usage: %s -user addresses ...  (you forgot the addresses)",
                                   invo_name);
 
                for (i = 0; i < vecp; i++)
                        print_usr(vec[i], list, normalize);
 
-               exit(0);
+               exit(EX_OK);
        }
 
        if (vecp) {
@@ -163,7 +164,7 @@ main(int argc, char **argv)
                }
        }
 
-       return 0;
+       return EX_OK;
 }
 
 static void
@@ -214,9 +215,9 @@ print_usr(char *s, int list, int norm)
        register struct mailname *mp, *np;
 
        if ((pp = getname(s)) == NULL)
-               adios(NULL, "no address in \"%s\"", s);
+               adios(EX_DATAERR, NULL, "no address in \"%s\"", s);
        if ((mp = getm(pp, NULL, 0, norm, NULL)) == NULL)
-               adios(NULL, "bad address \"%s\"", s);
+               adios(EX_DATAERR, NULL, "bad address \"%s\"", s);
        while (getname(""))
                continue;
 
index 7a65a7f..1c97179 100644 (file)
@@ -21,6 +21,7 @@
 #include <ctype.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static enum { MODE_ADD, MODE_DEL, MODE_LIST } mode = MODE_ADD;
 
@@ -90,20 +91,19 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               /* sysexits.h EX_USAGE */
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf),
                                        "%s [+folder] [msgs] [switches]",
                                        invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case DELETESW:  /* delete annotations */
                                mode = MODE_DEL;
@@ -115,23 +115,23 @@ main(int argc, char **argv)
 
                        case COMPSW:
                                if (comp)
-                                       adios(NULL, "only one component at a time!");
+                                       adios(EX_USAGE, NULL, "only one component at a time!");
                                if (!(comp = *argp++) || *comp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
                        case TEXTSW:
                                if (text)
-                                       adios(NULL, "only one body at a time!");
+                                       adios(EX_USAGE, NULL, "only one body at a time!");
                                if (!(text = *argp++) || *text == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
                        case NUMBERSW: /* number listing or delete by number */
                                if (mode == MODE_ADD) {
-                                       adios(NULL, "-number switch must appear after -list or -delete, only.");
+                                       adios(EX_USAGE, NULL, "-number switch must appear after -list or -delete, only.");
                                }
                                if (mode == MODE_LIST) {
                                        number = 1;
@@ -139,7 +139,7 @@ main(int argc, char **argv)
                                }
                                /* MODE_DEL */
                                if (number) {
-                                       adios(NULL, "only one number at a time!");
+                                       adios(EX_USAGE, NULL, "only one number at a time!");
                                }
                                if (*argp && strcmp(*argp, "all")==0) {
                                        number = -1;
@@ -147,11 +147,11 @@ main(int argc, char **argv)
                                        continue;
                                }
                                if (!*argp || !(number = atoi(*argp))) {
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-1]);
                                }
                                if (number < 0) {
-                                       adios(NULL, "invalid number (%d).",
+                                       adios(EX_USAGE, NULL, "invalid number (%d).",
                                                        number);
                                }
                                argp++;
@@ -179,12 +179,12 @@ main(int argc, char **argv)
                }
                if (*cp == '+' || *cp == '@') {
                        if (folder)
-                               adios(NULL, "only one folder at a time!");
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
                        else
                                folder = getcpy(expandfol(cp));
                } else if (*cp == '/' || *cp == '.') {
                        if (file)
-                               adios(NULL, "only one file at a time!");
+                               adios(EX_USAGE, NULL, "only one file at a time!");
                        file = cp;
                } else {
                        app_msgarg(&msgs, cp);
@@ -192,13 +192,13 @@ main(int argc, char **argv)
        }
 
        if (file && (folder || msgs.size)) {
-               adios(NULL, "Don't intermix files and messages.");
+               adios(EX_USAGE, NULL, "Don't intermix files and messages.");
        }
        if (!datesw && !text) {
-               adios(NULL, "-nodate without -text is a no-op.");
+               adios(EX_USAGE, NULL, "-nodate without -text is a no-op.");
        }
        if (number && text) {
-               adios(NULL, "Don't combine -number with -text.");
+               adios(EX_USAGE, NULL, "Don't combine -number with -text.");
        }
 
        if (file) {
@@ -207,7 +207,7 @@ main(int argc, char **argv)
                else
                        annotate(file, comp, text, datesw, number,
                                        append, preserve);
-               exit(0);
+               exit(EX_OK);
        }
 
        if (!msgs.size)
@@ -217,21 +217,20 @@ main(int argc, char **argv)
        maildir = toabsdir(folder);
 
        if (chdir(maildir) == NOTOK)
-               adios(maildir, "unable to change directory to");
+               adios(EX_OSERR, maildir, "unable to change directory to");
 
        /* read folder and create message structure */
        if (!(mp = folder_read(folder)))
-               adios(NULL, "unable to read folder %s", folder);
+               adios(EX_IOERR, NULL, "unable to read folder %s", folder);
 
        /* check for empty folder */
        if (mp->nummsg == 0)
-               adios(NULL, "no messages in %s", folder);
+               adios(EX_DATAERR, NULL, "no messages in %s", folder);
 
        /* parse all the message ranges/sequences and set SELECTED */
        for (msgnum = 0; msgnum < msgs.size; msgnum++) {
                if (!m_convert(mp, msgs.msgs[msgnum])) {
-                       /* sysexits.h EX_USAGE */
-                       exit(1);
+                       exit(EX_SOFTWARE);
                }
        }
 
@@ -265,8 +264,7 @@ make_comp(unsigned char **ap)
                fflush(stdout);
 
                if (!fgets(buffer, sizeof buffer, stdin)) {
-                       /* sysexits.h EX_IOERR */
-                       exit(1);
+                       exit(EX_IOERR);
                }
                *ap = trimcpy(buffer);
        }
@@ -274,15 +272,15 @@ make_comp(unsigned char **ap)
        if ((cp = *ap + strlen(*ap) - 1) > *ap && *cp == ':')
                *cp = '\0';
        if (strlen(*ap) == 0)
-               adios(NULL, "null component name");
+               adios(EX_SOFTWARE, NULL, "null component name");
        if (**ap == '-')
-               adios(NULL, "invalid component name %s", *ap);
+               adios(EX_CONFIG, NULL, "invalid component name %s", *ap);
        if (strlen(*ap) >= NAMESZ)
-               adios(NULL, "too large component name %s", *ap);
+               adios(EX_SOFTWARE, NULL, "too large component name %s", *ap);
 
        for (cp = *ap; *cp; cp++)
                if (!isalnum(*cp) && *cp != '-')
-                       adios(NULL, "invalid component name %s", *ap);
+                       adios(EX_CONFIG, NULL, "invalid component name %s", *ap);
 }
 
 
@@ -303,7 +301,7 @@ annolist(char *file, unsigned char *comp, int number)
        int n;  /* number of bytes written */
 
        if ((fp = fopen(file, "r")) == NULL) {
-               adios(file, "unable to open");
+               adios(EX_IOERR, file, "unable to open");
        }
 
        /* We'll grow this buffer as needed. */
@@ -402,7 +400,7 @@ annotate(char *file, unsigned char *comp, char *text, int datesw,
        fclose(tmp);
 
        if ((tmpfd = open(tmpfil, O_RDONLY)) == NOTOK) {
-               adios(tmpfil, "unable to open for re-reading");
+               adios(EX_IOERR, tmpfil, "unable to open for re-reading");
        }
        lseek(fd, (off_t) 0, SEEK_SET);
 
@@ -411,7 +409,7 @@ annotate(char *file, unsigned char *comp, char *text, int datesw,
        **  so the file has to be truncated or it will contain garbage.
        */
        if (mode == MODE_DEL && ftruncate(fd, 0) == -1) {
-               adios(tmpfil, "unable to truncate.");
+               adios(EX_IOERR, tmpfil, "unable to truncate.");
        }
        cpydata(tmpfd, fd, tmpfil, file);
        close(tmpfd);
@@ -459,7 +457,7 @@ dodel(int fd, unsigned char *comp, char *text, FILE *tmp, int number)
        ** This buffer is grown as needed later.
        */
        if ((fp = fdopen(fd, "r")) == NULL) {
-               adios(NULL, "unable to fdopen file.");
+               adios(EX_IOERR, NULL, "unable to fdopen file.");
        }
        field = (char *)mh_xmalloc(field_size);
 
@@ -541,7 +539,7 @@ dodel(int fd, unsigned char *comp, char *text, FILE *tmp, int number)
                /* Copy it. */
                if ((n = fputs(field, tmp)) == EOF ||
                                (c=='\n' && fputc('\n', tmp)==EOF)) {
-                       adios(NULL, "unable to write temporary file.");
+                       adios(EX_CANTCREAT, NULL, "unable to write temporary file.");
                }
 
        } while (*field && *field != '-');
@@ -558,7 +556,7 @@ dodel(int fd, unsigned char *comp, char *text, FILE *tmp, int number)
        ** not the pointer.
        */
        if (lseek(fd, (off_t)ftell(fp), SEEK_SET) == (off_t)-1) {
-               adios(NULL, "can't seek.");
+               adios(EX_IOERR, NULL, "can't seek.");
        }
 }
 
@@ -582,7 +580,7 @@ doadd(int fd, unsigned char *comp, char *text, FILE *tmp, int datesw,
                ** read in.  This buffer is grown as needed later.
                */
                if ((fp = fdopen(fd, "r")) == NULL) {
-                       adios(NULL, "unable to fdopen file.");
+                       adios(EX_IOERR, NULL, "unable to fdopen file.");
                }
                /* Find the end of the headers. */
                if ((c = getc(fp)) == '\n') {
@@ -640,7 +638,7 @@ doadd(int fd, unsigned char *comp, char *text, FILE *tmp, int datesw,
        */
        if (append) {
                if (lseek(fd, (off_t)ftell(fp), SEEK_SET) == (off_t)-1) {
-                       adios(NULL, "can't seek.");
+                       adios(EX_IOERR, NULL, "can't seek.");
                }
        }
 }
index a74eb96..af97e9e 100644 (file)
--- a/uip/ap.c
+++ b/uip/ap.c
@@ -10,6 +10,7 @@
 #include <h/addrsbr.h>
 #include <h/fmt_scan.h>
 #include <locale.h>
+#include <sysexits.h>
 
 #define NADDRS 100
 
@@ -62,23 +63,22 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               /* sysexits.h EX_USAGE */
-                               exit(1);
+                               exit(EX_USAGE);
 
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [switches] addrs ...", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case FORMSW:
                                if (!(form = *argp++) || *form == '-')
-                                       adios(NULL, "missing argument to %s", argp[-2]);
+                                       adios(EX_USAGE, NULL, "missing argument to %s", argp[-2]);
                                continue;
 
                        case NORMSW:
@@ -90,14 +90,14 @@ main(int argc, char **argv)
                        }
                }
                if (addrp > NADDRS)
-                       adios(NULL, "more than %d addresses", NADDRS);
+                       adios(EX_USAGE, NULL, "more than %d addresses", NADDRS);
                else
                        addrs[addrp++] = cp;
        }
        addrs[addrp] = NULL;
 
        if (addrp == 0)
-               adios(NULL, "usage: %s [switches] addrs ...", invo_name);
+               adios(EX_USAGE, NULL, "usage: %s [switches] addrs ...", invo_name);
 
        /* get new format string */
        fmtstr = new_fs(form, FORMAT);
@@ -114,8 +114,7 @@ main(int argc, char **argv)
        for (addrp = 0; addrs[addrp]; addrp++)
                status += process(addrs[addrp], normalize);
 
-       exit(status);
-       return 1;
+       return status;
 }
 
 struct pqpair {
@@ -140,7 +139,7 @@ process(char *arg, int norm)
        while ((cp = getname(arg))) {
                if ((p = (struct pqpair *)
                                calloc((size_t) 1, sizeof(*p))) == NULL)
-                       adios(NULL, "unable to allocate pqpair memory");
+                       adios(EX_OSERR, NULL, "unable to allocate pqpair memory");
                if ((mp = getm(cp, NULL, 0, norm, error)) == NULL) {
                        p->pq_text = getcpy(cp);
                        p->pq_error = getcpy(error);
index 21b218b..37dc9b1 100644 (file)
@@ -10,6 +10,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define VERBSW 0
@@ -62,18 +63,17 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               /* sysexits.h EX_USAGE */
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown\n", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown\n", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case VERBSW:
                                verbosw++;
@@ -85,7 +85,7 @@ main(int argc, char **argv)
                }
                if (*cp == '+' || *cp == '@') {
                        if (folder)
-                               adios(NULL, "only one folder at a time!");
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
                        else
                                folder = getcpy(expandfol(cp));
                } else {
@@ -100,27 +100,26 @@ main(int argc, char **argv)
        maildir = toabsdir(folder);
 
        if (chdir(maildir) == NOTOK)
-               adios(maildir, "unable to change directory to");
+               adios(EX_SOFTWARE, maildir, "unable to change directory to");
 
        /* read folder and create message structure */
        if (!(mp = folder_read(folder)))
-               adios(NULL, "unable to read folder %s", folder);
+               adios(EX_IOERR, NULL, "unable to read folder %s", folder);
 
        /* check for empty folder */
        if (mp->nummsg == 0)
-               adios(NULL, "no messages in %s", folder);
+               adios(EX_DATAERR, 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]))
-                       /* sysexits.h EX_USAGE */
-                       exit(1);
+                       exit(EX_SOFTWARE);
        seq_setprev(mp);  /* set the previous-sequence */
 
        smsgs = (struct smsg *)
                calloc((size_t) (MAXFOLDER + 2), sizeof(*smsgs));
        if (smsgs == NULL)
-               adios(NULL, "unable to allocate burst storage");
+               adios(EX_OSERR, NULL, "unable to allocate burst storage");
 
        hi = mp->hghmsg + 1;
 
@@ -134,7 +133,7 @@ main(int argc, char **argv)
                        } else if (numburst == 0) {
                                admonish(NULL, "message %d not in digest format", msgnum);
                        } else {
-                               adios(NULL, "burst() botch -- you lose big");
+                               adios(EX_SOFTWARE, NULL, "burst() botch -- you lose big");
                        }
                }
        }
@@ -174,7 +173,7 @@ find_delim(int msgnum, struct smsg *smsgs)
        ld3 = strlen(delim3);
 
        if ((in = fopen(msgnam = m_name(msgnum), "r")) == NULL)
-               adios(msgnam, "unable to read message");
+               adios(EX_IOERR, msgnam, "unable to read message");
 
        for (msgp = 0, pos = 0L; msgp <= MAXFOLDER; msgp++) {
                while (fgets(buffer, sizeof(buffer), in) && buffer[0] == '\n')
@@ -227,7 +226,7 @@ burst(struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst,
        struct msgs *mp;
 
        if ((in = fopen(msgnam = m_name(msgnum), "r")) == NULL)
-               adios(msgnam, "unable to read message");
+               adios(EX_IOERR, msgnam, "unable to read message");
 
        mode = fstat(fileno(in), &st) != NOTOK ?
                        (int)(st.st_mode & 0777) : m_gmprot();
@@ -239,7 +238,7 @@ burst(struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst,
        */
        if ((mp->hghmsg + numburst > mp->hghoff) && !(mp = folder_realloc(mp,
                        mp->lowoff, mp->hghmsg + numburst)))
-               adios(NULL, "unable to allocate folder storage");
+               adios(EX_OSERR, NULL, "unable to allocate folder storage");
        *mpp = mp;
 
        /*
@@ -251,7 +250,7 @@ burst(struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst,
        for (j=1, i=mp->hghmsg+1; j<=numburst; j++, i++) {
                snprintf(destfil, sizeof destfil, "%s/%d", maildir, i);
                if (!(out = fopen(destfil, "w"))) {
-                       adios(destfil, "unable to open");
+                       adios(EX_IOERR, destfil, "unable to open");
                }
                if (verbosw) {
                        printf("message %d of digest %d becomes message %d\n",
@@ -331,7 +330,7 @@ cpybrst(FILE *in, FILE *out, char *ifile, char *ofile, int len)
        }
 
        if (ferror(in) && !feof(in))
-               adios(ifile, "error reading");
+               adios(EX_IOERR, ifile, "error reading");
        if (ferror(out))
-               adios(ofile, "error writing");
+               adios(EX_IOERR, ofile, "error writing");
 }
index 62e4cd2..159d7e7 100644 (file)
@@ -11,6 +11,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define EDITRSW  0
@@ -57,32 +58,34 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               /* sysexits.h EX_USAGE */
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] [msg] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case EDITRSW:
-                               if (!(ed = *argp++) || *ed == '-')
-                                       adios(NULL, "missing argument to %s", argp[-2]);
+                               if (!(ed = *argp++) || *ed == '-') {
+                                       adios(EX_USAGE, NULL, "missing argument to %s", argp[-2]);
+                               }
                                continue;
 
                        case WHATSW:
-                               if (!(whatnowproc = *argp++) || *whatnowproc == '-')
-                                       adios(NULL, "missing argument to %s", argp[-2]);
+                               if (!(whatnowproc = *argp++) || *whatnowproc == '-') {
+                                       adios(EX_USAGE, NULL, "missing argument to %s", argp[-2]);
+                               }
                                continue;
 
                        case FORMSW:
-                               if (!(form = *argp++) || *form == '-')
-                                       adios(NULL, "missing argument to %s", argp[-2]);
+                               if (!(form = *argp++) || *form == '-') {
+                                       adios(EX_USAGE, NULL, "missing argument to %s", argp[-2]);
+                               }
                                continue;
 
                        case USESW:
@@ -94,25 +97,29 @@ main(int argc, char **argv)
                        }
                }
                if (*cp == '+' || *cp == '@') {
-                       if (folder)
-                               adios(NULL, "only one folder at a time!");
-                       else
+                       if (folder) {
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
+                       } else {
                                folder = getcpy(expandfol(cp));
+                       }
                } else {
-                       if (msg)
-                               adios(NULL, "only one message at a time!");
-                       else
+                       if (msg) {
+                               adios(EX_USAGE, NULL, "only one message at a time!");
+                       } else {
                                msg = cp;
+                       }
                }
        }
 
        cwd = getcpy(pwd());
 
-       if (form && (folder || msg))
-               adios(NULL, "can't mix forms and folders/msgs");
+       if (form && (folder || msg)) {
+               adios(EX_USAGE, NULL, "can't mix forms and folders/msgs");
+       }
 
-       if (use && folder)
-               adios(NULL, "can't mix -use and +folder");
+       if (use && folder) {
+               adios(EX_USAGE, NULL, "can't mix -use and +folder");
+       }
 
        if (use) {
                /* Don't copy; the draft shall get removed in the end. */
@@ -125,28 +132,33 @@ main(int argc, char **argv)
                if (!folder)
                        folder = getcurfol();
                maildir = toabsdir(folder);
-               if (chdir(maildir) == NOTOK)
-                       adios(maildir, "unable to change directory to");
+               if (chdir(maildir) == NOTOK) {
+                       adios(EX_OSERR, maildir, "unable to change directory to");
+               }
                /* read folder and create message structure */
-               if (!(mp = folder_read(folder)))
-                       adios(NULL, "unable to read folder %s", folder);
+               if (!(mp = folder_read(folder))) {
+                       adios(EX_IOERR, NULL, "unable to read folder %s", folder);
+               }
                /* check for empty folder */
-               if (mp->nummsg == 0)
-                       adios(NULL, "no messages in %s", folder);
+               if (mp->nummsg == 0) {
+                       adios(EX_DATAERR, NULL, "no messages in %s", folder);
+               }
                /* parse the message range/sequence/name and set SELECTED */
-               if (!m_convert(mp, msg))
-                       /* sysexits.h EX_USAGE */
-                       exit(1);
+               if (!m_convert(mp, msg)) {
+                       exit(EX_SOFTWARE);
+               }
                seq_setprev(mp);  /* set the previous-sequence */
-               if (mp->numsel > 1)
-                       adios(NULL, "only one message at a time!");
+               if (mp->numsel > 1) {
+                       adios(EX_USAGE, NULL, "only one message at a time!");
+               }
                if ((in = open(form = getcpy(m_name(mp->lowsel)),
-                               O_RDONLY)) == NOTOK)
-                       adios(form, "unable to open message");
+                               O_RDONLY)) == NOTOK) {
+                       adios(EX_IOERR, form, "unable to open message");
+               }
 
                strncpy(drft, m_draft(seq_beyond), sizeof(drft));
                if ((out = creat(drft, m_gmprot())) == NOTOK) {
-                       adios(drft, "unable to create");
+                       adios(EX_CANTCREAT, drft, "unable to create");
                }
                cpydata(in, out, form, drft);
                close(in);
@@ -156,16 +168,15 @@ main(int argc, char **argv)
                fmtstr = new_fs(form, components);
                strncpy(drft, m_draft(seq_beyond), sizeof(drft));
                if ((out = creat(drft, m_gmprot())) == NOTOK) {
-                       adios(drft, "unable to create");
+               adios(EX_CANTCREAT, drft, "unable to create");
                }
                if (write(out, fmtstr, strlen(fmtstr)) != (int)strlen(fmtstr)) {
-                       adios(drft, "error writing");
+                       adios(EX_IOERR, drft, "error writing");
                }
                close(out);
        }
 
        context_save();
        what_now(ed, use, drft, NULL, 0, NULLMP, NULL, cwd);
-       /* sysexits.h EX_SOFTWARE */
-       return 1;
+       return EX_OSERR;
 }
index 21c6702..0710712 100644 (file)
@@ -11,6 +11,7 @@
 #include <fcntl.h>
 #include <unistd.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define ANNOSW  0
@@ -57,18 +58,18 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               /* sysexits.h EX_USAGE*/
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] [msg] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
+
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case ANNOSW:
                                anot++;
@@ -79,76 +80,88 @@ main(int argc, char **argv)
 
                        case EDITRSW:
                                if (!(ed = *argp++) || *ed == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
                        case WHATSW:
-                               if (!(whatnowproc = *argp++) || *whatnowproc == '-')
-                                       adios(NULL, "missing argument to %s",
+                               if (!(whatnowproc = *argp++) || *whatnowproc == '-') {
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
+                               }
                                continue;
 
                        case FORMSW:
-                               if (!(form = *argp++) || *form == '-')
-                                       adios(NULL, "missing argument to %s",
+                               if (!(form = *argp++) || *form == '-') {
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
+                               }
                                continue;
                        }
                }
                if (*cp == '+' || *cp == '@') {
-                       if (folder)
-                               adios(NULL, "only one folder at a time!");
-                       else
+                       if (folder) {
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
+                       } else {
                                folder = getcpy(expandfol(cp));
+                       }
                } else {
-                       if (msg)
-                               adios(NULL, "only one message at a time!");
-                       else
+                       if (msg) {
+                               adios(EX_USAGE, NULL, "only one message at a time!");
+                       } else {
                                msg = cp;
+                       }
                }
        }
 
        cwd = getcpy(pwd());
 
        strncpy(drft, m_draft(seq_beyond), sizeof(drft));
-       if ((out = creat(drft, m_gmprot())) == NOTOK)
-               adios(drft, "unable to create");
+       if ((out = creat(drft, m_gmprot())) == NOTOK) {
+               adios(EX_CANTCREAT, drft, "unable to create");
+       }
 
        fmtstr = new_fs(form, distcomps);
        if (write(out, fmtstr, strlen(fmtstr)) != (int)strlen(fmtstr)) {
-               adios(drft, "error writing");
+               adios(EX_IOERR, drft, "error writing");
        }
        close(out);
 
-       if (!msg)
+       if (!msg) {
                msg = seq_cur;
-       if (!folder)
+       }
+       if (!folder) {
                folder = getcurfol();
+       }
        maildir = toabsdir(folder);
 
-       if (chdir(maildir) == NOTOK)
-               adios(maildir, "unable to change directory to");
+       if (chdir(maildir) == NOTOK) {
+               adios(EX_OSERR, maildir, "unable to change directory to");
+       }
 
-       if (!(mp = folder_read(folder)))
-               adios(NULL, "unable to read folder %s", folder);
+       if (!(mp = folder_read(folder))) {
+               adios(EX_IOERR, NULL, "unable to read folder %s", folder);
+       }
 
        /* check for empty folder */
-       if (mp->nummsg == 0)
-               adios(NULL, "no messages in %s", folder);
+       if (mp->nummsg == 0) {
+               adios(EX_NOINPUT, NULL, "no messages in %s", folder);
+       }
 
        /* parse the message range/sequence/name and set SELECTED */
-       if (!m_convert(mp, msg))
-               /* sysexits.h EX_USAGE*/
-               exit(1);
+       if (!m_convert(mp, msg)) {
+               exit(EX_USAGE);
+       }
        seq_setprev(mp);
 
-       if (mp->numsel > 1)
-               adios(NULL, "only one message at a time!");
+       if (mp->numsel > 1) {
+               adios(EX_USAGE, NULL, "only one message at a time!");
+       }
 
        msgnam = getcpy(m_name(mp->lowsel));
-       if ((in = open(msgnam, O_RDONLY)) == NOTOK)
-               adios(msgnam, "unable to open message");
+       if ((in = open(msgnam, O_RDONLY)) == NOTOK) {
+               adios(EX_IOERR, msgnam, "unable to open message");
+       }
 
        context_replace(curfolder, folder);
        seq_setcur(mp, mp->lowsel);
@@ -156,6 +169,5 @@ main(int argc, char **argv)
        context_save();
 
        what_now(ed, NOUSE, drft, msgnam, 1, mp, anot ? "Resent" : NULL, cwd);
-       /*sysexits.h EX_SOFTWARE*/
-       return 1;
+       return EX_SOFTWARE;
 }
index b6efbe8..1cbb7ed 100644 (file)
--- a/uip/dp.c
+++ b/uip/dp.c
@@ -10,6 +10,7 @@
 #include <h/fmt_scan.h>
 #include <h/tws.h>
 #include <locale.h>
+#include <sysexits.h>
 
 #define NDATES 100
 
@@ -57,36 +58,35 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               /* sysexits.h EX_USAGE */
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [switches] dates ...", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case FORMSW:
                                if (!(form = *argp++) || *form == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
                        }
                }
                if (datep > NDATES)
-                       adios(NULL, "more than %d dates", NDATES);
+                       adios(EX_USAGE, NULL, "more than %d dates", NDATES);
                else
                        dates[datep++] = cp;
        }
        dates[datep] = NULL;
 
        if (datep == 0)
-               adios(NULL, "usage: %s [switches] dates ...", invo_name);
+               adios(EX_USAGE, NULL, "usage: %s [switches] dates ...", invo_name);
 
        /* get new format string */
        fmtstr = new_fs(form, FORMAT);
index c0a056c..091def7 100644 (file)
@@ -21,6 +21,7 @@
 #include <dirent.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <sysexits.h>
 
 /*
 ** We allocate space to record the names of folders
@@ -154,27 +155,27 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               /* sysexits.h EX_USAGE */
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder1 [+folder2 ...]][switches]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
+
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case SEQSW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
 
                                /* check if too many sequences specified */
                                if (numsequences >= NUMATTRS)
-                                       adios(NULL, "too many sequences (more than %d) specified", NUMATTRS);
+                                       adios(EX_USAGE, NULL, "too many sequences (more than %d) specified", NUMATTRS);
                                sequencesToDo[numsequences++] = cp;
                                break;
 
@@ -245,7 +246,7 @@ main(int argc, char **argv)
 
                if ((cp = context_find(usequence))) {
                        if (!*cp) {
-                               adios(NULL, "profile entry %s set, but empty, and no sequence given", usequence);
+                               adios(EX_CONFIG, NULL, "profile entry %s set, but empty, and no sequence given", usequence);
                        }
                } else {
                        cp = seq_unseen;  /* use default */
@@ -254,7 +255,7 @@ main(int argc, char **argv)
                ap = brkstring(dp, " ", "\n");
                for (; ap && *ap; ap++) {
                        if (numsequences >= NUMATTRS) {
-                               adios(NULL, "too many sequences (more than %d) in %s profile entry", NUMATTRS, usequence);
+                               adios(EX_USAGE, NULL, "too many sequences (more than %d) in %s profile entry", NUMATTRS, usequence);
                        } else {
                                sequencesToDo[numsequences++] = *ap;
                        }
@@ -266,7 +267,7 @@ main(int argc, char **argv)
        qsort(folders, nFolders, sizeof(struct Folder),
                        (qsort_comp) CompareFolders);
        PrintFolders();
-       return 0;
+       return EX_OK;
 }
 
 /*
@@ -315,7 +316,7 @@ ScanFolders(void)
         * change directory to base of nmh directory
         */
        if (chdir(nmhdir) == NOTOK)
-               adios(nmhdir, "unable to change directory to");
+               adios(EX_OSERR, nmhdir, "unable to change directory to");
 
        if (numfolders > 0) {
                /* Update context */
@@ -401,7 +402,7 @@ BuildFolderListRecurse(char *dirName, struct stat *s, int searchdepth)
        nlinks = s->st_nlink;
 
        if (!(dir = opendir(dirName)))
-               adios(dirName, "can't open directory");
+               adios(EX_IOERR, dirName, "can't open directory");
 
        /*
        ** A hack so that we don't see a
index 884aa4f..c9b28cf 100644 (file)
@@ -11,6 +11,7 @@
 #include <h/fmt_compile.h>
 #include <h/scansbr.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define FORMSW  0
@@ -61,30 +62,29 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               /*sysexits.h EX_USAGE*/
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [switches]",
                                                invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case FORMSW:
                                if (!(form = *argp++) || *form == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
                        }
                }
                if (form)
-                       adios(NULL, "only one form at a time!");
+                       adios(EX_USAGE, NULL, "only one form at a time!");
                else
                        form = cp;
        }
@@ -96,7 +96,7 @@ main(int argc, char **argv)
        fmt_compile(fmtstr, &fmt);
 
        fmt_dump(fmt);
-       return 0;
+       return EX_OK;
 }
 
 static void
index 84b4365..77029dc 100644 (file)
@@ -14,6 +14,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define ALLSW  0
@@ -138,18 +139,17 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               /*sysexits.h EX_USAGE*/
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] [msg] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case ALLSW:
                                all = 1;
@@ -229,12 +229,12 @@ main(int argc, char **argv)
                }
                if (*cp == '+' || *cp == '@') {
                        if (argfolder)
-                               adios(NULL, "only one folder at a time!");
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
                        else
                                argfolder = getcpy(expandfol(cp));
                } else {
                        if (msg)
-                               adios(NULL, "only one (current) message at a time!");
+                               adios(EX_USAGE, NULL, "only one (current) message at a time!");
                        else
                                msg = cp;
                }
@@ -259,7 +259,7 @@ main(int argc, char **argv)
                                ap = brkstring(dp, " ", "\n");
                                argfolder = getcpy(*ap++);
                        } else {
-                               adios(NULL, "no other folder");
+                               adios(EX_USAGE, NULL, "no other folder");
                        }
                        for (cp = getcpy(getcurfol()); *ap; ap++)
                                cp = add(*ap, add(" ", cp));
@@ -276,13 +276,13 @@ main(int argc, char **argv)
        /* Popping a folder off of the folder stack */
        if (popsw) {
                if (argfolder)
-                       adios(NULL, "sorry, no folders allowed with -pop");
+                       adios(EX_USAGE, NULL, "sorry, no folders allowed with -pop");
                if ((cp = context_find(stack))) {
                        dp = getcpy(cp);
                        ap = brkstring(dp, " ", "\n");
                        argfolder = getcpy(*ap++);
                } else {
-                       adios(NULL, "folder stack empty");
+                       adios(EX_DATAERR, NULL, "folder stack empty");
                }
                if (*ap) {
                        /* if there's anything left in the stack */
@@ -299,7 +299,7 @@ main(int argc, char **argv)
        if (pushsw || popsw) {
                cp = toabsdir(argfolder);
                if (access(cp, F_OK) == NOTOK)
-                       adios(cp, "unable to find folder");
+                       adios(EX_DATAERR, cp, "unable to find folder");
                /* update current folder   */
                context_replace(curfolder, argfolder);
                context_save();  /* save the context file   */
@@ -318,7 +318,7 @@ main(int argc, char **argv)
                printf("\n");
 
                if (!printsw) {
-                       exit(0);
+                       exit(EX_OK);
                }
        }
 
@@ -338,7 +338,7 @@ main(int argc, char **argv)
                ** crawl_folders
                */
                if (chdir(nmhdir) == NOTOK)
-                       adios(nmhdir, "unable to change directory to");
+                       adios(EX_OSERR, nmhdir, "unable to change directory to");
                if (!argfolder) {
                        if (msg)
                                admonish(NULL, "no folder given for message %s", msg);
@@ -383,7 +383,7 @@ main(int argc, char **argv)
        print_folders();
 
        context_save();
-       return 0;
+       return EX_OK;
 }
 
 static int
@@ -426,7 +426,7 @@ get_folder_info_body(char *fold, char *msg, boolean *crawl_children)
 
                if (fpack) {
                        if (folder_pack(&mp, fverb) == -1) {
-                               exit(0);
+                               exit(EX_OK);
                        }
                        seq_save(mp);  /* synchronize the sequences */
                        context_save();  /* save the context file */
index 91ce04a..c754b27 100644 (file)
@@ -13,6 +13,7 @@
 #include <h/utils.h>
 #include <unistd.h>
 #include <locale.h>
+#include <sysexits.h>
 
 #define IFORMAT  "digest-issue-%s"
 #define VFORMAT  "digest-volume-%s"
@@ -83,18 +84,17 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               /* sysexits.h EX_USAGE */
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case ANNOSW:
                                anot++;
@@ -105,14 +105,14 @@ main(int argc, char **argv)
 
                        case EDITRSW:
                                if (!(ed = *argp++) || *ed == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
                        case WHATSW:
                                if (!(whatnowproc = *argp++) ||
                                                *whatnowproc == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
@@ -122,37 +122,37 @@ main(int argc, char **argv)
 
                        case FORMSW:
                                if (!(form = *argp++) || *form == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
                        case DGSTSW:
                                if (!(digest = *argp++) || *digest == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                //mime = 0;
                                continue;
                        case ISSUESW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                if ((issue = atoi(cp)) < 1)
-                                       adios(NULL, "bad argument %s %s",
+                                       adios(EX_USAGE, NULL, "bad argument %s %s",
                                                        argp[-2], cp);
                                continue;
                        case VOLUMSW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                if ((volume = atoi(cp)) < 1)
-                                       adios(NULL, "bad argument %s %s",
+                                       adios(EX_USAGE, NULL, "bad argument %s %s",
                                                        argp[-2], cp);
                                continue;
                        }
                }
                if (*cp == '+' || *cp == '@') {
                        if (folder)
-                               adios(NULL, "only one folder at a time!");
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
                        else
                                folder = getcpy(expandfol(cp));
                } else {
@@ -180,27 +180,26 @@ main(int argc, char **argv)
        maildir = toabsdir(folder);
 
        if (chdir(maildir) == NOTOK)
-               adios(maildir, "unable to change directory to");
+               adios(EX_OSERR, maildir, "unable to change directory to");
 
        /* read folder and create message structure */
        if (!(mp = folder_read(folder)))
-               adios(NULL, "unable to read folder %s", folder);
+               adios(EX_IOERR, NULL, "unable to read folder %s", folder);
 
        /* check for empty folder */
        if (mp->nummsg == 0)
-               adios(NULL, "no messages in %s", folder);
+               adios(EX_DATAERR, 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])) {
-                       /* sysexits.h EX_USAGE */
-                       exit(1);
+                       exit(EX_SOFTWARE);
                }
        }
        seq_setprev(mp);  /* set the previous sequence */
 
        if ((out = creat(drft, m_gmprot())) == NOTOK)
-               adios(drft, "unable to create");
+               adios(EX_CANTCREAT, drft, "unable to create");
 
        /* Open form (component) file. */
        if (digest) {
@@ -225,7 +224,7 @@ main(int argc, char **argv)
        } else {
                fmtstr = new_fs(form, forwcomps);
                if (write(out, fmtstr, strlen(fmtstr)) != (int)strlen(fmtstr)) {
-                       adios(drft, "error writing");
+                       adios(EX_IOERR, drft, "error writing");
                }
        }
        close(out);
@@ -247,11 +246,10 @@ main(int argc, char **argv)
        context_save();  /* save the context file */
 
        if (buildsw)
-               exit(0);
+               exit(EX_OK);
        what_now(ed, NOUSE, drft, NULL, 0, mp,
                anot ? "Forwarded" : NULL, cwd);
-       /* sysexits.h EX_SOFTWARE */
-       return 1;
+       return EX_OSERR;
 }
 
 
@@ -280,7 +278,7 @@ add_forw_hdr(char *draft)
                }
                if (strlen(buf) + 1 + strlen(m_name(msgnum)) + 1
                                > sizeof buf) {
-                       adios(NULL, "Attachment header line too long. "
+                       adios(EX_DATAERR, NULL, "Attachment header line too long. "
                                        "Forward less messages.");
                }
                strcat(buf, " ");
@@ -328,18 +326,20 @@ build_form(char *form, char *digest, int volume, int issue)
        dat[4] = 0;
 
        cp = m_mktemp2(NULL, invo_name, NULL, &tmp);
-       if (cp == NULL) adios("forw", "unable to create temporary file");
+       if (cp == NULL) {
+               adios(EX_CANTCREAT, "forw", "unable to create temporary file");
+       }
        strncpy(tmpfil, cp, sizeof(tmpfil));
        unlink(tmpfil);
        if ((in = dup(fileno(tmp))) == NOTOK)
-               adios("dup", "unable to");
+               adios(EX_OSERR, "dup", "unable to");
 
        line = mh_xmalloc((unsigned) fmtsize);
        fmt_scan(fmt, line, fmtsize, dat);
        fputs(line, tmp);
        free(line);
        if (fclose(tmp))
-               adios(tmpfil, "error writing");
+               adios(EX_IOERR, tmpfil, "error writing");
 
        lseek(in, (off_t) 0, SEEK_SET);
        return in;
index 1cac19f..368bce3 100644 (file)
--- a/uip/inc.c
+++ b/uip/inc.c
@@ -38,6 +38,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <sysexits.h>
 
 #ifdef HAVE_SYS_PARAM_H
 # include <sys/param.h>
@@ -106,12 +107,12 @@ static int return_gid;
 #define DROPGROUPPRIVS() \
     if (setegid(getgid()) != 0) { \
         advise ("setegid", "unable to set group to %ld", (long) getgid()); \
-               _exit (-1); \
+               _exit (EX_OSERR); \
     }
 #define GETGROUPPRIVS() \
     if (setegid(return_gid) != 0) { \
         advise ("setegid", "unable to set group to %ld", (long) return_gid); \
-               _exit (-1); \
+               _exit (EX_OSERR); \
     }
 #define SAVEGROUPPRIVS() return_gid = getegid()
 #else
@@ -158,7 +159,7 @@ main(int argc, char **argv)
        char *maildir_copy = NULL;
 
        if (atexit(inc_done) != 0) {
-               adios(NULL, "atexit failed");
+               adios(EX_OSERR, NULL, "atexit failed");
        }
 
 /*
@@ -182,22 +183,21 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               /* sysexits.h EX_USAGE */
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case AUDSW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s", argp[-2]);
+                                       adios(EX_USAGE, NULL, "missing argument to %s", argp[-2]);
                                audfile = getcpy(expanddir(cp));
                                continue;
                        case NAUDSW:
@@ -227,7 +227,7 @@ main(int argc, char **argv)
 
                        case FILESW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                from = getcpy(expanddir(cp));
 
@@ -248,13 +248,13 @@ main(int argc, char **argv)
 
                        case FORMSW:
                                if (!(form = *argp++) || *form == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
                        case WIDTHSW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                width = atoi(cp);
                                continue;
@@ -262,11 +262,11 @@ main(int argc, char **argv)
                }
                if (*cp == '+' || *cp == '@') {
                        if (folder)
-                               adios(NULL, "only one folder at a time!");
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
                        else
                                folder = getcpy(expandfol(cp));
                } else {
-                       adios(NULL, "usage: %s [+folder] [switches]",
+                       adios(EX_USAGE, NULL, "usage: %s [+folder] [switches]",
                                        invo_name);
                }
        }
@@ -292,10 +292,10 @@ main(int argc, char **argv)
                newmail = concat(mailspool, "/", getusername(), NULL);
        }
        if (stat(newmail, &s1) == NOTOK || s1.st_size == 0)
-               adios(NULL, "no mail to incorporate");
+               adios(EX_DATAERR, NULL, "no mail to incorporate");
 
        if ((cp = strdup(newmail)) == NULL)
-               adios(NULL, "error allocating memory to copy newmail");
+               adios(EX_OSERR, NULL, "error allocating memory to copy newmail");
 
        newmail = cp;
 
@@ -304,16 +304,16 @@ main(int argc, char **argv)
        maildir = toabsdir(folder);
 
        if ((maildir_copy = strdup(maildir)) == NULL)
-               adios(maildir, "error allocating memory to copy maildir");
+               adios(EX_OSERR, maildir, "error allocating memory to copy maildir");
 
        create_folder(maildir, noisy ? 0 : 1, exit);
 
        if (chdir(maildir) == NOTOK)
-               adios(maildir, "unable to change directory to");
+               adios(EX_OSERR, maildir, "unable to change directory to");
 
        /* read folder and create message structure */
        if (!(mp = folder_read(folder)))
-               adios(NULL, "unable to read folder %s", folder);
+               adios(EX_IOERR, NULL, "unable to read folder %s", folder);
 
        if (access(newmail, W_OK) != NOTOK) {
                locked++;
@@ -328,12 +328,12 @@ main(int argc, char **argv)
                in = lkfopen(newmail, "r");
                DROPGROUPPRIVS();
                if (in == NULL)
-                       adios(NULL, "unable to lock and fopen %s", newmail);
+                       adios(EX_IOERR, NULL, "unable to lock and fopen %s", newmail);
                fstat(fileno(in), &s1);
        } else {
                trnflag = 0;
                if ((in = fopen(newmail, "r")) == NULL)
-                       adios(newmail, "unable to read");
+                       adios(EX_IOERR, newmail, "unable to read");
        }
 
        /* This shouldn't be necessary but it can't hurt. */
@@ -344,7 +344,7 @@ main(int argc, char **argv)
                if ((i = stat(audfile, &st)) == NOTOK)
                        advise(NULL, "Creating Receive-Audit: %s", audfile);
                if ((aud = fopen(audfile, "a")) == NULL)
-                       adios(audfile, "unable to append to");
+                       adios(EX_IOERR, audfile, "unable to append to");
                else if (i == NOTOK)
                        chmod(audfile, m_gmprot());
 
@@ -444,7 +444,7 @@ main(int argc, char **argv)
                } else {
                        fclose(in); in = NULL;
                }
-               adios(NULL, "failed");
+               adios(EX_SOFTWARE, NULL, "failed");
        }
 
        if (aud)
index 57a6553..a6ac480 100644 (file)
@@ -12,6 +12,7 @@
 #include <h/utils.h>
 #include <unistd.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define ADDSW  0
@@ -75,18 +76,17 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               /*sysexits.h EX_USAGE*/
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown\n", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown\n", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case ADDSW:
                                addsw++;
@@ -102,13 +102,15 @@ main(int argc, char **argv)
                                continue;
 
                        case SEQSW:
-                               if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                               if (!(cp = *argp++) || *cp == '-') {
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
+                               }
 
                                /* check if too many sequences specified */
-                               if (seqp >= NUMATTRS)
-                                       adios(NULL, "too many sequences (more than %d) specified", NUMATTRS);
+                               if (seqp >= NUMATTRS) {
+                                       adios(EX_USAGE, NULL, "too many sequences (more than %d) specified", NUMATTRS);
+                               }
                                seqs[seqp++] = cp;
                                continue;
 
@@ -132,12 +134,14 @@ main(int argc, char **argv)
                        }
                }
                if (*cp == '+' || *cp == '@') {
-                       if (folder)
-                               adios(NULL, "only one folder at a time!");
-                       else
+                       if (folder) {
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
+                       } else {
                                folder = getcpy(expandfol(cp));
-               } else
+                       }
+               } else {
                        app_msgarg(&msgs, cp);
+               }
        }
 
        /*
@@ -158,58 +162,62 @@ main(int argc, char **argv)
                folder = getcurfol();
        maildir = toabsdir(folder);
 
-       if (chdir(maildir) == NOTOK)
-               adios(maildir, "unable to change directory to");
+       if (chdir(maildir) == NOTOK) {
+               adios(EX_OSERR, maildir, "unable to change directory to");
+       }
 
        /* read folder and create message structure */
-       if (!(mp = folder_read(folder)))
-               adios(NULL, "unable to read folder %s", folder);
+       if (!(mp = folder_read(folder))) {
+               adios(EX_IOERR, NULL, "unable to read folder %s", folder);
+       }
 
        /* print some general debugging info */
        if (debugsw)
                print_debug(mp);
 
        /* check for empty folder */
-       if (mp->nummsg == 0)
-               adios(NULL, "no messages in %s", folder);
+       if (mp->nummsg == 0) {
+               adios(EX_DATAERR, NULL, "no messages in %s", folder);
+       }
 
        /* parse all the message ranges/sequences and set SELECTED */
        for (msgnum = 0; msgnum < msgs.size; msgnum++) {
                if (!m_convert(mp, msgs.msgs[msgnum])) {
-                       /*sysexits.h EX_USAGE*/
-                       exit(1);
+                       exit(EX_USAGE);
                }
        }
 
-       if (publicsw == 1 && is_readonly(mp))
-               adios(NULL, "folder %s is read-only, so -public not allowed",
+       if (publicsw == 1 && is_readonly(mp)) {
+               adios(EX_NOPERM, NULL, "folder %s is read-only, so -public not allowed",
                                folder);
+       }
 
        /*
        ** Make sure at least one sequence has been
        ** specified if we are adding or deleting.
        */
-       if (seqp == 0 && (addsw || deletesw))
-               adios(NULL, "-%s requires at least one -sequence argument",
+       if (seqp == 0 && (addsw || deletesw)) {
+               adios(EX_USAGE, NULL, "-%s requires at least one -sequence argument",
                                addsw ? "add" : "delete");
+       }
        seqs[seqp] = NULL;
 
        /* Adding messages to sequences */
        if (addsw) {
                for (seqp = 0; seqs[seqp]; seqp++) {
                        if (!seq_addsel(mp, seqs[seqp], publicsw, zerosw)) {
-                               /*TODO find best exitcode*/
-                               exit(1);
+                               exit(EX_SOFTWARE);
                        }
                }
        }
 
        /* Deleting messages from sequences */
        if (deletesw) {
-               for (seqp = 0; seqs[seqp]; seqp++)
-                       if (!seq_delsel(mp, seqs[seqp], publicsw, zerosw))
-                               /*TODO find best exitcode*/
-                               exit(1);
+               for (seqp = 0; seqs[seqp]; seqp++) {
+                       if (!seq_delsel(mp, seqs[seqp], publicsw, zerosw)) {
+                               exit(EX_SOFTWARE);
+                       }
+               }
        }
 
        /* Listing messages in sequences */
@@ -232,7 +240,7 @@ main(int argc, char **argv)
        context_replace(curfolder, folder);  /* update current folder */
        context_save();  /* save the context file */
        folder_free(mp);  /* free folder/message structure */
-       return 0;
+       return EX_OK;
 }
 
 
index c862bc3..de2cf45 100644 (file)
@@ -24,6 +24,7 @@
 #include <ctype.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <sysexits.h>
 
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
@@ -118,7 +119,7 @@ main(int argc, char **argv)
        FILE *fp_out = NULL;
 
        if (atexit(unlink_done) != 0) {
-               adios(NULL, "atexit failed");
+               adios(EX_OSERR, NULL, "atexit failed");
        }
 
        setlocale(LC_ALL, "");
@@ -133,7 +134,7 @@ main(int argc, char **argv)
        while ((cp = *argp++)) {
                if (cp[0] == '-' && cp[1] == '\0') {
                        if (compfile)
-                               adios(NULL, "cannot specify both standard input and a file");
+                               adios(EX_USAGE, NULL, "cannot specify both standard input and a file");
                        else
                                compfile = cp;
                        verbosw = 0;  /* turn off -verbose listings */
@@ -143,18 +144,17 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               /* sysexits.h EX_USAGE */
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [switches] file", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case VERBSW:
                                verbosw++;
@@ -168,7 +168,7 @@ main(int argc, char **argv)
                        }
                }
                if (compfile)
-                       adios(NULL, "only one composition file allowed");
+                       adios(EX_USAGE, NULL, "only one composition file allowed");
                else
                        compfile = cp;
        }
@@ -208,7 +208,7 @@ main(int argc, char **argv)
 
        /* Check if we have a file to process */
        if (!compfile)
-               adios(NULL, "need to specify a %s composition file",
+               adios(EX_USAGE, NULL, "need to specify a %s composition file",
                                invo_name);
 
        /*
@@ -237,7 +237,7 @@ main(int argc, char **argv)
 
                /* output the temp file to standard output */
                if ((fp = fopen(outfile, "r")) == NULL)
-                       adios(outfile, "unable to open");
+                       adios(EX_IOERR, outfile, "unable to open");
                while (fgets(buffer, BUFSIZ, fp))
                        fputs(buffer, stdout);
                fclose(fp);
@@ -249,7 +249,7 @@ main(int argc, char **argv)
                unlink_outfile = 0;
 
                free_content(ct);
-               exit(0);
+               exit(EX_OK);
        }
 
        /*
@@ -271,15 +271,14 @@ main(int argc, char **argv)
        /* Rename composition draft */
        snprintf(buffer, sizeof(buffer), "%s.orig", compfile);
        if (rename(compfile, buffer) == NOTOK) {
-               adios(buffer, "unable to rename draft %s to", compfile);
+               adios(EX_IOERR, buffer, "unable to rename draft %s to", compfile);
        }
 
        /* Rename output file to take its place */
        if (rename(outfile, compfile) == NOTOK) {
                advise(compfile, "unable to rename output %s to", outfile);
                rename(buffer, compfile);
-               /* sysexits.h EX_IOERR */
-               exit(1);
+               exit(EX_IOERR);
        }
        unlink_outfile = 0;
 
@@ -325,13 +324,13 @@ build_mime(char *infile)
 
        /* open the composition draft */
        if ((in = fopen(infile, "r")) == NULL)
-               adios(infile, "unable to open for reading");
+               adios(EX_IOERR, infile, "unable to open for reading");
 
        /*
        ** Allocate space for primary (outside) content
        */
        if ((ct = (CT) calloc(1, sizeof(*ct))) == NULL)
-               adios(NULL, "out of memory");
+               adios(EX_OSERR, NULL, "out of memory");
 
        /*
        ** Allocate structure for handling decoded content
@@ -354,14 +353,14 @@ build_mime(char *infile)
 
                        /* abort if draft has Mime-Version header field */
                        if (!mh_strcasecmp(name, VRSN_FIELD))
-                               adios(NULL, "draft shouldn't contain %s: field", VRSN_FIELD);
+                               adios(EX_CONFIG, NULL, "draft shouldn't contain %s: field", VRSN_FIELD);
 
                        /*
                        ** abort if draft has Content-Transfer-Encoding
                        ** header field
                        */
                        if (!mh_strcasecmp(name, ENCODING_FIELD))
-                               adios(NULL, "draft shouldn't contain %s: field", ENCODING_FIELD);
+                               adios(EX_CONFIG, NULL, "draft shouldn't contain %s: field", ENCODING_FIELD);
 
                        /* ignore any Content-Type fields in the header */
                        if (!mh_strcasecmp(name, TYPE_FIELD)) {
@@ -392,7 +391,7 @@ finish_field:
                        /* else fall... */
 
                case FILEEOF:
-                       adios(NULL, "draft has empty body -- no directives!");
+                       adios(EX_CONFIG, NULL, "draft has empty body -- no directives!");
                        /* NOTREACHED */
 
                case BODY:
@@ -402,11 +401,11 @@ finish_field:
 
                case LENERR:
                case FMTERR:
-                       adios(NULL, "message format error in component #%d",
+                       adios(EX_CONFIG, NULL, "message format error in component #%d",
                                        compnum);
 
                default:
-                       adios(NULL, "getfld() returned %d", state);
+                       adios(EX_SOFTWARE, NULL, "getfld() returned %d", state);
                }
                break;
        }
@@ -425,15 +424,14 @@ finish_field:
        ** We can remove this later, if it is not needed.
        */
        if (get_ctinfo("multipart/mixed", ct, 0) == NOTOK) {
-               /* sysexits.h EX_DATAERR */
-               exit(1);
+               exit(EX_DATAERR);
        }
        ct->c_type = CT_MULTIPART;
        ct->c_subtype = MULTI_MIXED;
        ct->c_file = getcpy(infile);
 
        if ((m = (struct multipart *) calloc(1, sizeof(*m))) == NULL)
-               adios(NULL, "out of memory");
+               adios(EX_OSERR, NULL, "out of memory");
        ct->c_ctparams = (void *) m;
        pp = &m->mp_parts;
 
@@ -453,7 +451,7 @@ finish_field:
                        continue;
 
                if ((part = (struct part *) calloc(1, sizeof(*part))) == NULL)
-                       adios(NULL, "out of memory");
+                       adios(EX_OSERR, NULL, "out of memory");
                *pp = part;
                pp = &part->mp_next;
                part->mp_part = p;
@@ -467,7 +465,7 @@ finish_field:
 
        /* check if any contents were found */
        if (!m->mp_parts)
-               adios(NULL, "no content directives found");
+               adios(EX_OSERR, NULL, "no content directives found");
 
        /*
        ** If only one content was found, then remove and
@@ -498,7 +496,7 @@ finish_field:
        compose_content(ct);
 
        if ((cp = strchr(prefix, 'a')) == NULL)
-               adios(NULL, "internal error(4)");
+               adios(EX_SOFTWARE, NULL, "internal error(4)");
 
        /*
        ** Scan the contents.  Choose a transfer encoding, and
@@ -510,7 +508,7 @@ finish_field:
                        (*cp)++;
                } else {
                        if (*++cp == 0)
-                               adios(NULL, "giving up trying to find a unique delimiter string");
+                               adios(EX_SOFTWARE, NULL, "giving up trying to find a unique delimiter string");
                                else
                                (*cp)++;
                }
@@ -534,7 +532,7 @@ init_decoded_content(CT ct)
        CE ce;
 
        if ((ce = (CE) calloc(1, sizeof(*ce))) == NULL)
-               adios(NULL, "out of memory");
+               adios(EX_OSERR, NULL, "out of memory");
 
        ct->c_cefile     = ce;
        ct->c_ceopenfnx  = open7Bit;  /* since unencoded */
@@ -595,7 +593,7 @@ user_content(FILE *in, char *file, char *buf, CT *ctp)
 
        /* allocate basic Content structure */
        if ((ct = (CT) calloc(1, sizeof(*ct))) == NULL)
-               adios(NULL, "out of memory");
+               adios(EX_OSERR, NULL, "out of memory");
        *ctp = ct;
 
        /* allocate basic structure for handling decoded content */
@@ -623,7 +621,7 @@ user_content(FILE *in, char *file, char *buf, CT *ctp)
 
                cp = m_mktemp2(NULL, invo_name, NULL, &out);
                if (cp == NULL)
-                       adios("mhbuild", "unable to create temporary file");
+                       adios(EX_CANTCREAT, "mhbuild", "unable to create temporary file");
 
                /* use a temp file to collect the plain text lines */
                ce->ce_file = getcpy(cp);
@@ -651,7 +649,7 @@ user_content(FILE *in, char *file, char *buf, CT *ctp)
 again_descr:
                                ct->c_descr = add(buffer + i + 1, ct->c_descr);
                                if (!fgetstr(buffer, sizeof(buffer) - 1, in))
-                                       adios(NULL, "end-of-file after %s: field in plaintext", DESCR_FIELD);
+                                       adios(EX_DATAERR, NULL, "end-of-file after %s: field in plaintext", DESCR_FIELD);
                                switch (buffer[0]) {
                                case ' ':
                                case '\t':
@@ -659,7 +657,7 @@ again_descr:
                                        goto again_descr;
 
                                case '#':
-                                       adios(NULL, "#-directive after %s: field in plaintext", DESCR_FIELD);
+                                       adios(EX_DATAERR, NULL, "#-directive after %s: field in plaintext", DESCR_FIELD);
                                        /* NOTREACHED */
 
                                default:
@@ -674,7 +672,7 @@ again_descr:
 again_dispo:
                                ct->c_dispo = add(buffer + i + 1, ct->c_dispo);
                                if (!fgetstr(buffer, sizeof(buffer) - 1, in))
-                                       adios(NULL, "end-of-file after %s: field in plaintext", DISPO_FIELD);
+                                       adios(EX_DATAERR, NULL, "end-of-file after %s: field in plaintext", DISPO_FIELD);
                                switch (buffer[0]) {
                                case ' ':
                                case '\t':
@@ -682,7 +680,7 @@ again_dispo:
                                        goto again_dispo;
 
                                case '#':
-                                       adios(NULL, "#-directive after %s: field in plaintext", DISPO_FIELD);
+                                       adios(EX_DATAERR, NULL, "#-directive after %s: field in plaintext", DISPO_FIELD);
                                        /* NOTREACHED */
 
                                default:
@@ -714,8 +712,7 @@ rock_and_roll:
 
                /* parse content type */
                if (get_ctinfo(content, ct, inlineD) == NOTOK)
-                       /* sysexits.h EX_USAGE */
-                       exit(1);
+                       exit(EX_DATAERR);
 
                for (s2i = str2cts; s2i->si_key; s2i++)
                        if (!mh_strcasecmp(ci->ci_type, s2i->si_key))
@@ -734,7 +731,7 @@ rock_and_roll:
                        }
                        /* else fall... */
                case CT_MULTIPART:
-                       adios(NULL, "it doesn't make sense to define an in-line %s content",
+                       adios(EX_DATAERR, NULL, "it doesn't make sense to define an in-line %s content",
                                        ct->c_type == CT_MESSAGE ? "message" :
                                        "multipart");
                        /* NOTREACHED */
@@ -757,14 +754,13 @@ call_init:
        */
 
        if (buf[1] == '@') {
-               adios(NULL, "The #@ directive i.e. message/external-body "
+               adios(EX_DATAERR, NULL, "The #@ directive i.e. message/external-body "
                                "is not supported anymore.");
        }
 
        /* parse directive */
        if (get_ctinfo(buf+1, ct, 1) == NOTOK)
-               /* sysexits.h EX_DATAERR */
-               exit(1);
+               exit(EX_DATAERR);
 
        /* check directive against the list of MIME types */
        for (s2i = str2cts; s2i->si_key; s2i++)
@@ -779,18 +775,18 @@ call_init:
        */
        if (s2i->si_key) {
                if (!ci->ci_subtype)
-                       adios(NULL, "missing subtype in \"#%s\"", ci->ci_type);
+                       adios(EX_DATAERR, NULL, "missing subtype in \"#%s\"", ci->ci_type);
 
                switch (ct->c_type = s2i->si_val) {
                case CT_MULTIPART:
-                       adios(NULL, "use \"#begin ... #end\" instead of \"#%s/%s\"", ci->ci_type, ci->ci_subtype);
+                       adios(EX_DATAERR, NULL, "use \"#begin ... #end\" instead of \"#%s/%s\"", ci->ci_type, ci->ci_subtype);
                        /* NOTREACHED */
 
                case CT_MESSAGE:
                        if (!mh_strcasecmp(ci->ci_subtype, "partial") ||
                                        !mh_strcasecmp(ci->ci_subtype,
                                        "external-body")) {
-                               adios(NULL, "sorry, \"#%s/%s\" isn't supported", ci->ci_type, ci->ci_subtype);
+                               adios(EX_DATAERR, NULL, "sorry, \"#%s/%s\" isn't supported", ci->ci_type, ci->ci_subtype);
                        }
 use_forw:
                        admonish(NULL, "use \"#forw [+folder] [msgs]\" instead of \"#%s/%s\"", ci->ci_type, ci->ci_subtype);
@@ -809,7 +805,7 @@ use_forw:
                                for (cp = ci->ci_magic + 1; isspace(*cp); cp++)
                                        continue;
                                if (!*cp)
-                                       adios(NULL, "empty pipe command for #%s directive", ci->ci_type);
+                                       adios(EX_DATAERR, NULL, "empty pipe command for #%s directive", ci->ci_type);
                                cp = getcpy(cp);
                                free(ci->ci_magic);
                                ci->ci_magic = cp;
@@ -817,7 +813,7 @@ use_forw:
                                /* record filename of decoded contents */
                                ce->ce_file = ci->ci_magic;
                                if (access(ce->ce_file, R_OK) == NOTOK)
-                                       adios("reading", "unable to access %s for", ce->ce_file);
+                                       adios(EX_IOERR, "reading", "unable to access %s for", ce->ce_file);
                                ci->ci_magic = NULL;
                        }
                        return OK;
@@ -835,8 +831,7 @@ use_forw:
                        if ((cp = context_find(buffer)) == NULL ||
                                        *cp == '\0') {
                                content_error(NULL, ct, "don't know how to compose content");
-                               /* sysexits.h EX_USAGE */
-                               exit(1);
+                               exit(EX_CONFIG);
                        }
                }
                ci->ci_magic = getcpy(cp);
@@ -872,7 +867,7 @@ use_forw:
                        cp = *ap;
                        if (*cp == '+' || *cp == '@') {
                                if (folder)
-                                       adios(NULL, "only one folder per #forw directive");
+                                       adios(EX_USAGE, NULL, "only one folder per #forw directive");
                                else
                                        folder = getcpy(expandfol(cp));
                        }
@@ -883,13 +878,12 @@ use_forw:
                        folder = getcpy(getcurfol());
 
                if (!(mp = folder_read(folder)))
-                       adios(NULL, "unable to read folder %s", folder);
+                       adios(EX_IOERR, NULL, "unable to read folder %s", folder);
                for (ap = arguments; *ap; ap++) {
                        cp = *ap;
                        if (*cp != '+' && *cp != '@')
                                if (!m_convert(mp, cp))
-                                       /* sysexits.h EX_USAGE */
-                                       exit(1);
+                                       exit(EX_USAGE);
                }
                free(folder);
                free_ctinfo(ct);
@@ -903,14 +897,13 @@ use_forw:
                if (mp->numsel > 1) {
                        /* we are forwarding multiple messages */
                        if (get_ctinfo("multipart/digest", ct, 0) == NOTOK)
-                               /* sysexits.h EX_DATAERR */
-                               exit(1);
+                               exit(EX_DATAERR);
                        ct->c_type = CT_MULTIPART;
                        ct->c_subtype = MULTI_DIGEST;
 
                        if ((m = (struct multipart *)
                                        calloc(1, sizeof(*m))) == NULL)
-                               adios(NULL, "out of memory");
+                               adios(EX_OSERR, NULL, "out of memory");
                        ct->c_ctparams = (void *) m;
                        pp = &m->mp_parts;
 
@@ -922,13 +915,12 @@ use_forw:
 
                                        if ((p = (CT) calloc(1, sizeof(*p)))
                                                        == NULL)
-                                               adios(NULL, "out of memory");
+                                               adios(EX_OSERR, NULL, "out of memory");
                                        init_decoded_content(p);
                                        pe = p->c_cefile;
                                        if (get_ctinfo("message/rfc822", p, 0)
                                                        == NOTOK)
-                                               /* sysexits.h EX_DATAERR */
-                                               exit(1);
+                                               exit(EX_DATAERR);
                                        p->c_type = CT_MESSAGE;
                                        p->c_subtype = MESSAGE_RFC822;
 
@@ -938,7 +930,7 @@ use_forw:
                                        pe->ce_file = getcpy(buffer);
 
                                        if ((part = (struct part *) calloc(1, sizeof(*part))) == NULL)
-                                               adios(NULL, "out of memory");
+                                               adios(EX_OSERR, NULL, "out of memory");
                                        *pp = part;
                                        pp = &part->mp_next;
                                        part->mp_part = p;
@@ -947,8 +939,7 @@ use_forw:
                } else {
                        /* we are forwarding one message */
                        if (get_ctinfo("message/rfc822", ct, 0) == NOTOK)
-                               /* sysexits.h EX_DATAERR */
-                               exit(1);
+                               exit(EX_DATAERR);
                        ct->c_type = CT_MESSAGE;
                        ct->c_subtype = MESSAGE_RFC822;
 
@@ -994,13 +985,12 @@ use_forw:
                free_ctinfo(ct);
                snprintf(buffer, sizeof(buffer), "multipart/%s", cp);
                if (get_ctinfo(buffer, ct, 0) == NOTOK)
-                       /* sysexits.h EX_DATAERR */
-                       exit(1);
+                       exit(EX_DATAERR);
                ct->c_type = CT_MULTIPART;
                ct->c_subtype = vrsn;
 
                if ((m = (struct multipart *) calloc(1, sizeof(*m))) == NULL)
-                       adios(NULL, "out of memory");
+                       adios(EX_OSERR, NULL, "out of memory");
                ct->c_ctparams = (void *) m;
 
                pp = &m->mp_parts;
@@ -1010,7 +1000,7 @@ use_forw:
 
                        if (user_content(in, file, buffer, &p) == DONE) {
                                if (!m->mp_parts)
-                                       adios(NULL, "empty \"#begin ... #end\" sequence");
+                                       adios(EX_DATAERR, NULL, "empty \"#begin ... #end\" sequence");
                                return OK;
                        }
                        if (!p)
@@ -1018,7 +1008,7 @@ use_forw:
 
                        if ((part = (struct part *)
                                        calloc(1, sizeof(*part))) == NULL)
-                               adios(NULL, "out of memory");
+                               adios(EX_OSERR, NULL, "out of memory");
                        *pp = part;
                        pp = &part->mp_next;
                        part->mp_part = p;
@@ -1030,7 +1020,7 @@ use_forw:
        /*
        ** Unknown directive
        */
-       adios(NULL, "unknown directive \"#%s\"", ci->ci_type);
+       adios(EX_DATAERR, NULL, "unknown directive \"#%s\"", ci->ci_type);
        return NOTOK;  /* NOT REACHED */
 }
 
@@ -1114,11 +1104,11 @@ compose_content(CT ct)
                        char *tfile = NULL;
 
                        if (!(cp = ci->ci_magic))
-                               adios(NULL, "internal error(5)");
+                               adios(EX_SOFTWARE, NULL, "internal error(5)");
 
                        tfile = m_mktemp2(NULL, invo_name, NULL, NULL);
                        if (tfile == NULL) {
-                               adios("mhbuild", "unable to create temporary file");
+                               adios(EX_CANTCREAT, "mhbuild", "unable to create temporary file");
                        }
                        ce->ce_file = getcpy(tfile);
                        ce->ce_unlink = 1;
@@ -1206,11 +1196,11 @@ raw:
                        vec[3] = NULL;
 
                        if ((out = fopen(ce->ce_file, "w")) == NULL)
-                               adios(ce->ce_file, "unable to open for writing");
+                               adios(EX_IOERR, ce->ce_file, "unable to open for writing");
 
                        switch (child_id = fork()) {
                        case NOTOK:
-                               adios("fork", "unable to fork");
+                               adios(EX_OSERR, "fork", "unable to fork");
                                /* NOTREACHED */
 
                        case OK:
@@ -1220,14 +1210,13 @@ raw:
                                execvp("/bin/sh", vec);
                                fprintf(stderr, "unable to exec ");
                                perror("/bin/sh");
-                               _exit(-1);
+                               _exit(EX_OSERR);
                                /* NOTREACHED */
 
                        default:
                                fclose(out);
                                if (pidXwait(child_id, NULL))
-                                       /* sysexits.h EX_SOFTWARE */
-                                       exit(1);
+                                       exit(EX_SOFTWARE);
                                break;
                        }
                }
@@ -1336,7 +1325,7 @@ scan_content(CT ct)
        */
        if (check8bit || checklinelen || checklinespace || checkboundary) {
                if ((in = fopen(ce->ce_file, "r")) == NULL)
-                       adios(ce->ce_file, "unable to open for reading");
+                       adios(EX_IOERR, ce->ce_file, "unable to open for reading");
                len = strlen(prefix);
 
                while (fgets(buffer, sizeof(buffer) - 1, in)) {
@@ -1562,7 +1551,7 @@ build_headers(CT ct)
 
        case CE_8BIT:
                if (ct->c_type == CT_MESSAGE)
-                       adios(NULL, "internal error, invalid encoding");
+                       adios(EX_DATAERR, NULL, "internal error, invalid encoding");
 
                np = getcpy(ENCODING_FIELD);
                vp = concat(" ", "8bit", "\n", NULL);
@@ -1571,7 +1560,7 @@ build_headers(CT ct)
 
        case CE_QUOTED:
                if (ct->c_type == CT_MESSAGE || ct->c_type == CT_MULTIPART)
-                       adios(NULL, "internal error, invalid encoding");
+                       adios(EX_DATAERR, NULL, "internal error, invalid encoding");
 
                np = getcpy(ENCODING_FIELD);
                vp = concat(" ", "quoted-printable", "\n", NULL);
@@ -1580,7 +1569,7 @@ build_headers(CT ct)
 
        case CE_BASE64:
                if (ct->c_type == CT_MESSAGE || ct->c_type == CT_MULTIPART)
-                       adios(NULL, "internal error, invalid encoding");
+                       adios(EX_DATAERR, NULL, "internal error, invalid encoding");
 
                np = getcpy(ENCODING_FIELD);
                vp = concat(" ", "base64", "\n", NULL);
@@ -1589,7 +1578,7 @@ build_headers(CT ct)
 
        case CE_BINARY:
                if (ct->c_type == CT_MESSAGE)
-                       adios(NULL, "internal error, invalid encoding");
+                       adios(EX_DATAERR, NULL, "internal error, invalid encoding");
 
                np = getcpy(ENCODING_FIELD);
                vp = concat(" ", "binary", "\n", NULL);
@@ -1597,7 +1586,7 @@ build_headers(CT ct)
                break;
 
        default:
-               adios(NULL, "unknown transfer encoding in content");
+               adios(EX_DATAERR, NULL, "unknown transfer encoding in content");
                break;
        }
 
index 386cf95..c201a95 100644 (file)
--- a/uip/mhl.c
+++ b/uip/mhl.c
@@ -16,6 +16,7 @@
 #include <ctype.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <sysexits.h>
 
 /*
 ** MAJOR BUG:
@@ -233,30 +234,30 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown\n", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown\n", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [switches] [files ...]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case FORMSW:
                                if (!(form = *argp++) || *form == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
                        case WIDTHSW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                if ((width = atoi(cp)) < 1)
-                                       adios(NULL, "bad argument %s %s",
+                                       adios(EX_USAGE, NULL, "bad argument %s %s",
                                                        argp[-2], cp);
                                continue;
 
@@ -290,7 +291,7 @@ main(int argc, char **argv)
 
        fflush(stdout);
        if (ferror(stdout)) {
-               adios("output", "error writing");
+               adios(EX_IOERR, "output", "error writing");
        }
 
        return exitstat;
@@ -321,7 +322,7 @@ mhl_format(char *file, int width)
        }
 
        if ((fp = fopen(etcpath(file), "r")) == NULL)
-               adios(file, "unable to open format file");
+               adios(EX_IOERR, file, "unable to open format file");
 
        if (fstat(fileno(fp), &st) != NOTOK) {
                mtime = st.st_mtime;
@@ -383,7 +384,7 @@ mhl_format(char *file, int width)
                        parptr = bp;
                        while (*parptr) {
                                if (evalvar(&global))
-                                       adios(NULL, "format file syntax error: %s", bp);
+                                       adios(EX_CONFIG, NULL, "format file syntax error: %s", bp);
                                if (*parptr)
                                        parptr++;
                        }
@@ -394,7 +395,7 @@ mhl_format(char *file, int width)
                        while (*parptr == ':' || *parptr == ',') {
                                parptr++;
                                if (evalvar(c1))
-                                       adios(NULL, "format file syntax error: %s", bp);
+                                       adios(EX_CONFIG, NULL, "format file syntax error: %s", bp);
                        }
                        if (!c1->c_fstr && global.c_fstr) {
                                if ((c1->c_flags & DATEFMT) &&
@@ -408,7 +409,7 @@ mhl_format(char *file, int width)
                        continue;
 
                default:
-                       adios(NULL, "format file syntax error: %s", bp);
+                       adios(EX_CONFIG, NULL, "format file syntax error: %s", bp);
                }
        }
        fclose(fp);
@@ -700,7 +701,7 @@ mhlfile(FILE *fp, char *mname, int ofilen, int ofilec)
                        return;
 
                default:
-                       adios(NULL, "getfld() returned %d", state);
+                       adios(EX_SOFTWARE, NULL, "getfld() returned %d", state);
                }
        }
 }
@@ -781,7 +782,7 @@ mcomp_format(struct mcomp *c1, struct mcomp *c2)
        while ((cp = getname(ap))) {
                if ((p = (struct pqpair *)
                                calloc((size_t) 1, sizeof(*p))) == NULL)
-                       adios(NULL, "unable to allocate pqpair memory");
+                       adios(EX_OSERR, NULL, "unable to allocate pqpair memory");
 
                if ((mp = getm(cp, NULL, 0, AD_NAME, error)) == NULL) {
                        p->pq_text = getcpy(cp);
@@ -829,7 +830,7 @@ add_queue(struct mcomp **head, struct mcomp **tail, char *name,
        struct mcomp *c1;
 
        if ((c1 = (struct mcomp *) calloc((size_t) 1, sizeof(*c1))) == NULL)
-               adios(NULL, "unable to allocate comp memory");
+               adios(EX_OSERR, NULL, "unable to allocate comp memory");
 
        c1->c_flags = flags & ~INIT;
        if ((c1->c_name = name ? getcpy(name) : NULL))
@@ -892,7 +893,7 @@ putcomp(struct mcomp *c1, struct mcomp *c2, int flag)
        if ((ovtxt = c1->c_ovtxt ? c1->c_ovtxt : global.c_ovtxt) == NULL)
                ovtxt = "";
        if (wid < ovoff + strlen(ovtxt) + 5)
-               adios(NULL, "component: %s width(%d) too small for overflow(%d)", c1->c_name, wid, ovoff + strlen(ovtxt) + 5);
+               adios(EX_SOFTWARE, NULL, "component: %s width(%d) too small for overflow(%d)", c1->c_name, wid, ovoff + strlen(ovtxt) + 5);
        onelp = NULL;
 
        if (c1->c_flags & CLEARTEXT) {
index ceb9336..c4682b4 100644 (file)
@@ -18,6 +18,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define VERBSW  0
@@ -96,7 +97,7 @@ main(int argc, char **argv)
        CT ct, *ctp;
 
        if (atexit(freects_done) != 0) {
-               adios(NULL, "atexit failed");
+               adios(EX_OSERR, NULL, "atexit failed");
        }
 
        setlocale(LC_ALL, "");
@@ -116,39 +117,39 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case PARTSW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                if (npart >= NPARTS)
-                                       adios(NULL, "too many parts (starting with %s), %d max", cp, NPARTS);
+                                       adios(EX_USAGE, NULL, "too many parts (starting with %s), %d max", cp, NPARTS);
                                parts[npart++] = cp;
                                continue;
 
                        case TYPESW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                if (ntype >= NTYPES)
-                                       adios(NULL, "too many types (starting with %s), %d max", cp, NTYPES);
+                                       adios(EX_USAGE, NULL, "too many types (starting with %s), %d max", cp, NTYPES);
                                types[ntype++] = cp;
                                continue;
 
                        case FILESW:
                                if (!(cp = *argp++) || (*cp == '-' && cp[1]))
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                file = *cp == '-' ? cp : getcpy(expanddir(cp));
                                continue;
@@ -166,7 +167,7 @@ main(int argc, char **argv)
                }
                if (*cp == '+' || *cp == '@') {
                        if (folder)
-                               adios(NULL, "only one folder at a time!");
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
                        else
                                folder = getcpy(expandfol(cp));
                } else
@@ -190,14 +191,14 @@ main(int argc, char **argv)
                tmp = getcpy(toabsdir(invo_name));
 
        if (file && msgs.size)
-               adios(NULL, "cannot specify msg and file at same time!");
+               adios(EX_USAGE, NULL, "cannot specify msg and file at same time!");
 
        /*
        ** check if message is coming from file
        */
        if (file) {
                if (!(cts = (CT *) calloc((size_t) 2, sizeof(*cts))))
-                       adios(NULL, "out of memory");
+                       adios(EX_OSERR, NULL, "out of memory");
                ctp = cts;
 
                if ((ct = parse_mime(file)))
@@ -213,28 +214,27 @@ main(int argc, char **argv)
                maildir = toabsdir(folder);
 
                if (chdir(maildir) == NOTOK)
-                       adios(maildir, "unable to change directory to");
+                       adios(EX_OSERR, maildir, "unable to change directory to");
 
                /* read folder and create message structure */
                if (!(mp = folder_read(folder)))
-                       adios(NULL, "unable to read folder %s", folder);
+                       adios(EX_IOERR, NULL, "unable to read folder %s", folder);
 
                /* check for empty folder */
                if (mp->nummsg == 0)
-                       adios(NULL, "no messages in %s", folder);
+                       adios(EX_DATAERR, NULL, "no messages in %s", folder);
 
                /* parse all the message ranges/sequences and set SELECTED */
                for (msgnum = 0; msgnum < msgs.size; msgnum++) {
                        if (!m_convert(mp, msgs.msgs[msgnum])) {
-                               /* sysexits.h EX_USAGE */
-                               exit(1);
+                               exit(EX_SOFTWARE);
                        }
                }
                seq_setprev(mp);  /* set the previous-sequence */
 
                if (!(cts = (CT *) calloc((size_t) (mp->numsel + 1),
                                sizeof(*cts))))
-                       adios(NULL, "out of memory");
+                       adios(EX_OSERR, NULL, "out of memory");
                ctp = cts;
 
                for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
@@ -249,7 +249,7 @@ main(int argc, char **argv)
        }
 
        if (!*cts)
-               exit(1);
+               exit(EX_SOFTWARE);
 
        userrs = 1;
        SIGNAL(SIGQUIT, quitser);
@@ -290,7 +290,7 @@ main(int argc, char **argv)
                context_save();  /* save the context file  */
        }
 
-       return 0;
+       return EX_OK;
 }
 
 
@@ -304,6 +304,6 @@ pipeser(int i)
                fflush(stderr);
        }
 
-       exit(1);
+       _exit(EX_IOERR);
        /* NOTREACHED */
 }
index a59e0e8..2a4f504 100644 (file)
@@ -15,6 +15,7 @@
 #include <h/mhparse.h>
 #include <h/utils.h>
 #include <sys/stat.h>
+#include <sysexits.h>
 
 /* mhmisc.c */
 int part_ok(CT, int);
@@ -117,7 +118,7 @@ list_switch(CT ct, int toplevel, int verbose, int debug)
 
        default:
                /* list_debug (ct); */
-               adios(NULL, "unknown content type %d", ct->c_type);
+               adios(EX_DATAERR, NULL, "unknown content type %d", ct->c_type);
                break;
        }
 
index eea92b7..1515858 100644 (file)
@@ -14,6 +14,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define BODYSW  0
@@ -54,7 +55,7 @@ main(int argc, char **argv)
 
        /* Without arguments, exit. */
        if (argc == 1) {
-               adios(NULL, "no interactive mail shell. Use inc/scan/show instead.");
+               adios(EX_USAGE, NULL, "no interactive mail shell. Use inc/scan/show instead.");
        }
 
        context_read();
@@ -67,30 +68,29 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               /* sysexits.h EX_USAGE */
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf),
                                                "%s addrs... [switches]",
                                                invo_name);
                                print_help(buf, switches, 0);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case FROMSW:
                                if (!(from = *argp++) || *from == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
                        case BODYSW:
                                if (!(body = *argp++) || *body == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
@@ -100,7 +100,7 @@ main(int argc, char **argv)
 
                        case SUBJSW:
                                if (!(subject = *argp++) || *subject == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
                        }
@@ -114,11 +114,11 @@ main(int argc, char **argv)
        }
 
        if (tolist == NULL)
-               adios(NULL, "usage: %s addrs ... [switches]", invo_name);
+               adios(EX_USAGE, NULL, "usage: %s addrs ... [switches]", invo_name);
 
        tfile = m_mktemp2("/tmp/", invo_name, NULL, &out);
        if (tfile == NULL)
-               adios("mhmail", "unable to create temporary file");
+               adios(EX_CANTCREAT, "mhmail", "unable to create temporary file");
        chmod(tfile, 0600);
        strncpy(tmpfil, tfile, sizeof(tmpfil));
 
@@ -147,12 +147,12 @@ main(int argc, char **argv)
                        }
                        empty = 0;
                        if (fputs(buf, out) == EOF) {
-                               adios(tmpfil, "error writing");
+                               adios(EX_IOERR, tmpfil, "error writing");
                        }
                }
                if (empty) {
                        unlink(tmpfil);
-                       adios(NULL, "not sending message with empty body");
+                       adios(EX_DATAERR, NULL, "not sending message with empty body");
                }
        }
        fclose(out);
@@ -171,8 +171,7 @@ main(int argc, char **argv)
                if (in == -1 || out == -1) {
                        fprintf(stderr, "Letter left at %s.\n",
                                        tmpfil);
-                       /* sysexits.h exit-status from spost */
-                       exit(status ? 1 : 0);
+                       exit(status);
                }
                cpydata(in, out, tmpfil, "dead.letter");
                close(in);
@@ -180,8 +179,7 @@ main(int argc, char **argv)
                fprintf(stderr, "Letter saved in dead.letter\n");
        }
        unlink(tmpfil);
-       /* sysexits.h exit status from spost */
-       exit(status ? 1 : 0);
+       exit(status);
 }
 
 
@@ -189,6 +187,6 @@ static void
 intrser(int i)
 {
        unlink(tmpfil);
-       exit(i != 0 ? 1 : 0);
+       _exit(EX_IOERR);
 }
 
index 1d95377..6ac0a22 100644 (file)
@@ -10,6 +10,7 @@
 */
 
 #include <h/mh.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define COMPSW  0
@@ -140,18 +141,17 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               /*sysexits.h EX_USAGE*/
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [profile-components] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case COMPSW:
                                components = 1;
index a325926..fad75d7 100644 (file)
@@ -17,6 +17,7 @@
 #include <unistd.h>
 #include <ctype.h>
 #include <sys/stat.h>
+#include <sysexits.h>
 
 extern int debugsw;
 
@@ -138,7 +139,7 @@ pidcheck(int status)
 
        fflush(stdout);
        fflush(stderr);
-       exit(1);
+       exit(EX_SOFTWARE);
        return 1;
 }
 
@@ -238,7 +239,7 @@ get_content(FILE *in, char *file, int toplevel)
 
        /* allocate the content structure */
        if (!(ct = (CT) calloc(1, sizeof(*ct))))
-               adios(NULL, "out of memory");
+               adios(EX_OSERR, NULL, "out of memory");
 
        ct->c_fp = in;
        ct->c_file = getcpy(file);
@@ -287,11 +288,11 @@ get_content(FILE *in, char *file, int toplevel)
 
                case LENERR:
                case FMTERR:
-                       adios(NULL, "message format error in component #%d",
+                       adios(EX_DATAERR, NULL, "message format error in component #%d",
                                        compnum);
 
                default:
-                       adios(NULL, "getfld() returned %d", state);
+                       adios(EX_SOFTWARE, NULL, "getfld() returned %d", state);
                }
 
                /* break out of the loop */
@@ -981,7 +982,7 @@ InitText(CT ct)
 
        /* allocate text character set structure */
        if ((t = (struct text *) calloc(1, sizeof(*t))) == NULL)
-               adios(NULL, "out of memory");
+               adios(EX_OSERR, NULL, "out of memory");
        ct->c_ctparams = (void *) t;
 
        /* scan for charset parameter */
@@ -1063,7 +1064,7 @@ InitMultiPart(CT ct)
 
        /* allocate primary structure for multipart info */
        if ((m = (struct multipart *) calloc(1, sizeof(*m))) == NULL)
-               adios(NULL, "out of memory");
+               adios(EX_OSERR, NULL, "out of memory");
        ct->c_ctparams = (void *) m;
 
        /* check if boundary parameter contains only whitespace characters */
@@ -1108,7 +1109,7 @@ InitMultiPart(CT ct)
 next_part:
                        if ((part = (struct part *) calloc(1, sizeof(*part)))
                                        == NULL)
-                               adios(NULL, "out of memory");
+                               adios(EX_OSERR, NULL, "out of memory");
                        *next = part;
                        next = &part->mp_next;
 
@@ -1223,7 +1224,7 @@ reverse_parts(CT ct)
 
        /* allocate array of pointers to the parts */
        if (!(base = (struct part **) calloc((size_t) (i + 1), sizeof(*base))))
-               adios(NULL, "out of memory");
+               adios(EX_OSERR, NULL, "out of memory");
        bmp = base;
 
        /* point at all the parts */
@@ -1280,7 +1281,7 @@ InitMessage(CT ct)
                struct partial *p;
 
                if ((p = (struct partial *) calloc(1, sizeof(*p))) == NULL)
-                       adios(NULL, "out of memory");
+               adios(EX_OSERR, NULL, "out of memory");
                ct->c_ctparams = (void *) p;
 
                /*
@@ -1393,7 +1394,7 @@ init_encoding(CT ct, OpenCEFunc openfnx)
        CE ce;
 
        if ((ce = (CE) calloc(1, sizeof(*ce))) == NULL)
-               adios(NULL, "out of memory");
+               adios(EX_OSERR, NULL, "out of memory");
 
        ct->c_cefile     = ce;
        ct->c_ceopenfnx  = openfnx;
@@ -1549,7 +1550,7 @@ openBase64(CT ct, char **file)
                        char *file_org = strdup(ce->ce_file);
                        ce->ce_file = add(cp, ce->ce_file);
                        if (rename(file_org, ce->ce_file)) {
-                               adios(ce->ce_file, "unable to rename %s to ",
+                               adios(EX_IOERR, ce->ce_file, "unable to rename %s to ",
                                                file_org);
                        }
                        free(file_org);
@@ -1566,7 +1567,7 @@ openBase64(CT ct, char **file)
        }
 
        if ((len = ct->c_end - ct->c_begin) < 0)
-               adios(NULL, "internal error(1)");
+               adios(EX_SOFTWARE, NULL, "internal error(1)");
 
        if (!ct->c_fp) {
                if ((ct->c_fp = fopen(ct->c_file, "r")) == NULL) {
@@ -1760,7 +1761,7 @@ openQuoted(CT ct, char **file)
                        char *file_org = strdup(ce->ce_file);
                        ce->ce_file = add(cp, ce->ce_file);
                        if (rename(file_org, ce->ce_file)) {
-                               adios(ce->ce_file, "unable to rename %s to ",
+                               adios(EX_IOERR, ce->ce_file, "unable to rename %s to ",
                                                file_org);
                        }
                        free(file_org);
@@ -1777,7 +1778,7 @@ openQuoted(CT ct, char **file)
        }
 
        if ((len = ct->c_end - ct->c_begin) < 0)
-               adios(NULL, "internal error(2)");
+               adios(EX_SOFTWARE, NULL, "internal error(2)");
 
        if (!ct->c_fp) {
                if ((ct->c_fp = fopen(ct->c_file, "r")) == NULL) {
@@ -1977,7 +1978,7 @@ open7Bit(CT ct, char **file)
                        char *file_org = strdup(ce->ce_file);
                        ce->ce_file = add(cp, ce->ce_file);
                        if (rename(file_org, ce->ce_file)) {
-                               adios(ce->ce_file, "unable to rename %s to ",
+                               adios(EX_IOERR, ce->ce_file, "unable to rename %s to ",
                                                file_org);
                        }
                        free(file_org);
@@ -2043,7 +2044,7 @@ open7Bit(CT ct, char **file)
        }
 
        if ((len = ct->c_end - ct->c_begin) < 0)
-               adios(NULL, "internal error(3)");
+               adios(EX_SOFTWARE, NULL, "internal error(3)");
 
        if (!ct->c_fp) {
                if ((ct->c_fp = fopen(ct->c_file, "r")) == NULL) {
index 47146f4..c400fa6 100644 (file)
@@ -10,6 +10,7 @@
 #include <h/utils.h>
 #include <unistd.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define VERSIONSW 0
@@ -46,26 +47,28 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1); //sysexits.h EX_TEMPFAIL
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0); //sysexits.h EX_OK
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0); //sysexits.h EX_OK
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        }
                }
                if (*cp == '+' || *cp == '@') {
-                       if (folder)
-                               adios(NULL, "only one folder at a time!");
-                       else
+                       if (folder) {
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
+                       } else {
                                folder = getcpy(expandfol(cp));
-               } else
+                       }
+               } else {
                        app_msgarg(&msgs, cp);
+               }
        }
 
        if (!folder)
@@ -75,15 +78,15 @@ main(int argc, char **argv)
        /* If no messages are given, print folder pathname */
        if (!msgs.size) {
                printf("%s\n", maildir);
-               exit(0); //sysexits.h EX_OK
+               exit(EX_OK);
        }
 
        if (chdir(maildir) == NOTOK)
-               adios(maildir, "unable to change directory to");
+               adios(EX_OSERR, maildir, "unable to change directory to");
 
        /* read folder and create message structure */
        if (!(mp = folder_read(folder)))
-               adios(NULL, "unable to read folder %s", folder);
+               adios(EX_IOERR, NULL, "unable to read folder %s", folder);
 
        /*
        ** We need to make sure there is message status space
@@ -92,11 +95,13 @@ main(int argc, char **argv)
        ** space at the end, we go ahead and add 10 slots.
        */
        if (mp->hghmsg >= mp->hghoff) {
-               if (!(mp = folder_realloc(mp, 1, mp->hghmsg + 10)))
-                       adios(NULL, "unable to allocate folder storage");
+               if (!(mp = folder_realloc(mp, 1, mp->hghmsg + 10))) {
+                       adios(EX_OSERR, NULL, "unable to allocate folder storage");
+               }
        } else if (mp->lowoff > 1) {
-               if (!(mp = folder_realloc(mp, 1, mp->hghoff)))
-                       adios(NULL, "unable to allocate folder storage");
+               if (!(mp = folder_realloc(mp, 1, mp->hghoff))) {
+                       adios(EX_OSERR, NULL, "unable to allocate folder storage");
+               }
        }
        /*
        ** TODO: As folder_realloc() checks itself if the realloc
@@ -112,7 +117,7 @@ main(int argc, char **argv)
        /* parse all the message ranges/sequences and set SELECTED */
        for (i = 0; i < msgs.size; i++) {
                if (!m_convert(mp, msgs.msgs[i])) {
-                       exit(1); //sysexits.h EX_USAGE
+                       exit(EX_SOFTWARE);
                }
        }
 
@@ -126,5 +131,5 @@ main(int argc, char **argv)
        seq_save(mp);  /* synchronize message sequences */
        context_save();  /* save the context file */
        folder_free(mp);  /* free folder/message structure */
-       return 0;
+       return EX_OK;
 }
index 3713495..9ae5bf0 100644 (file)
@@ -18,6 +18,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define VERBSW  0
@@ -102,7 +103,7 @@ main(int argc, char **argv)
        int ontty = 0;
 
        if (atexit(freects_done) != 0) {
-               adios(NULL, "atexit failed");
+               adios(EX_OSERR, NULL, "atexit failed");
        }
 
        setlocale(LC_ALL, "");
@@ -127,51 +128,50 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               /* sysexits.h EX_USAGE */
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] %s[switches]", invo_name, mode==SHOW ? "[msgs] " : "");
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case PARTSW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                if (npart >= NPARTS)
-                                       adios(NULL, "too many parts (starting with %s), %d max", cp, NPARTS);
+                                       adios(EX_USAGE, NULL, "too many parts (starting with %s), %d max", cp, NPARTS);
                                parts[npart++] = cp;
                                continue;
 
                        case TYPESW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                if (ntype >= NTYPES)
-                                       adios(NULL, "too many types (starting with %s), %d max", cp, NTYPES);
+                                       adios(EX_USAGE, NULL, "too many types (starting with %s), %d max", cp, NTYPES);
                                types[ntype++] = cp;
                                continue;
 
                        case FILESW:
                                if (mode != SHOW) {
-                                       adios(NULL, "Either call show as `%s' or use -file", invo_name);
+                                       adios(EX_USAGE, NULL, "Either call show as `%s' or use -file", invo_name);
                                }
 
                                if (!(cp = *argp++) || (*cp == '-' && cp[1]))
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                file = *cp == '-' ? cp : getcpy(expanddir(cp));
                                continue;
 
                        case FORMSW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                if (formsw)
                                        free(formsw);
@@ -191,11 +191,11 @@ main(int argc, char **argv)
                }
                if (*cp == '+' || *cp == '@') {
                        if (folder)
-                               adios(NULL, "only one folder at a time!");
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
                        else
                                folder = getcpy(expandfol(cp));
                } else if (mode != SHOW) {
-                       adios(NULL, "Either call show as `%s' or give message arguments", invo_name);
+                       adios(EX_USAGE, NULL, "Either call show as `%s' or give message arguments", invo_name);
                } else {
                        app_msgarg(&msgs, cp);
                }
@@ -243,14 +243,14 @@ main(int argc, char **argv)
                tmp = getcpy(toabsdir(invo_name));
 
        if (file && msgs.size)
-               adios(NULL, "cannot specify msg and file at same time!");
+               adios(EX_USAGE, NULL, "cannot specify msg and file at same time!");
 
        /*
        ** check if message is coming from file
        */
        if (file) {
                if (!(cts = (CT *) calloc((size_t) 2, sizeof(*cts))))
-                       adios(NULL, "out of memory");
+                       adios(EX_OSERR, NULL, "out of memory");
                ctp = cts;
 
                if ((ct = parse_mime(file)))
@@ -277,21 +277,20 @@ main(int argc, char **argv)
                maildir = toabsdir(folder);
 
                if (chdir(maildir) == NOTOK)
-                       adios(maildir, "unable to change directory to");
+                       adios(EX_OSERR, maildir, "unable to change directory to");
 
                /* read folder and create message structure */
                if (!(mp = folder_read(folder)))
-                       adios(NULL, "unable to read folder %s", folder);
+                       adios(EX_IOERR, NULL, "unable to read folder %s", folder);
 
                /* check for empty folder */
                if (mp->nummsg == 0)
-                       adios(NULL, "no messages in %s", folder);
+                       adios(EX_DATAERR, NULL, "no messages in %s", folder);
 
                /* parse all the message ranges/sequences and set SELECTED */
                for (msgnum = 0; msgnum < msgs.size; msgnum++)
                        if (!m_convert(mp, msgs.msgs[msgnum]))
-                               /* sysexits.h EX_USAGE */
-                               exit(1);
+                               exit(EX_USAGE);
 
                /*
                ** Set the SELECT_UNSEEN bit for all the SELECTED messages,
@@ -307,7 +306,7 @@ main(int argc, char **argv)
 
                if (!(cts = (CT *) calloc((size_t) (mp->numsel + 1),
                                sizeof(*cts))))
-                       adios(NULL, "out of memory");
+                       adios(EX_OSERR, NULL, "out of memory");
                ctp = cts;
 
                /*
@@ -325,7 +324,7 @@ main(int argc, char **argv)
        }
 
        if (!*cts)
-               exit(1);
+               exit(EX_SOFTWARE);
 
        userrs = 1;
        SIGNAL(SIGQUIT, quitser);
@@ -388,7 +387,7 @@ pipeser(int i)
                fflush(stderr);
        }
 
-       exit(1);
+       _exit(EX_IOERR);
        /* NOTREACHED */
 }
 
@@ -403,14 +402,14 @@ m_popen(char *name)
        int pd[2];
 
        if ((sd = dup(fileno(stdout))) == NOTOK)
-               adios("standard output", "unable to dup()");
+               adios(EX_OSERR, "standard output", "unable to dup()");
 
        if (pipe(pd) == NOTOK)
-               adios("pipe", "unable to");
+               adios(EX_OSERR, "pipe", "unable to");
 
        switch (m_pid = fork()) {
        case NOTOK:
-               adios("fork", "unable to");
+               adios(EX_OSERR, "fork", "unable to");
 
        case OK:
                SIGNAL(SIGINT, SIG_DFL);
@@ -424,7 +423,7 @@ m_popen(char *name)
                execlp(name, mhbasename(name), NULL);
                fprintf(stderr, "unable to exec ");
                perror(name);
-               _exit(-1);
+               _exit(EX_OSERR);
 
        default:
                close(pd[0]);
@@ -445,7 +444,7 @@ m_pclose(void)
        if (sd != NOTOK) {
                fflush(stdout);
                if (dup2(sd, fileno(stdout)) == NOTOK)
-                       adios("standard output", "unable to dup2()");
+                       adios(EX_OSERR, "standard output", "unable to dup2()");
 
                clearerr(stdout);
                close(sd);
index f6d86cd..aeaf0e8 100644 (file)
@@ -18,6 +18,7 @@
 #include <sys/wait.h>
 #include <unistd.h>
 #include <sys/stat.h>
+#include <sysexits.h>
 
 extern int debugsw;
 
@@ -156,14 +157,14 @@ DisplayMsgHeader(CT ct, char *form)
 
        switch (child_id = fork()) {
        case NOTOK:
-               adios("fork", "unable to");
+               adios(EX_OSERR, "fork", "unable to");
                /* NOTREACHED */
 
        case OK:
                execvp("mhl", vec);
                fprintf(stderr, "unable to exec ");
                perror("mhl");
-               _exit(-1);
+               _exit(EX_OSERR);
                /* NOTREACHED */
 
        default:
@@ -215,7 +216,7 @@ show_switch(CT ct, int alternate)
                break;
 
        default:
-               adios(NULL, "unknown content type %d", ct->c_type);
+               adios(EX_DATAERR, NULL, "unknown content type %d", ct->c_type);
                break;
        }
 
@@ -481,7 +482,7 @@ show_content_aux2(CT ct, int alternate, char *cracked,
                execlp("/bin/sh", "/bin/sh", "-c", buffer, NULL);
                fprintf(stderr, "unable to exec ");
                perror("/bin/sh");
-               _exit(-1);
+               _exit(EX_OSERR);
                /* NOTREACHED */
 
        default:
@@ -908,12 +909,12 @@ show_external(CT ct, int alternate)
                msg = add(concat("\t", *ap, ": ", *ep, NULL), msg);
        }
        if (!(fp = fopen(ct->c_file, "r"))) {
-               adios(ct->c_file, "unable to open");
+               adios(EX_IOERR, ct->c_file, "unable to open");
        }
        fseek(fp, ct->c_begin, SEEK_SET);
        while (!feof(fp) && ftell(fp) < ct->c_end) {
                if (!fgets(buf, sizeof buf, fp)) {
-                       adios(ct->c_file, "unable to read");
+                       adios(EX_IOERR, ct->c_file, "unable to read");
                }
                *strchr(buf, '\n') = '\0';
                if (!*buf) {
index 74442ad..4234d25 100644 (file)
@@ -18,6 +18,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define AUTOSW  0
@@ -133,7 +134,7 @@ main(int argc, char **argv)
        FILE *fp;
 
        if (atexit(freects_done) != 0) {
-               adios(NULL, "atexit failed");
+               adios(EX_OSERR, NULL, "atexit failed");
        }
 
        setlocale(LC_ALL, "");
@@ -153,17 +154,17 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case AUTOSW:
                                autosw++;
@@ -174,25 +175,25 @@ main(int argc, char **argv)
 
                        case PARTSW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                if (npart >= NPARTS)
-                                       adios(NULL, "too many parts (starting with %s), %d max", cp, NPARTS);
+                                       adios(EX_USAGE, NULL, "too many parts (starting with %s), %d max", cp, NPARTS);
                                parts[npart++] = cp;
                                continue;
 
                        case TYPESW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                if (ntype >= NTYPES)
-                                       adios(NULL, "too many types (starting with %s), %d max", cp, NTYPES);
+                                       adios(EX_USAGE, NULL, "too many types (starting with %s), %d max", cp, NTYPES);
                                types[ntype++] = cp;
                                continue;
 
                        case FILESW:
                                if (!(cp = *argp++) || (*cp == '-' && cp[1]))
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                file = *cp == '-' ? cp : getcpy(expanddir(cp));
                                continue;
@@ -204,7 +205,7 @@ main(int argc, char **argv)
                }
                if (*cp == '+' || *cp == '@') {
                        if (folder)
-                               adios(NULL, "only one folder at a time!");
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
                        else
                                folder = getcpy(expandfol(cp));
                } else
@@ -254,14 +255,14 @@ main(int argc, char **argv)
                tmp = getcpy(toabsdir(invo_name));
 
        if (file && msgs.size)
-               adios(NULL, "cannot specify msg and file at same time!");
+               adios(EX_USAGE, NULL, "cannot specify msg and file at same time!");
 
        /*
        ** check if message is coming from file
        */
        if (file) {
                if (!(cts = (CT *) calloc((size_t) 2, sizeof(*cts))))
-                       adios(NULL, "out of memory");
+                       adios(EX_OSERR, NULL, "out of memory");
                ctp = cts;
 
                if ((ct = parse_mime(file)))
@@ -277,25 +278,25 @@ main(int argc, char **argv)
                maildir = toabsdir(folder);
 
                if (chdir(maildir) == NOTOK)
-                       adios(maildir, "unable to change directory to");
+                       adios(EX_OSERR, maildir, "unable to change directory to");
 
                /* read folder and create message structure */
                if (!(mp = folder_read(folder)))
-                       adios(NULL, "unable to read folder %s", folder);
+                       adios(EX_IOERR, NULL, "unable to read folder %s", folder);
 
                /* check for empty folder */
                if (mp->nummsg == 0)
-                       adios(NULL, "no messages in %s", folder);
+                       adios(EX_DATAERR, NULL, "no messages in %s", folder);
 
                /* parse all the message ranges/sequences and set SELECTED */
                for (msgnum = 0; msgnum < msgs.size; msgnum++)
                        if (!m_convert(mp, msgs.msgs[msgnum]))
-                               exit(1);
+                               exit(EX_USAGE);
                seq_setprev(mp);  /* set the previous-sequence */
 
                if (!(cts = (CT *) calloc((size_t) (mp->numsel + 1),
                                sizeof(*cts))))
-                       adios(NULL, "out of memory");
+                       adios(EX_OSERR, NULL, "out of memory");
                ctp = cts;
 
                for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
@@ -310,7 +311,7 @@ main(int argc, char **argv)
        }
 
        if (!*cts)
-               exit(1);
+               exit(EX_SOFTWARE);
 
        userrs = 1;
        SIGNAL(SIGQUIT, quitser);
@@ -363,9 +364,10 @@ pipeser(int i)
                fflush(stdout);
                fprintf(stderr, "\n");
                fflush(stderr);
+               exit(EX_TEMPFAIL);
        }
 
-       exit(1);
+       exit(EX_IOERR);
        /* NOTREACHED */
 }
 
@@ -455,7 +457,7 @@ store_switch(CT ct)
                break;
 
        default:
-               adios(NULL, "unknown content type %d", ct->c_type);
+               adios(EX_DATAERR, NULL, "unknown content type %d", ct->c_type);
                break;
        }
 
@@ -569,7 +571,7 @@ store_partial(CT ct)
        }
 
        if ((base = (CT *) calloc((size_t) (i + 1), sizeof(*base))) == NULL)
-               adios(NULL, "out of memory");
+               adios(EX_OSERR, NULL, "out of memory");
 
        ctq = base;
        for (ctp = cts; *ctp; ctp++) {
@@ -648,12 +650,12 @@ store_external(CT ct)
                msg = add(concat("\n\t", *ap, ": ", *ep, NULL), msg);
        }
        if (!(fp = fopen(ct->c_file, "r"))) {
-               adios(ct->c_file, "unable to open");
+               adios(EX_IOERR, ct->c_file, "unable to open");
        }
        fseek(fp, ct->c_begin, SEEK_SET);
        while (!feof(fp) && ftell(fp) < ct->c_end) {
                if (!fgets(buf, sizeof buf, fp)) {
-                       adios(ct->c_file, "unable to read");
+                       adios(EX_IOERR, ct->c_file, "unable to read");
                }
                *strchr(buf, '\n') = '\0';
                msg = add(concat("\n\t", buf, NULL), msg);
index c31a2dc..5b47f22 100644 (file)
@@ -18,6 +18,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define VERBSW  0
@@ -99,7 +100,7 @@ main(int argc, char **argv)
        CT ct, *ctp;
 
        if (atexit(freects_done) != 0) {
-               adios(NULL, "atexit failed");
+               adios(EX_OSERR, NULL, "atexit failed");
        }
 
        setlocale(LC_ALL, "");
@@ -119,45 +120,45 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case PARTSW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s", argp[-2]);
+                                       adios(EX_USAGE, NULL, "missing argument to %s", argp[-2]);
                                if (npart >= NPARTS)
-                                       adios(NULL, "too many parts (starting with %s), %d max", cp, NPARTS);
+                                       adios(EX_USAGE, NULL, "too many parts (starting with %s), %d max", cp, NPARTS);
                                parts[npart++] = cp;
                                continue;
 
                        case TYPESW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s", argp[-2]);
+                                       adios(EX_USAGE, NULL, "missing argument to %s", argp[-2]);
                                if (ntype >= NTYPES)
-                                       adios(NULL, "too many types (starting with %s), %d max",
+                                       adios(EX_USAGE, NULL, "too many types (starting with %s), %d max",
                                                   cp, NTYPES);
                                types[ntype++] = cp;
                                continue;
 
                        case FILESW:
                                if (!(cp = *argp++) || (*cp == '-' && cp[1]))
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                file = *cp == '-' ? cp : getcpy(expanddir(cp));
                                continue;
 
                        case OUTFILESW:
                                if (!(cp = *argp++) || (*cp == '-' && cp[1]))
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                outfile = *cp == '-' ? cp : getcpy(expanddir(cp));
                                continue;
@@ -175,7 +176,7 @@ main(int argc, char **argv)
                }
                if (*cp == '+' || *cp == '@') {
                        if (folder)
-                               adios(NULL, "only one folder at a time!");
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
                        else
                                folder = getcpy(expandfol(cp));
                } else
@@ -189,7 +190,7 @@ main(int argc, char **argv)
        set_endian();
 
        if (outfile == NULL)
-               adios(NULL, "must specify output file");
+               adios(EX_USAGE, NULL, "must specify output file");
 
        /*
        ** Check for storage directory.  If specified,
@@ -202,14 +203,14 @@ main(int argc, char **argv)
                tmp = getcpy(toabsdir(invo_name));
 
        if (file && msgs.size)
-               adios(NULL, "cannot specify msg and file at same time!");
+               adios(EX_USAGE, NULL, "cannot specify msg and file at same time!");
 
        /*
        ** check if message is coming from file
        */
        if (file) {
                if (!(cts = (CT *) calloc((size_t) 2, sizeof(*cts))))
-                       adios(NULL, "out of memory");
+                       adios(EX_OSERR, NULL, "out of memory");
                ctp = cts;
 
                if ((ct = parse_mime(file)))
@@ -225,25 +226,25 @@ main(int argc, char **argv)
                maildir = toabsdir(folder);
 
                if (chdir(maildir) == NOTOK)
-                       adios(maildir, "unable to change directory to");
+                       adios(EX_OSERR, maildir, "unable to change directory to");
 
                /* read folder and create message structure */
                if (!(mp = folder_read(folder)))
-                       adios(NULL, "unable to read folder %s", folder);
+                       adios(EX_IOERR, NULL, "unable to read folder %s", folder);
 
                /* check for empty folder */
                if (mp->nummsg == 0)
-                       adios(NULL, "no messages in %s", folder);
+                       adios(EX_DATAERR, NULL, "no messages in %s", folder);
 
                /* parse all the message ranges/sequences and set SELECTED */
                for (msgnum = 0; msgnum < msgs.size; msgnum++)
                        if (!m_convert(mp, msgs.msgs[msgnum]))
-                               exit(1);
+                               exit(EX_USAGE);
                seq_setprev(mp);  /* set the previous-sequence */
 
                if (!(cts = (CT *) calloc((size_t) (mp->numsel + 1),
                                sizeof(*cts))))
-                       adios(NULL, "out of memory");
+                       adios(EX_OSERR, NULL, "out of memory");
                ctp = cts;
 
                for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
@@ -258,7 +259,7 @@ main(int argc, char **argv)
        }
 
        if (!*cts)
-               exit(1);
+               exit(EX_SOFTWARE);
 
        userrs = 1;
        SIGNAL(SIGQUIT, quitser);
@@ -299,7 +300,7 @@ main(int argc, char **argv)
                context_save();  /* save the context file  */
        }
 
-       return 0;
+       return EX_OK;
 }
 
 
@@ -328,6 +329,6 @@ pipeser(int i)
                fflush(stderr);
        }
 
-       exit(1);
+       exit(EX_IOERR);
        /* NOTREACHED */
 }
index e95ee6a..90e2da7 100644 (file)
--- a/uip/new.c
+++ b/uip/new.c
@@ -19,6 +19,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define MODESW 0
@@ -160,7 +161,7 @@ get_msgnums(char *folder, char *sequences[])
 
                case BODY:
                case BODYEOF:
-                       adios(NULL, "no blank lines are permitted in %s",
+                       adios(EX_DATAERR, NULL, "no blank lines are permitted in %s",
                                        seqfile);
                        /* fall */
 
@@ -168,7 +169,7 @@ get_msgnums(char *folder, char *sequences[])
                        break;
 
                default:
-                       adios(NULL, "%s is poorly formatted", seqfile);
+                       adios(EX_SOFTWARE, NULL, "%s is poorly formatted", seqfile);
                }
                break;  /* break from for loop */
        }
@@ -256,7 +257,7 @@ check_folders(struct node **first, struct node **last,
        } else {
                fp = fopen(folders, "r");
                if (fp  == NULL) {
-                       adios(NULL, "failed to read %s", folders);
+                       adios(EX_IOERR, NULL, "failed to read %s", folders);
                }
                while (vfgets(fp, &line) == OK) {
                        len = strlen(line) - 1;
@@ -457,28 +458,28 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(help, sizeof(help),
                                                "%s [switches] [sequences]",
                                                invo_name);
                                print_help(help, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case FOLDERSSW:
                                if (!(folders = *argp++) || *folders == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
                        case MODESW:
                                if (!(invo_name = *argp++) || *invo_name == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                invo_name = mhbasename(invo_name);
                                continue;
@@ -512,7 +513,7 @@ main(int argc, char **argv)
                /* no sequence arguments; use unseen */
                if ((unseen = context_find(usequence))) {
                        if (!*unseen) {
-                               adios(NULL, "profile entry %s set, but empty, and no sequences given", usequence);
+                               adios(EX_CONFIG, NULL, "profile entry %s set, but empty, and no sequences given", usequence);
                        }
                } else {
                        unseen = seq_unseen;  /* use default */
@@ -526,7 +527,7 @@ main(int argc, char **argv)
 
        folder = doit(context_find(curfolder), folders, sequences);
        if (folder == NULL) {
-               exit(0);
+               exit(EX_OK);
                return 1;
        }
 
index 78f64c0..c81db88 100644 (file)
@@ -13,6 +13,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define VERSIONSW  0
@@ -49,22 +50,22 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        }
                }
                if (*cp == '+' || *cp == '@') {
                        if (folder)
-                               adios(NULL, "only one folder at a time!");
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
                        folder = getcpy(expandfol(cp));
                } else
                        app_msgarg(&msgs, cp);
@@ -79,20 +80,20 @@ main(int argc, char **argv)
        maildir = toabsdir(folder);
 
        if (chdir(maildir) == NOTOK)
-               adios(maildir, "unable to change directory to ");
+               adios(EX_OSERR, maildir, "unable to change directory to ");
 
        /* read folder and create message structure */
        if (!(mp = folder_read(folder)))
-               adios(NULL, "unable to read folder %s", folder);
+               adios(EX_IOERR, NULL, "unable to read folder %s", folder);
 
        /* check for empty folder */
        if (mp->nummsg == 0)
-               adios(NULL, "no messages in %s", folder);
+               adios(EX_DATAERR, NULL, "no messages in %s", folder);
 
        /* parse all the message ranges/sequences and set SELECTED */
        for (msgnum = 0; msgnum < msgs.size; msgnum++)
                if (!m_convert(mp, msgs.msgs[msgnum]))
-                       exit(1);
+                       exit(EX_USAGE);
        seq_setprev(mp);  /* set the previous-sequence */
 
        /* copy all the SELECTED messages to stdout */
@@ -104,7 +105,7 @@ main(int argc, char **argv)
                                break;
                        }
                        if (mbox_copy(fileno(stdout), fd) == NOTOK) {
-                               adios(NULL, "error writing to stdout");
+                               adios(EX_IOERR, NULL, "error writing to stdout");
                        }
                        close(fd);
                }
index 07dca9a..a487adc 100644 (file)
@@ -11,6 +11,7 @@
 #include <h/utils.h>
 #include <unistd.h>
 #include <locale.h>
+#include <sysexits.h>
 
 #ifdef HAVE_SYS_TIME_H
 # include <sys/time.h>
@@ -94,7 +95,7 @@ main(int argc, char **argv)
        register FILE *fp;
 
         if (atexit(putzero_done) != 0) {
-               adios(NULL, "atexit failed");
+               adios(EX_OSERR, NULL, "atexit failed");
        }
 
        setlocale(LC_ALL, "");
@@ -116,19 +117,19 @@ main(int argc, char **argv)
                        case AMBIGSW:
                                ambigsw(cp, switches);
                                listsw = 0;  /* HACK */
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
                                print_help(buf, switches, 1);
                                listsw = 0;  /* HACK */
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
                                listsw = 0;  /* HACK */
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case CCSW:
                        case DATESW:
@@ -142,12 +143,12 @@ main(int argc, char **argv)
                                vec[vecp++] = --cp;
                        pattern:
                                if (!(cp = *argp++)) /* allow -xyz arguments */
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                vec[vecp++] = cp;
                                continue;
                        case OTHRSW:
-                               adios(NULL, "internal error!");
+                               adios(EX_SOFTWARE, NULL, "internal error!");
 
                        case ANDSW:
                        case ORSW:
@@ -159,15 +160,15 @@ main(int argc, char **argv)
 
                        case SEQSW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
 
                                /* check if too many sequences specified */
                                if (seqp >= NUMATTRS)
-                                       adios(NULL, "too many sequences (more than %d) specified", NUMATTRS);
+                                       adios(EX_USAGE, NULL, "too many sequences (more than %d) specified", NUMATTRS);
 
                                if (!seq_nameok(cp))
-                                       exit(1);
+                                       exit(EX_USAGE);
 
                                seqs[seqp++] = cp;
                                continue;
@@ -194,7 +195,7 @@ main(int argc, char **argv)
                }
                if (*cp == '+' || *cp == '@') {
                        if (folder)
-                               adios(NULL, "only one folder at a time!");
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
                        else
                                folder = getcpy(expandfol(cp));
                } else
@@ -214,20 +215,20 @@ main(int argc, char **argv)
        maildir = toabsdir(folder);
 
        if (chdir(maildir) == NOTOK)
-               adios(maildir, "unable to change directory to");
+               adios(EX_OSERR, maildir, "unable to change directory to");
 
        /* read folder and create message structure */
        if (!(mp = folder_read(folder)))
-               adios(NULL, "unable to read folder %s", folder);
+               adios(EX_IOERR, NULL, "unable to read folder %s", folder);
 
        /* check for empty folder */
        if (mp->nummsg == 0)
-               adios(NULL, "no messages in %s", folder);
+               adios(EX_DATAERR, NULL, "no messages in %s", folder);
 
        /* parse all the message ranges/sequences and set SELECTED */
        for (msgnum = 0; msgnum < msgs.size; msgnum++)
                if (!m_convert(mp, msgs.msgs[msgnum]))
-                       exit(1);
+                       exit(EX_USAGE);
        seq_setprev(mp);  /* set the previous-sequence */
 
        /*
@@ -238,11 +239,11 @@ main(int argc, char **argv)
                listsw = !seqp;
 
        if (publicsw == 1 && is_readonly(mp))
-               adios(NULL, "folder %s is read-only, so -public not allowed",
+               adios(EX_NOPERM, NULL, "folder %s is read-only, so -public not allowed",
                                folder);
 
        if (!pcompile(vec, NULL))
-               exit(1);
+               exit(EX_SOFTWARE);
 
        lo = mp->lowsel;
        hi = mp->hghsel;
@@ -284,7 +285,7 @@ main(int argc, char **argv)
        mp->hghsel = hi;
 
        if (mp->numsel <= 0)
-               adios(NULL, "no messages match specification");
+               adios(EX_DATAERR, NULL, "no messages match specification");
 
        seqs[seqp] = NULL;
 
@@ -293,7 +294,7 @@ main(int argc, char **argv)
        */
        for (seqp = 0; seqs[seqp]; seqp++)
                if (!seq_addsel(mp, seqs[seqp], publicsw, zerosw))
-                       exit(1);
+                       exit(EX_USAGE);
 
        /*
        ** Print total matched if not printing each matched message number.
@@ -768,7 +769,7 @@ newnexus(int (*action)())
        register struct nexus *p;
 
        if ((p = (struct nexus *) calloc((size_t) 1, sizeof *p)) == NULL)
-               adios(NULL, "unable to allocate component storage");
+               adios(EX_OSERR, NULL, "unable to allocate component storage");
 
        p->n_action = action;
        return p;
@@ -1270,7 +1271,7 @@ plist
                        return 0;
 
                default:
-                       adios(NULL, "internal error -- you lose");
+                       adios(EX_SOFTWARE, NULL, "internal error -- you lose");
                }
                break;
        }
index 2bcd92a..0ca1e83 100644 (file)
@@ -16,6 +16,7 @@
 #include <ctype.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define PREPSW  0
@@ -75,19 +76,20 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buffer, sizeof(buffer),
                                                "%s [switches] file",
                                                invo_name);
                                print_help(buffer, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
+
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case PREPSW:
                                prepend++;
@@ -115,14 +117,17 @@ main(int argc, char **argv)
                }
        }
 
-       if (!drft)
-               adios(NULL, "usage: %s [switches] file", invo_name);
-       if ((in = fopen(drft, "r")) == NULL)
-               adios(drft, "unable to open");
+       if (!drft) {
+               adios(EX_USAGE, NULL, "usage: %s [switches] file", invo_name);
+       }
+       if ((in = fopen(drft, "r")) == NULL) {
+               adios(EX_IOERR, drft, "unable to open");
+       }
 
        tfile = m_mktemp2(NULL, invo_name, NULL, &out);
-       if (tfile == NULL)
-               adios("prompter", "unable to create temporary file");
+       if (tfile == NULL) {
+               adios(EX_CANTCREAT, "prompter", "unable to create temporary file");
+       }
        chmod(tmpfil, 0600);
        strncpy(tmpfil, tfile, sizeof(tmpfil));
 
@@ -164,8 +169,7 @@ main(int argc, char **argv)
                                if (i == -1) {
 abort:
                                        unlink(tmpfil);
-                                       /* sysexits.h EX_DATAERR */
-                                       exit(1);
+                                       exit(EX_DATAERR);
                                }
                                if (i || (field[0]!='\n' && field[0]!='\0')) {
                                        fprintf(out, "%s:", name);
@@ -236,7 +240,7 @@ has_no_body:
                        break;
 
                default:
-                       adios(NULL, "skeleton is poorly formatted");
+                       adios(EX_DATAERR, NULL, "skeleton is poorly formatted");
                }
                break;
        }
@@ -249,17 +253,19 @@ has_no_body:
        fclose(out);
        SIGNAL(SIGINT, SIG_IGN);
 
-       if ((fdi = open(tmpfil, O_RDONLY)) == NOTOK)
-               adios(tmpfil, "unable to re-open");
-       if ((fdo = creat(drft, m_gmprot())) == NOTOK)
-               adios(drft, "unable to write");
+       if ((fdi = open(tmpfil, O_RDONLY)) == NOTOK) {
+               adios(EX_IOERR, tmpfil, "unable to re-open");
+       }
+       if ((fdo = creat(drft, m_gmprot())) == NOTOK) {
+               adios(EX_IOERR, drft, "unable to write");
+       }
        cpydata(fdi, fdo, tmpfil, drft);
        close(fdi);
        close(fdo);
        unlink(tmpfil);
 
        context_save();  /* save the context file */
-       return 0;
+       return EX_OK;
 }
 
 
index 4e052cc..4027ea2 100644 (file)
@@ -14,6 +14,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define FORMSW  0
@@ -46,7 +47,7 @@ main(int argc, char **argv)
        char *tfile = NULL;
 
        if (atexit(unlink_done) != 0) {
-               adios(NULL, "atexit failed");
+               adios(EX_OSERR, NULL, "atexit failed");
        }
 
        setlocale(LC_ALL, "");
@@ -63,7 +64,7 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
                                vec[vecp++] = --cp;
                                continue;
@@ -71,14 +72,14 @@ main(int argc, char **argv)
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [switches] [switches for spost] address ...", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case FORMSW:
                                if (!(form = *argp++) || *form == '-') {
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                }
                                continue;
@@ -88,28 +89,27 @@ main(int argc, char **argv)
        }
 
        if (!addrs) {
-               adios(NULL, "usage: %s [switches] [switches for spost] address ...", invo_name);
+               adios(EX_USAGE, NULL, "usage: %s [switches] [switches for spost] address ...", invo_name);
        }
 
        umask(~m_gmprot());
 
        tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
-       if (tfile == NULL) adios("rcvdist", "unable to create temporary file");
+       if (tfile == NULL) adios(EX_CANTCREAT, "rcvdist", "unable to create temporary file");
        strncpy(tmpfil, tfile, sizeof(tmpfil));
 
        cpydata(fileno(stdin), fileno(fp), "message", tmpfil);
        fseek(fp, 0L, SEEK_SET);
 
        tfile = m_mktemp2(NULL, invo_name, NULL, NULL);
-       if (tfile == NULL) adios("forw", "unable to create temporary file");
+       if (tfile == NULL) adios(EX_CANTCREAT, "forw", "unable to create temporary file");
        strncpy(drft, tfile, sizeof(tmpfil));
 
        rcvdistout(fp, form, addrs);
        fclose(fp);
 
        if (distout(drft, tmpfil, backup) == NOTOK) {
-               /* sysexits.h EX_DATAERR */
-               exit(1);
+               exit(EX_IOERR);
        }
 
        vec[0] = "spost";
@@ -120,7 +120,7 @@ main(int argc, char **argv)
        execvp(*vec, vec);
        fprintf(stderr, "unable to exec ");
        perror(*vec);
-       _exit(1);
+       _exit(EX_OSERR);
        return 0;  /* dead code to satisfy the compiler */
 }
 
@@ -163,7 +163,7 @@ rcvdistout(FILE *inb, char *form, char *addrs)
        FILE *out;
 
        if (!(out = fopen(drft, "w"))) {
-               adios(drft, "unable to create");
+               adios(EX_CANTCREAT, drft, "unable to create");
        }
 
        /* get new format string */
@@ -172,12 +172,12 @@ rcvdistout(FILE *inb, char *form, char *addrs)
        ncomps = fmt_compile(cp, &fmt) + 1;
        if (!(nxtbuf = compbuffers =
                        (char **) calloc((size_t) ncomps, sizeof(char *)))) {
-               adios(NULL, "unable to allocate component buffers");
+               adios(EX_OSERR, NULL, "unable to allocate component buffers");
        }
        if (!(savecomp = used_buf =
                        (struct comp **) calloc((size_t) (ncomps + 1),
                        sizeof(struct comp *)))) {
-               adios(NULL, "unable to allocate component buffer stack");
+               adios(EX_OSERR, NULL, "unable to allocate component buffer stack");
        }
        savecomp += ncomps + 1;
        *--savecomp = 0;
@@ -250,7 +250,7 @@ rcvdistout(FILE *inb, char *form, char *addrs)
                        goto finished;
 
                default:
-                       adios(NULL, "m_getfld() returned %d", state);
+                       adios(EX_SOFTWARE, NULL, "m_getfld() returned %d", state);
                }
        }
 finished: ;
@@ -263,7 +263,7 @@ finished: ;
        fputs(scanl, out);
 
        if (ferror(out)) {
-               adios(drft, "error writing");
+               adios(EX_IOERR, drft, "error writing");
        }
        fclose(out);
 
index 4c271df..bd6bacb 100644 (file)
@@ -12,6 +12,7 @@
 #include <h/tws.h>
 #include <unistd.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define VERSIONSW  0
@@ -44,23 +45,23 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf),
                                                "%s [switches] file",
                                                invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        }
                }
                if (file)
-                       adios(NULL, "only one file at a time!");
+                       adios(EX_USAGE, NULL, "only one file at a time!");
                else
                        file = cp;
        }
index 61a91b2..9c84270 100644 (file)
@@ -14,6 +14,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define CRETSW  0
@@ -62,7 +63,7 @@ main(int argc, char **argv)
        struct stat st;
 
        if (atexit(unlink_done) != 0) {
-               adios(NULL, "atexit failed");
+               adios(EX_OSERR, NULL, "atexit failed");
        }
 
        setlocale(LC_ALL, "");
@@ -80,27 +81,27 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf),
                                                "%s [+folder] [switches]",
                                                invo_name);
                                print_help(buf, switches, 1);
-                               exit(1);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(1);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case SEQSW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument name to %s", argp[-2]);
+                                       adios(EX_USAGE, NULL, "missing argument name to %s", argp[-2]);
 
                                /* check if too many sequences specified */
                                if (seqp >= NUMATTRS)
-                                       adios(NULL, "too many sequences (more than %d) specified", NUMATTRS);
+                                       adios(EX_USAGE, NULL, "too many sequences (more than %d) specified", NUMATTRS);
                                seqs[seqp++] = cp;
                                continue;
 
@@ -135,11 +136,11 @@ main(int argc, char **argv)
                }
                if (*cp == '+' || *cp == '@') {
                        if (folder)
-                               adios(NULL, "only one folder at a time!");
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
                        else
                                folder = getcpy(expandfol(cp));
                } else {
-                       adios(NULL, "usage: %s [+folder] [switches]",
+                       adios(EX_USAGE, NULL, "usage: %s [+folder] [switches]",
                                        invo_name);
                }
        }
@@ -154,15 +155,15 @@ main(int argc, char **argv)
        /* check if folder exists */
        if (stat(maildir, &st) == NOTOK) {
                if (errno != ENOENT)
-                       adios(maildir, "error on folder");
+                       adios(EX_IOERR, maildir, "error on folder");
                if (!create)
-                       adios(NULL, "folder %s doesn't exist", maildir);
+                       adios(EX_USAGE, NULL, "folder %s doesn't exist", maildir);
                if (!makedir(maildir))
-                       adios(NULL, "unable to create folder %s", maildir);
+                       adios(EX_CANTCREAT, NULL, "unable to create folder %s", maildir);
        }
 
        if (chdir(maildir) == NOTOK)
-               adios(maildir, "unable to change directory to");
+               adios(EX_OSERR, maildir, "unable to change directory to");
 
        /* ignore a few signals */
        SIGNAL(SIGHUP, SIG_IGN);
@@ -173,7 +174,7 @@ main(int argc, char **argv)
        /* create a temporary file */
        tmpfilenam = m_mktemp(invo_name, &fd, NULL);
        if (tmpfilenam == NULL) {
-               adios("rcvstore", "unable to create temporary file");
+               adios(EX_CANTCREAT, "rcvstore", "unable to create temporary file");
        }
        chmod(tmpfilenam, m_gmprot());
 
@@ -182,23 +183,23 @@ main(int argc, char **argv)
 
        if (fstat(fd, &st) == NOTOK) {
                unlink(tmpfilenam);
-               adios(tmpfilenam, "unable to fstat");
+               adios(EX_IOERR, tmpfilenam, "unable to fstat");
        }
        if (close(fd) == NOTOK)
-               adios(tmpfilenam, "error closing");
+               adios(EX_IOERR, tmpfilenam, "error closing");
 
        /* don't add file if it is empty */
        if (st.st_size == 0) {
                unlink(tmpfilenam);
                advise(NULL, "empty file");
-               exit(0);
+               exit(EX_OK);
        }
 
        /*
        ** read folder and create message structure
        */
        if (!(mp = folder_read(folder)))
-               adios(NULL, "unable to read folder %s", folder);
+               adios(EX_IOERR, NULL, "unable to read folder %s", folder);
 
        /*
        ** Link message into folder, and possibly add
@@ -206,7 +207,7 @@ main(int argc, char **argv)
        */
        if ((msgnum = folder_addmsg(&mp, tmpfilenam, 0, unseensw, 0, 0, NULL))
                        == -1)
-               exit(1);
+               exit(EX_SOFTWARE);
 
        /*
        ** Add the message to any extra sequences
@@ -214,7 +215,7 @@ main(int argc, char **argv)
        */
        for (seqp = 0; seqs[seqp]; seqp++) {
                if (!seq_addmsg(mp, seqs[seqp], msgnum, publicsw, zerosw))
-                       exit(1);
+                       exit(EX_SOFTWARE);
        }
 
        seq_setunseen(mp, 1);  /* add new msgs to unseen sequences */
@@ -225,7 +226,7 @@ main(int argc, char **argv)
        unlink(tmpfilenam);  /* remove temporary file */
        tmpfilenam = NULL;
 
-       return 0;
+       return EX_OK;
 }
 
 /*
index 17e6d61..01f205b 100644 (file)
@@ -13,6 +13,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define LINKSW  0
@@ -75,17 +76,17 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown\n", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown\n", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [msgs] [switches] +folder ...", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case LINKSW:
                                linkf++;
@@ -96,18 +97,18 @@ main(int argc, char **argv)
 
                        case SRCSW:
                                if (folder)
-                                       adios(NULL, "only one source folder at a time!");
+                                       adios(EX_USAGE, NULL, "only one source folder at a time!");
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                folder = getcpy(expandfol(cp));
                                continue;
                        case FILESW:
                                if (filep > NFOLDERS)
-                                       adios(NULL, "only %d files allowed!",
+                                       adios(EX_USAGE, NULL, "only %d files allowed!",
                                                        NFOLDERS);
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                files[filep++] = getcpy(expanddir(cp));
                                continue;
@@ -115,7 +116,7 @@ main(int argc, char **argv)
                }
                if (*cp == '+' || *cp == '@') {
                        if (foldp > NFOLDERS)
-                               adios(NULL, "only %d folders allowed!",
+                               adios(EX_USAGE, NULL, "only %d folders allowed!",
                                                NFOLDERS);
                        folders[foldp++].f_name = getcpy(expandfol(cp));
                } else
@@ -123,19 +124,18 @@ main(int argc, char **argv)
        }
 
        if (foldp == 0)
-               adios(NULL, "no folder specified");
+               adios(EX_USAGE, NULL, "no folder specified");
 
        /*
        ** We are refiling a file to the folders
        */
        if (filep > 0) {
                if (folder || msgs.size)
-                       adios(NULL, "use -file or msgs, not both");
+                       adios(EX_USAGE, NULL, "use -file or msgs, not both");
                opnfolds(folders, foldp);
                for (i = 0; i < filep; i++)
                        if (m_file(files[i], folders, foldp, 0))
-                               /* sysexits.h EX_IOERR */
-                               exit(1);
+                               exit(EX_IOERR);
                /* If -nolink, then unlink files */
                if (!linkf) {
                        int i;
@@ -147,7 +147,7 @@ main(int argc, char **argv)
                                        admonish(files[i], "unable to unlink");
                        }
                }
-               exit(0);
+               exit(EX_OK);
        }
 
        if (!msgs.size)
@@ -157,21 +157,20 @@ main(int argc, char **argv)
        strncpy(maildir, toabsdir(folder), sizeof(maildir));
 
        if (chdir(maildir) == NOTOK)
-               adios(maildir, "unable to change directory to");
+               adios(EX_OSERR, maildir, "unable to change directory to");
 
        /* read source folder and create message structure */
        if (!(mp = folder_read(folder)))
-               adios(NULL, "unable to read folder %s", folder);
+               adios(EX_IOERR, NULL, "unable to read folder %s", folder);
 
        /* check for empty folder */
        if (mp->nummsg == 0)
-               adios(NULL, "no messages in %s", folder);
+               adios(EX_DATAERR, NULL, "no messages in %s", folder);
 
        /* parse the message range/sequence/name and set SELECTED */
        for (msgnum = 0; msgnum < msgs.size; msgnum++)
                if (!m_convert(mp, msgs.msgs[msgnum]))
-                       /* sysexits.h EX_USAGE */
-                       exit(1);
+                       exit(EX_SOFTWARE);
        seq_setprev(mp);  /* set the previous-sequence */
 
        /* create folder structures for each destination folder */
@@ -187,8 +186,7 @@ main(int argc, char **argv)
                if (is_selected(mp, msgnum)) {
                        cp = getcpy(m_name(msgnum));
                        if (m_file(cp, folders, foldp, !linkf))
-                               /* sysexits.h EX_IOERR */
-                               exit(1);
+                               exit(EX_IOERR);
                        free(cp);
                }
        }
@@ -235,9 +233,9 @@ opnfolds(struct st_fold *folders, int nfolders)
                create_folder(nmaildir, 0, exit);
 
                if (chdir(nmaildir) == NOTOK)
-                       adios(nmaildir, "unable to change directory to");
+                       adios(EX_OSERR, nmaildir, "unable to change directory to");
                if (!(mp = folder_read(fp->f_name)))
-                       adios(NULL, "unable to read folder %s", fp->f_name);
+                       adios(EX_IOERR, NULL, "unable to read folder %s", fp->f_name);
                mp->curmsg = 0;
 
                fp->f_mp = mp;
index a5864c1..0ff86b8 100644 (file)
@@ -16,6 +16,7 @@
 #include <ctype.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define GROUPSW  0
@@ -160,17 +161,17 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s: [+folder] [msg] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case GROUPSW:
                                groupreply++;
@@ -188,27 +189,27 @@ main(int argc, char **argv)
 
                        case CCSW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                docc(cp, 1);
                                continue;
                        case NCCSW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                docc(cp, 0);
                                continue;
 
                        case EDITRSW:
                                if (!(ed = *argp++) || *ed == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
                        case WHATSW:
                                if (!(whatnowproc = *argp++) ||
                                                *whatnowproc == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
@@ -218,21 +219,21 @@ main(int argc, char **argv)
 
                        case FILESW:
                                if (file)
-                                       adios(NULL, "only one file at a time!");
+                                       adios(EX_USAGE, NULL, "only one file at a time!");
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                file = getcpy(expanddir(cp));
                                continue;
                        case FORMSW:
                                if (!(form = *argp++) || *form == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
                        case FILTSW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                filter = getcpy(etcpath(cp));
                                continue;
@@ -258,12 +259,12 @@ main(int argc, char **argv)
                }
                if (*cp == '+' || *cp == '@') {
                        if (folder)
-                               adios(NULL, "only one folder at a time!");
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
                        else
                                folder = getcpy(expandfol(cp));
                } else {
                        if (msg)
-                               adios(NULL, "only one message at a time!");
+                               adios(EX_USAGE, NULL, "only one message at a time!");
                        else
                                msg = cp;
                }
@@ -279,7 +280,7 @@ main(int argc, char **argv)
        cwd = getcpy(pwd());
 
        if (file && (msg || folder))
-               adios(NULL, "can't mix files and folders/msgs");
+               adios(EX_USAGE, NULL, "can't mix files and folders/msgs");
 
        strncpy(drft, buildsw ? toabsdir("reply") : m_draft(seq_beyond),
                        sizeof(drft));
@@ -306,24 +307,23 @@ main(int argc, char **argv)
                maildir = toabsdir(folder);
 
                if (chdir(maildir) == NOTOK)
-                       adios(maildir, "unable to change directory to");
+                       adios(EX_OSERR, maildir, "unable to change directory to");
 
                /* read folder and create message structure */
                if (!(mp = folder_read(folder)))
-                       adios(NULL, "unable to read folder %s", folder);
+                       adios(EX_IOERR, NULL, "unable to read folder %s", folder);
 
                /* check for empty folder */
                if (mp->nummsg == 0)
-                       adios(NULL, "no messages in %s", folder);
+                       adios(EX_DATAERR, NULL, "no messages in %s", folder);
 
                /* parse the message range/sequence/name and set SELECTED */
                if (!m_convert(mp, msg))
-                       /* sysexits.h EX_USAGE */
-                       exit(1);
+                       exit(EX_SOFTWARE);
                seq_setprev(mp);  /* set the previous-sequence */
 
                if (mp->numsel > 1)
-                       adios(NULL, "only one message at a time!");
+                       adios(EX_USAGE, NULL, "only one message at a time!");
 
                context_replace(curfolder, folder); /* update current folder */
                seq_setcur(mp, mp->lowsel);  /* update current message  */
@@ -334,7 +334,7 @@ main(int argc, char **argv)
        msg = file ? file : getcpy(m_name(mp->lowsel));
 
        if ((in = fopen(msg, "r")) == NULL)
-               adios(msg, "unable to open");
+               adios(EX_IOERR, msg, "unable to open");
 
        /* find form (components) file */
        if (!form) {
@@ -348,10 +348,9 @@ main(int argc, char **argv)
        fclose(in);
 
        if (buildsw)
-               exit(0);
+               exit(EX_OK);
        what_now(ed, NOUSE, drft, msg, 0, mp, anot ? "Replied" : NULL, cwd);
-       /* sysexits.h EX_SOFTWARE */
-       return 1;
+       return EX_OSERR;
 }
 
 static void
@@ -360,9 +359,9 @@ docc(char *cp, int ccflag)
        switch (smatch(cp, ccswitches)) {
        case AMBIGSW:
                ambigsw(cp, ccswitches);
-               exit(1);
+               exit(EX_USAGE);
        case UNKWNSW:
-               adios(NULL, "-%scc %s unknown", ccflag ? "" : "no", cp);
+               adios(EX_USAGE, NULL, "-%scc %s unknown", ccflag ? "" : "no", cp);
 
        case CTOSW:
                ccto = ccflag;
@@ -402,7 +401,7 @@ replout(FILE *inb, char *drft, struct msgs *mp,
 
        mask = umask(~m_gmprot());
        if ((out = fopen(drft, "w")) == NULL)
-               adios(drft, "unable to create");
+               adios(EX_CANTCREAT, drft, "unable to create");
 
        umask(mask);
 
@@ -415,10 +414,10 @@ replout(FILE *inb, char *drft, struct msgs *mp,
 
        if (!(nxtbuf = compbuffers = (char **)
                        calloc((size_t) ncomps, sizeof(char *))))
-               adios(NULL, "unable to allocate component buffers");
+               adios(EX_OSERR, NULL, "unable to allocate component buffers");
        if (!(savecomp = used_buf = (struct comp **)
                        calloc((size_t) (ncomps+1), sizeof(struct comp *))))
-               adios(NULL, "unable to allocate component buffer stack");
+               adios(EX_OSERR, NULL, "unable to allocate component buffer stack");
        savecomp += ncomps + 1;
        *--savecomp = NULL;  /* point at zero'd end minus 1 */
 
@@ -514,7 +513,7 @@ replout(FILE *inb, char *drft, struct msgs *mp,
                        goto finished;
 
                default:
-                       adios(NULL, "m_getfld() returned %d", state);
+                       adios(EX_SOFTWARE, NULL, "m_getfld() returned %d", state);
                }
        }
 
@@ -563,14 +562,14 @@ finished:
        if (filter) {
                fflush(out);
                if (ferror(out))
-                       adios(drft, "error writing");
+                       adios(EX_IOERR, drft, "error writing");
 
                replfilter(inb, out, filter);
        }
 
        fflush(out);
        if (ferror(out))
-               adios(drft, "error writing");
+               adios(EX_IOERR, drft, "error writing");
        fclose(out);
 
        if (mime && mp) {
@@ -750,14 +749,14 @@ replfilter(FILE *in, FILE *out, char *filter)
                return;
 
        if (access(filter, R_OK) == NOTOK)
-               adios(filter, "unable to read");
+               adios(EX_IOERR, filter, "unable to read");
 
        rewind(in);
        lseek(fileno(in), (off_t) 0, SEEK_SET);
 
        switch (pid = fork()) {
        case NOTOK:
-               adios("fork", "unable to");
+               adios(EX_OSERR, "fork", "unable to");
 
        case OK:
                dup2(fileno(in), fileno(stdin));
@@ -771,12 +770,11 @@ replfilter(FILE *in, FILE *out, char *filter)
                write(2, "unable to exec mhl: ", 20);
                write(2, errstr, strlen(errstr));
                write(2, "\n", 1);
-               _exit(-1);
+               _exit(EX_OSERR);
 
        default:
                if (pidXwait(pid, "mhl"))
-                       /* sysexits.h EX_SOFTWARE */
-                       exit(1);
+                       exit(EX_SOFTWARE);
                fseek(out, 0L, SEEK_END);
                break;
        }
index 615369c..f246004 100644 (file)
--- a/uip/rmf.c
+++ b/uip/rmf.c
@@ -10,6 +10,7 @@
 #include <unistd.h>
 #include <dirent.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define INTRSW  0
@@ -51,17 +52,17 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case INTRSW:
                                interactive = 1;
@@ -73,11 +74,11 @@ main(int argc, char **argv)
                }
                if (*cp == '+' || *cp == '@') {
                        if (folder)
-                               adios(NULL, "only one folder at a time!");
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
                        else
                                folder = getcpy(expandfol(cp));
                } else {
-                       adios(NULL, "usage: %s [+folder] [switches]",
+                       adios(EX_USAGE, NULL, "usage: %s [+folder] [switches]",
                                        invo_name);
                }
        }
@@ -87,7 +88,7 @@ main(int argc, char **argv)
                defolder++;
        }
        if (strcmp(toabsdir(folder), pwd()) == 0)
-               adios(NULL, "You can't remove the current working directory");
+               adios(EX_USAGE, NULL, "You can't remove the current working directory");
 
        if (interactive == -1)
                interactive = defolder;
@@ -108,7 +109,7 @@ main(int argc, char **argv)
        if (interactive) {
                cp = concat("Remove folder \"", folder, "\"? ", NULL);
                if (!getanswer(cp))
-                       exit(0);
+                       exit(EX_OK);
                free(cp);
        }
 
@@ -152,7 +153,7 @@ rmf(char *folder)
        }
 
        if ((dd = opendir(".")) == NULL)
-               adios(NULL, "unable to read folder +%s", folder);
+               adios(EX_IOERR, NULL, "unable to read folder +%s", folder);
        others = 0;
 
        /*
index 520ce03..f99dcbc 100644 (file)
--- a/uip/rmm.c
+++ b/uip/rmm.c
@@ -10,6 +10,7 @@
 #include <h/utils.h>
 #include <unistd.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define UNLINKSW  0
@@ -48,17 +49,17 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown\n", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown\n", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case UNLINKSW:
                                unlink_msgs++;
@@ -70,7 +71,7 @@ main(int argc, char **argv)
                }
                if (*cp == '+' || *cp == '@') {
                        if (folder) {
-                               adios(NULL, "only one folder at a time!");
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
                        } else {
                                folder = getcpy(expandfol(cp));
                        }
@@ -88,15 +89,15 @@ main(int argc, char **argv)
        maildir = toabsdir(folder);
 
        if (chdir(maildir) == NOTOK) {
-               adios(maildir, "unable to change directory to");
+               adios(EX_OSERR, maildir, "unable to change directory to");
        }
 
        /* read folder and create message structure */
        if (!(mp = folder_read(folder))) {
-               adios(NULL, "unable to read folder %s", folder);
+               adios(EX_IOERR, NULL, "unable to read folder %s", folder);
        }
        if (mp->nummsg == 0) {
-               adios(NULL, "no messages in %s", folder);
+               adios(EX_DATAERR, NULL, "no messages in %s", folder);
        }
        /*
        ** parse all the message ranges/sequences and set SELECTED
@@ -105,8 +106,7 @@ main(int argc, char **argv)
        */
        for (msgnum = 0; msgnum < msgs.size; msgnum++) {
                if (!m_convert(mp, msgs.msgs[msgnum])) {
-                       /* sysexits EX_USAGE */
-                       exit(1);
+                       exit(EX_USAGE);
                }
        }
 
@@ -128,7 +128,7 @@ main(int argc, char **argv)
        fflush(stdout);
 
        if (msgs.size+6 > MAXARGS) {
-               adios(NULL, "more than %d messages for refile exec",
+               adios(EX_SOFTWARE, NULL, "more than %d messages for refile exec",
                                MAXARGS - 6);
        }
        vec = (char **)mh_xmalloc((size_t)(msgs.size + 6) * sizeof(*vec));
index f53cf1d..0f755ca 100644 (file)
@@ -14,6 +14,7 @@
 #include <errno.h>
 #include <unistd.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define FORMSW  0
@@ -60,34 +61,34 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case FORMSW:
                                if (!(form = *argp++) || *form == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
                        case WIDTHSW:
                                if (!(cp = *argp++) || *cp == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                width = atoi(cp);
                                continue;
 
                        case FILESW:
                                if (!(cp = *argp++) || (cp[0] == '-' && cp[1]))
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                if (strcmp(file = cp, "-")!=0)
                                        file = getcpy(expanddir(cp));
@@ -96,7 +97,7 @@ main(int argc, char **argv)
                }
                if (*cp == '+' || *cp == '@') {
                        if (folder)
-                               adios(NULL, "only one folder at a time!");
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
                        else
                                folder = getcpy(expandfol(cp));
                } else
@@ -113,16 +114,16 @@ main(int argc, char **argv)
        */
        if (file) {
                if (msgs.size)
-                       adios(NULL, "\"msgs\" not allowed with -file");
+                       adios(EX_USAGE, NULL, "\"msgs\" not allowed with -file");
                if (folder)
-                       adios(NULL, "\"+folder\" not allowed with -file");
+                       adios(EX_USAGE, NULL, "\"+folder\" not allowed with -file");
 
                /* check if "file" is really stdin */
                if (strcmp(file, "-") == 0) {
                        in = stdin;
                        file = "stdin";
                } else if (!(in = fopen(file, "r"))) {
-                       adios(file, "unable to open");
+                       adios(EX_IOERR, file, "unable to open");
                }
 
                thisisanmbox(in);
@@ -132,7 +133,7 @@ main(int argc, char **argv)
                                break;
                }
                fclose(in);
-               exit(0);
+               exit(EX_OK);
        }
 
        /*
@@ -146,20 +147,20 @@ main(int argc, char **argv)
        maildir = toabsdir(folder);
 
        if (chdir(maildir) == NOTOK)
-               adios(maildir, "unable to change directory to");
+               adios(EX_OSERR, maildir, "unable to change directory to");
 
        /* read folder and create message structure */
        if (!(mp = folder_read(folder)))
-               adios(NULL, "unable to read folder %s", folder);
+               adios(EX_IOERR, NULL, "unable to read folder %s", folder);
 
        /* check for empty folder */
        if (mp->nummsg == 0)
-               adios(NULL, "no messages in %s", folder);
+               adios(EX_DATAERR, NULL, "no messages in %s", folder);
 
        /* parse all the message ranges/sequences and set SELECTED */
        for (msgnum = 0; msgnum < msgs.size; msgnum++)
                if (!m_convert(mp, msgs.msgs[msgnum]))
-                       exit(1);
+                       exit(EX_USAGE);
        seq_setprev(mp);  /* set the Previous-Sequence */
 
        context_replace(curfolder, folder);  /* update current folder */
@@ -212,7 +213,7 @@ main(int argc, char **argv)
                                break;
 
                        default:
-                               adios(NULL, "scan() botch(%d)", state);
+                               adios(EX_SOFTWARE, NULL, "scan() botch(%d)", state);
 
                        case SCNEOF:
                                advise(NULL, "message %d: empty", msgnum);
index 4fa5a0d..9c74f04 100644 (file)
@@ -14,6 +14,7 @@
 #include <h/utils.h>
 #include <ctype.h>
 #include <sys/stat.h>
+#include <sysexits.h>
 
 #ifdef _FSTDIO
 # define _ptr _p  /* Gag */
@@ -42,7 +43,7 @@ char *scanl = NULL;  /* text of most recent scanline */
 
 #define FPUTS(buf) {\
                if (fputs(buf, scnout) == EOF)\
-                       adios(scnmsg, "write error on");\
+                       adios(EX_IOERR, scnmsg, "write error on");\
        }
 
 /*
@@ -100,11 +101,11 @@ scan(FILE *inb, int innum, int outnum, char *fmtstr, int width, int curflg,
                nxtbuf = compbuffers = (char **) calloc((size_t) ncomps,
                                sizeof(char *));
                if (!nxtbuf)
-                       adios(NULL, "unable to allocate component buffers");
+                       adios(EX_OSERR, NULL, "unable to allocate component buffers");
                used_buf = (struct comp **) calloc((size_t) (ncomps+1),
                                sizeof(struct comp *));
                if (!used_buf)
-                       adios(NULL, "unable to allocate component buffer stack");
+                       adios(EX_OSERR, NULL, "unable to allocate component buffer stack");
                /* NULL-terminate array */
                used_buf += ncomps;
                *used_buf = NULL;
@@ -142,7 +143,7 @@ scan(FILE *inb, int innum, int outnum, char *fmtstr, int width, int curflg,
                if (*scnmsg == '?')  /* msg num out of range */
                        return SCNNUM;
                if (!(scnout = fopen(scnmsg, "w")))
-                       adios(scnmsg, "unable to write");
+                       adios(EX_IOERR, scnmsg, "unable to write");
        }
 
        /* scan - main loop */
@@ -233,7 +234,7 @@ body:;
                        goto finished;
 
                default:
-                       adios(NULL, "getfld() returned %d", state);
+                       adios(EX_SOFTWARE, NULL, "getfld() returned %d", state);
                }
        }
 
@@ -247,10 +248,10 @@ finished:
 
        if (incing) {
                if ((dat[2] = ftell(scnout)) == EOF)
-                       adios(scnmsg, "write error on");
+                       adios(EX_IOERR, scnmsg, "write error on");
        } else if (!scanfolder) {
                if ((dat[2] = ftell(inb)) == EOF)
-                       adios(scnmsg, "write error on");
+                       adios(EX_IOERR, scnmsg, "write error on");
                dat[2] -= fpos;
        }
 
@@ -264,7 +265,7 @@ finished:
                                if (!datecomp->c_tws)
                                        datecomp->c_tws = (struct tws *) calloc((size_t) 1, sizeof(*datecomp->c_tws));
                                if (!datecomp->c_tws)
-                                       adios(NULL, "unable to allocate tws buffer");
+                                       adios(EX_OSERR, NULL, "unable to allocate tws buffer");
                                *datecomp->c_tws = *dlocaltime((time_t *) &st.st_mtime);
                                datecomp->c_flags |= CF_DATEFAB|CF_TRUE;
                        } else {
@@ -285,7 +286,7 @@ finished:
        *--nxtbuf = tmpbuf;
 
        if (incing && (ferror(scnout) || fclose(scnout) == EOF))
-               adios(scnmsg, "write error on");
+               adios(EX_IOERR, scnmsg, "write error on");
 
        return (state != FILEEOF ? SCNERR : SCNMSG);
 }
index 41ef92a..ec9b76d 100644 (file)
@@ -103,19 +103,19 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown\n", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown\n", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf),
                                                "%s [file] [switches]",
                                                invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case DEBUGSW:
                                debugsw++;
@@ -141,20 +141,20 @@ main(int argc, char **argv)
        if (nmsgs) {
                maildir = toabsdir(draftfolder);
                if (chdir(maildir) == NOTOK) {
-                       adios(maildir, "unable to change directory to");
+                       adios(EX_OSERR, maildir, "unable to change directory to");
                }
                if (!(mp = folder_read(draftfolder))) {
-                       adios(NULL, "unable to read draft folder %s",
+                       adios(EX_IOERR, NULL, "unable to read draft folder %s",
                                        draftfolder);
                }
                if (mp->nummsg == 0) {
-                       adios(NULL, "no messages in draft folder %s",
+                       adios(EX_DATAERR, NULL, "no messages in draft folder %s",
                                        draftfolder);
                }
                /* parse all the msgranges/sequences and set SELECTED */
                for (msgnum = 0; msgnum < nmsgs; msgnum++) {
                        if (!m_convert(mp, msgs[msgnum])) {
-                               exit(1);
+                               exit(EX_USAGE);
                        }
                }
                seq_setprev(mp);
@@ -179,7 +179,7 @@ main(int argc, char **argv)
 
        for (n = 0; n < nfiles; n++) {
                if (stat(files[n], &st) == NOTOK) {
-                       adios(files[n], "unable to stat draft file");
+                       adios(EX_IOERR, files[n], "unable to stat draft file");
                }
        }
 
@@ -193,12 +193,12 @@ main(int argc, char **argv)
        if ((cp = getenv("mhdist")) && *cp && (distsw = atoi(cp)) && altmsg) {
                vec[vecp++] = "-dist";
                if ((in = open(altmsg, O_RDONLY)) == NOTOK) {
-                       adios(altmsg, "unable to open for reading");
+                       adios(EX_IOERR, altmsg, "unable to open for reading");
                }
                fstat(in, &st2);
                distfile = getcpy(m_mktemp2(NULL, invo_name, NULL, NULL));
                if ((out = creat(distfile, (int)st2.st_mode & 0777))==NOTOK) {
-                       adios(distfile, "unable to open for writing");
+                       adios(EX_IOERR, distfile, "unable to open for writing");
                }
                cpydata(in, out, altmsg, distfile);
                close(in);
@@ -331,7 +331,7 @@ attach(char *draft_file_name)
        char *p;
 
        if (!(draft_file = fopen(draft_file_name, "r"))) {
-               adios(NULL, "can't open draft file `%s'.", draft_file_name);
+               adios(EX_IOERR, NULL, "can't open draft file `%s'.", draft_file_name);
        }
 
        /* We'll grow the buffer as needed. */
@@ -395,7 +395,7 @@ attach(char *draft_file_name)
 
        if ((has_body && !body_file) || !composition_file) {
                clean_up_temporary_files();
-               adios(NULL, "unable to open all of the temporary files.");
+               adios(EX_IOERR, NULL, "unable to open all of the temporary files.");
        }
 
        /* Copy non-attachment header fields to the temp composition file. */
@@ -466,7 +466,7 @@ signandenc(char *draft_file_name)
        int ret;
 
        if (!(draft_file = fopen(draft_file_name, "r"))) {
-               adios(NULL, "can't open draft file `%s'.", draft_file_name);
+               adios(EX_IOERR, NULL, "can't open draft file `%s'.", draft_file_name);
        }
 
        /* We'll grow the buffer as needed. */
@@ -569,7 +569,7 @@ make_mime_composition_file_entry(char *file_name)
 
        if (!(fp = popen(cmdbuf, "r"))) {
                clean_up_temporary_files();
-               adios(NULL, "unable to determine content type with `%s'",
+               adios(EX_IOERR, NULL, "unable to determine content type with `%s'",
                                cmdbuf);
        }
        if (fgets(content_type, sizeof content_type, fp) &&
@@ -585,14 +585,14 @@ make_mime_composition_file_entry(char *file_name)
        /* TODO: don't use access(2) because it checks for ruid, not euid */
        if (access(file_name, R_OK) != 0) {
                clean_up_temporary_files();
-               adios(NULL, "unable to access file `%s'", file_name);
+               adios(EX_IOERR, NULL, "unable to access file `%s'", file_name);
        }
 
        /* Check for broken file(1). See man page mh-profile(5). */
        for (cp=content_type; *cp; cp++) {
                if (isspace(*cp)) {
                        if (!semicolon) {
-                               adios(NULL, "Sorry, your Mime-Type-Query command (%s) is broken.\n\tThe output misses a semicolon before the whitespace.\n\tOutput was: %s", cmd, content_type);
+                               adios(EX_SOFTWARE, NULL, "Sorry, your Mime-Type-Query command (%s) is broken.\n\tThe output misses a semicolon before the whitespace.\n\tOutput was: %s", cmd, content_type);
                        }
                } else if (*cp == ';') {
                        semicolon = 1;
@@ -637,7 +637,7 @@ sendaux(char **vec, int vecp, char *drft, struct stat *st)
                execvp(*vec, vec);
                fprintf(stderr, "unable to exec ");
                perror(*vec);
-               _exit(-1);
+               _exit(EX_OSERR);
                break;  /* NOT REACHED */
 
        default:
index 41f986d..eac77e4 100644 (file)
@@ -28,6 +28,7 @@
 #include <stdarg.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <sysexits.h>
 
 #ifdef INITGROUPS_HEADER
 #include INITGROUPS_HEADER
@@ -189,72 +190,72 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [switches] [address info sender]", invo_name);
                                print_help(buf, switches, 0);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case ADDRSW:
                                if (!(addr = *argp++)) {
                                        /* allow -xyz arguments */
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                }
                                continue;
                        case INFOSW:
                                if (!(info = *argp++)) {
                                        /* allow -xyz arguments */
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                }
                                continue;
                        case USERSW:
                                if (!(user = *argp++)) {
                                        /* allow -xyz arguments */
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                }
                                continue;
                        case FILESW:
                                if (!(file = *argp++) || *file == '-') {
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                }
                                continue;
                        case SENDERSW:
                                if (!(sender = *argp++)) {
                                        /* allow -xyz arguments */
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                }
                                continue;
                        case MAILBOXSW:
                                if (!(mbox = *argp++) || *mbox == '-') {
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                }
                                continue;
                        case HOMESW:
                                if (!(home = *argp++) || *home == '-') {
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                }
                                continue;
 
                        case MAILSW:
                                if (!(cp = *argp++) || *cp == '-') {
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                }
                                if (mdlvr) {
-                                       adios(NULL, "only one maildelivery file at a time!");
+                                       adios(EX_USAGE, NULL, "only one maildelivery file at a time!");
                                }
                                mdlvr = cp;
                                continue;
@@ -292,7 +293,7 @@ main(int argc, char **argv)
                user = (cp = strchr(addr, '.')) ? ++cp : addr;
        }
        if (!(pw = getpwnam(user))) {
-               adios(NULL, "no such local user as %s", user);
+               adios(EX_NOUSER, NULL, "no such local user as %s", user);
        }
 
        if (chdir(pw->pw_dir) == -1) {
@@ -314,7 +315,7 @@ main(int argc, char **argv)
 
        /* Record the delivery time */
        if (!(now = dlocaltimenow())) {
-               adios(NULL, "unable to ascertain local time");
+               adios(EX_OSERR, NULL, "unable to ascertain local time");
        }
        snprintf(ddate, sizeof(ddate), "Delivery-Date: %s\n", dtimenow());
 
@@ -326,14 +327,14 @@ main(int argc, char **argv)
 
                /* getting message from file */
                if ((tempfd = open(file, O_RDONLY)) == -1) {
-                       adios(file, "unable to open");
+                       adios(EX_IOERR, file, "unable to open");
                }
                if (debug) {
                        debug_printf("retrieving message from file \"%s\"\n",
                                        file);
                }
                if ((fd = copy_message(tempfd, tmpfil, 1)) == -1) {
-                       adios(NULL, "unable to create temporary file");
+                       adios(EX_CANTCREAT, NULL, "unable to create temporary file");
                }
                close(tempfd);
        } else {
@@ -342,7 +343,7 @@ main(int argc, char **argv)
                        debug_printf("retrieving message from stdin\n");
                }
                if ((fd = copy_message(fileno(stdin), tmpfil, 1)) == -1) {
-                       adios(NULL, "unable to create temporary file");
+                       adios(EX_CANTCREAT, NULL, "unable to create temporary file");
                }
        }
 
@@ -368,7 +369,7 @@ main(int argc, char **argv)
        unlink(tmpfil);
 
        if (!(fp = fdopen(fd, "r+"))) {
-               adios(NULL, "unable to access temporary file");
+               adios(EX_IOERR, NULL, "unable to access temporary file");
        }
 
        /* If no sender given, extract it from envelope information. */
@@ -1032,7 +1033,7 @@ usr_pipe(int fd, char *cmd, char *pgm, char **vec, int suppress)
                m_putenv("PATH", path);
 
                execvp(pgm, vec);
-               _exit(-1);
+               _exit(EX_OSERR);
 
        default:
                /* parent process */
index 734b63b..802e010 100644 (file)
@@ -13,6 +13,7 @@
 #include <ctype.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <sysexits.h>
 
 #ifdef HAVE_SYS_PARAM_H
 # include <sys/param.h>
@@ -98,31 +99,31 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf), "%s [+folder] [msgs] [switches]", invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case DATESW:
                                if (datesw)
-                                       adios(NULL, "only one date field at a time");
+                                       adios(EX_USAGE, NULL, "only one date field at a time");
                                if (!(datesw = *argp++) || *datesw == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
                        case TEXTSW:
                                if (subjsort)
-                                       adios(NULL, "only one text field at a time");
+                                       adios(EX_USAGE, NULL, "only one text field at a time");
                                if (!(subjsort = *argp++) || *subjsort == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
@@ -132,7 +133,7 @@ main(int argc, char **argv)
 
                        case LIMSW:
                                if (!(cp = *argp++) || *cp == '-')
-                                               adios(NULL, "missing argument to %s", argp[-2]);
+                                               adios(EX_USAGE, NULL, "missing argument to %s", argp[-2]);
                                while (*cp == '0')
                                        cp++;  /* skip any leading zeros */
                                if (!*cp) {  /* hit end of string */
@@ -140,7 +141,7 @@ main(int argc, char **argv)
                                        continue;
                                }
                                if (!isdigit(*cp) || !(datelimit = atoi(cp)))
-                                       adios(NULL, "impossible limit %s", cp);
+                                       adios(EX_USAGE, NULL, "impossible limit %s", cp);
                                datelimit *= 60*60*24;
                                continue;
                        case NLIMSW:
@@ -158,7 +159,7 @@ main(int argc, char **argv)
                }
                if (*cp == '+' || *cp == '@') {
                        if (folder)
-                               adios(NULL, "only one folder at a time!");
+                               adios(EX_USAGE, NULL, "only one folder at a time!");
                        else
                                folder = getcpy(expandfol(cp));
                } else
@@ -174,24 +175,24 @@ main(int argc, char **argv)
        maildir = toabsdir(folder);
 
        if (chdir(maildir) == NOTOK)
-               adios(maildir, "unable to change directory to");
+               adios(EX_OSERR, maildir, "unable to change directory to");
 
        /* read folder and create message structure */
        if (!(mp = folder_read(folder)))
-               adios(NULL, "unable to read folder %s", folder);
+               adios(EX_IOERR, NULL, "unable to read folder %s", folder);
 
        /* check for empty folder */
        if (mp->nummsg == 0)
-               adios(NULL, "no messages in %s", folder);
+               adios(EX_DATAERR, NULL, "no messages in %s", folder);
 
        /* parse all the message ranges/sequences and set SELECTED */
        for (msgnum = 0; msgnum < msgs.size; msgnum++)
                if (!m_convert(mp, msgs.msgs[msgnum]))
-                       exit(1);
+                       exit(EX_USAGE);
        seq_setprev(mp);  /* set the previous sequence */
 
        if ((nmsgs = read_hdrs(mp, datesw)) <= 0)
-               adios(NULL, "no messages to sort");
+               adios(EX_DATAERR, NULL, "no messages to sort");
 
        /*
        ** sort a list of pointers to our "messages to be sorted".
@@ -236,7 +237,7 @@ main(int argc, char **argv)
                */
                il = (struct smsg ***) calloc(mp->hghsel+1, sizeof(*il));
                if (! il)
-                       adios(NULL, "couldn't allocate msg list");
+                       adios(EX_OSERR, NULL, "couldn't allocate msg list");
                for (i = 0; i < nmsgs; i++)
                        il[slist[i]->s_msg] = &slist[i];
                /*
@@ -297,7 +298,7 @@ read_hdrs(struct msgs *mp, char *datesw)
        smsgs = (struct smsg *) calloc((size_t) (mp->hghsel - mp->lowsel + 2),
                        sizeof(*smsgs));
        if (smsgs == NULL)
-               adios(NULL, "unable to allocate sort storage");
+               adios(EX_OSERR, NULL, "unable to allocate sort storage");
 
        s = smsgs;
        for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
@@ -381,7 +382,7 @@ get_fields(char *datesw, int msg, struct smsg *smsg)
                        return (0);
 
                default:
-                       adios(NULL, "internal error -- you lose");
+                       adios(EX_SOFTWARE, NULL, "internal error -- you lose");
                }
                break;
        }
@@ -509,7 +510,7 @@ rename_chain(struct msgs *mp, struct smsg **mlist, int msg, int endmsg)
                ext_hook("ref-hook", oldname, newbuf);
 
                if (rename(oldname, newname) == NOTOK)
-                       adios(newname, "unable to rename %s to", oldname);
+                       adios(EX_IOERR, newname, "unable to rename %s to", oldname);
 
                copy_msg_flags(mp, new, old);
                if (mp->curmsg == old)
@@ -568,7 +569,7 @@ rename_msgs(struct msgs *mp, struct smsg **mlist)
                ext_hook("ref-hook", f1, newbuf);
 
                if (rename(f1, tmpfil) == NOTOK)
-                       adios(tmpfil, "unable to rename %s to ", f1);
+                       adios(EX_IOERR, tmpfil, "unable to rename %s to ", f1);
 
                get_msg_flags(mp, &tmpset, old);
 
@@ -583,7 +584,7 @@ rename_msgs(struct msgs *mp, struct smsg **mlist)
                ext_hook("ref-hook", newbuf, f1);
 
                if (rename(tmpfil, m_name(new)) == NOTOK)
-                       adios(m_name(new), "unable to rename %s to", tmpfil);
+                       adios(EX_IOERR, m_name(new), "unable to rename %s to", tmpfil);
 
                set_msg_flags(mp, &tmpset, new);
                mp->msgflags |= SEQMOD;
index 449d1a7..476227b 100644 (file)
@@ -18,6 +18,7 @@
 #include <h/utils.h>
 #include <unistd.h>
 #include <locale.h>
+#include <sysexits.h>
 
 #define MAX_SM_FIELD 1476  /* < largest hdr field sendmail will accept */
 
@@ -151,19 +152,19 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf),
                                                "%s [switches] file",
                                                invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case DEBUGSW:
                                debug++;
@@ -182,16 +183,16 @@ main(int argc, char **argv)
                        }
                }
                if (msg)
-                       adios(NULL, "only one message at a time!");
+                       adios(EX_USAGE, NULL, "only one message at a time!");
                else
                        msg = cp;
        }
 
        if (!msg)
-               adios(NULL, "usage: %s [switches] file", invo_name);
+               adios(EX_USAGE, NULL, "usage: %s [switches] file", invo_name);
 
        if ((in = fopen(msg, "r")) == NULL)
-               adios(msg, "unable to open");
+               adios(EX_IOERR, msg, "unable to open");
 
        if (debug) {
                verbose++;
@@ -208,7 +209,7 @@ main(int argc, char **argv)
                for (ap=brkstring(dp=getcpy(cp), " ", "\n"); ap && *ap;
                                ap++) {
                        if ((state = alias(etcpath(*ap))) != AK_OK) {
-                               adios(NULL, "aliasing error in file %s: %s",
+                               adios(EX_IOERR, NULL, "aliasing error in file %s: %s",
                                                *ap, akerror(state));
                        }
                }
@@ -252,11 +253,11 @@ main(int argc, char **argv)
 
                case LENERR:
                case FMTERR:
-                       adios(NULL, "message format error in component #%d",
+                       adios(EX_DATAERR, NULL, "message format error in component #%d",
                                        compnum);
 
                default:
-                       adios(NULL, "getfld() returned %d", state);
+                       adios(EX_SOFTWARE, NULL, "getfld() returned %d", state);
                }
                break;
        }
@@ -264,7 +265,7 @@ main(int argc, char **argv)
 
        if (debug) {
                /* stop here */
-               exit(0);
+               exit(EX_OK);
        }
 
        fclose(out);
@@ -279,7 +280,7 @@ main(int argc, char **argv)
                if (!(msgflags & MVIS)) {
                        /* only Bcc rcpts: we're finished here */
                        unlink(tmpfil);
-                       exit(0);
+                       exit(EX_OK);
                }
        }
 
@@ -288,7 +289,7 @@ main(int argc, char **argv)
        ** the msg temp file as std in.
        */
        if (!freopen(tmpfil, "r", stdin)) {
-               adios(tmpfil, "can't reopen for sendmail");
+               adios(EX_IOERR, tmpfil, "can't reopen for sendmail");
        }
        unlink(tmpfil);
 
@@ -302,7 +303,7 @@ main(int argc, char **argv)
        }
        *argp = NULL;
        execv(sendmail, sargv);
-       adios(sendmail, "can't exec");
+       adios(EX_OSERR, sendmail, "can't exec");
        return -1;
 }
 
@@ -452,7 +453,7 @@ finish_headers(FILE *out)
        }
        if (badmsg) {
                unlink(tmpfil);
-               adios(NULL, "re-format message and try again");
+               adios(EX_DATAERR, NULL, "re-format message and try again");
        }
 }
 
@@ -565,7 +566,7 @@ process_fcc(char *str)
        int state = 0;
 
        if (strlen(str)+strlen(fccs) > sizeof fccs /2) {
-               adios(NULL, "Too much Fcc data");
+               adios(EX_DATAERR, NULL, "Too much Fcc data");
        }
        /* todo: better have three states: SEPARATOR, PLUS, WORD */
        for (cp=pp=str; *cp; cp++) {
@@ -608,7 +609,7 @@ fcc(char *file, char *folders)
                fflush(stdout);
        }
        if (100+strlen(file)+strlen(folders) > sizeof cmd) {
-               adios(NULL, "Too much Fcc data");
+               adios(EX_DATAERR, NULL, "Too much Fcc data");
        }
        /* hack: read from /dev/null and refile(1) won't question us */
        snprintf(cmd, sizeof cmd, "</dev/null refile -link -file '%s' %s",
index cd72e44..7e54929 100644 (file)
@@ -14,6 +14,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <sysexits.h>
 
 #ifdef HAVE_SYS_PARAM_H
 # include <sys/param.h>
@@ -109,7 +110,7 @@ main(int argc, char **argv)
        */
 
        if (!getcwd(cwd, sizeof (cwd))) {
-               adios("getcwd", "could not get working directory");
+               adios(EX_USAGE, "getcwd", "could not get working directory");
        }
 
        while ((cp = *argp++)) {
@@ -117,36 +118,36 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf),
                                                "%s [switches] [file]",
                                                invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case EDITRSW:
                                if (!(ed = *argp++) || *ed == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
                        case PRMPTSW:
                                if (!(myprompt = *argp++) || *myprompt == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
                        }
                }
                if (drft)
-                       adios(NULL, "only one draft at a time!");
+                       adios(EX_USAGE, NULL, "only one draft at a time!");
                else
                        drft = cp;
        }
@@ -167,16 +168,14 @@ main(int argc, char **argv)
                        if (!use) {
                                unlink(drft);
                        }
-                       advise(NULL, "Try again.");
-                       /* sysexits.h EX_SOFTWARE */
-                       exit(1);
+                       adios(EX_SOFTWARE, NULL, "Try again.");
                }
        }
 
        snprintf(prompt, sizeof(prompt), myprompt, invo_name);
        for (;;) {
                if (!(argp = getans(prompt, aleqs))) {
-                       exit(1);
+                       exit(EX_IOERR);
                }
                switch (smatch(*argp, aleqs)) {
                case DISPSW:
@@ -207,12 +206,12 @@ main(int argc, char **argv)
                        if (stat(drft, &st) != NOTOK) {
                                advise(NULL, "draft left on %s", drft);
                        }
-                       exit(1);
+                       exit(EX_OK);
 
                case DELETESW:
                        /* Delete draft and exit */
                        removefile(drft);
-                       exit(1);
+                       exit(EX_OK);
 
                case SENDSW:
                        /* Send draft */
@@ -222,7 +221,7 @@ main(int argc, char **argv)
                case REFILEOPT:
                        /* Refile the draft */
                        if (refile(++argp, drft) == 0) {
-                               exit(0);
+                               exit(EX_OK);
                        }
                        break;
 
@@ -414,7 +413,7 @@ writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp)
        */
        int trailln = strlen(trailcmd) + 3;
        if (ln < 0 || ln + trailln > bufsz)
-               adios(NULL, "arguments too long");
+               adios(EX_USAGE, NULL, "arguments too long");
 
        cp = buf + ln;
 
@@ -422,7 +421,7 @@ writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp)
                ln = strlen(*argp);
                /* +1 for leading space */
                if (ln + trailln + 1 > bufsz - (cp-buf))
-                       adios(NULL, "arguments too long");
+                       adios(EX_USAGE, NULL, "arguments too long");
                *cp++ = ' ';
                memcpy(cp, *argp, ln+1);
                cp += ln;
@@ -456,12 +455,12 @@ system_in_dir(const char *dir, const char *cmd)
        char olddir[BUFSIZ];
        int r;
        if (getcwd(olddir, sizeof(olddir)) == 0)
-               adios("getcwd", "could not get working directory");
+               adios(EX_OSERR, "getcwd", "could not get working directory");
        if (chdir(dir) != 0)
-               adios("chdir", "could not change working directory");
+               adios(EX_OSERR, "chdir", "could not change working directory");
        r = system(cmd);
        if (chdir(olddir) != 0)
-               adios("chdir", "could not change working directory");
+               adios(EX_OSERR, "chdir", "could not change working directory");
        return r;
 }
 
@@ -472,12 +471,12 @@ popen_in_dir(const char *dir, const char *cmd, const char *type)
        char olddir[BUFSIZ];
        FILE *f;
        if (getcwd(olddir, sizeof(olddir)) == 0)
-               adios("getcwd", "could not get working directory");
+               adios(EX_OSERR, "getcwd", "could not get working directory");
        if (chdir(dir) != 0)
-               adios("chdir", "could not change working directory");
+               adios(EX_OSERR, "chdir", "could not change working directory");
        f = popen(cmd, type);
        if (chdir(olddir) != 0)
-               adios("chdir", "could not change working directory");
+               adios(EX_OSERR, "chdir", "could not change working directory");
        return f;
 }
 
@@ -519,7 +518,7 @@ editfile(char **ed, char **arg, char *file, int use)
        switch (pid = fork()) {
        case NOTOK:
                advise("fork", "unable to");
-               status = NOTOK;
+               status = EX_OSERR;
                break;
 
        case OK:
@@ -534,13 +533,13 @@ editfile(char **ed, char **arg, char *file, int use)
                execvp(*ed, vec);
                fprintf(stderr, "%s: unable to exec ", invo_name);
                perror(*ed);
-               _exit(-1);
+               _exit(EX_OSERR);
 
        default:
                if ((status = pidwait(pid, NOTOK))) {
                        if ((status & 0xff00) == 0xff00) {
                                /* cmd not found or pidwait() failed */
-                               status = -1;
+                               status = EX_SOFTWARE;
                                break;
                        }
                        if (status & 0x00ff) {
@@ -588,7 +587,7 @@ sendfile(char **arg, char *file)
        execvp(*vec, vec);
        fprintf(stderr, "%s: unable to exec ", invo_name);
        perror("send");
-       _exit(-1);
+       _exit(EX_OSERR);
 }
 
 
@@ -626,7 +625,7 @@ static int
 removefile(char *drft)
 {
        if (unlink(drft) == NOTOK)
-               adios(drft, "unable to unlink");
+               adios(EX_IOERR, drft, "unable to unlink");
 
        return OK;
 }
index 3d3eb84..e61dc62 100644 (file)
@@ -11,6 +11,7 @@
 #include <h/fmt_scan.h>
 #include <h/utils.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define VERSIONSW 0
@@ -86,20 +87,20 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               exit(1);
+                               exit(EX_USAGE);
 
                        case UNKWNSW:
-                               adios(NULL, "-%s unknown", cp);
+                               adios(EX_USAGE, NULL, "-%s unknown", cp);
 
                        case HELPSW:
                                snprintf(buf, sizeof(buf),
                                                "%s [switches] file ...",
                                                invo_name);
                                print_help(buf, switches, 1);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case TOCCSW:
                                toccsw = 1;
@@ -124,7 +125,7 @@ main(int argc, char **argv)
                        }
                }
                if (filep > NFILES) {
-                       adios(NULL, "too many files (more than %d)",
+                       adios(EX_USAGE, NULL, "too many files (more than %d)",
                                        NFILES);
                } else {
                        files[filep++] = cp;
@@ -132,10 +133,10 @@ main(int argc, char **argv)
        }
        files[filep] = NULL;
        if (!filep) {
-               adios(NULL, "usage: %s [switches] file ...", invo_name);
+               adios(EX_USAGE, NULL, "usage: %s [switches] file ...", invo_name);
        }
        if (!toccsw && !bccsw) {
-               adios(NULL, "give -tocc or -bcc or both to produce output");
+               adios(EX_USAGE, NULL, "give -tocc or -bcc or both to produce output");
        }
        for (filep=0; files[filep]; filep++) {
                process(files[filep]);
@@ -144,7 +145,7 @@ main(int argc, char **argv)
        cmd = add("ali -list", NULL);
        if ((n=print()) && alisw) {
                if (!(in = popen(cmd, "r"))) {
-                       adios("popen", "unable to");
+                       adios(EX_IOERR, "popen", "unable to");
                }
                while (fgets(buf, sizeof buf, in)) {
                        fputs(buf, stdout);
@@ -157,7 +158,7 @@ main(int argc, char **argv)
        cmd = add("ali -list", NULL);
        if ((n=printbcc()) && alisw) {
                if (!(in = popen(cmd, "r"))) {
-                       adios("popen", "unable to");
+                       adios(EX_IOERR, "popen", "unable to");
                }
                while (fgets(buf, sizeof buf, in)) {
                        fputs(buf, stdout);
@@ -180,7 +181,7 @@ process(char *file)
 
 
        if ((in = fopen(file, "r")) == NULL) {
-               adios(file, "unable to open");
+               adios(EX_IOERR, file, "unable to open");
        }
 
        for (compnum = 1, state = FLD;;) {
@@ -208,11 +209,11 @@ process(char *file)
 
                case LENERR:
                case FMTERR:
-                       adios(NULL, "message format error in component #%d",
+                       adios(EX_DATAERR, NULL, "message format error in component #%d",
                                        compnum);
 
                default:
-                       adios(NULL, "getfld() returned %d", state);
+                       adios(EX_SOFTWARE, NULL, "getfld() returned %d", state);
                }
                break;
        }
@@ -264,7 +265,7 @@ proc_hdr(char *name, char *val)
 
        while ((cp = getname(val))) {
                if (!(mp->m_next = getm(cp, NULL, 0, AD_NAME, NULL))) {
-                       adios(NULL, "illegal address: %s", cp);
+                       adios(EX_DATAERR, NULL, "illegal address: %s", cp);
                }
                mp = mp->m_next;
                if (mp->m_type == BADHOST) {