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?
* 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.
/*
** 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 *, ...);
** complete copyright information.
*/
+#include <sysexits.h>
#include <h/mh.h>
#include <h/addrsbr.h>
#include <h/mf.h>
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;
}
** complete copyright information.
*/
+#include <sysexits.h>
#include <h/mh.h>
#include <h/utils.h>
}
}
}
- adios("brkstring()", "reached unreachable point");
+ adios(EX_SOFTWARE, "brkstring()", "reached unreachable point");
}
#include <pwd.h> /* structure for getpwuid() results */
#include <unistd.h>
#include <sys/stat.h>
+#include <sysexits.h>
void
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;
}
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.");
}
}
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;
}
** 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;
}
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)
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);
}
/*
* because there no longer are setuid/setgid programs in nmh.
*/
+#include <sysexits.h>
#include <h/mh.h>
#include <h/signals.h>
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);
** complete copyright information.
*/
+#include <sysexits.h>
#include <unistd.h>
#include <h/mh.h>
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");
}
** complete copyright information.
*/
+#include <sysexits.h>
#include <unistd.h>
#include <h/mh.h>
#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
}
if (i == -1)
- adios(ifile, "error reading");
+ adios(EX_IOERR, ifile, "error reading");
flush();
}
** 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);
}
#include <h/mh.h>
#include <unistd.h>
#include <stdarg.h>
+#include <sysexits.h>
int
execvp(cmd, arg);
fprintf(stderr, "unable to exec ");
perror(cmd);
- _exit(-1);
+ _exit(EX_OSERR);
default:
/* parent */
#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>
advise(NULL, "\"%s\": format compile error - %s",
&usr_fstring[errpos-errctx], str);
- adios(NULL, "%*s", errctx+1, "^");
+ adios(EX_SOFTWARE, NULL, "%*s", errctx+1, "^");
}
/*
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;
#include <h/utils.h>
#include <unistd.h>
#include <sys/stat.h>
+#include <sysexits.h>
static char *formats = NULL;
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);
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);
#include <h/tws.h>
#include <h/fmt_compile.h>
#include <ctype.h>
+#include <sysexits.h>
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
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);
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);
}
** complete copyright information.
*/
+#include <sysexits.h>
#include <unistd.h>
#include <h/mh.h>
/* 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;
** complete copyright information.
*/
+#include <sysexits.h>
#include <h/mh.h>
#include <h/utils.h>
/* 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 */
#include <h/mh.h>
#include <h/utils.h>
#include <errno.h>
+#include <sysexits.h>
/*
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);
*/
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 */
** (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,
#include <h/mh.h>
#include <h/utils.h>
#include <ctype.h>
+#include <sysexits.h>
/*
** This module has a long and checkered history.
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;
*/
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 ";
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
** complete copyright information.
*/
+#include <sysexits.h>
#include <h/mh.h>
#include <pwd.h>
#include <unistd.h>
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 */
** complete copyright information.
*/
+#include <sysexits.h>
#include <h/mh.h>
#include <h/utils.h>
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;
}
** (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");
}
}
** complete copyright information.
*/
+#include <sysexits.h>
#include <h/mh.h>
#include <h/utils.h>
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 */
break;
default:
- adios(NULL, "%s is poorly formatted", seqfile);
+ adios(EX_CONFIG, NULL, "%s is poorly formatted", seqfile);
}
break; /* break from for loop */
}
#include <errno.h>
#include <unistd.h>
#include <sys/stat.h>
+#include <sysexits.h>
/*
** We allocate space for messages (msgs array)
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;
}
}
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;
}
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);
}
}
/* 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;
** complete copyright information.
*/
+#include <sysexits.h>
#include <h/mh.h>
#include <h/utils.h>
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;
#include <h/aliasbr.h>
#include <h/utils.h>
#include <locale.h>
+#include <sysexits.h>
/*
** maximum number of names
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;
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));
}
}
*/
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) {
}
}
- return 0;
+ return EX_OK;
}
static void
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;
#include <ctype.h>
#include <sys/stat.h>
#include <locale.h>
+#include <sysexits.h>
static enum { MODE_ADD, MODE_DEL, MODE_LIST } mode = MODE_ADD;
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;
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;
}
/* 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;
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++;
}
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);
}
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) {
else
annotate(file, comp, text, datesw, number,
append, preserve);
- exit(0);
+ exit(EX_OK);
}
if (!msgs.size)
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);
}
}
fflush(stdout);
if (!fgets(buffer, sizeof buffer, stdin)) {
- /* sysexits.h EX_IOERR */
- exit(1);
+ exit(EX_IOERR);
}
*ap = trimcpy(buffer);
}
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);
}
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. */
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);
** 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);
** 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);
/* 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 != '-');
** 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.");
}
}
** 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') {
*/
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.");
}
}
}
#include <h/addrsbr.h>
#include <h/fmt_scan.h>
#include <locale.h>
+#include <sysexits.h>
#define NADDRS 100
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:
}
}
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);
for (addrp = 0; addrs[addrp]; addrp++)
status += process(addrs[addrp], normalize);
- exit(status);
- return 1;
+ return status;
}
struct pqpair {
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);
#include <unistd.h>
#include <sys/stat.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define VERBSW 0
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++;
}
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 {
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;
} 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");
}
}
}
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')
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();
*/
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;
/*
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",
}
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");
}
#include <fcntl.h>
#include <unistd.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define EDITRSW 0
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:
}
}
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. */
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);
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;
}
#include <fcntl.h>
#include <unistd.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define ANNOSW 0
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++;
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);
context_save();
what_now(ed, NOUSE, drft, msgnam, 1, mp, anot ? "Resent" : NULL, cwd);
- /*sysexits.h EX_SOFTWARE*/
- return 1;
+ return EX_SOFTWARE;
}
#include <h/fmt_scan.h>
#include <h/tws.h>
#include <locale.h>
+#include <sysexits.h>
#define NDATES 100
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);
#include <dirent.h>
#include <sys/stat.h>
#include <locale.h>
+#include <sysexits.h>
/*
** We allocate space to record the names of folders
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;
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 */
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;
}
qsort(folders, nFolders, sizeof(struct Folder),
(qsort_comp) CompareFolders);
PrintFolders();
- return 0;
+ return EX_OK;
}
/*
* 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 */
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
#include <h/fmt_compile.h>
#include <h/scansbr.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define FORMSW 0
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;
}
fmt_compile(fmtstr, &fmt);
fmt_dump(fmt);
- return 0;
+ return EX_OK;
}
static void
#include <errno.h>
#include <unistd.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define ALLSW 0
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;
}
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;
}
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));
/* 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 */
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 */
printf("\n");
if (!printsw) {
- exit(0);
+ exit(EX_OK);
}
}
** 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);
print_folders();
context_save();
- return 0;
+ return EX_OK;
}
static int
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 */
#include <h/utils.h>
#include <unistd.h>
#include <locale.h>
+#include <sysexits.h>
#define IFORMAT "digest-issue-%s"
#define VFORMAT "digest-volume-%s"
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++;
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;
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 {
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) {
} 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);
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;
}
}
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, " ");
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;
#include <unistd.h>
#include <sys/stat.h>
#include <locale.h>
+#include <sysexits.h>
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
#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
char *maildir_copy = NULL;
if (atexit(inc_done) != 0) {
- adios(NULL, "atexit failed");
+ adios(EX_OSERR, NULL, "atexit failed");
}
/*
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:
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));
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;
}
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);
}
}
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;
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++;
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. */
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());
} else {
fclose(in); in = NULL;
}
- adios(NULL, "failed");
+ adios(EX_SOFTWARE, NULL, "failed");
}
if (aud)
#include <h/utils.h>
#include <unistd.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define ADDSW 0
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++;
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;
}
}
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);
+ }
}
/*
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 */
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;
}
#include <ctype.h>
#include <sys/stat.h>
#include <locale.h>
+#include <sysexits.h>
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
FILE *fp_out = NULL;
if (atexit(unlink_done) != 0) {
- adios(NULL, "atexit failed");
+ adios(EX_OSERR, NULL, "atexit failed");
}
setlocale(LC_ALL, "");
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 */
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++;
}
}
if (compfile)
- adios(NULL, "only one composition file allowed");
+ adios(EX_USAGE, NULL, "only one composition file allowed");
else
compfile = cp;
}
/* 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);
/*
/* 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);
unlink_outfile = 0;
free_content(ct);
- exit(0);
+ exit(EX_OK);
}
/*
/* 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;
/* 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
/* 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)) {
/* 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:
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;
}
** 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;
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;
/* 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
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
(*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)++;
}
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 */
/* 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 */
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);
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':
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:
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':
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:
/* 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))
}
/* 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 */
*/
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++)
*/
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);
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;
/* 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;
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);
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));
}
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);
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;
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;
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;
} 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;
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;
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)
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;
/*
** Unknown directive
*/
- adios(NULL, "unknown directive \"#%s\"", ci->ci_type);
+ adios(EX_DATAERR, NULL, "unknown directive \"#%s\"", ci->ci_type);
return NOTOK; /* NOT REACHED */
}
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;
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:
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;
}
}
*/
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)) {
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);
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);
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);
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);
break;
default:
- adios(NULL, "unknown transfer encoding in content");
+ adios(EX_DATAERR, NULL, "unknown transfer encoding in content");
break;
}
#include <ctype.h>
#include <sys/stat.h>
#include <locale.h>
+#include <sysexits.h>
/*
** MAJOR BUG:
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;
fflush(stdout);
if (ferror(stdout)) {
- adios("output", "error writing");
+ adios(EX_IOERR, "output", "error writing");
}
return exitstat;
}
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;
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++;
}
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) &&
continue;
default:
- adios(NULL, "format file syntax error: %s", bp);
+ adios(EX_CONFIG, NULL, "format file syntax error: %s", bp);
}
}
fclose(fp);
return;
default:
- adios(NULL, "getfld() returned %d", state);
+ adios(EX_SOFTWARE, NULL, "getfld() returned %d", state);
}
}
}
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);
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))
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) {
#include <unistd.h>
#include <sys/stat.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define VERBSW 0
CT ct, *ctp;
if (atexit(freects_done) != 0) {
- adios(NULL, "atexit failed");
+ adios(EX_OSERR, NULL, "atexit failed");
}
setlocale(LC_ALL, "");
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;
}
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
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)))
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++) {
}
if (!*cts)
- exit(1);
+ exit(EX_SOFTWARE);
userrs = 1;
SIGNAL(SIGQUIT, quitser);
context_save(); /* save the context file */
}
- return 0;
+ return EX_OK;
}
fflush(stderr);
}
- exit(1);
+ _exit(EX_IOERR);
/* NOTREACHED */
}
#include <h/mhparse.h>
#include <h/utils.h>
#include <sys/stat.h>
+#include <sysexits.h>
/* mhmisc.c */
int part_ok(CT, int);
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;
}
#include <unistd.h>
#include <sys/stat.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define BODYSW 0
/* 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();
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;
case SUBJSW:
if (!(subject = *argp++) || *subject == '-')
- adios(NULL, "missing argument to %s",
+ adios(EX_USAGE, NULL, "missing argument to %s",
argp[-2]);
continue;
}
}
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));
}
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);
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);
fprintf(stderr, "Letter saved in dead.letter\n");
}
unlink(tmpfil);
- /* sysexits.h exit status from spost */
- exit(status ? 1 : 0);
+ exit(status);
}
intrser(int i)
{
unlink(tmpfil);
- exit(i != 0 ? 1 : 0);
+ _exit(EX_IOERR);
}
*/
#include <h/mh.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define COMPSW 0
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;
#include <unistd.h>
#include <ctype.h>
#include <sys/stat.h>
+#include <sysexits.h>
extern int debugsw;
fflush(stdout);
fflush(stderr);
- exit(1);
+ exit(EX_SOFTWARE);
return 1;
}
/* 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);
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 */
/* 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 */
/* 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 */
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;
/* 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 */
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;
/*
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;
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);
}
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) {
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);
}
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) {
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);
}
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) {
#include <h/utils.h>
#include <unistd.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define VERSIONSW 0
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)
/* 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
** 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
/* 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);
}
}
seq_save(mp); /* synchronize message sequences */
context_save(); /* save the context file */
folder_free(mp); /* free folder/message structure */
- return 0;
+ return EX_OK;
}
#include <unistd.h>
#include <sys/stat.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define VERBSW 0
int ontty = 0;
if (atexit(freects_done) != 0) {
- adios(NULL, "atexit failed");
+ adios(EX_OSERR, NULL, "atexit failed");
}
setlocale(LC_ALL, "");
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);
}
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);
}
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)))
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,
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;
/*
}
if (!*cts)
- exit(1);
+ exit(EX_SOFTWARE);
userrs = 1;
SIGNAL(SIGQUIT, quitser);
fflush(stderr);
}
- exit(1);
+ _exit(EX_IOERR);
/* NOTREACHED */
}
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);
execlp(name, mhbasename(name), NULL);
fprintf(stderr, "unable to exec ");
perror(name);
- _exit(-1);
+ _exit(EX_OSERR);
default:
close(pd[0]);
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);
#include <sys/wait.h>
#include <unistd.h>
#include <sys/stat.h>
+#include <sysexits.h>
extern int debugsw;
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:
break;
default:
- adios(NULL, "unknown content type %d", ct->c_type);
+ adios(EX_DATAERR, NULL, "unknown content type %d", ct->c_type);
break;
}
execlp("/bin/sh", "/bin/sh", "-c", buffer, NULL);
fprintf(stderr, "unable to exec ");
perror("/bin/sh");
- _exit(-1);
+ _exit(EX_OSERR);
/* NOTREACHED */
default:
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) {
#include <unistd.h>
#include <sys/stat.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define AUTOSW 0
FILE *fp;
if (atexit(freects_done) != 0) {
- adios(NULL, "atexit failed");
+ adios(EX_OSERR, NULL, "atexit failed");
}
setlocale(LC_ALL, "");
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++;
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;
}
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
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)))
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++) {
}
if (!*cts)
- exit(1);
+ exit(EX_SOFTWARE);
userrs = 1;
SIGNAL(SIGQUIT, quitser);
fflush(stdout);
fprintf(stderr, "\n");
fflush(stderr);
+ exit(EX_TEMPFAIL);
}
- exit(1);
+ exit(EX_IOERR);
/* NOTREACHED */
}
break;
default:
- adios(NULL, "unknown content type %d", ct->c_type);
+ adios(EX_DATAERR, NULL, "unknown content type %d", ct->c_type);
break;
}
}
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++) {
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);
#include <unistd.h>
#include <sys/stat.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define VERBSW 0
CT ct, *ctp;
if (atexit(freects_done) != 0) {
- adios(NULL, "atexit failed");
+ adios(EX_OSERR, NULL, "atexit failed");
}
setlocale(LC_ALL, "");
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;
}
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
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,
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)))
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++) {
}
if (!*cts)
- exit(1);
+ exit(EX_SOFTWARE);
userrs = 1;
SIGNAL(SIGQUIT, quitser);
context_save(); /* save the context file */
}
- return 0;
+ return EX_OK;
}
fflush(stderr);
}
- exit(1);
+ exit(EX_IOERR);
/* NOTREACHED */
}
#include <string.h>
#include <unistd.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define MODESW 0
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 */
break;
default:
- adios(NULL, "%s is poorly formatted", seqfile);
+ adios(EX_SOFTWARE, NULL, "%s is poorly formatted", seqfile);
}
break; /* break from for loop */
}
} 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;
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;
/* 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 */
folder = doit(context_find(curfolder), folders, sequences);
if (folder == NULL) {
- exit(0);
+ exit(EX_OK);
return 1;
}
#include <errno.h>
#include <unistd.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define VERSIONSW 0
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);
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 */
break;
}
if (mbox_copy(fileno(stdout), fd) == NOTOK) {
- adios(NULL, "error writing to stdout");
+ adios(EX_IOERR, NULL, "error writing to stdout");
}
close(fd);
}
#include <h/utils.h>
#include <unistd.h>
#include <locale.h>
+#include <sysexits.h>
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
register FILE *fp;
if (atexit(putzero_done) != 0) {
- adios(NULL, "atexit failed");
+ adios(EX_OSERR, NULL, "atexit failed");
}
setlocale(LC_ALL, "");
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:
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:
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;
}
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
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 */
/*
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;
mp->hghsel = hi;
if (mp->numsel <= 0)
- adios(NULL, "no messages match specification");
+ adios(EX_DATAERR, NULL, "no messages match specification");
seqs[seqp] = NULL;
*/
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.
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;
return 0;
default:
- adios(NULL, "internal error -- you lose");
+ adios(EX_SOFTWARE, NULL, "internal error -- you lose");
}
break;
}
#include <ctype.h>
#include <sys/stat.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define PREPSW 0
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++;
}
}
- 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));
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);
break;
default:
- adios(NULL, "skeleton is poorly formatted");
+ adios(EX_DATAERR, NULL, "skeleton is poorly formatted");
}
break;
}
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;
}
#include <unistd.h>
#include <sys/stat.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define FORMSW 0
char *tfile = NULL;
if (atexit(unlink_done) != 0) {
- adios(NULL, "atexit failed");
+ adios(EX_OSERR, NULL, "atexit failed");
}
setlocale(LC_ALL, "");
switch (smatch(++cp, switches)) {
case AMBIGSW:
ambigsw(cp, switches);
- exit(1);
+ exit(EX_USAGE);
case UNKWNSW:
vec[vecp++] = --cp;
continue;
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;
}
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";
execvp(*vec, vec);
fprintf(stderr, "unable to exec ");
perror(*vec);
- _exit(1);
+ _exit(EX_OSERR);
return 0; /* dead code to satisfy the compiler */
}
FILE *out;
if (!(out = fopen(drft, "w"))) {
- adios(drft, "unable to create");
+ adios(EX_CANTCREAT, drft, "unable to create");
}
/* get new format string */
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;
goto finished;
default:
- adios(NULL, "m_getfld() returned %d", state);
+ adios(EX_SOFTWARE, NULL, "m_getfld() returned %d", state);
}
}
finished: ;
fputs(scanl, out);
if (ferror(out)) {
- adios(drft, "error writing");
+ adios(EX_IOERR, drft, "error writing");
}
fclose(out);
#include <h/tws.h>
#include <unistd.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define VERSIONSW 0
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;
}
#include <unistd.h>
#include <sys/stat.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define CRETSW 0
struct stat st;
if (atexit(unlink_done) != 0) {
- adios(NULL, "atexit failed");
+ adios(EX_OSERR, NULL, "atexit failed");
}
setlocale(LC_ALL, "");
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;
}
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);
}
}
/* 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);
/* 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());
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
*/
if ((msgnum = folder_addmsg(&mp, tmpfilenam, 0, unseensw, 0, 0, NULL))
== -1)
- exit(1);
+ exit(EX_SOFTWARE);
/*
** Add the message to any extra sequences
*/
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 */
unlink(tmpfilenam); /* remove temporary file */
tmpfilenam = NULL;
- return 0;
+ return EX_OK;
}
/*
#include <errno.h>
#include <unistd.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define LINKSW 0
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++;
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;
}
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
}
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;
admonish(files[i], "unable to unlink");
}
}
- exit(0);
+ exit(EX_OK);
}
if (!msgs.size)
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 */
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);
}
}
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;
#include <ctype.h>
#include <sys/stat.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define GROUPSW 0
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++;
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;
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;
}
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;
}
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));
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 */
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) {
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
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;
mask = umask(~m_gmprot());
if ((out = fopen(drft, "w")) == NULL)
- adios(drft, "unable to create");
+ adios(EX_CANTCREAT, drft, "unable to create");
umask(mask);
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 */
goto finished;
default:
- adios(NULL, "m_getfld() returned %d", state);
+ adios(EX_SOFTWARE, NULL, "m_getfld() returned %d", state);
}
}
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) {
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));
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;
}
#include <unistd.h>
#include <dirent.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define INTRSW 0
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;
}
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);
}
}
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;
if (interactive) {
cp = concat("Remove folder \"", folder, "\"? ", NULL);
if (!getanswer(cp))
- exit(0);
+ exit(EX_OK);
free(cp);
}
}
if ((dd = opendir(".")) == NULL)
- adios(NULL, "unable to read folder +%s", folder);
+ adios(EX_IOERR, NULL, "unable to read folder +%s", folder);
others = 0;
/*
#include <h/utils.h>
#include <unistd.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define UNLINKSW 0
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++;
}
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));
}
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
*/
for (msgnum = 0; msgnum < msgs.size; msgnum++) {
if (!m_convert(mp, msgs.msgs[msgnum])) {
- /* sysexits EX_USAGE */
- exit(1);
+ exit(EX_USAGE);
}
}
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));
#include <errno.h>
#include <unistd.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define FORMSW 0
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));
}
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 (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);
break;
}
fclose(in);
- exit(0);
+ exit(EX_OK);
}
/*
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 */
break;
default:
- adios(NULL, "scan() botch(%d)", state);
+ adios(EX_SOFTWARE, NULL, "scan() botch(%d)", state);
case SCNEOF:
advise(NULL, "message %d: empty", msgnum);
#include <h/utils.h>
#include <ctype.h>
#include <sys/stat.h>
+#include <sysexits.h>
#ifdef _FSTDIO
# define _ptr _p /* Gag */
#define FPUTS(buf) {\
if (fputs(buf, scnout) == EOF)\
- adios(scnmsg, "write error on");\
+ adios(EX_IOERR, scnmsg, "write error on");\
}
/*
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;
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 */
goto finished;
default:
- adios(NULL, "getfld() returned %d", state);
+ adios(EX_SOFTWARE, NULL, "getfld() returned %d", state);
}
}
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;
}
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 {
*--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);
}
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++;
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);
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");
}
}
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);
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. */
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. */
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. */
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) &&
/* 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;
execvp(*vec, vec);
fprintf(stderr, "unable to exec ");
perror(*vec);
- _exit(-1);
+ _exit(EX_OSERR);
break; /* NOT REACHED */
default:
#include <stdarg.h>
#include <sys/stat.h>
#include <locale.h>
+#include <sysexits.h>
#ifdef INITGROUPS_HEADER
#include INITGROUPS_HEADER
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;
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) {
/* 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());
/* 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 {
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");
}
}
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. */
m_putenv("PATH", path);
execvp(pgm, vec);
- _exit(-1);
+ _exit(EX_OSERR);
default:
/* parent process */
#include <ctype.h>
#include <sys/stat.h>
#include <locale.h>
+#include <sysexits.h>
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
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;
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 */
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:
}
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
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".
*/
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];
/*
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++) {
return (0);
default:
- adios(NULL, "internal error -- you lose");
+ adios(EX_SOFTWARE, NULL, "internal error -- you lose");
}
break;
}
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)
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);
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;
#include <h/utils.h>
#include <unistd.h>
#include <locale.h>
+#include <sysexits.h>
#define MAX_SM_FIELD 1476 /* < largest hdr field sendmail will accept */
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++;
}
}
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++;
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));
}
}
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;
}
if (debug) {
/* stop here */
- exit(0);
+ exit(EX_OK);
}
fclose(out);
if (!(msgflags & MVIS)) {
/* only Bcc rcpts: we're finished here */
unlink(tmpfil);
- exit(0);
+ exit(EX_OK);
}
}
** 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);
}
*argp = NULL;
execv(sendmail, sargv);
- adios(sendmail, "can't exec");
+ adios(EX_OSERR, sendmail, "can't exec");
return -1;
}
}
if (badmsg) {
unlink(tmpfil);
- adios(NULL, "re-format message and try again");
+ adios(EX_DATAERR, NULL, "re-format message and try again");
}
}
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++) {
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",
#include <unistd.h>
#include <sys/stat.h>
#include <locale.h>
+#include <sysexits.h>
#ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
*/
if (!getcwd(cwd, sizeof (cwd))) {
- adios("getcwd", "could not get working directory");
+ adios(EX_USAGE, "getcwd", "could not get working directory");
}
while ((cp = *argp++)) {
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;
}
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:
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 */
case REFILEOPT:
/* Refile the draft */
if (refile(++argp, drft) == 0) {
- exit(0);
+ exit(EX_OK);
}
break;
*/
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;
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;
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;
}
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;
}
switch (pid = fork()) {
case NOTOK:
advise("fork", "unable to");
- status = NOTOK;
+ status = EX_OSERR;
break;
case OK:
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) {
execvp(*vec, vec);
fprintf(stderr, "%s: unable to exec ", invo_name);
perror("send");
- _exit(-1);
+ _exit(EX_OSERR);
}
removefile(char *drft)
{
if (unlink(drft) == NOTOK)
- adios(drft, "unable to unlink");
+ adios(EX_IOERR, drft, "unable to unlink");
return OK;
}
#include <h/fmt_scan.h>
#include <h/utils.h>
#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define VERSIONSW 0
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;
}
}
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;
}
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]);
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);
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);
if ((in = fopen(file, "r")) == NULL) {
- adios(file, "unable to open");
+ adios(EX_IOERR, file, "unable to open");
}
for (compnum = 1, state = FLD;;) {
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;
}
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) {