small fixes for compaibility

This commit is contained in:
Vítor Santos Costa 2015-10-18 11:48:14 +01:00
parent f4eee4782e
commit 684e733c8b

View File

@ -67,9 +67,7 @@ INLINE_ONLY inline EXTERN Term MkCharTerm (Int c);
*
* @return the term.
*/
INLINE_ONLY inline EXTERN Term
MkCharTerm (Int c)
{
INLINE_ONLY inline EXTERN Term MkCharTerm(Int c) {
wchar_t cs[2];
if (c < 0)
return MkAtomTerm(AtomEof);
@ -78,7 +76,6 @@ MkCharTerm (Int c)
return MkAtomTerm(Yap_LookupMaybeWideAtom(cs));
}
/**
* CharOfAtom: convert an atom into a single character.
*
@ -86,9 +83,7 @@ MkCharTerm (Int c)
*
* @return the char .
*/
INLINE_ONLY inline EXTERN Int
CharOfAtom (Atom at)
{
INLINE_ONLY inline EXTERN Int CharOfAtom(Atom at) {
if (IsWideAtom(at)) {
return at->WStrOfAE[0];
} else {
@ -96,14 +91,11 @@ CharOfAtom (Atom at)
}
}
static int
plUnGetc( int sno, int ch )
{
static int plUnGetc(int sno, int ch) {
return ungetc(ch, GLOBAL_Stream[sno].file);
}
Int Yap_peek( int sno )
{
Int Yap_peek(int sno) {
CACHE_REGS
Int ocharcount, olinecount, olinepos;
StreamDesc *s;
@ -130,8 +122,7 @@ Int Yap_peek( int sno )
return ch;
}
static Int dopeek_byte( int sno )
{
static Int dopeek_byte(int sno) {
Int ocharcount, olinecount, olinepos;
StreamDesc *s;
Int ch;
@ -149,9 +140,7 @@ static Int dopeek_byte( int sno )
return ch;
}
static Int
at_end_of_stream ( USES_REGS1 )
{ /* at_end_of_stream */
static Int at_end_of_stream(USES_REGS1) { /* at_end_of_stream */
/* the next character is a EOF */
int sno = Yap_CheckStream(ARG1, Input_Stream_f, NULL);
Int out;
@ -170,9 +159,7 @@ at_end_of_stream ( USES_REGS1 )
return out;
}
static Int
at_end_of_stream_0 ( USES_REGS1 )
{ /* at_end_of_stream */
static Int at_end_of_stream_0(USES_REGS1) { /* at_end_of_stream */
/* the next character is a EOF */
Int out;
@ -185,27 +172,18 @@ at_end_of_stream_0 ( USES_REGS1 )
return out;
}
static int
yap_fflush( sno)
{
static int yap_fflush(sno) {
Yap_ReadlineFlush(sno);
if ((GLOBAL_Stream[sno].status & Output_Stream_f) &&
!(GLOBAL_Stream[sno].status &
(Null_Stream_f|
InMemory_Stream_f|
Socket_Stream_f|
Pipe_Stream_f|
(Null_Stream_f | InMemory_Stream_f | Socket_Stream_f | Pipe_Stream_f |
Free_Stream_f))) {
return (fflush(GLOBAL_Stream[sno].file));
} else
return (0);
}
static Int
get ( USES_REGS1 )
{ /* '$get'(Stream,-N) */
static Int get(USES_REGS1) { /* '$get'(Stream,-N) */
int sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "get/2");
int ch;
Int status;
@ -219,9 +197,7 @@ get ( USES_REGS1 )
return (Yap_unify_constant(ARG2, MkIntegerTerm(ch)));
}
static Int
get_char ( USES_REGS1 )
{ /* '$get'(Stream,-N) */
static Int get_char(USES_REGS1) { /* '$get'(Stream,-N) */
int sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "get/2");
int ch;
Int status;
@ -234,9 +210,7 @@ get_char ( USES_REGS1 )
return (Yap_unify_constant(ARG2, MkCharTerm(ch)));
}
static Int
get_code ( USES_REGS1 )
{ /* get0(Stream,-N) */
static Int get_code(USES_REGS1) { /* get0(Stream,-N) */
int sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "get0/2");
Int status;
Int out;
@ -249,10 +223,7 @@ get_code ( USES_REGS1 )
return (Yap_unify_constant(ARG2, MkIntegerTerm(out)));
}
static Int
get_1 ( USES_REGS1 )
{ /* get_code1(Stream,-N) */
static Int get_1(USES_REGS1) { /* get_code1(Stream,-N) */
int sno = LOCAL_c_input_stream;
int ch;
Int status;
@ -265,9 +236,7 @@ get_1 ( USES_REGS1 )
return (Yap_unify_constant(ARG2, MkIntegerTerm(ch)));
}
static Int
getcode_1 ( USES_REGS1 )
{ /* get0(Stream,-N) */
static Int getcode_1(USES_REGS1) { /* get0(Stream,-N) */
int sno = LOCAL_c_input_stream;
Int status;
Int out;
@ -279,9 +248,7 @@ getcode_1 ( USES_REGS1 )
return (Yap_unify_constant(ARG1, MkIntegerTerm(out)));
}
static Int
getchar_1 ( USES_REGS1 )
{ /* get0(Stream,-N) */
static Int getchar_1(USES_REGS1) { /* get0(Stream,-N) */
int sno = LOCAL_c_input_stream;
Int status;
Int out;
@ -293,10 +260,7 @@ getchar_1 ( USES_REGS1 )
return (Yap_unify_constant(ARG1, MkCharTerm(out)));
}
static Int
get0_line_codes ( USES_REGS1 )
{ /* '$get0'(Stream,-N) */
static Int get0_line_codes(USES_REGS1) { /* '$get0'(Stream,-N) */
int sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "get0/2");
Int status;
Term out;
@ -315,9 +279,7 @@ get0_line_codes ( USES_REGS1 )
return Yap_unify(out, ARG2);
}
static Int
get_byte ( USES_REGS1 )
{ /* '$get_byte'(Stream,-N) */
static Int get_byte(USES_REGS1) { /* '$get_byte'(Stream,-N) */
int sno = Yap_CheckStream(ARG1, Input_Stream_f, "get_byte/2");
Int status;
Term out;
@ -337,9 +299,7 @@ get_byte ( USES_REGS1 )
return Yap_unify_constant(ARG2, out);
}
static Int
get_byte_1 ( USES_REGS1 )
{ /* '$get_byte'(Stream,-N) */
static Int get_byte_1(USES_REGS1) { /* '$get_byte'(Stream,-N) */
int sno = LOCAL_c_input_stream;
Int status;
Term out;
@ -358,9 +318,7 @@ get_byte_1 ( USES_REGS1 )
return Yap_unify_constant(ARG1, out);
}
static Int
put_code_1 ( USES_REGS1 )
{ /* '$put'(,N) */
static Int put_code_1(USES_REGS1) { /* '$put'(,N) */
int sno = LOCAL_c_output_stream, ch;
Term t2;
@ -384,9 +342,7 @@ put_code_1 ( USES_REGS1 )
return (TRUE);
}
static Int
put_code ( USES_REGS1 )
{ /* '$put'(Stream,N) */
static Int put_code(USES_REGS1) { /* '$put'(Stream,N) */
int ch;
Term t2;
int sno;
@ -419,9 +375,7 @@ put_code ( USES_REGS1 )
return (TRUE);
}
static Int
put_char_1 ( USES_REGS1 )
{ /* '$put'(,N) */
static Int put_char_1(USES_REGS1) { /* '$put'(,N) */
int sno = LOCAL_c_output_stream;
Term t2;
int ch;
@ -451,9 +405,7 @@ put_char_1 ( USES_REGS1 )
return (TRUE);
}
static Int
put_char ( USES_REGS1 )
{ /* '$put'(Stream,N) */
static Int put_char(USES_REGS1) { /* '$put'(Stream,N) */
Term t2;
int ch;
int sno;
@ -485,9 +437,7 @@ put_char ( USES_REGS1 )
return (TRUE);
}
static Int
tab_1 ( USES_REGS1 )
{ /* nl */
static Int tab_1(USES_REGS1) { /* nl */
int sno = LOCAL_c_output_stream;
Term t2;
Int tabs, i;
@ -519,9 +469,7 @@ tab_1 ( USES_REGS1 )
return (TRUE);
}
static Int
tab ( USES_REGS1 )
{ /* nl(Stream) */
static Int tab(USES_REGS1) { /* nl(Stream) */
int sno = LOCAL_c_output_stream;
Term t2;
Int tabs, i;
@ -555,9 +503,7 @@ tab ( USES_REGS1 )
return (TRUE);
}
static Int
nl_1 ( USES_REGS1 )
{ /* nl */
static Int nl_1(USES_REGS1) { /* nl */
int sno = LOCAL_c_output_stream;
LOCK(GLOBAL_Stream[sno].streamlock);
if (GLOBAL_Stream[sno].status & Binary_Stream_f) {
@ -574,9 +520,7 @@ nl_1 ( USES_REGS1 )
return (TRUE);
}
static Int
nl ( USES_REGS1 )
{ /* nl(Stream) */
static Int nl(USES_REGS1) { /* nl(Stream) */
int sno = Yap_CheckTextStream(ARG1, Output_Stream_f, "nl/1");
if (sno < 0)
return (FALSE);
@ -594,9 +538,7 @@ nl ( USES_REGS1 )
return (TRUE);
}
static Int
put_byte ( USES_REGS1 )
{ /* '$put_byte'(Stream,N) */
static Int put_byte(USES_REGS1) { /* '$put_byte'(Stream,N) */
Term t2;
Int ch;
if (IsVarTerm(t2 = Deref(ARG2))) {
@ -628,9 +570,7 @@ put_byte ( USES_REGS1 )
return (TRUE);
}
static Int
put_byte_1 ( USES_REGS1 )
{ /* '$put_byte'(Stream,N) */
static Int put_byte_1(USES_REGS1) { /* '$put_byte'(Stream,N) */
Term t2;
Int ch;
int sno = LOCAL_c_output_stream;
@ -657,10 +597,7 @@ put_byte_1 ( USES_REGS1 )
return (TRUE);
}
static Int
skip_1 ( USES_REGS1 )
{ /* '$skip'(Stream,N) */
static Int skip_1(USES_REGS1) { /* '$skip'(Stream,N) */
Int n;
Term t2;
int sno;
@ -685,9 +622,7 @@ skip_1 ( USES_REGS1 )
return (TRUE);
}
static Int
skip ( USES_REGS1 )
{ /* '$skip'(Stream,N) */
static Int skip(USES_REGS1) { /* '$skip'(Stream,N) */
Int n;
Term t2;
int sno;
@ -720,9 +655,7 @@ skip ( USES_REGS1 )
* @param +_Stream_
*
*/
static Int
flush_output ( USES_REGS1 )
{ /* flush_output(Stream) */
static Int flush_output(USES_REGS1) { /* flush_output(Stream) */
int sno = Yap_CheckStream(ARG1, Output_Stream_f, "flush_output/1");
if (sno < 0)
return (FALSE);
@ -734,21 +667,18 @@ flush_output ( USES_REGS1 )
/**
* @pred flush_output
*
* Flush the current output stream, that is, make sure all pending output is committed
* Flush the current output stream, that is, make sure all pending output is
*committed
* before any further execution. By default this is user_output, but it may be
* changed by current_output/1.
*
*/
static Int
flush_output0 ( USES_REGS1 )
{ /* flush_output */
static Int flush_output0(USES_REGS1) { /* flush_output */
yap_fflush(LOCAL_c_output_stream);
return (TRUE);
}
static Int
flush_all_streams ( USES_REGS1 )
{ /* $flush_all_streams */
static Int flush_all_streams(USES_REGS1) { /* $flush_all_streams */
#if BROKEN_FFLUSH_NULL
int i;
for (i = 0; i < MaxStreams; ++i) {
@ -782,9 +712,7 @@ current stream and unify its code with _C_, while
leaving the current stream position unaltered.
*/
static Int
peek_code ( USES_REGS1 )
{ /* at_end_of_stream */
static Int peek_code(USES_REGS1) { /* at_end_of_stream */
/* the next character is a EOF */
int sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "peek/2");
Int ch;
@ -797,14 +725,15 @@ peek_code ( USES_REGS1 )
return FALSE;
}
if ((ch = Yap_peek(sno)) < 0) {
#ifdef PEEK_EOF
UNLOCK(GLOBAL_Stream[sno].streamlock);
return false;
#endif
}
UNLOCK(GLOBAL_Stream[sno].streamlock);
return (Yap_unify_constant(ARG2, MkIntTerm(ch)));
}
/** @pred peek_code( - _C_) is iso
@ -814,9 +743,7 @@ current stream and unify its code with _C_, while
leaving the current stream position unaltered.
*/
static Int
peek_code_1 ( USES_REGS1 )
{ /* at_end_of_stream */
static Int peek_code_1(USES_REGS1) { /* at_end_of_stream */
/* the next character is a EOF */
int sno = LOCAL_c_input_stream;
Int ch;
@ -828,14 +755,15 @@ peek_code_1 ( USES_REGS1 )
return FALSE;
}
if ((ch = Yap_peek(sno)) < 0) {
#ifdef PEEK_EOF
UNLOCK(GLOBAL_Stream[sno].streamlock);
return false;
#endif
}
UNLOCK(GLOBAL_Stream[sno].streamlock);
return (Yap_unify_constant(ARG1, MkIntTerm(ch)));
}
/** @pred peek_byte(+Stream, - _C_) is iso
@ -843,9 +771,7 @@ If _C_ is unbound, or is a character code, and _Stream_ is a
binary stream, read the next byte from the current stream and unify its
code with _C_, while leaving the current stream position unaltered.
*/
static Int
peek_byte ( USES_REGS1 )
{ /* at_end_of_stream */
static Int peek_byte(USES_REGS1) { /* at_end_of_stream */
/* the next character is a EOF */
int sno = Yap_CheckStream(ARG1, Input_Stream_f, "peek_byte/2");
Int ch;
@ -858,14 +784,15 @@ peek_byte ( USES_REGS1 )
return (FALSE);
}
if ((ch = dopeek_byte(sno)) < 0) {
#ifdef PEEK_EOF
UNLOCK(GLOBAL_Stream[sno].streamlock);
return false;
#endif
}
UNLOCK(GLOBAL_Stream[sno].streamlock);
return (Yap_unify_constant(ARG2, MkIntTerm(ch)));
}
/** @pred peek_byte( - _C_) is iso
@ -873,9 +800,7 @@ If _C_ is unbound, or is a character code, and _Stream_ is a
binary stream, read the next byte from the current stream and unify its
code with _C_, while leaving the current stream position unaltered.
*/
static Int
peek_byte_1 ( USES_REGS1 )
{ /* at_end_of_stream */
static Int peek_byte_1(USES_REGS1) { /* at_end_of_stream */
/* the next character is a EOF */
int sno = LOCAL_c_input_stream;
Int ch;
@ -889,14 +814,15 @@ peek_byte_1 ( USES_REGS1 )
return (FALSE);
}
if ((ch = dopeek_byte(sno)) < 0) {
#ifdef PEEK_EOF
UNLOCK(GLOBAL_Stream[sno].streamlock);
return false;
#endif
}
UNLOCK(GLOBAL_Stream[sno].streamlock);
return (Yap_unify_constant(ARG2, MkIntTerm(ch)));
}
/** @pred peek_char(+_S_, - _C_) is iso
@ -904,16 +830,14 @@ If _C_ is unbound, or is a character code, and the stream _S_ is a
binary stream, read the next byte from the current stream and unify the
atom with _C_, while leaving the stream position unaltered.
*/
static Int
peek_char ( USES_REGS1 )
{
static Int peek_char(USES_REGS1) {
/* the next character is a EOF */
int sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "peek/2");
wchar_t wsinp[2];
Int ch;
if (sno < 0)
return(FALSE);
return false;
if ((GLOBAL_Stream[sno].status & Binary_Stream_f)) {
UNLOCK(GLOBAL_Stream[sno].streamlock);
Yap_Error(PERMISSION_ERROR_INPUT_TEXT_STREAM, ARG1, "peek_byte/2");
@ -921,7 +845,7 @@ peek_char ( USES_REGS1 )
}
if ((ch = Yap_peek(sno)) < 0) {
UNLOCK(GLOBAL_Stream[sno].streamlock);
return false;
return Yap_unify_constant(ARG2, MkAtomTerm(AtomEof));
}
UNLOCK(GLOBAL_Stream[sno].streamlock);
wsinp[1] = '\0';
@ -936,9 +860,7 @@ If _C_ is unbound, or is a character code, and the current input stream is a
binary stream, read the next byte from the current stream and unify the
atom with _C_, while leaving the stream position unaltered.
*/
static Int
peek_char_1 ( USES_REGS1 )
{
static Int peek_char_1(USES_REGS1) {
/* the next character is a EOF */
int sno = LOCAL_c_input_stream;
wchar_t wsinp[2];
@ -947,7 +869,8 @@ peek_char_1 ( USES_REGS1 )
LOCK(GLOBAL_Stream[sno].streamlock);
if ((ch = Yap_peek(sno)) < 0) {
UNLOCK(GLOBAL_Stream[sno].streamlock);
return false;
return Yap_unify_constant(ARG2, MkAtomTerm(AtomEof));
// return false;
}
UNLOCK(GLOBAL_Stream[sno].streamlock);
wsinp[1] = '\0';
@ -955,7 +878,6 @@ peek_char_1 ( USES_REGS1 )
return Yap_unify_constant(ARG2, MkAtomTerm(Yap_LookupMaybeWideAtom(wsinp)));
}
/** @pred peek(+ _S_, - _C_) is deprecated
@ -977,23 +899,11 @@ leaving the current stream position unaltered.
*/
void Yap_flush(void) { CACHE_REGS(void)flush_all_streams(PASS_REGS1); }
void Yap_FlushStreams(void) { CACHE_REGS(void)flush_all_streams(PASS_REGS1); }
void Yap_flush(void)
{
CACHE_REGS
(void)flush_all_streams(PASS_REGS1);
}
void Yap_FlushStreams(void)
{
CACHE_REGS
(void)flush_all_streams(PASS_REGS1);
}
void
Yap_InitCharsio( void )
{
void Yap_InitCharsio(void) {
Yap_InitCPred("get", 2, get, SafePredFlag | SyncPredFlag);
Yap_InitCPred("get_code", 2, get_code, SafePredFlag | SyncPredFlag);
Yap_InitCPred("get_char", 2, get_char, SafePredFlag | SyncPredFlag);
@ -1002,7 +912,8 @@ Yap_InitCharsio( void )
Yap_InitCPred("get_code", 1, getcode_1, SafePredFlag | SyncPredFlag);
Yap_InitCPred("get_char", 1, getchar_1, SafePredFlag | SyncPredFlag);
Yap_InitCPred("get0", 1, getcode_1, SafePredFlag | SyncPredFlag);
Yap_InitCPred ("$get0_line_codes", 2, get0_line_codes, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("$get0_line_codes", 2, get0_line_codes,
SafePredFlag | SyncPredFlag | HiddenPredFlag);
Yap_InitCPred("get_byte", 2, get_byte, SafePredFlag | SyncPredFlag);
Yap_InitCPred("get_byte", 1, get_byte_1, SafePredFlag | SyncPredFlag);
Yap_InitCPred("put", 1, put_code_1, SafePredFlag | SyncPredFlag);
@ -1020,12 +931,15 @@ Yap_InitCharsio( void )
Yap_InitCPred("nl", 0, nl_1, SafePredFlag | SyncPredFlag);
Yap_InitCPred("nl", 1, nl, SafePredFlag | SyncPredFlag);
Yap_InitCPred ("$flush_all_streams", 0, flush_all_streams, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred("$flush_all_streams", 0, flush_all_streams,
SafePredFlag | SyncPredFlag | HiddenPredFlag);
Yap_InitCPred("flush_output", 1, flush_output, SafePredFlag | SyncPredFlag);
Yap_InitCPred("flush_output", 0, flush_output0, SafePredFlag | SyncPredFlag);
Yap_InitCPred ("at_end_of_stream", 1, at_end_of_stream, SafePredFlag|SyncPredFlag);
Yap_InitCPred ("at_end_of_stream_0", 0, at_end_of_stream_0, SafePredFlag|SyncPredFlag);
Yap_InitCPred("at_end_of_stream", 1, at_end_of_stream,
SafePredFlag | SyncPredFlag);
Yap_InitCPred("at_end_of_stream_0", 0, at_end_of_stream_0,
SafePredFlag | SyncPredFlag);
// Yap_InitCPred ("$past_eof", 1, past_eof, SafePredFlag|SyncPredFlag);
Yap_InitCPred("peek", 2, peek_code, SafePredFlag | SyncPredFlag);
Yap_InitCPred("peek_code", 2, peek_code, SafePredFlag | SyncPredFlag);
@ -1039,6 +953,4 @@ Yap_InitCharsio( void )
Yap_InitCPred("skip1", 1, skip_1, SafePredFlag | SyncPredFlag);
Yap_InitCPred("tab", 2, tab, SafePredFlag | SyncPredFlag);
Yap_InitCPred("tab1", 1, tab_1, SafePredFlag | SyncPredFlag);
}