version 1.24, 2001/11/17 19:10:25 |
version 1.25, 2001/11/20 20:50:00 |
|
|
|
|
|
|
int *msgvec; |
int *msgvec; |
int reset_on_stop; /* do a reset() if stopped */ |
int reset_on_stop; /* reset prompt if stopped */ |
|
|
/* |
/* |
* Interpret user commands one by one. If standard input is not a tty, |
* Interpret user commands one by one. If standard input is not a tty, |
|
|
void |
void |
commands() |
commands() |
{ |
{ |
int n; |
int n, sig, *sigp; |
volatile int eofloop = 0; |
int eofloop = 0; |
char linebuf[LINESIZE]; |
char linebuf[LINESIZE]; |
|
|
if (!sourcing) { |
prompt: |
if (signal(SIGINT, SIG_IGN) != SIG_IGN) |
|
(void)signal(SIGINT, intr); |
|
if (signal(SIGHUP, SIG_IGN) != SIG_IGN) |
|
(void)signal(SIGHUP, hangup); |
|
(void)signal(SIGTSTP, stop); |
|
(void)signal(SIGTTOU, stop); |
|
(void)signal(SIGTTIN, stop); |
|
} |
|
setexit(); |
|
for (;;) { |
for (;;) { |
/* |
/* |
* Print the prompt, if needed. Clear out |
* Print the prompt, if needed. Clear out |
|
|
* and handle end of file specially. |
* and handle end of file specially. |
*/ |
*/ |
n = 0; |
n = 0; |
|
sig = 0; |
|
sigp = sourcing ? NULL : &sig; |
for (;;) { |
for (;;) { |
if (readline(input, &linebuf[n], LINESIZE - n) < 0) { |
if (readline(input, &linebuf[n], LINESIZE - n, sigp) < 0) { |
|
if (sig) { |
|
if (sig == SIGINT) |
|
dointr(); |
|
else if (sig == SIGHUP) |
|
/* nothing to do? */ |
|
exit(1); |
|
else { |
|
/* Stopped by job control */ |
|
(void)kill(0, sig); |
|
if (reset_on_stop) |
|
reset_on_stop = 0; |
|
} |
|
goto prompt; |
|
} |
if (n == 0) |
if (n == 0) |
n = -1; |
n = -1; |
break; |
break; |
|
|
|
|
int inithdr; /* am printing startup headers */ |
int inithdr; /* am printing startup headers */ |
|
|
/*ARGSUSED*/ |
|
void |
void |
intr(s) |
dointr() |
int s; |
|
{ |
{ |
|
|
noreset = 0; |
noreset = 0; |
|
|
image = -1; |
image = -1; |
} |
} |
fputs("Interrupt\n", stderr); |
fputs("Interrupt\n", stderr); |
reset(0); |
|
} |
|
|
|
/* |
|
* When we wake up after ^Z, reprint the prompt. |
|
*/ |
|
void |
|
stop(s) |
|
int s; |
|
{ |
|
sig_t old_action = signal(s, SIG_DFL); |
|
sigset_t nset; |
|
|
|
(void)sigemptyset(&nset); |
|
(void)sigaddset(&nset, s); |
|
(void)sigprocmask(SIG_UNBLOCK, &nset, NULL); |
|
(void)kill(0, s); |
|
(void)sigprocmask(SIG_BLOCK, &nset, NULL); |
|
(void)signal(s, old_action); |
|
if (reset_on_stop) { |
|
reset_on_stop = 0; |
|
reset(0); |
|
} |
|
} |
|
|
|
/* |
|
* Branch here on hangup signal and simulate "exit". |
|
*/ |
|
/*ARGSUSED*/ |
|
void |
|
hangup(s) |
|
int s; |
|
{ |
|
|
|
/* nothing to do? */ |
|
exit(1); |
|
} |
} |
|
|
/* |
/* |