install correct aliases file
[unix-history] / usr / src / usr.bin / mail / fio.c
index 210c86e..c40efe9 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)fio.c      5.14 (Berkeley) %G%";
+static char sccsid[] = "@(#)fio.c      5.18 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -413,6 +413,12 @@ expand(name)
        struct stat sbuf;
        extern union wait wait_status;
 
        struct stat sbuf;
        extern union wait wait_status;
 
+       /*
+        * The order of evaluation is "%" and "#" expand into constants.
+        * "&" can expand into "+".  "+" can expand into shell meta characters.
+        * Shell meta characters expand into constants.
+        * This way, we make no recursive expansion.
+        */
        switch (*name) {
        case '%':
                findmail(name[1] ? name + 1 : myname, xname);
        switch (*name) {
        case '%':
                findmail(name[1] ? name + 1 : myname, xname);
@@ -426,16 +432,19 @@ expand(name)
                }
                return savestr(prevfile);
        case '&':
                }
                return savestr(prevfile);
        case '&':
-               if (name[1] == 0 && (name = value("mbox")) == NOSTR) {
-                       sprintf(xname, "%s/mbox", homedir);
-                       name = savestr(xname);
-               }
+               if (name[1] == 0 && (name = value("MBOX")) == NOSTR)
+                       name = "~/mbox";
                /* fall through */
        }
        if (name[0] == '+' && getfold(cmdbuf) >= 0) {
                sprintf(xname, "%s/%s", cmdbuf, name + 1);
                name = savestr(xname);
        }
                /* fall through */
        }
        if (name[0] == '+' && getfold(cmdbuf) >= 0) {
                sprintf(xname, "%s/%s", cmdbuf, name + 1);
                name = savestr(xname);
        }
+       /* catch the most common shell meta character */
+       if (name[0] == '~' && (name[1] == '/' || name[1] == '\0')) {
+               sprintf(xname, "%s%s", homedir, name + 1);
+               name = savestr(xname);
+       }
        if (!anyof(name, "~{[*?$`'\"\\"))
                return name;
        if (pipe(pivec) < 0) {
        if (!anyof(name, "~{[*?$`'\"\\"))
                return name;
        if (pipe(pivec) < 0) {
@@ -455,7 +464,7 @@ expand(name)
        l = read(pivec[0], xname, BUFSIZ);
        close(pivec[0]);
        if (wait_child(pid) < 0 && wait_status.w_termsig != SIGPIPE) {
        l = read(pivec[0], xname, BUFSIZ);
        close(pivec[0]);
        if (wait_child(pid) < 0 && wait_status.w_termsig != SIGPIPE) {
-               fprintf(stderr, "\"Echo\" failed\n");
+               fprintf(stderr, "\"%s\": Expansion failed.\n", name);
                return NOSTR;
        }
        if (l < 0) {
                return NOSTR;
        }
        if (l < 0) {
@@ -463,19 +472,19 @@ expand(name)
                return NOSTR;
        }
        if (l == 0) {
                return NOSTR;
        }
        if (l == 0) {
-               fprintf(stderr, "\"%s\": No match\n", name);
+               fprintf(stderr, "\"%s\": No match.\n", name);
                return NOSTR;
        }
        if (l == BUFSIZ) {
                return NOSTR;
        }
        if (l == BUFSIZ) {
-               fprintf(stderr, "Buffer overflow expanding \"%s\"\n", name);
+               fprintf(stderr, "\"%s\": Expansion buffer overflow.\n", name);
                return NOSTR;
        }
        xname[l] = 0;
        for (cp = &xname[l-1]; *cp == '\n' && cp > xname; cp--)
                ;
        cp[1] = '\0';
                return NOSTR;
        }
        xname[l] = 0;
        for (cp = &xname[l-1]; *cp == '\n' && cp > xname; cp--)
                ;
        cp[1] = '\0';
-       if (any(' ', xname) && stat(xname, &sbuf) < 0) {
-               fprintf(stderr, "\"%s\": Ambiguous\n", name);
+       if (index(xname, ' ') && stat(xname, &sbuf) < 0) {
+               fprintf(stderr, "\"%s\": Ambiguous.\n", name);
                return NOSTR;
        }
        return savestr(xname);
                return NOSTR;
        }
        return savestr(xname);
@@ -498,6 +507,25 @@ getfold(name)
        return (0);
 }
 
        return (0);
 }
 
+/*
+ * Return the name of the dead.letter file.
+ */
+char *
+getdeadletter()
+{
+       register char *cp;
+
+       if ((cp = value("DEAD")) == NOSTR || (cp = expand(cp)) == NOSTR)
+               cp = expand("~/dead.letter");
+       else if (*cp != '/') {
+               char buf[PATHSIZE];
+
+               (void) sprintf(buf, "~/%s", cp);
+               cp = expand(buf);
+       }
+       return cp;
+}
+
 /*
  * A nicer version of Fdopen, which allows us to fclose
  * without losing the open file.
 /*
  * A nicer version of Fdopen, which allows us to fclose
  * without losing the open file.