Add define for Kirk Smith's USR Courier driver. Change default baud
[unix-history] / usr / src / usr.bin / mail / lex.c
index 9501294..ec8d536 100644 (file)
@@ -1,6 +1,16 @@
-#
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.  The Berkeley software License Agreement
+ * specifies the terms and conditions for redistribution.
+ */
+
+#ifndef lint
+static char *sccsid = "@(#)lex.c       5.4 (Berkeley) %G%";
+#endif not lint
 
 #include "rcv.h"
 
 #include "rcv.h"
+#include <sys/stat.h>
+#include <errno.h>
 
 /*
  * Mail -- a mail program
 
 /*
  * Mail -- a mail program
@@ -8,8 +18,6 @@
  * Lexical processing of commands.
  */
 
  * Lexical processing of commands.
  */
 
-static char *SccsId = "@(#)lex.c       2.5.1.1 %G%";
-
 char   *prompt = "& ";
 
 /*
 char   *prompt = "& ";
 
 /*
@@ -24,15 +32,37 @@ setfile(name, isedit)
 {
        FILE *ibuf;
        int i;
 {
        FILE *ibuf;
        int i;
+       struct stat stb;
        static int shudclob;
        static char efile[128];
        extern char tempMesg[];
        static int shudclob;
        static char efile[128];
        extern char tempMesg[];
+       extern int errno;
 
 
-       if ((ibuf = fopen(name, "r")) == NULL) {
-               if (isedit)
-                       perror(name);
-               else
-                       printf("No mail for %s\n", myname);
+       if ((ibuf = fopen(name, "r")) == NULL)
+               return(-1);
+
+       if (fstat(fileno(ibuf), &stb) < 0) {
+               fclose(ibuf);
+               return (-1);
+       }
+
+       switch (stb.st_mode & S_IFMT) {
+       case S_IFDIR:
+               fclose(ibuf);
+               errno = EISDIR;
+               return (-1);
+
+       case S_IFREG:
+               break;
+
+       default:
+               fclose(ibuf);
+               errno = EINVAL;
+               return (-1);
+       }
+
+       if (!edit && stb.st_size == 0) {
+               fclose(ibuf);
                return(-1);
        }
 
                return(-1);
        }
 
@@ -126,11 +156,13 @@ commands()
                eofloop = 0;
 top:
                if (shudprompt) {
                eofloop = 0;
 top:
                if (shudprompt) {
+                       printf(prompt);
+                       fflush(stdout);
+# ifdef VMUNIX
                        sigset(SIGCONT, contin);
 # endif VMUNIX
                        sigset(SIGCONT, contin);
 # endif VMUNIX
-                       printf(prompt);
-               }
-               flush();
+               } else
+                       fflush(stdout);
                sreset();
 
                /*
                sreset();
 
                /*
@@ -355,7 +387,8 @@ execute(linebuf, contxt)
                /*
                 * A vector of strings, in shell style.
                 */
                /*
                 * A vector of strings, in shell style.
                 */
