rc

[fork] interactive rc shell
Log | Files | Refs | README | LICENSE

commit ac8a8fcf0dad4e73b16a584d4ba3c02b89c1b86e
parent ed765fba692da152247018becb1f407a4ee64452
Author: tgoodwin <tgoodwin>
Date:   Mon, 23 Feb 1998 15:45:05 +0000

incorporate Tom Culliton's patches for readline

Diffstat:
Minput.c | 25++++++++++++++++++++++---
Mrc.h | 26++++++++++++++++++--------
Msignal.c | 26++++++++++++++++++++++++++
Msystem-bsd.c | 22----------------------
4 files changed, 66 insertions(+), 33 deletions(-)

diff --git a/input.c b/input.c @@ -2,6 +2,8 @@ #include <errno.h> #include <setjmp.h> +#include <signal.h> + #include "rc.h" #include "jbwrap.h" @@ -22,11 +24,28 @@ typedef struct Input { #if READLINE extern void add_history(char *); -static char *rlinebuf; -char *prompt; +extern char *readline(char *); + +static char *rlinebuf, *prompt; +bool in_readline; + +static char *rc_readline(char *prompt) { + char *r; + void (*old)(int); + + in_readline = TRUE; + old = signal(SIGINT, sigint); + r = readline(prompt); + signal(SIGINT, old); + in_readline = FALSE; + sigchk(); + + return r; +} + #endif -char *prompt2; +static char *prompt2; bool rcrc; static int dead(void); diff --git a/rc.h b/rc.h @@ -194,7 +194,6 @@ enum { /* rc prototypes */ /* main.c */ -extern char *prompt, *prompt2; extern Rq *redirq; extern bool dashdee, dashee, dashvee, dashex, dashell, dasheye, dashen, dashpee, interactive; @@ -289,6 +288,7 @@ extern int heredoc(int); extern int qdoc(Node *, Node *); extern Hq *hq; + /* input.c */ extern void initinput(void); extern Node *parseline(char *); @@ -304,6 +304,12 @@ extern void closefds(void); extern int last; extern bool rcrc; +#if READLINE +extern bool in_readline; +extern int rl_pending_input; /* Really from readline library. */ +#endif + + /* lex.c */ extern int yylex(void); extern void inityy(void); @@ -365,6 +371,7 @@ extern void initparse(void); /* redir.c */ extern void doredirs(void); + /* signal.c */ extern void initsignal(void); extern void catcher(int); @@ -373,6 +380,13 @@ extern void (*rc_signal(int, void (*)(int)))(int); extern void (*sighandlers[])(int); extern volatile SIG_ATOMIC_T slow, interrupt_happened; +#if READLINE +extern void rl_clean_up_for_exit(void); +extern void rl_deprep_terminal(void); +extern int rl_clear_signals(void); +#endif + + /* status.c */ extern int istrue(void); extern int getstatus(void); @@ -390,17 +404,13 @@ extern void writeall(int, char *, size_t); #if HAVE_RESTARTABLE_SYSCALLS extern int rc_read(int, char *, size_t); -#if READLINE -extern char *rc_readline(char *prompt); -#endif +extern pid_t rc_wait(int *); #else /* HAVE_RESTARTABLE_SYSCALLS */ + #define rc_read read +#include <sys/wait.h> #define rc_wait wait -#if READLINE -#define rc_readline readline -#endif - #endif /* HAVE_RESTARTABLE_SYSCALLS */ diff --git a/signal.c b/signal.c @@ -23,6 +23,32 @@ extern void catcher(int s) { } signal(s, catcher); +#if READLINE + if (in_readline) { + in_readline = FALSE; + switch (s) { + default: + rl_clean_up_for_exit(); + rl_deprep_terminal(); + rl_clear_signals(); + rl_pending_input = 0; + break; + +/* These signals are already cleaned up by readline. */ + + case SIGINT: + case SIGALRM: +#ifdef SIGTSTP + case SIGTSTP: + case SIGTTOU: + case SIGTTIN: +#endif + break; + } + } +#endif /* READLINE */ + + #if HAVE_RESTARTABLE_SYSCALLS interrupt_happened = TRUE; if (slow) diff --git a/system-bsd.c b/system-bsd.c @@ -69,25 +69,3 @@ extern pid_t rc_wait(int *stat) { } return r; } - -/* signal-safe readline wrapper */ -#if READLINE -extern char *rc_readline(char *prompt) { - char *r; - - interrupt_happened = FALSE; - if (!sigsetjmp(slowbuf.j, 1)) { - slow = TRUE; - if (!interrupt_happened) - r = readline(prompt); - else - r = NULL; - } else - r = NULL; - slow = FALSE; - if (r == NULL) - errno = EINTR; - sigchk(); - return r; -} -#endif /* READLINE */