*/
#include <h/mh.h>
+#include <h/utils.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define VERBSW 0
{ NULL, 0 }
};
+char *version=VERSION;
+
static char delim3[] = "-------";
struct smsg {
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));
+ folder = mh_xstrdup(expandfol(cp));
} else {
msgs[msgp++] = cp;
}
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");
+ smsgs = mh_xcalloc(MAXFOLDER + 2, sizeof(*smsgs));
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");
}
}
}
- free(smsgs);
+ mh_free0(&smsgs);
context_replace(curfolder, folder);
/*
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");
}