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:
vsc 2001-06-12 17:25:28 +00:00
parent 474be299f4
commit c9c8aeb3cc
3 changed files with 19 additions and 23 deletions

View File

@ -760,8 +760,6 @@ static char *ttyptr = NULL;
static char *_line = (char *) NULL; static char *_line = (char *) NULL;
int in_readline = FALSE;
static int cur_out_sno = 2; static int cur_out_sno = 2;
#define READLINE_OUT_BUF_MAX 256 #define READLINE_OUT_BUF_MAX 256
@ -776,8 +774,7 @@ static int
ReadlinePutc (int sno, int ch) ReadlinePutc (int sno, int ch)
{ {
if (ReadlinePos != ReadlineBuf && if (ReadlinePos != ReadlineBuf &&
(sno != cur_out_sno || (ReadlinePos - ReadlineBuf == READLINE_OUT_BUF_MAX-1 /* overflow */ ||
ReadlinePos - ReadlineBuf == READLINE_OUT_BUF_MAX-1 ||
#if MAC || _MSC_VER #if MAC || _MSC_VER
ch == 10 || ch == 10 ||
#endif #endif
@ -824,7 +821,6 @@ ReadlineGetc(int sno)
rl_instream = Stream[sno].u.file.file; rl_instream = Stream[sno].u.file.file;
rl_outstream = Stream[cur_out_sno].u.file.file; rl_outstream = Stream[cur_out_sno].u.file.file;
/* window of vulnerability opened */ /* window of vulnerability opened */
in_readline = TRUE;
if (newline) { if (newline) {
char *cptr = Prompt, ch; char *cptr = Prompt, ch;
@ -848,7 +844,6 @@ ReadlineGetc(int sno)
} }
} }
newline=FALSE; newline=FALSE;
in_readline = FALSE;
strncpy (Prompt, RepAtom (*AtPrompt)->StrOfAE, MAX_PROMPT); strncpy (Prompt, RepAtom (*AtPrompt)->StrOfAE, MAX_PROMPT);
/* window of vulnerability closed */ /* window of vulnerability closed */
if (PrologMode & AbortMode) { if (PrologMode & AbortMode) {

View File

@ -81,6 +81,9 @@ static char SccsId[] = "%W% %G%";
#include <sys/param.h> #include <sys/param.h>
#endif #endif
#endif #endif
#if HAVE_LIBREADLINE
#include <readline/readline.h>
#endif
STATIC_PROTO (void InitPageSize, (void)); STATIC_PROTO (void InitPageSize, (void));
STATIC_PROTO (void InitTime, (void)); STATIC_PROTO (void InitTime, (void));
@ -1060,6 +1063,11 @@ void (*handler)(int);
#endif #endif
#if HAVE_LIBREADLINE
static char *_line = NULL;
#endif
void void
ProcessSIGINT(void) ProcessSIGINT(void)
{ {
@ -1070,12 +1078,18 @@ ProcessSIGINT(void)
int ch0; int ch0;
#endif #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): "); YP_fprintf(YP_stderr, "\nAction (h for help): ");
ch = YP_getchar ( ); ch = YP_getchar ( );
#if HAVE_LIBREADLINE
if (!in_readline)
#endif
while ((YP_getchar()) != '\n'); while ((YP_getchar()) != '\n');
#endif
switch (ch) switch (ch)
{ {
case 'a': case 'a':
@ -1094,13 +1108,8 @@ ProcessSIGINT(void)
#ifdef VAX #ifdef VAX
VaxFixFrame (CritMode); VaxFixFrame (CritMode);
#endif #endif
#if HAVE_LIBREADLINE
/* we cannot abort until we finish readline :-( */ /* we cannot abort until we finish readline :-( */
if (in_readline) { if (!(PrologMode & CritMode)) {
/* readline must eat a newline, otherwise we will
have to wait before we do the Abort() */
} else if (!(PrologMode & CritMode)) {
#endif
#if defined(__MINGW32__) || _MSC_VER #if defined(__MINGW32__) || _MSC_VER
/* we can't do a direct abort, so ask the system to do it for us */ /* we can't do a direct abort, so ask the system to do it for us */
p_creep(); p_creep();
@ -1201,10 +1210,6 @@ ProcessSIGINT(void)
YP_fprintf(YP_stderr, " e for exit\n t for trace\n s for statistics\n"); YP_fprintf(YP_stderr, " e for exit\n t for trace\n s for statistics\n");
break; break;
} }
#if HAVE_LIBREADLINE
/* we must do the reading now, because libreadline won't have a chance here */
while ((YP_getchar()) != '\n');
#endif
} }
} }

View File

@ -283,10 +283,6 @@ void STD_PROTO(plwrite,(Term,int (*)(int, int),int));
/* grow.c */ /* grow.c */
int STD_PROTO(growstack_in_parser, (tr_fr_ptr *, TokEntry **, VarEntry **)); int STD_PROTO(growstack_in_parser, (tr_fr_ptr *, TokEntry **, VarEntry **));
#ifdef HAVE_LIBREADLINE
extern int in_readline;
#endif
#if HAVE_ERRNO_H #if HAVE_ERRNO_H
#include <errno.h> #include <errno.h>
#else #else