Improve readline code:
don't flush if we change output stream; use readline from interrupt handler. git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@85 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
parent
474be299f4
commit
c9c8aeb3cc
@ -760,8 +760,6 @@ static char *ttyptr = NULL;
|
||||
|
||||
static char *_line = (char *) NULL;
|
||||
|
||||
int in_readline = FALSE;
|
||||
|
||||
static int cur_out_sno = 2;
|
||||
|
||||
#define READLINE_OUT_BUF_MAX 256
|
||||
@ -776,8 +774,7 @@ static int
|
||||
ReadlinePutc (int sno, int ch)
|
||||
{
|
||||
if (ReadlinePos != ReadlineBuf &&
|
||||
(sno != cur_out_sno ||
|
||||
ReadlinePos - ReadlineBuf == READLINE_OUT_BUF_MAX-1 ||
|
||||
(ReadlinePos - ReadlineBuf == READLINE_OUT_BUF_MAX-1 /* overflow */ ||
|
||||
#if MAC || _MSC_VER
|
||||
ch == 10 ||
|
||||
#endif
|
||||
@ -824,7 +821,6 @@ ReadlineGetc(int sno)
|
||||
rl_instream = Stream[sno].u.file.file;
|
||||
rl_outstream = Stream[cur_out_sno].u.file.file;
|
||||
/* window of vulnerability opened */
|
||||
in_readline = TRUE;
|
||||
if (newline) {
|
||||
char *cptr = Prompt, ch;
|
||||
|
||||
@ -848,7 +844,6 @@ ReadlineGetc(int sno)
|
||||
}
|
||||
}
|
||||
newline=FALSE;
|
||||
in_readline = FALSE;
|
||||
strncpy (Prompt, RepAtom (*AtPrompt)->StrOfAE, MAX_PROMPT);
|
||||
/* window of vulnerability closed */
|
||||
if (PrologMode & AbortMode) {
|
||||
|
31
C/sysbits.c
31
C/sysbits.c
@ -81,6 +81,9 @@ static char SccsId[] = "%W% %G%";
|
||||
#include <sys/param.h>
|
||||
#endif
|
||||
#endif
|
||||
#if HAVE_LIBREADLINE
|
||||
#include <readline/readline.h>
|
||||
#endif
|
||||
|
||||
STATIC_PROTO (void InitPageSize, (void));
|
||||
STATIC_PROTO (void InitTime, (void));
|
||||
@ -1060,6 +1063,11 @@ void (*handler)(int);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if HAVE_LIBREADLINE
|
||||
static char *_line = NULL;
|
||||
#endif
|
||||
|
||||
void
|
||||
ProcessSIGINT(void)
|
||||
{
|
||||
@ -1070,12 +1078,18 @@ ProcessSIGINT(void)
|
||||
int ch0;
|
||||
#endif
|
||||
|
||||
#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)
|
||||
continue;
|
||||
ch = _line[0];
|
||||
#else
|
||||
YP_fprintf(YP_stderr, "\nAction (h for help): ");
|
||||
ch = YP_getchar ( );
|
||||
#if HAVE_LIBREADLINE
|
||||
if (!in_readline)
|
||||
#endif
|
||||
while ((YP_getchar()) != '\n');
|
||||
#endif
|
||||
switch (ch)
|
||||
{
|
||||
case 'a':
|
||||
@ -1094,13 +1108,8 @@ ProcessSIGINT(void)
|
||||
#ifdef VAX
|
||||
VaxFixFrame (CritMode);
|
||||
#endif
|
||||
#if HAVE_LIBREADLINE
|
||||
/* we cannot abort until we finish readline :-( */
|
||||
if (in_readline) {
|
||||
/* readline must eat a newline, otherwise we will
|
||||
have to wait before we do the Abort() */
|
||||
} else if (!(PrologMode & CritMode)) {
|
||||
#endif
|
||||
if (!(PrologMode & CritMode)) {
|
||||
#if defined(__MINGW32__) || _MSC_VER
|
||||
/* we can't do a direct abort, so ask the system to do it for us */
|
||||
p_creep();
|
||||
@ -1201,10 +1210,6 @@ ProcessSIGINT(void)
|
||||
YP_fprintf(YP_stderr, " e for exit\n t for trace\n s for statistics\n");
|
||||
break;
|
||||
}
|
||||
#if HAVE_LIBREADLINE
|
||||
/* we must do the reading now, because libreadline won't have a chance here */
|
||||
while ((YP_getchar()) != '\n');
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user