From f928b9452b7add9696a3056d85ea0e7bacc86561 Mon Sep 17 00:00:00 2001 From: vsc Date: Fri, 21 Sep 2001 14:22:32 +0000 Subject: [PATCH] another try at improving ^c with readline git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@160 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- C/iopreds.c | 25 +++++++++++-------------- C/sysbits.c | 30 ++++++++++++++++-------------- H/yapio.h | 3 ++- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/C/iopreds.c b/C/iopreds.c index 244782998..ec13d8969 100644 --- a/C/iopreds.c +++ b/C/iopreds.c @@ -88,8 +88,6 @@ int in_getc = FALSE; FILE *rl_instream, *rl_outstream; #endif -sigjmp_buf readline_jmpbuf; - #endif typedef struct @@ -821,7 +819,7 @@ extern void add_history (const char *); static char *ttyptr = NULL; -static char *_line = (char *) NULL; +char *_line = (char *) NULL; static int cur_out_sno = 2; @@ -881,17 +879,6 @@ ReadlineGetc(int sno) while (ttyptr == NULL) { in_getc = TRUE; - /* Do it the gnu way */ - if (sigsetjmp(readline_jmpbuf, TRUE)) { - if (PrologMode & InterruptMode) { - PrologMode &= ~InterruptMode; - ProcessSIGINT(); - if (PrologMode & AbortMode) { - PrologMode &= ~AbortMode; - Abort(""); - } - } - } /* Only sends a newline if we are at the start of a line */ if (_line != NULL && _line != (char *) EOF) free (_line); @@ -920,6 +907,16 @@ ReadlineGetc(int sno) _line = readline (NULL); } } + /* Do it the gnu way */ + if (PrologMode & InterruptMode) { + PrologMode &= ~InterruptMode; + ProcessSIGINT(); + if (PrologMode & AbortMode) { + PrologMode &= ~AbortMode; + Abort(""); + } + continue; + } newline=FALSE; strncpy (Prompt, RepAtom (*AtPrompt)->StrOfAE, MAX_PROMPT); in_getc = FALSE; diff --git a/C/sysbits.c b/C/sysbits.c index a96954ca2..70fcba884 100644 --- a/C/sysbits.c +++ b/C/sysbits.c @@ -1055,10 +1055,6 @@ void (*handler)(int); #endif -#if HAVE_LIBREADLINE -static char *_line = NULL; -#endif - static int InteractSIGINT(char ch) { switch (ch) { @@ -1172,16 +1168,21 @@ ProcessSIGINT(void) do { #if HAVE_LIBREADLINE - if (_line != (char *) NULL && _line != (char *) EOF) - free (_line); - _line = readline ("Action (h for help): "); - if (_line == (char *)NULL || _line == (char *)EOF) { - ch = EOF; - continue; + if (_line != (char *) NULL) { + ch = _line[0]; + free(_line); + _line = NULL; + } else { + _line = readline ("Action (h for help): "); + if (_line == (char *)NULL || _line == (char *)EOF) { + ch = EOF; + continue; + } else { + ch = _line[0]; + free(_line); + _line = NULL; + } } - ch = _line[0]; - free(_line); - _line = NULL; #else /* ask for a new line */ fprintf(stderr, "Action (h for help): "); @@ -1215,7 +1216,8 @@ HandleSIGINT (int sig) PrologMode |= InterruptMode; #if HAVE_LIBREADLINE if (in_getc) { - siglongjmp(readline_jmpbuf, 0); + fprintf(stderr, "Action (h for help): "); + rl_set_prompt("Action (h for help): "); } #endif return; diff --git a/H/yapio.h b/H/yapio.h index 994dabb37..ce7ab20ec 100644 --- a/H/yapio.h +++ b/H/yapio.h @@ -319,5 +319,6 @@ extern jmp_buf IOBotch; extern int in_getc; #ifdef HAVE_LIBREADLINE -extern sigjmp_buf readline_jmpbuf; +extern char *_line; #endif +