X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Fburst.c;h=12d1f9d408b2809eba2671a4590e54919be933ab;hp=e657c33fa5fc1cf282c3fd9a8e3e59da431cc7a9;hb=6e9577f324bef90765a5edc02044eb111ec48072;hpb=ccf4f175ef4c4e7522f9510a4a1149c15d810dd9 diff --git a/uip/burst.c b/uip/burst.c index e657c33..12d1f9d 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 @@ -20,6 +25,8 @@ static struct swit switches[] = { { NULL, 0 } }; +char *version=VERSION; + static char delim3[] = "-------"; struct smsg { @@ -59,17 +66,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,9 +88,9 @@ 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)); + folder = mh_xstrdup(expandfol(cp)); } else { msgs[msgp++] = cp; } @@ -96,26 +103,23 @@ 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"); + smsgs = mh_xcalloc(MAXFOLDER + 2, sizeof(*smsgs)); hi = mp->hghmsg + 1; @@ -129,12 +133,12 @@ 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"); } } } - free(smsgs); + mh_free0(&smsgs); context_replace(curfolder, folder); /* @@ -148,8 +152,7 @@ main(int argc, char **argv) seq_save(mp); context_save(); folder_free(mp); - done(0); - return 1; + return 0; } @@ -170,7 +173,7 @@ find_delim(int msgnum, struct smsg *smsgs) ld3 = strlen(delim3); if ((in = fopen(msgnam = m_name(msgnum), "r")) == NULL) - adios(msgnam, "unable to read message"); + adios(EX_IOERR, msgnam, "unable to read message"); for (msgp = 0, pos = 0L; msgp <= MAXFOLDER; msgp++) { while (fgets(buffer, sizeof(buffer), in) && buffer[0] == '\n') @@ -223,7 +226,7 @@ burst(struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst, struct msgs *mp; if ((in = fopen(msgnam = m_name(msgnum), "r")) == NULL) - adios(msgnam, "unable to read message"); + adios(EX_IOERR, msgnam, "unable to read message"); mode = fstat(fileno(in), &st) != NOTOK ? (int)(st.st_mode & 0777) : m_gmprot(); @@ -235,7 +238,7 @@ burst(struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst, */ if ((mp->hghmsg + numburst > mp->hghoff) && !(mp = folder_realloc(mp, mp->lowoff, mp->hghmsg + numburst))) - adios(NULL, "unable to allocate folder storage"); + adios(EX_OSERR, NULL, "unable to allocate folder storage"); *mpp = mp; /* @@ -247,7 +250,7 @@ burst(struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst, for (j=1, i=mp->hghmsg+1; j<=numburst; j++, i++) { snprintf(destfil, sizeof destfil, "%s/%d", maildir, i); if (!(out = fopen(destfil, "w"))) { - adios(destfil, "unable to open"); + adios(EX_IOERR, destfil, "unable to open"); } if (verbosw) { printf("message %d of digest %d becomes message %d\n", @@ -327,7 +330,7 @@ cpybrst(FILE *in, FILE *out, char *ifile, char *ofile, int len) } if (ferror(in) && !feof(in)) - adios(ifile, "error reading"); + adios(EX_IOERR, ifile, "error reading"); if (ferror(out)) - adios(ofile, "error writing"); + adios(EX_IOERR, ofile, "error writing"); }