avoid unnecessary flushing in readline

fixes to manual
make flush work for readline


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@140 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2001-08-13 09:19:00 +00:00
parent a09e21bf68
commit 5d5ddd864e
5 changed files with 37 additions and 23 deletions

View File

@ -313,17 +313,26 @@ YP_putc(int ch, int sno)
int int
YP_fflush(int sno) YP_fflush(int sno)
{ {
#if HAVE_LIBREADLINE
if (Stream[sno].status & Tty_Stream_f &&
Stream[sno].status & Output_Stream_f) {
if (ReadlinePos != ReadlineBuf) {
ReadlinePos[0] = '\0';
fputs( ReadlineBuf, Stream[sno].u.file.file);
}
ReadlinePos = ReadlineBuf;
}
#endif
if ( (Stream[sno].status & Output_Stream_f) && if ( (Stream[sno].status & Output_Stream_f) &&
! (Stream[sno].status & ! (Stream[sno].status &
(Null_Stream_f| (Null_Stream_f|
InMemory_Stream_f| InMemory_Stream_f|
Socket_Stream_f| Socket_Stream_f|
Pipe_Stream_f| Pipe_Stream_f|
Free_Stream_f)) ) Free_Stream_f)) ) {
return(fflush(Stream[sno].u.file.file)); return(fflush(Stream[sno].u.file.file));
else } else
return(0); return(0);
return(fflush(Stream[sno].u.file.file));
} }
static void static void
@ -883,7 +892,6 @@ ReadlineGetc(int sno)
} }
} }
} }
YP_fflush (YP_stdout);
/* Only sends a newline if we are at the start of a line */ /* Only sends a newline if we are at the start of a line */
if (_line != NULL && _line != (char *) EOF) if (_line != NULL && _line != (char *) EOF)
free (_line); free (_line);
@ -901,7 +909,7 @@ ReadlineGetc(int sno)
} }
_line = readline (Prompt); _line = readline (Prompt);
} else { } else {
_line = readline (""); _line = readline (NULL);
} }
} else { } else {
if (ReadlinePos != ReadlineBuf) { if (ReadlinePos != ReadlineBuf) {
@ -909,7 +917,7 @@ ReadlineGetc(int sno)
ReadlinePos = ReadlineBuf; ReadlinePos = ReadlineBuf;
_line = readline (ReadlineBuf); _line = readline (ReadlineBuf);
} else { } else {
_line = readline (""); _line = readline (NULL);
} }
} }
newline=FALSE; newline=FALSE;
@ -4352,8 +4360,7 @@ p_flush (void)
int sno = CheckStream (ARG1, Output_Stream_f, "flush_output/1"); int sno = CheckStream (ARG1, Output_Stream_f, "flush_output/1");
if (sno < 0) if (sno < 0)
return (FALSE); return (FALSE);
if (!(Stream[sno].status & (Null_Stream_f|Socket_Stream_f|Pipe_Stream_f|InMemory_Stream_f))) YP_fflush (sno);
YP_fflush (sno);
return (TRUE); return (TRUE);
} }

View File

@ -1240,11 +1240,11 @@ HandleALRM (int s, siginfo_t *x, ucontext_t *y)
HandleALRM(int s) HandleALRM(int s)
#endif #endif
{ {
my_signal (SIGALRM, HandleALRM);
/* force the system to creep */ /* force the system to creep */
p_creep (); p_creep ();
/* now, say what is going on */ /* now, say what is going on */
PutValue(AtomAlarm, MkAtomTerm(AtomTrue)); PutValue(AtomAlarm, MkAtomTerm(AtomTrue));
my_signal (SIGALRM, HandleALRM);
} }
#endif #endif
@ -1934,7 +1934,7 @@ p_alarm(void)
Int left; Int left;
Term tout; Term tout;
left = alarm(IntOfTerm(t)); left = alarm(IntegerOfTerm(t));
tout = MkIntegerTerm(left); tout = MkIntegerTerm(left);
return(unify(ARG2,tout)); return(unify(ARG2,tout));
} }

View File

