X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fburst.c;h=04e5450a403989f72ffbb27e5704b9f606ee35d4;hp=e657c33fa5fc1cf282c3fd9a8e3e59da431cc7a9;hb=6e7d34c614291079de750ceda1d4f5ec537beb81;hpb=ccf4f175ef4c4e7522f9510a4a1149c15d810dd9 diff --git a/uip/burst.c b/uip/burst.c index e657c33..04e5450 100644 --- a/uip/burst.c +++ b/uip/burst.c @@ -7,6 +7,11 @@ */ #include +#include +#include +#include +#include +#include static struct swit switches[] = { #define VERBSW 0 @@ -59,17 +64,17 @@ main(int argc, char **argv) switch (smatch(++cp, switches)) { case AMBIGSW: ambigsw(cp, switches); - done(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); - done(1); + exit(argc == 2 ? EX_OK : EX_USAGE); case VERSIONSW: print_version(invo_name); - done(1); + exit(argc == 2 ? EX_OK : EX_USAGE); case VERBSW: verbosw++; @@ -81,7 +86,7 @@ main(int argc, char **argv) } if (*cp == '+' || *cp == '@') { if (folder) - adios(NULL, "only one folder at a time!"); + adios(EX_USAGE, NULL, "only one folder at a time!"); else folder = getcpy(expandfol(cp)); } else { @@ -96,26 +101,24 @@ main(int argc, char **argv) maildir = toabsdir(folder); if (chdir(maildir) == NOTOK) - adios(maildir, "unable to change directory to"); + adios(EX_SOFTWARE, maildir, "unable to change directory to"); /* read folder and create message structure */ if (!(mp = folder_read(folder))) - adios(NULL, "unable to read folder %s", folder); + adios(EX_IOERR, NULL, "unable to read folder %s", folder); /* check for empty folder */ if (mp->nummsg == 0) - adios(NULL, "no messages in %s", folder); + adios(EX_DATAERR, NULL, "no messages in %s", folder); /* parse all the message ranges/sequences and set SELECTED */ for (msgnum = 0; msgnum < msgp; msgnum++) if (!m_convert(mp, msgs[msgnum])) - done(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"); + mh_xcalloc((size_t) (MAXFOLDER + 2), sizeof(*smsgs)); hi = mp->hghmsg + 1; @@ -129,7 +132,7 @@ main(int argc, char **argv) } else if (numburst == 0) { admonish(NULL, "message %d not in digest format", msgnum); } else { - adios(NULL, "burst() botch -- you lose big"); + adios(EX_SOFTWARE, NULL, "burst() botch -- you lose big"); } } } @@ -148,8 +151,7 @@ main(int argc, char **argv) seq_save(mp); context_save(); folder_free(mp); - done(0); - return 1; + return 0; } @@ -170,7 +172,7 @@ find_delim(int msgnum, struct smsg *smsgs) ld3 = strlen(delim3); if ((in = fopen(msgnam = m_name(msgnum), "r")) == NULL) - adios(msgnam, "unable to read message"); + adios(EX_IOERR, msgnam, "unable to read message"); for (msgp = 0, pos = 0L; msgp <= MAXFOLDER; msgp++) { while (fgets(buffer, sizeof(buffer), in) && buffer[0] == '\n') @@ -223,7 +225,7 @@ burst(struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst, struct msgs *mp; if ((in = fopen(msgnam = m_name(msgnum), "r")) == NULL) - adios(msgnam, "unable to read message"); + adios(EX_IOERR, msgnam, "unable to read message"); mode = fstat(fileno(in), &st) != NOTOK ? (int)(st.st_mode & 0777) : m_gmprot(); @@ -235,7 +237,7 @@ burst(struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst, */ if ((mp->hghmsg + numburst > mp->hghoff) && !(mp = folder_realloc(mp, mp->lowoff, mp->hghmsg + numburst))) - adios(NULL, "unable to allocate folder storage"); + adios(EX_OSERR, NULL, "unable to allocate folder storage"); *mpp = mp; /* @@ -247,7 +249,7 @@ burst(struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst, for (j=1, i=mp->hghmsg+1; j<=numburst; j++, i++) { snprintf(destfil, sizeof destfil, "%s/%d", maildir, i); if (!(out = fopen(destfil, "w"))) { - adios(destfil, "unable to open"); + adios(EX_IOERR, destfil, "unable to open"); } if (verbosw) { printf("message %d of digest %d becomes message %d\n", @@ -327,7 +329,7 @@ cpybrst(FILE *in, FILE *out, char *ifile, char *ofile, int len) } if (ferror(in) && !feof(in)) - adios(ifile, "error reading"); + adios(EX_IOERR, ifile, "error reading"); if (ferror(out)) - adios(ofile, "error writing"); + adios(EX_IOERR, ofile, "error writing"); }