fix batched job :(

This commit is contained in:
Vítor Santos Costa 2016-02-26 17:47:40 +00:00
parent 54985f4678
commit 77123269e7

View File

@ -28,10 +28,7 @@ static char SccsId[] = "%W% %G%";
/// @addtogroup readutil
static Int
rl_to_codes(Term TEnd, int do_as_binary, int arity USES_REGS)
{
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;
@ -67,7 +64,7 @@ rl_to_codes(Term TEnd, int do_as_binary, int arity USES_REGS)
*pt++ = ch = st->stream_wgetc_for_read(sno);
if (pt + 1 == buf + buf_sz)
break;
} while (ch != '\n');
} while (ch != '\n' && ch != EOF);
sz = pt - buf;
}
if (do_as_binary && !binary_stream)
@ -97,11 +94,11 @@ rl_to_codes(Term TEnd, int do_as_binary, int arity USES_REGS)
end = TermNil;
else
end = Deref(XREGS[arity]);
if (GLOBAL_Stream[sno].encoding == ENC_ISO_UTF8)
return Yap_unify(ARG2, Yap_UTF8ToDiffListOfCodes((const char *)TR, end PASS_REGS)) ;
else if (GLOBAL_Stream[sno].encoding == ENC_WCHAR)
return Yap_unify(ARG2, Yap_WCharsToDiffListOfCodes((const wchar_t *)TR, end PASS_REGS)) ;
return Yap_unify(ARG2, Yap_CharsToDiffListOfCodes((const char *)TR, end, ENC_ISO_LATIN1 PASS_REGS)) ;
return Yap_unify(ARG2, Yap_WCharsToDiffListOfCodes((const wchar_t *)TR,
end PASS_REGS));
return Yap_unify(ARG2,
Yap_CharsToDiffListOfCodes((const char *)TR, end,
ENC_ISO_LATIN1 PASS_REGS));
}
buf += (buf_sz - 1);
max_inp -= (buf_sz - 1);
@ -113,25 +110,19 @@ rl_to_codes(Term TEnd, int do_as_binary, int arity USES_REGS)
}
}
static Int
read_line_to_codes(USES_REGS1)
{
static Int read_line_to_codes(USES_REGS1) {
return rl_to_codes(TermNil, FALSE, 2 PASS_REGS);
}
static Int
read_line_to_codes2(USES_REGS1)
{
static Int read_line_to_codes2(USES_REGS1) {
return rl_to_codes(TermNil, TRUE, 3 PASS_REGS);
}
static Int
read_line_to_string( USES_REGS1 )
{
static Int 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;
int *buf;
size_t max_inp, buf_sz;
unsigned char *buf;
StreamDesc *st = GLOBAL_Stream + sno;
if (sno < 0)
@ -142,8 +133,8 @@ read_line_to_string( USES_REGS1 )
return Yap_unify_constant(ARG2, MkAtomTerm(AtomEof));
}
max_inp = (ASP - HR) / 2 - 1024;
buf = (int *)TR;
buf_sz = (int *)LOCAL_TrailTop-buf;
buf = (unsigned char *)TR;
buf_sz = (unsigned char *)LOCAL_TrailTop - buf;
while (true) {
size_t sz;
@ -154,11 +145,16 @@ read_line_to_string( USES_REGS1 )
char *b = (char *)TR;
sz = fread(b, 1, buf_sz, GLOBAL_Stream[sno].file);
} else {
int ch;
int *pt = buf;
uint32_t ch;
unsigned char *pt = buf;
do {
*pt++ = ch = st->stream_wgetc_for_read(sno);
if (pt+1 == buf+buf_sz)
ch = st->stream_wgetc_for_read(sno);
if (ch == EOF) {
sz = -1;
break;
}
pt += put_utf8(pt, ch);
if (pt + 4 == buf + buf_sz)
break;
} while (ch != '\n');
sz = pt - buf;
@ -191,7 +187,8 @@ read_line_to_string( USES_REGS1 )
} else if (GLOBAL_Stream[sno].encoding == ENC_WCHAR) {
return Yap_unify(ARG2, Yap_WCharsToString((const wchar_t *)TR PASS_REGS));
} else {
return Yap_unify(ARG2, Yap_CharsToString((const char *)TR, ENC_ISO_LATIN1 PASS_REGS) );
return Yap_unify(
ARG2, Yap_CharsToString((const char *)TR, ENC_ISO_LATIN1 PASS_REGS));
}
buf += (buf_sz - 1);
max_inp -= (buf_sz - 1);
@ -203,10 +200,9 @@ read_line_to_string( USES_REGS1 )
}
}
static Int
read_stream_to_codes(USES_REGS1)
{
int sno = Yap_CheckStream (ARG1, Input_Stream_f, "reaMkAtomTerm (AtomEofd_line_to_codes/2");
static Int read_stream_to_codes(USES_REGS1) {
int sno = Yap_CheckStream(ARG1, Input_Stream_f,
"reaMkAtomTerm (AtomEofd_line_to_codes/2");
CELL *HBASE = HR;
CELL *h0 = &ARG4;
@ -244,12 +240,9 @@ read_stream_to_codes(USES_REGS1)
RESET_VARIABLE(HR - 1);
Yap_unify(HR[-1], ARG3);
return Yap_unify(AbsPair(HBASE), ARG2);
}
static Int
read_stream_to_terms(USES_REGS1)
{
static Int read_stream_to_terms(USES_REGS1) {
int sno = Yap_CheckStream(ARG1, Input_Stream_f, "read_line_to_codes/2");
Term t, hd;
yhandle_t tails, news;
@ -287,9 +280,7 @@ read_stream_to_terms(USES_REGS1)
return Yap_unify(t, ARG2);
}
void
Yap_InitReadUtil(void)
{
void Yap_InitReadUtil(void) {
CACHE_REGS
Term cm = CurrentModule;
@ -301,4 +292,3 @@ Yap_InitReadUtil(void)
Yap_InitCPred("read_stream_to_terms", 3, read_stream_to_terms, SyncPredFlag);
CurrentModule = cm;
}