* Lexical processing of commands.
*/
-static char *SccsId = "@(#)lex.c 1.19 %G%";
+static char *SccsId = "@(#)lex.c 2.10 %G%";
+
+char *prompt = "& ";
/*
* Set up editing on the given file name.
static char efile[128];
extern char tempMesg[];
- 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);
- }
/*
* Looks like all will be well. We must now relinquish our
setmsize(msgCount);
fclose(ibuf);
relsesigs();
- shudann = 1;
sawcom = 0;
return(0);
}
commands()
{
- int prompt, firstsw, stop();
+ int eofloop, shudprompt, stop();
register int n;
char linebuf[LINESIZE];
int hangup(), contin();
- sigset(SIGCONT, contin);
- sighold(SIGCONT);
- if (rcvmode) {
+# ifdef VMUNIX
+ sigset(SIGCONT, SIG_DFL);
+# endif VMUNIX
+ if (rcvmode && !sourcing) {
if (sigset(SIGINT, SIG_IGN) != SIG_IGN)
sigset(SIGINT, stop);
if (sigset(SIGHUP, SIG_IGN) != SIG_IGN)
sigset(SIGHUP, hangup);
}
- input = stdin;
- prompt = 1;
- if (!intty)
- prompt = 0;
- firstsw = 1;
+ shudprompt = intty && !sourcing;
for (;;) {
setexit();
- if (firstsw > 0) {
- firstsw = 0;
- source1(mailrc);
- if (!nosrc)
- source1(MASTER);
- }
-
- /*
- * How's this for obscure: after we
- * finish sourcing for the first time,
- * go off and print the headers!
- */
-
- if (shudann && !sourcing) {
- shudann = 0;
- if (rcvmode)
- announce(edit);
- }
/*
* Print the prompt, if needed. Clear out
if (!rcvmode && !sourcing)
return;
+ eofloop = 0;
top:
- if (prompt && !sourcing) {
- sigrelse(SIGCONT);
- printf("_\r");
+ if (shudprompt) {
+# ifdef VMUNIX
+ sigset(SIGCONT, contin);
+# endif VMUNIX
+ printf(prompt);
}
flush();
sreset();
if (readline(input, &linebuf[n]) <= 0) {
if (n != 0)
break;
+ if (loading)
+ return;
if (sourcing) {
unstack();
goto more;
}
- if (value("ignoreeof") != NOSTR && prompt) {
- printf("Use \"quit\" to quit.\n");
- goto top;
+ if (value("ignoreeof") != NOSTR && shudprompt) {
+ if (++eofloop < 25) {
+ printf("Use \"quit\" to quit.\n");
+ goto top;
+ }
}
- if (!edit)
- return;
- edstop();
+ if (edit)
+ edstop();
return;
}
if ((n = strlen(linebuf)) == 0)
break;
linebuf[n++] = ' ';
}
- sighold(SIGCONT);
+# ifdef VMUNIX
+ sigset(SIGCONT, SIG_DFL);
+# endif VMUNIX
if (execute(linebuf, 0))
return;
more: ;
return(0);
com = lex(word);
if (com == NONE) {
- printf("What?\n");
+ printf("Unknown command: \"%s\"\n", word);
+ if (loading)
+ return(1);
if (sourcing)
unstack();
return(0);
*/
if (com->c_func == edstop && sourcing) {
+ if (loading)
+ return(1);
unstack();
return(0);
}
if (!rcvmode && (com->c_argtype & M) == 0) {
printf("May not execute \"%s\" while sending\n",
com->c_name);
+ if (loading)
+ return(1);
if (sourcing)
unstack();
return(0);
if (sourcing && com->c_argtype & I) {
printf("May not execute \"%s\" while sourcing\n",
com->c_name);
+ if (loading)
+ return(1);
unstack();
return(0);
}
if (readonly && com->c_argtype & W) {
printf("May not execute \"%s\" -- message file is read only\n",
com->c_name);
+ if (loading)
+ return(1);
if (sourcing)
unstack();
return(0);
* A message list defaulting to nearest forward
* legal message.
*/
+ if (msgvec == 0) {
+ printf("Illegal use of \"message list\"\n");
+ return(-1);
+ }
if ((c = getmsglist(cp, msgvec, com->c_msgflag)) < 0)
break;
if (c == 0) {
* A message list with no defaults, but no error
* if none exist.
*/
+ if (msgvec == 0) {
+ printf("Illegal use of \"message list\"\n");
+ return(-1);
+ }
if (getmsglist(cp, msgvec, com->c_msgflag) < 0)
break;
e = (*com->c_func)(msgvec);
* error.
*/
+ if (e && loading)
+ return(1);
if (e && sourcing)
unstack();
if (com->c_func == edstop)
contin(s)
{
- printf("_\r");
+ printf(prompt);
fflush(stdout);
}
{
register FILE *fp;
+# ifndef VMUNIX
+ s = SIGINT;
+# endif VMUNIX
noreset = 0;
if (!inithdr)
sawcom++;
}
clrbuf(stdout);
printf("Interrupt\n");
+# ifdef VMUNIX
sigrelse(s);
+# else
+ signal(s, stop);
+# endif
reset(0);
}
* give the message count, and print a header listing.
*/
-char *greeting = "Mail version 2.1 %s. Type ? for help.\n";
+char *greeting = "Mail version %s. Type ? for help.\n";
announce(pr)
{
* Announce information about the file we are editing.
* Return a likely place to set dot.
*/
-
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++)
if (mp->m_flag & MNEW)
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++;
+ if (mp->m_flag & MDELETED)
+ d++;
+ if (mp->m_flag & MSAVED)
+ s++;
+ }
+ ename = mailname;
+ if (getfold(fname) >= 0) {
+ strcat(fname, "/");
+ if (strncmp(fname, mailname, strlen(fname)) == 0) {
+ sprintf(zname, "+%s", mailname + strlen(fname));
+ ename = zname;
+ }
}
- printf("\"%s\": ", mailname);
+ printf("\"%s\": ", ename);
if (msgCount == 1)
printf("1 message");
else
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");
pversion(e)
{
- printf(greeting, version);
+ printf("Version %s\n", version);
return(0);
}
+
+/*
+ * Load a file of user definitions.
+ */
+load(name)
+ char *name;
+{
+ register FILE *in, *oldin;
+
+ if ((in = fopen(name, "r")) == NULL)
+ return;
+ oldin = input;
+ input = in;
+ loading = 1;
+ sourcing = 1;
+ commands();
+ loading = 0;
+ sourcing = 0;
+ input = oldin;
+ fclose(in);
+}