-               if ((c = getrawlist(cp, arglist)) < 0)
+               if ((c = getrawlist(cp, arglist,
+                               sizeof arglist / sizeof *arglist)) < 0)
                        break;
                if (c < com->c_minargs) {
                        printf("%s requires at least %d arg(s)\n",
                        break;
                if (c < com->c_minargs) {
                        printf("%s requires at least %d arg(s)\n",
@@ -492,6 +525,34 @@ isprefix(as1, as2)
 
 int    inithdr;                        /* am printing startup headers */
 
 
 int    inithdr;                        /* am printing startup headers */
 
+#ifdef _NFILE
+static
+_fwalk(function)
+       register int (*function)();
+{
+       register FILE *iop;
+
+       for (iop = _iob; iop < _iob + _NFILE; iop++)
+               (*function)(iop);
+}
+#endif
+
+static
+xclose(iop)
+       register FILE *iop;
+{
+       if (iop == stdin || iop == stdout ||
+           iop == stderr || iop == itf || iop == otf)
+               return;
+
+       if (iop != pipef)
+               fclose(iop);
+       else {
+               pclose(pipef);
+               pipef = NULL;
+       }
+}
+
 stop(s)
 {
        register FILE *fp;
 stop(s)
 {
        register FILE *fp;
@@ -506,29 +567,18 @@ stop(s)
        while (sourcing)
                unstack();
        getuserid((char *) -1);
        while (sourcing)
                unstack();
        getuserid((char *) -1);
-       for (fp = &_iob[0]; fp < &_iob[_NFILE]; fp++) {
-               if (fp == stdin || fp == stdout)
-                       continue;
-               if (fp == itf || fp == otf)
-                       continue;
-               if (fp == stderr)
-                       continue;
-               if (fp == pipef) {
-                       pclose(pipef);
-                       pipef = NULL;
-                       continue;
-               }
-               fclose(fp);
-       }
+
+       /*
+        * Walk through all the open FILEs, applying xclose() to them
+        */
+       _fwalk(xclose);
+
        if (image >= 0) {
                close(image);
                image = -1;
        }
        if (image >= 0) {
                close(image);
                image = -1;
        }
-       clrbuf(stdout);
-       printf("Interrupt\n");
-# ifdef VMUNIX
-       sigrelse(s);
-# else
+       fprintf(stderr, "Interrupt\n");
+# ifndef VMUNIX
        signal(s, stop);
 # endif
        reset(0);
        signal(s, stop);
 # endif
        reset(0);
@@ -546,11 +596,11 @@ announce(pr)
        int vec[2], mdot;
        extern char *version;
 
        int vec[2], mdot;
        extern char *version;
 
+       if (pr && value("quiet") == NOSTR)
+               printf(greeting, version);
        mdot = newfileinfo();
        vec[0] = mdot;
        vec[1] = 0;
        mdot = newfileinfo();
        vec[0] = mdot;
        vec[1] = 0;
-       if (pr && value("quiet") == NOSTR)
-               printf(greeting, version);
        dot = &message[mdot - 1];
        if (msgCount > 0 && !noheader) {
                inithdr++;
        dot = &message[mdot - 1];
        if (msgCount > 0 && !noheader) {
                inithdr++;
@@ -566,7 +616,7 @@ announce(pr)
 newfileinfo()
 {
        register struct message *mp;
 newfileinfo()
 {
        register struct message *mp;
-       register int u, n, mdot;
+       register int u, n, mdot, d, s;
        char fname[BUFSIZ], zname[BUFSIZ], *ename;
 
        for (mp = &message[0]; mp < &message[msgCount]; mp++)
        char fname[BUFSIZ], zname[BUFSIZ], *ename;
 
        for (mp = &message[0]; mp < &message[msgCount]; mp++)
@@ -580,11 +630,16 @@ newfileinfo()
                mdot = mp - &message[0] + 1;
        else
                mdot = 1;
                mdot = mp - &message[0] + 1;
        else
                mdot = 1;
+       s = d = 0;
        for (mp = &message[0], n = 0, u = 0; mp < &message[msgCount]; mp++) {
                if (mp->m_flag & MNEW)
                        n++;
                if ((mp->m_flag & MREAD) == 0)
                        u++;
        for (mp = &message[0], n = 0, u = 0; mp < &message[msgCount]; mp++) {
                if (mp->m_flag & MNEW)
                        n++;
                if ((mp->m_flag & MREAD) == 0)
                        u++;
+               if (mp->m_flag & MDELETED)
+                       d++;
+               if (mp->m_flag & MSAVED)
+                       s++;
        }
        ename = mailname;
        if (getfold(fname) >= 0) {
        }
        ename = mailname;
        if (getfold(fname) >= 0) {
@@ -603,6 +658,10 @@ newfileinfo()
                printf(" %d new", n);
        if (u-n > 0)
                printf(" %d unread", u);
                printf(" %d new", n);
        if (u-n > 0)
                printf(" %d unread", u);
+       if (d > 0)
+               printf(" %d deleted", d);
+       if (s > 0)
+               printf(" %d saved", s);
        if (readonly)
                printf(" [Read only]");
        printf("\n");
        if (readonly)
                printf(" [Read only]");
        printf("\n");