Simplify Input/Output
get rid of string I/O, did not add much getc is never actually used by Prolog try to use system I/O, even if it may be slower, at least for now. extend IO C-interface to allow reading clauses
This commit is contained in:
@@ -33,9 +33,10 @@ static Int
|
||||
rl_to_codes(Term TEnd, int do_as_binary, int arity USES_REGS)
|
||||
{
|
||||
int sno = Yap_CheckStream (ARG1, Input_Stream_f, "read_line_to_codes/2");
|
||||
StreamDesc *st = GLOBAL_Stream+sno;
|
||||
Int status;
|
||||
UInt max_inp, buf_sz, sz;
|
||||
char *buf;
|
||||
int *buf;
|
||||
bool binary_stream;
|
||||
|
||||
if (sno < 0)
|
||||
@@ -47,15 +48,28 @@ rl_to_codes(Term TEnd, int do_as_binary, int arity USES_REGS)
|
||||
return Yap_unify_constant(ARG2, MkAtomTerm (AtomEof));
|
||||
}
|
||||
max_inp = (ASP-HR)/2-1024;
|
||||
buf = (char *)TR;
|
||||
buf_sz = (char *)LOCAL_TrailTop-buf;
|
||||
buf = (int *)TR;
|
||||
buf_sz = (int *)LOCAL_TrailTop-buf;
|
||||
while (TRUE) {
|
||||
if ( buf_sz > max_inp ) {
|
||||
buf_sz = max_inp;
|
||||
}
|
||||
if (do_as_binary && !binary_stream)
|
||||
if (do_as_binary && !binary_stream) {
|
||||
GLOBAL_Stream[sno].status |= Binary_Stream_f;
|
||||
sz = GLOBAL_Stream[sno].stream_gets(sno, buf_sz, buf);
|
||||
}
|
||||
if (st->status & Binary_Stream_f) {
|
||||
char *b = (char *)TR;
|
||||
sz = fread( b,1 , buf_sz, GLOBAL_Stream[sno].file);
|
||||
} else {
|
||||
int ch;
|
||||
int *pt = buf;
|
||||
do {
|
||||
*pt++ = ch = st->stream_wgetc_for_read(sno);
|
||||
if (pt+1 == buf+buf_sz)
|
||||
break;
|
||||
} while (ch != '\n');
|
||||
sz = pt-buf;
|
||||
}
|
||||
if (do_as_binary && !binary_stream)
|
||||
GLOBAL_Stream[sno].status &= ~Binary_Stream_f;
|
||||
if (sz == -1 || sz == 0) {
|
||||
@@ -117,7 +131,8 @@ read_line_to_string( USES_REGS1 )
|
||||
int sno = Yap_CheckStream (ARG1, Input_Stream_f, "read_line_to_codes/2");
|
||||
Int status;
|
||||
UInt max_inp, buf_sz;
|
||||
char *buf;
|
||||
int *buf;
|
||||
StreamDesc *st = GLOBAL_Stream+sno;
|
||||
|
||||
if (sno < 0)
|
||||
return FALSE;
|
||||
@@ -127,15 +142,27 @@ read_line_to_string( USES_REGS1 )
|
||||
return Yap_unify_constant(ARG2, MkAtomTerm (AtomEof));
|
||||
}
|
||||
max_inp = (ASP-HR)/2-1024;
|
||||
buf = (char *)TR;
|
||||
buf_sz = (char *)LOCAL_TrailTop-buf;
|
||||
buf = (int *)TR;
|
||||
buf_sz = (int *)LOCAL_TrailTop-buf;
|
||||
while (true) {
|
||||
size_t sz;
|
||||
|
||||
if ( buf_sz > max_inp ) {
|
||||
buf_sz = max_inp;
|
||||
}
|
||||
sz = GLOBAL_Stream[sno].stream_gets(sno, buf_sz, buf);
|
||||
if (st->status & Binary_Stream_f) {
|
||||
char *b = (char *)TR;
|
||||
sz = fread( b,1 , buf_sz, GLOBAL_Stream[sno].file);
|
||||
} else {
|
||||
int ch;
|
||||
int *pt = buf;
|
||||
do {
|
||||
*pt++ = ch = st->stream_wgetc_for_read(sno);
|
||||
if (pt+1 == buf+buf_sz)
|
||||
break;
|
||||
} while (ch != '\n');
|
||||
sz = pt-buf;
|
||||
}
|
||||
if (sz == -1 || sz == 0) {
|
||||
if (GLOBAL_Stream[sno].status & Eof_Stream_f) {
|
||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||
|
Reference in New Issue
Block a user