X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=uip%2Frcvstore.c;h=5fd9ae06df622099567784b322a84c88162c12da;hp=fc98b4ac11b9016fca32672154fad56243adacf1;hb=9cf6132a6ea29968131a000bc2fb6860affac45e;hpb=d5b5e6e4813b7fd77dc1664df4304537f3002cf3 diff --git a/uip/rcvstore.c b/uip/rcvstore.c index fc98b4a..5fd9ae0 100644 --- a/uip/rcvstore.c +++ b/uip/rcvstore.c @@ -7,32 +7,37 @@ */ #include +#include #include #include #include #include +#include +#include +#include +#include static struct swit switches[] = { #define CRETSW 0 { "create", 0 }, #define NCRETSW 1 - { "nocreate", 0 }, + { "nocreate", 2 }, #define UNSEENSW 2 { "unseen", 0 }, #define NUNSEENSW 3 - { "nounseen", 0 }, + { "nounseen", 2 }, #define PUBSW 4 { "public", 0 }, #define NPUBSW 5 - { "nopublic", 0 }, + { "nopublic", 2 }, #define ZEROSW 6 { "zero", 0 }, #define NZEROSW 7 - { "nozero", 0 }, + { "nozero", 2 }, #define SEQSW 8 { "sequence name", 0 }, #define VERSIONSW 9 - { "version", 0 }, + { "Version", 0 }, #define HELPSW 10 { "help", 0 }, { NULL, 0 } @@ -44,7 +49,7 @@ static struct swit switches[] = { */ static char *tmpfilenam = NULL; -static void unlink_done(int) NORETURN; +void unlink_done(); int main(int argc, char **argv) @@ -58,11 +63,11 @@ main(int argc, char **argv) struct msgs *mp; struct stat st; - done=unlink_done; + if (atexit(unlink_done) != 0) { + adios(EX_OSERR, NULL, "atexit failed"); + } -#ifdef LOCALE setlocale(LC_ALL, ""); -#endif invo_name = mhbasename(argv[0]); /* read user profile/context */ @@ -77,27 +82,27 @@ 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", cp); + adios(EX_USAGE, NULL, "-%s unknown", cp); case HELPSW: snprintf(buf, sizeof(buf), "%s [+folder] [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 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; @@ -132,11 +137,11 @@ main(int argc, char **argv) } if (*cp == '+' || *cp == '@') { if (folder) - adios(NULL, "only one folder at a time!"); + adios(EX_USAGE, NULL, "only one folder at a time!"); else - folder = getcpy(expandfol(cp)); + folder = mh_xstrdup(expandfol(cp)); } else { - adios(NULL, "usage: %s [+folder] [switches]", + adios(EX_USAGE, NULL, "usage: %s [+folder] [switches]", invo_name); } } @@ -151,15 +156,15 @@ main(int argc, char **argv) /* check if folder exists */ if (stat(maildir, &st) == NOTOK) { if (errno != ENOENT) - adios(maildir, "error on folder"); + adios(EX_IOERR, maildir, "error on folder"); if (!create) - adios(NULL, "folder %s doesn't exist", maildir); + adios(EX_USAGE, NULL, "folder %s doesn't exist", maildir); if (!makedir(maildir)) - adios(NULL, "unable to create folder %s", maildir); + adios(EX_CANTCREAT, NULL, "unable to create folder %s", maildir); } if (chdir(maildir) == NOTOK) - adios(maildir, "unable to change directory to"); + adios(EX_OSERR, maildir, "unable to change directory to"); /* ignore a few signals */ SIGNAL(SIGHUP, SIG_IGN); @@ -170,7 +175,7 @@ main(int argc, char **argv) /* create a temporary file */ tmpfilenam = m_mktemp(invo_name, &fd, NULL); if (tmpfilenam == NULL) { - adios("rcvstore", "unable to create temporary file"); + adios(EX_CANTCREAT, "rcvstore", "unable to create temporary file"); } chmod(tmpfilenam, m_gmprot()); @@ -179,23 +184,23 @@ main(int argc, char **argv) if (fstat(fd, &st) == NOTOK) { unlink(tmpfilenam); - adios(tmpfilenam, "unable to fstat"); + adios(EX_IOERR, tmpfilenam, "unable to fstat"); } if (close(fd) == NOTOK) - adios(tmpfilenam, "error closing"); + adios(EX_IOERR, tmpfilenam, "error closing"); /* don't add file if it is empty */ if (st.st_size == 0) { unlink(tmpfilenam); advise(NULL, "empty file"); - done(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 @@ -203,7 +208,7 @@ main(int argc, char **argv) */ if ((msgnum = folder_addmsg(&mp, tmpfilenam, 0, unseensw, 0, 0, NULL)) == -1) - done(1); + exit(EX_SOFTWARE); /* ** Add the message to any extra sequences @@ -211,7 +216,7 @@ main(int argc, char **argv) */ for (seqp = 0; seqs[seqp]; seqp++) { if (!seq_addmsg(mp, seqs[seqp], msgnum, publicsw, zerosw)) - done(1); + exit(EX_SOFTWARE); } seq_setunseen(mp, 1); /* add new msgs to unseen sequences */ @@ -222,17 +227,16 @@ main(int argc, char **argv) unlink(tmpfilenam); /* remove temporary file */ tmpfilenam = NULL; - done(0); - return 1; + return EX_OK; } /* ** Clean up and exit */ -static void -unlink_done(int status) +void +unlink_done() { - if (tmpfilenam && *tmpfilenam) + if (tmpfilenam && *tmpfilenam) { unlink(tmpfilenam); - exit(status); + } }