From: Kurt A. Schoens Date: Sun, 19 Oct 1980 10:10:52 +0000 (-0800) Subject: fixed # in file() command -- prevfile is now set up right X-Git-Tag: BSD-4^3~229 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/d344b00cec7199d3cbed9cfe63399efebdde1d0c?ds=inline fixed # in file() command -- prevfile is now set up right added conditional command implementations ifcmd(), elsecmd(), endifcmd() SCCS-vsn: usr.bin/mail/cmd3.c 1.5 --- diff --git a/usr/src/usr.bin/mail/cmd3.c b/usr/src/usr.bin/mail/cmd3.c index b8e191d30d..ebd97a727b 100644 --- a/usr/src/usr.bin/mail/cmd3.c +++ b/usr/src/usr.bin/mail/cmd3.c @@ -9,7 +9,7 @@ * Still more user commands. */ -static char *SccsId = "@(#)cmd3.c 1.4 %G%"; +static char *SccsId = "@(#)cmd3.c 1.5 %G%"; /* * Process a shell escape by saving signals, ignoring signals, @@ -518,7 +518,7 @@ file(argv) * file name -- for any other file */ -char prevfile[BUFSIZ]; +char prevfile[PATHSIZE]; char * getfilename(name) @@ -529,6 +529,7 @@ getfilename(name) switch (*name) { case '%': + strcpy(prevfile, mailname); if (name[1] != 0) { strcpy(savename, myname); strncpy(myname, name+1, PATHSIZE-1); @@ -548,15 +549,20 @@ getfilename(name) printf("No previous file\n"); return(NOSTR); } - return(prevfile); + strcpy(savename, prevfile); + strcpy(prevfile, mailname); + strcpy(mailname, savename); + return(mailname); case '&': + strcpy(prevfile, mailname); if (name[1] == 0) return(mbox); /* Fall into . . . */ default: regular: + strcpy(prevfile, mailname); cp = expand(name); return(cp); } @@ -622,3 +628,79 @@ Respond(msgvec) mail1(&head); return(0); } + +/* + * Conditional commands. These allow one to parameterize one's + * .mailrc and do some things if sending, others if receiving. + */ + +ifcmd(argv) + char **argv; +{ + register char *cp; + + if (cond != CANY) { + printf("Illegal nested \"if\"\n"); + return(1); + } + cond = CANY; + cp = argv[0]; + switch (*cp) { + case 'r': case 'R': + cond = CRCV; + break; + + case 's': case 'S': + cond = CSEND; + break; + + default: + printf("Unrecognized if-keyword: \"%s\"\n", cp); + return(1); + } + return(0); +} + +/* + * Implement 'else'. This is pretty simple -- we just + * flip over the conditional flag. + */ + +elsecmd() +{ + + switch (cond) { + case CANY: + printf("\"Else\" without matching \"if\"\n"); + return(1); + + case CSEND: + cond = CRCV; + break; + + case CRCV: + cond = CSEND; + break; + + default: + printf("Mail's idea of conditions is screwed up\n"); + cond = CANY; + break; + } + return(0); +} + +/* + * End of if statement. Just set cond back to anything. + */ + +endifcmd() +{ + + if (cond == CANY) { + printf("\"Endif\" without matching \"if\"\n"); + return(1); + } + cond = CANY; + return(0); +}