projects
/
unix-history
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
tags
|
clone url
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
changed file() to call setfile() with proper arg for isedit;
[unix-history]
/
usr
/
src
/
usr.bin
/
mail
/
lex.c
diff --git
a/usr/src/usr.bin/mail/lex.c
b/usr/src/usr.bin/mail/lex.c
index
6883c6b
..
2c2053e
100644
(file)
--- a/
usr/src/usr.bin/mail/lex.c
+++ b/
usr/src/usr.bin/mail/lex.c
@@
-8,7
+8,9
@@
* Lexical processing of commands.
*/
* Lexical processing of commands.
*/
-static char *SccsId = "@(#)lex.c 1.16 %G%";
+static char *SccsId = "@(#)lex.c 2.7 %G%";
+
+char *prompt = "& ";
/*
* Set up editing on the given file name.
/*
* Set up editing on the given file name.
@@
-25,7
+27,6
@@
setfile(name, isedit)
static int shudclob;
static char efile[128];
extern char tempMesg[];
static int shudclob;
static char efile[128];
extern char tempMesg[];
- int (*sigs[3])();
if ((ibuf = fopen(name, "r")) == NULL) {
if (isedit)
if ((ibuf = fopen(name, "r")) == NULL) {
if (isedit)
@@
-37,12
+38,12
@@
setfile(name, isedit)
/*
* Looks like all will be well. We must now relinquish our
/*
* Looks like all will be well. We must now relinquish our
- * hold on the current set of stuff. Must
ignore
signals
+ * hold on the current set of stuff. Must
hold
signals
* while we are reading the new file, else we will ruin
* the message[] data structure.
*/
* while we are reading the new file, else we will ruin
* the message[] data structure.
*/
-
sigsave(sigs, SIG_IGN
);
+
holdsigs(
);
if (shudclob) {
if (edit)
edstop();
if (shudclob) {
if (edit)
edstop();
@@
-83,8
+84,7
@@
setfile(name, isedit)
setptr(ibuf);
setmsize(msgCount);
fclose(ibuf);
setptr(ibuf);
setmsize(msgCount);
fclose(ibuf);
- sigret(sigs);
- shudann = 1;
+ relsesigs();
sawcom = 0;
return(0);
}
sawcom = 0;
return(0);
}
@@
-98,42
+98,21
@@
int *msgvec;
commands()
{
commands()
{
- int
prompt, firstsw
, stop();
+ int
eofloop, shudprompt
, stop();
register int n;
char linebuf[LINESIZE];
register int n;
char linebuf[LINESIZE];
- int hangup();
+ int hangup()
, contin()
;
- if (rcvmode) {
+ sigset(SIGCONT, SIG_DFL);
+ if (rcvmode && !sourcing) {
if (sigset(SIGINT, SIG_IGN) != SIG_IGN)
sigset(SIGINT, stop);
if (sigset(SIGHUP, SIG_IGN) != SIG_IGN)
sigset(SIGHUP, hangup);
}
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();
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
/*
* Print the prompt, if needed. Clear out
@@
-142,9
+121,12
@@
commands()
if (!rcvmode && !sourcing)
return;
if (!rcvmode && !sourcing)
return;
+ eofloop = 0;
top:
top:
- if (prompt && !sourcing)
- printf("_\r");
+ if (shudprompt) {
+ sigset(SIGCONT, contin);
+ printf(prompt);
+ }
flush();
sreset();
flush();
sreset();
@@
-158,17
+140,20
@@
top:
if (readline(input, &linebuf[n]) <= 0) {
if (n != 0)
break;
if (readline(input, &linebuf[n]) <= 0) {
if (n != 0)
break;
+ if (loading)
+ return;
if (sourcing) {
unstack();
goto more;
}
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)
return;
}
if ((n = strlen(linebuf)) == 0)
@@
-178,6
+163,7
@@
top:
break;
linebuf[n++] = ' ';
}
break;
linebuf[n++] = ' ';
}
+ sigset(SIGCONT, SIG_DFL);
if (execute(linebuf, 0))
return;
more: ;
if (execute(linebuf, 0))
return;
more: ;
@@
-240,7
+226,9
@@
execute(linebuf, contxt)
return(0);
com = lex(word);
if (com == NONE) {
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 (sourcing)
unstack();
return(0);
@@
-262,6
+250,8
@@
execute(linebuf, contxt)
*/
if (com->c_func == edstop && sourcing) {
*/
if (com->c_func == edstop && sourcing) {
+ if (loading)
+ return(1);
unstack();
return(0);
}
unstack();
return(0);
}
@@
-280,6
+270,8
@@
execute(linebuf, contxt)
if (!rcvmode && (com->c_argtype & M) == 0) {
printf("May not execute \"%s\" while sending\n",
com->c_name);
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)
unstack();
return(0);
@@
-287,12
+279,16
@@
execute(linebuf, contxt)
if (sourcing && com->c_argtype & I) {
printf("May not execute \"%s\" while sourcing\n",
com->c_name);
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);
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);
if (sourcing)
unstack();
return(0);
@@
-308,6
+304,10
@@
execute(linebuf, contxt)
* A message list defaulting to nearest forward
* legal message.
*/
* 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) {
if ((c = getmsglist(cp, msgvec, com->c_msgflag)) < 0)
break;
if (c == 0) {
@@
-327,6
+327,10
@@
execute(linebuf, contxt)
* A message list with no defaults, but no error
* if none exist.
*/
* 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);
if (getmsglist(cp, msgvec, com->c_msgflag) < 0)
break;
e = (*com->c_func)(msgvec);
@@
-378,6
+382,8
@@
execute(linebuf, contxt)
* error.
*/
* error.
*/
+ if (e && loading)
+ return(1);
if (e && sourcing)
unstack();
if (com->c_func == edstop)
if (e && sourcing)
unstack();
if (com->c_func == edstop)
@@
-393,14
+399,23
@@
execute(linebuf, contxt)
return(0);
}
return(0);
}
+/*
+ * When we wake up after ^Z, reprint the prompt.
+ */
+contin(s)
+{
+
+ printf(prompt);
+ fflush(stdout);
+}
+
/*
* Branch here on hangup signal and simulate quit.
*/
hangup()
{
/*
* Branch here on hangup signal and simulate quit.
*/
hangup()
{
- int (*sigs[3])();
-
sigsave(sigs
);
+
holdsigs(
);
if (edit) {
if (setexit())
exit(0);
if (edit) {
if (setexit())
exit(0);
@@
-512,7
+527,7
@@
stop(s)
* give the message count, and print a header listing.
*/
* give the message count, and print a header listing.
*/
-char *greeting = "Mail version
2.0
%s. Type ? for help.\n";
+char *greeting = "Mail version %s. Type ? for help.\n";
announce(pr)
{
announce(pr)
{
@@
-536,11
+551,11
@@
announce(pr)
* Announce information about the file we are editing.
* Return a likely place to set dot.
*/
* 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;
newfileinfo()
{
register struct message *mp;
register int u, n, mdot;
+ char fname[BUFSIZ], zname[BUFSIZ], *ename;
for (mp = &message[0]; mp < &message[msgCount]; mp++)
if (mp->m_flag & MNEW)
for (mp = &message[0]; mp < &message[msgCount]; mp++)
if (mp->m_flag & MNEW)
@@
-559,7
+574,15
@@
newfileinfo()
if ((mp->m_flag & MREAD) == 0)
u++;
}
if ((mp->m_flag & MREAD) == 0)
u++;
}
- printf("\"%s\": ", mailname);
+ 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\": ", ename);
if (msgCount == 1)
printf("1 message");
else
if (msgCount == 1)
printf("1 message");
else
@@
-582,6
+605,27
@@
strace() {}
pversion(e)
{
pversion(e)
{
- printf(
greeting
, version);
+ printf(
"Version %s\n"
, version);
return(0);
}
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);
+}