Replace done with exit at uip
[mmh] / uip / rcvstore.c
index 99ec48c..fbddda7 100644 (file)
 #include <h/signals.h>
 #include <errno.h>
 #include <signal.h>
-#include <h/mts.h>
 
 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 }
@@ -45,30 +44,28 @@ static struct swit switches[] = {
 */
 static char *tmpfilenam = NULL;
 
-static void unlink_done(int) NORETURN;
+static void unlink_done();
 
 int
 main(int argc, char **argv)
 {
        int publicsw = -1, zerosw = 0;
        int create = 1, unseensw = 1;
-       int fd, msgnum, seqp = 0;
+       int fd, msgnum;
+       size_t seqp = 0;
        char *cp, *maildir, *folder = NULL, buf[BUFSIZ];
        char **argp, **arguments, *seqs[NUMATTRS+1];
        struct msgs *mp;
        struct stat st;
 
-       done=unlink_done;
+       atexit(unlink_done);
 
-#ifdef LOCALE
        setlocale(LC_ALL, "");
-#endif
        invo_name = mhbasename(argv[0]);
 
        /* read user profile/context */
        context_read();
 
-       mts_init(invo_name);
        arguments = getarguments(invo_name, argc, argv, 1);
        argp = arguments;
 
@@ -78,7 +75,7 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               done(1);
+                               exit(1);
                        case UNKWNSW:
                                adios(NULL, "-%s unknown", cp);
 
@@ -87,10 +84,10 @@ main(int argc, char **argv)
                                                "%s [+folder] [switches]",
                                                invo_name);
                                print_help(buf, switches, 1);
-                               done(1);
+                               exit(1);
                        case VERSIONSW:
                                print_version(invo_name);
-                               done(1);
+                               exit(1);
 
                        case SEQSW:
                                if (!(cp = *argp++) || *cp == '-')
@@ -189,7 +186,7 @@ main(int argc, char **argv)
        if (st.st_size == 0) {
                unlink(tmpfilenam);
                advise(NULL, "empty file");
-               done(0);
+               exit(0);
        }
 
        /*
@@ -202,9 +199,9 @@ main(int argc, char **argv)
        ** Link message into folder, and possibly add
        ** to the Unseen-Sequence's.
        */
-       if ((msgnum = folder_addmsg(&mp, tmpfilenam, 0, unseensw, 0, 0,
-                       (char *)0)) == -1)
-               done(1);
+       if ((msgnum = folder_addmsg(&mp, tmpfilenam, 0, unseensw, 0, 0, NULL))
+                       == -1)
+               exit(1);
 
        /*
        ** Add the message to any extra sequences
@@ -212,10 +209,10 @@ main(int argc, char **argv)
        */
        for (seqp = 0; seqs[seqp]; seqp++) {
                if (!seq_addmsg(mp, seqs[seqp], msgnum, publicsw, zerosw))
-                       done(1);
+                       exit(1);
        }
 
-       seq_setunseen(mp, 0);  /* synchronize any Unseen-Sequence's */
+       seq_setunseen(mp, 1);  /* add new msgs to unseen sequences */
        seq_save(mp);  /* synchronize and save message sequences */
        folder_free(mp);  /* free folder/message structure */
 
@@ -223,17 +220,16 @@ main(int argc, char **argv)
        unlink(tmpfilenam);  /* remove temporary file */
        tmpfilenam = NULL;
 
-       done(0);
-       return 1;
+       return 0;
 }
 
 /*
 ** Clean up and exit
 */
 static void
-unlink_done(int status)
+unlink_done()
 {
-       if (tmpfilenam && *tmpfilenam)
+       if (tmpfilenam && *tmpfilenam) {
                unlink(tmpfilenam);
-       exit(status);
+       }
 }