This commit is contained in:
ubu32 2011-02-14 11:50:30 -08:00
parent 6469a0d464
commit 85a7e7b9b0
3 changed files with 13 additions and 151 deletions

View File

@ -109,7 +109,6 @@ STATIC_PROTO (Int p_write2, (void));
STATIC_PROTO (Int p_set_read_error_handler, (void));
STATIC_PROTO (Int p_get_read_error_handler, (void));
STATIC_PROTO (Int p_read, (void));
STATIC_PROTO (Int p_peek, (void));
STATIC_PROTO (Int p_past_eof, (void));
STATIC_PROTO (Int p_put, (void));
STATIC_PROTO (Int p_put_byte, (void));
@ -1712,105 +1711,6 @@ p_past_eof (void)
return out;
}
static Int
p_peek_byte (void)
{ /* at_end_of_stream */
/* the next character is a EOF */
int sno = CheckStream (ARG1, Input_Stream_f, "peek/2");
StreamDesc *s;
Int ocharcount, olinecount, olinepos;
Int status;
Int ch;
if (sno < 0)
return(FALSE);
status = Stream[sno].status;
if (!(status & Binary_Stream_f)) {
UNLOCK(Stream[sno].streamlock);
Yap_Error(PERMISSION_ERROR_INPUT_TEXT_STREAM, ARG1, "peek/2");
return(FALSE);
}
UNLOCK(Stream[sno].streamlock);
if (Stream[sno].stream_getc == PlUnGetc) {
ch = MkIntTerm(Stream[sno].och);
/* sequence of peeks */
return Yap_unify_constant(ARG2,ch);
}
if (status & Eof_Stream_f) {
Yap_Error(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM, ARG1, "peek/2");
return(FALSE);
}
s = Stream+sno;
ocharcount = s->charcount;
olinecount = s->linecount;
olinepos = s->linepos;
ch = Stream[sno].stream_getc(sno);
s->charcount = ocharcount;
s->linecount = olinecount;
s->linepos = olinepos;
/* buffer the character */
s->och = ch;
/* mark a special function to recover this character */
s->stream_getc = PlUnGetc;
s->stream_wgetc = get_wchar;
s->stream_gets = DefaultGets;
if (CharConversionTable != NULL)
s->stream_wgetc_for_read = ISOWGetc;
else
s->stream_wgetc_for_read = s->stream_wgetc;
UNLOCK(s->streamlock);
return(Yap_unify_constant(ARG2,MkIntTerm(ch)));
}
static Int
p_peek (void)
{ /* at_end_of_stream */
/* the next character is a EOF */
int sno = CheckStream (ARG1, Input_Stream_f, "peek/2");
StreamDesc *s;
Int ocharcount, olinecount, olinepos;
Int status;
Int ch;
if (sno < 0)
return(FALSE);
status = Stream[sno].status;
if (status & Binary_Stream_f) {
UNLOCK(Stream[sno].streamlock);
Yap_Error(PERMISSION_ERROR_INPUT_BINARY_STREAM, ARG1, "peek/2");
return FALSE;
}
UNLOCK(Stream[sno].streamlock);
if (Stream[sno].stream_getc == PlUnGetc) {
ch = MkIntTerm(Stream[sno].och);
/* sequence of peeks */
return Yap_unify_constant(ARG2,ch);
}
LOCK(Stream[sno].streamlock);
s = Stream+sno;
ocharcount = s->charcount;
olinecount = s->linecount;
olinepos = s->linepos;
UNLOCK(Stream[sno].streamlock);
ch = get_wchar(sno);
LOCK(Stream[sno].streamlock);
s->charcount = ocharcount;
s->linecount = olinecount;
s->linepos = olinepos;
/* buffer the character */
s->och = ch;
/* mark a special function to recover this character */
s->stream_getc = PlUnGetc;
s->stream_wgetc = get_wchar;
s->stream_gets = DefaultGets;
if (CharConversionTable != NULL)
s->stream_wgetc_for_read = ISOWGetc;
else
s->stream_wgetc_for_read = s->stream_wgetc;
UNLOCK(Stream[sno].streamlock);
return(Yap_unify_constant(ARG2,MkIntTerm(ch)));
}
static Int
p_has_bom (void)
{ /* '$set_output'(+Stream,-ErrorMessage) */
@ -4192,8 +4092,6 @@ Yap_InitIOPreds(void)
Yap_InitCPred ("$set_stream_position", 2, p_set_stream_position, SafePredFlag|SyncPredFlag|HiddenPredFlag);
Yap_InitCPred ("$user_file_name", 2, p_user_file_name, SafePredFlag|SyncPredFlag),
Yap_InitCPred ("$past_eof", 1, p_past_eof, SafePredFlag|SyncPredFlag),
Yap_InitCPred ("$peek", 2, p_peek, SafePredFlag|SyncPredFlag),
Yap_InitCPred ("$peek_byte", 2, p_peek_byte, SafePredFlag|SyncPredFlag),
Yap_InitCPred ("$has_bom", 1, p_has_bom, SafePredFlag);
Yap_InitCPred ("$stream_representation_error", 2, p_representation_error, SafePredFlag|SyncPredFlag);
Yap_InitCPred ("$is_same_tty", 2, p_is_same_tty, SafePredFlag|SyncPredFlag|HiddenPredFlag);

View File

@ -1468,3 +1468,16 @@ get_code(C) :-
swi_get_code(C).
get_code(Stream, C) :-
swi_get_code(Stream, C).
peek_byte(C) :-
swi_peek_byte(C).
peek_byte(Stream, C) :-
swi_peek_byte(Stream, C).
peek_char(C) :-
swi_peek_char(C).
peek_char(Stream, C) :-
swi_peek_char(Stream, C).
peek_code(C) :-
swi_peek_code(C).
peek_code(Stream, C) :-
swi_peek_code(Stream, C).

View File

@ -124,12 +124,6 @@
'$check_priority_arg'(X,G) :-
'$do_error'(domain_error(write_option,priority(X)),G).
set_input(Stream) :-
'$set_input'(Stream).
set_output(Stream) :-
'$set_output'(Stream).
open_pipe_streams(Read, Write) :-
(
'$undefined'(pipe(_,_),unix)
@ -416,49 +410,6 @@ format(T) :-
/* character I/O */
peek_byte(V) :-
\+ var(V), (\+ integer(V) ; V < -1 ; V > 256), !,
'$do_error'(type_error(in_byte,V),get_byte(V)).
peek_byte(V) :-
current_input(S),
'$peek_byte'(S,V).
peek_byte(S,V) :-
\+ var(V), (\+ integer(V) ; V < -1 ; V > 256), !,
'$do_error'(type_error(in_byte,V),get_byte(S,V)).
peek_byte(S,V) :-
'$peek_byte'(S,V).
peek_char(V) :-
\+ var(V),
( atom(V) -> atom_codes(V,[_,_|_]), V \= end_of_file ; true ), !,
'$do_error'(type_error(in_character,V),get_char(V)).
peek_char(V) :-
current_input(S),
'$peek'(S,I),
( I = -1 -> V = end_of_file ; atom_codes(V,[I])).
peek_char(S,V) :-
\+ var(V),
( atom(V) -> atom_codes(V,[_,_|_]), V \= end_of_file ; true ), !,
'$do_error'(type_error(in_character,V),get_char(S,V)).
peek_char(S,V) :-
'$peek'(S,I),
( I = -1 -> V = end_of_file ; atom_codes(V,[I])).
peek_code(S,V) :-
\+ var(V), (\+ integer(V)), !,
'$do_error'(type_error(in_character_code,V),get_code(S,V)).
peek_code(S,V) :-
'$peek'(S,V).
peek_code(V) :-
\+ var(V), (\+ integer(V)), !,
'$do_error'(type_error(in_character_code,V),get_code(V)).
peek_code(V) :-
current_input(S),
'$peek'(S,V).
put_byte(V) :- var(V), !,
'$do_error'(instantiation_error,put_byte(V)).
put_byte(V) :-