@ -16,6 +16,9 @@
<h2>Yap-4.3.20:</h2> <h2>Yap-4.3.20:</h2>
<ul> <ul>
<li>FIXED: flush should work with readline.</li>
<li>FIXED: reset alarm at top-level.</li>
<li>FIXED: do signal(ALARM) immediately.</li>
<li>FIXED: don't use full optimization for parser.c in cygwin <li>FIXED: don't use full optimization for parser.c in cygwin
(report from Steve Moyle).</li> (report from Steve Moyle).</li>
<li>NEW: Erik Alphonse's apply_macros library.</li> <li>NEW: Erik Alphonse's apply_macros library.</li>

View File

@ -5388,8 +5388,9 @@ a certain procedure does not take longer than a certain amount of time:
@example @example
loop :- loop. loop :- loop.
:- alarm(10, throw(ball), _), :- catch((alarm(10, throw(ball), _),loop),
catch(loop, ball, format('Quota exhausted.~n',[])). ball,
format('Quota exhausted.~n',[])).
@end example @end example
In this case after @code{10} seconds our @code{loop} is interrupted, In this case after @code{10} seconds our @code{loop} is interrupted,
@code{ball} is thrown, and the handler writes @code{Quota exhausted}. @code{ball} is thrown, and the handler writes @code{Quota exhausted}.
@ -6294,7 +6295,7 @@ Library, Extensions, Builtins, Top
@end menu @end menu
@node Apply Macros, Association Trees, , Library @node Apply Macros, Association Lists, , Library
@section Apply Macros @section Apply Macros
@cindex macros @cindex macros
@ -6352,11 +6353,11 @@ applying the predicate @var{Pred} to all list elements on which
arguments of @var{TermIn} arguments of @var{TermIn}
@item sumargs(+@var{Pred}, +@var{Term}, ?@var{AccIn}, ?@var{AccOut}) @item sumargs(+@var{Pred}, +@var{Term}, ?@var{AccIn}, ?@var{AccOut})
@findex sumargs/3 @findex sumargs/4
@snindex sumargs/3 @snindex sumargs/4
@cnindex sumargs/3 @cnindex sumargs/4
Calls the predicate @var{Pred} on all arguments of @var{Term} and collects a Calls the predicate @var{Pred} on all arguments of @var{Term} and
result in @var{Accumulator} collects a result in @var{Accumulator}
@item mapnodes(+@var{Pred}, +@var{TermIn}, ?@var{TermOut}) @item mapnodes(+@var{Pred}, +@var{TermIn}, ?@var{TermOut})
@findex mapnodes/3 @findex mapnodes/3
@ -6372,10 +6373,10 @@ applying the predicate @var{Pred} to all list elements on which
Succeeds if the predicate @var{Pred} succeeds on all sub-terms of Succeeds if the predicate @var{Pred} succeeds on all sub-terms of
@var{Term} (depth-first and left-to-right order) @var{Term} (depth-first and left-to-right order)
@item sumnodes(+@var{Pred}, +var{Term}, ?@var{AccIn}, ?@var{AccOut}) @item sumnodes(+@var{Pred}, +@var{Term}, ?@var{AccIn}, ?@var{AccOut})
@findex sumnodes/3 @findex sumnodes/4
@snindex sumnodes/3 @snindex sumnodes/4
@cnindex sumnodes/3 @cnindex sumnodes/4
Calls the predicate @var{Pred} on all sub-terms of @var{Term} and Calls the predicate @var{Pred} on all sub-terms of @var{Term} and
collect a result in @var{Accumulator} (depth-first and left-to-right order) collect a result in @var{Accumulator} (depth-first and left-to-right order)
@end table @end table

View File

@ -15,7 +15,6 @@
* * * *
*************************************************************************/ *************************************************************************/
'$qery'((?-)).
% %
% This one should come first so that disjunctions and long distance % This one should come first so that disjunctions and long distance
% cuts are compiled right with co-routining. % cuts are compiled right with co-routining.
@ -150,6 +149,10 @@ nl.
'$read'(true,T,V), '$read'(true,T,V),
set_input(Old). set_input(Old).
% reset alarms when entering top-level.
'$enter_top_level' :-
'$alarm'(0, _),
fail.
'$enter_top_level' :- '$enter_top_level' :-
'$clean_up_dead_clauses', '$clean_up_dead_clauses',
fail. fail.