Fix uip/whom.c for C89 compatibility
[mmh] / uip / mhmail.c
index eea92b7..4215ecf 100644 (file)
@@ -14,6 +14,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <locale.h>
+#include <sysexits.h>
 
 static struct swit switches[] = {
 #define BODYSW  0
@@ -31,6 +32,8 @@ static struct swit switches[] = {
        { NULL, 0 }
 };
 
+char *version=VERSION;
+
 static char tmpfil[BUFSIZ];
 
 /*
@@ -54,7 +57,7 @@ main(int argc, char **argv)
 
        /* Without arguments, exit. */
        if (argc == 1) {
-               adios(NULL, "no interactive mail shell. Use inc/scan/show instead.");
+               adios(EX_USAGE, NULL, "no interactive mail shell. Use inc/scan/show instead.");
        }
 
        context_read();
@@ -67,30 +70,29 @@ main(int argc, char **argv)
                        switch (smatch(++cp, switches)) {
                        case AMBIGSW:
                                ambigsw(cp, switches);
-                               /* sysexits.h EX_USAGE */
-                               exit(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 addrs... [switches]",
                                                invo_name);
                                print_help(buf, switches, 0);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
                        case VERSIONSW:
                                print_version(invo_name);
-                               exit(0);
+                               exit(argc == 2 ? EX_OK : EX_USAGE);
 
                        case FROMSW:
                                if (!(from = *argp++) || *from == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
                        case BODYSW:
                                if (!(body = *argp++) || *body == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
 
@@ -100,25 +102,25 @@ main(int argc, char **argv)
 
                        case SUBJSW:
                                if (!(subject = *argp++) || *subject == '-')
-                                       adios(NULL, "missing argument to %s",
+                                       adios(EX_USAGE, NULL, "missing argument to %s",
                                                        argp[-2]);
                                continue;
                        }
                }
                if (iscc)
                        cclist = cclist ? add(cp, add(", ", cclist)) :
-                                       getcpy(cp);
+                                       mh_xstrdup(cp);
                else
                        tolist = tolist ? add(cp, add(", ", tolist)) :
-                                       getcpy(cp);
+                                       mh_xstrdup(cp);
        }
 
        if (tolist == NULL)
-               adios(NULL, "usage: %s addrs ... [switches]", invo_name);
+               adios(EX_USAGE, NULL, "usage: %s addrs ... [switches]", invo_name);
 
        tfile = m_mktemp2("/tmp/", invo_name, NULL, &out);
        if (tfile == NULL)
-               adios("mhmail", "unable to create temporary file");
+               adios(EX_CANTCREAT, "mhmail", "unable to create temporary file");
        chmod(tfile, 0600);
        strncpy(tmpfil, tfile, sizeof(tmpfil));
 
@@ -147,12 +149,12 @@ main(int argc, char **argv)
                        }
                        empty = 0;
                        if (fputs(buf, out) == EOF) {
-                               adios(tmpfil, "error writing");
+                               adios(EX_IOERR, tmpfil, "error writing");
                        }
                }
                if (empty) {
                        unlink(tmpfil);
-                       adios(NULL, "not sending message with empty body");
+                       adios(EX_DATAERR, NULL, "not sending message with empty body");
                }
        }
        fclose(out);
@@ -171,8 +173,7 @@ main(int argc, char **argv)
                if (in == -1 || out == -1) {
                        fprintf(stderr, "Letter left at %s.\n",
                                        tmpfil);
-                       /* sysexits.h exit-status from spost */
-                       exit(status ? 1 : 0);
+                       exit(status);
                }
                cpydata(in, out, tmpfil, "dead.letter");
                close(in);
@@ -180,8 +181,7 @@ main(int argc, char **argv)
                fprintf(stderr, "Letter saved in dead.letter\n");
        }
        unlink(tmpfil);
-       /* sysexits.h exit status from spost */
-       exit(status ? 1 : 0);
+       exit(status);
 }
 
 
@@ -189,6 +189,6 @@ static void
 intrser(int i)
 {
        unlink(tmpfil);
-       exit(i != 0 ? 1 : 0);
+       _exit(EX_IOERR);
 }