install correct aliases file
[unix-history] / usr / src / usr.bin / mail / fio.c
index e356b05..c40efe9 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)fio.c      5.11 (Berkeley) %G%";
+static char sccsid[] = "@(#)fio.c      5.18 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -308,7 +308,7 @@ edstop()
                if ((mp->m_flag & MDELETED) != 0)
                        continue;
                c++;
                if ((mp->m_flag & MDELETED) != 0)
                        continue;
                c++;
-               if (send(mp, obuf, 0) < 0) {
+               if (send(mp, obuf, (struct ignoretab *) NULL, NOSTR) < 0) {
                        perror(mailname);
                        relsesigs();
                        reset(0);
                        perror(mailname);
                        relsesigs();
                        reset(0);
@@ -405,17 +405,24 @@ char *
 expand(name)
        register char *name;
 {
 expand(name)
        register char *name;
 {
-       char xname[BUFSIZ];
-       char cmdbuf[BUFSIZ];
+       char xname[PATHSIZE];
+       char cmdbuf[PATHSIZE];          /* also used for file names */
        register int pid, l;
        register char *cp, *shell;
        int pivec[2];
        struct stat sbuf;
        register int pid, l;
        register char *cp, *shell;
        int pivec[2];
        struct stat sbuf;
-       union wait s;
-
+       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 '%':
        switch (*name) {
        case '%':
-               return savestr(findmail(name[1] ? name + 1 : myname));
+               findmail(name[1] ? name + 1 : myname, xname);
+               return savestr(xname);
        case '#':
                if (name[1] != 0)
                        break;
        case '#':
                if (name[1] != 0)
                        break;
@@ -425,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) {
@@ -453,10 +463,8 @@ expand(name)
        close(pivec[1]);
        l = read(pivec[0], xname, BUFSIZ);
        close(pivec[0]);
        close(pivec[1]);
        l = read(pivec[0], xname, BUFSIZ);
        close(pivec[0]);
-       while (wait(&s) != pid);
-               ;
-       if (s.w_status != 0 && s.w_termsig != SIGPIPE) {
-               fprintf(stderr, "\"Echo\" failed\n");
+       if (wait_child(pid) < 0 && wait_status.w_termsig != SIGPIPE) {
+               fprintf(stderr, "\"%s\": Expansion failed.\n", name);
                return NOSTR;
        }
        if (l < 0) {
                return NOSTR;
        }
        if (l < 0) {
@@ -464,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);
@@ -499,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.