more accurate error message when editing system mailbox
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Tue, 14 Feb 1989 15:51:56 +0000 (07:51 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Tue, 14 Feb 1989 15:51:56 +0000 (07:51 -0800)
SCCS-vsn: usr.bin/mail/lex.c 5.18
SCCS-vsn: usr.bin/mail/cmd3.c 5.19
SCCS-vsn: usr.bin/mail/main.c 5.22

usr/src/usr.bin/mail/cmd3.c
usr/src/usr.bin/mail/lex.c
usr/src/usr.bin/mail/main.c

index 4b661c8..22f31a6 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)cmd3.c     5.18 (Berkeley) %G%";
+static char sccsid[] = "@(#)cmd3.c     5.19 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -518,16 +518,12 @@ null(e)
 file(argv)
        register char **argv;
 {
 file(argv)
        register char **argv;
 {
-       char *cp;
 
        if (argv[0] == NOSTR) {
                newfileinfo();
                return 0;
        }
 
        if (argv[0] == NOSTR) {
                newfileinfo();
                return 0;
        }
-       if ((cp = expand(*argv)) == NOSTR)
-               return 1;
-       strcpy(prevfile, mailname);
-       if (setfile(cp, **argv != '%') < 0)
+       if (setfile(*argv) < 0)
                return 1;
        announce();
        return 0;
                return 1;
        announce();
        return 0;
index c56951d..01e938c 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)lex.c      5.17 (Berkeley) %G%";
+static char sccsid[] = "@(#)lex.c      5.18 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -33,22 +33,28 @@ char        *prompt = "& ";
 
 /*
  * Set up editing on the given file name.
 
 /*
  * Set up editing on the given file name.
- * If isedit is true, we are considered to be editing the file,
- * otherwise we are reading our mail which has signficance for
- * mbox and so forth.
+ * If the first character of name is %, we are considered to be
+ * editing the file, otherwise we are reading our mail which has
+ * signficance for mbox and so forth.
  */
  */
-
-setfile(name, isedit)
+setfile(name)
        char *name;
 {
        FILE *ibuf;
        int i;
        struct stat stb;
        char *name;
 {
        FILE *ibuf;
        int i;
        struct stat stb;
+       char isedit = *name != '%';
+       char *who = name[1] ? name + 1 : myname;
        static int shudclob;
        extern char tempMesg[];
        extern int errno;
 
        static int shudclob;
        extern char tempMesg[];
        extern int errno;
 
+       if ((name = expand(name)) == NOSTR)
+               return -1;
+
        if ((ibuf = fopen(name, "r")) == NULL) {
        if ((ibuf = fopen(name, "r")) == NULL) {
+               if (!isedit && errno == ENOENT)
+                       goto nomail;
                perror(name);
                return(-1);
        }
                perror(name);
                return(-1);
        }
@@ -103,6 +109,7 @@ setfile(name, isedit)
        }
        shudclob = 1;
        edit = isedit;
        }
        shudclob = 1;
        edit = isedit;
+       strcpy(prevfile, mailname);
        if (name != mailname)
                strcpy(mailname, name);
        mailsize = fsize(ibuf);
        if (name != mailname)
                strcpy(mailname, name);
        mailsize = fsize(ibuf);
@@ -120,6 +127,11 @@ setfile(name, isedit)
        fclose(ibuf);
        relsesigs();
        sawcom = 0;
        fclose(ibuf);
        relsesigs();
        sawcom = 0;
+       if (!edit && msgCount == 0) {
+nomail:
+               fprintf(stderr, "No mail for %s\n", who);
+               return -1;
+       }
        return(0);
 }
 
        return(0);
 }
 
index 8c13b9a..af7b4e2 100644 (file)
@@ -22,7 +22,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.21 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     5.22 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "rcv.h"
 #endif /* not lint */
 
 #include "rcv.h"
@@ -44,7 +44,6 @@ main(argc, argv)
        char *subject;
        char *ef;
        char nosrc = 0;
        char *subject;
        char *ef;
        char nosrc = 0;
-       char isedit = 0;
        int hdrstop(), (*prevint)();
        int sigchild();
        extern int getopt(), optind, opterr;
        int hdrstop(), (*prevint)();
        int sigchild();
        extern int getopt(), optind, opterr;
@@ -209,16 +208,10 @@ Usage: mail [-iInv] [-s subject] [-c cc-addr] [-b bcc-addr] to-addr ...\n\
         * Decide whether we are editing a mailbox or reading
         * the system mailbox, and open up the right stuff.
         */
         * Decide whether we are editing a mailbox or reading
         * the system mailbox, and open up the right stuff.
         */
-       if (ef != NOSTR)
-               isedit++;
-       else
+       if (ef == NOSTR)
                ef = "%";
                ef = "%";
-       if ((ef = expand(ef)) == NOSTR || setfile(ef, isedit) < 0)
+       if (setfile(ef) < 0)
                exit(1);                /* error already reported */
                exit(1);                /* error already reported */
-       if (!edit && msgCount == 0) {
-               fprintf(stderr, "No mail for %s\n", myname);
-               exit(1);
-       }
        if (setjmp(hdrjmp) == 0) {
                extern char *version;
 
        if (setjmp(hdrjmp) == 0) {
                extern char *version;