Move #include from h/mh.h to source files
[mmh] / uip / rcvstore.c
index fc98b4a..61a91b2 100644 (file)
 #include <h/signals.h>
 #include <errno.h>
 #include <signal.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <locale.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 }
@@ -44,7 +47,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 +61,11 @@ main(int argc, char **argv)
        struct msgs *mp;
        struct stat st;
 
-       done=unlink_done;
+       if (atexit(unlink_done) != 0) {
+               adios(NULL, "atexit failed");
+       }
 
-#ifdef LOCALE
        setlocale(LC_ALL, "");
-#endif
        invo_name = mhbasename(argv[0]);
 
        /* read user profile/context */
@@ -77,7 +80,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);
 
@@ -86,10 +89,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 == '-')
@@ -188,7 +191,7 @@ main(int argc, char **argv)
        if (st.st_size == 0) {
                unlink(tmpfilenam);
                advise(NULL, "empty file");
-               done(0);
+               exit(0);
        }
 
        /*
@@ -203,7 +206,7 @@ main(int argc, char **argv)
        */
        if ((msgnum = folder_addmsg(&mp, tmpfilenam, 0, unseensw, 0, 0, NULL))
                        == -1)
-               done(1);
+               exit(1);
 
        /*
        ** Add the message to any extra sequences
@@ -211,7 +214,7 @@ 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, 1);  /* add new msgs to unseen sequences */
@@ -222,17 +225,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)
+void
+unlink_done()
 {
-       if (tmpfilenam && *tmpfilenam)
+       if (tmpfilenam && *tmpfilenam) {
                unlink(tmpfilenam);
-       exit(status);
+       }
 }