I/O fixes.
This commit is contained in:
parent
d793651f89
commit
697f7c650c
26
C/iopreds.c
26
C/iopreds.c
@ -90,7 +90,6 @@ STATIC_PROTO (Int p_read, ( USES_REGS1 ));
|
|||||||
STATIC_PROTO (Int p_startline, ( USES_REGS1 ));
|
STATIC_PROTO (Int p_startline, ( USES_REGS1 ));
|
||||||
STATIC_PROTO (Int p_change_type_of_char, ( USES_REGS1 ));
|
STATIC_PROTO (Int p_change_type_of_char, ( USES_REGS1 ));
|
||||||
STATIC_PROTO (Int p_type_of_char, ( USES_REGS1 ));
|
STATIC_PROTO (Int p_type_of_char, ( USES_REGS1 ));
|
||||||
STATIC_PROTO (Term StreamPosition, (IOSTREAM *));
|
|
||||||
|
|
||||||
extern Atom Yap_FileName(IOSTREAM *s);
|
extern Atom Yap_FileName(IOSTREAM *s);
|
||||||
|
|
||||||
@ -559,9 +558,9 @@ static Int
|
|||||||
int emacs_cares = FALSE;
|
int emacs_cares = FALSE;
|
||||||
#endif
|
#endif
|
||||||
Term tmod = Deref(ARG3), OCurrentModule = CurrentModule, tpos;
|
Term tmod = Deref(ARG3), OCurrentModule = CurrentModule, tpos;
|
||||||
extern void Yap_setCurrentSourceLocation(IOSTREAM *s);
|
extern void Yap_setCurrentSourceLocation(IOSTREAM **s);
|
||||||
|
|
||||||
Yap_setCurrentSourceLocation(inp_stream);
|
Yap_setCurrentSourceLocation(&inp_stream);
|
||||||
if (IsVarTerm(tmod)) {
|
if (IsVarTerm(tmod)) {
|
||||||
tmod = CurrentModule;
|
tmod = CurrentModule;
|
||||||
} else if (!IsAtomTerm(tmod)) {
|
} else if (!IsAtomTerm(tmod)) {
|
||||||
@ -569,7 +568,7 @@ static Int
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
Yap_Error_TYPE = YAP_NO_ERROR;
|
Yap_Error_TYPE = YAP_NO_ERROR;
|
||||||
tpos = StreamPosition(inp_stream);
|
tpos = Yap_StreamPosition(inp_stream);
|
||||||
if (!Yap_unify(tpos,ARG5)) {
|
if (!Yap_unify(tpos,ARG5)) {
|
||||||
/* do this early so that we do not have to protect it in case of stack expansion */
|
/* do this early so that we do not have to protect it in case of stack expansion */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -587,7 +586,7 @@ static Int
|
|||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
old_H = H;
|
old_H = H;
|
||||||
Yap_eot_before_eof = FALSE;
|
Yap_eot_before_eof = FALSE;
|
||||||
tpos = StreamPosition(inp_stream);
|
tpos = Yap_StreamPosition(inp_stream);
|
||||||
tokstart = Yap_tokptr = Yap_toktide = Yap_tokenizer(inp_stream, &tpos);
|
tokstart = Yap_tokptr = Yap_toktide = Yap_tokenizer(inp_stream, &tpos);
|
||||||
if (Yap_Error_TYPE != YAP_NO_ERROR && seekable) {
|
if (Yap_Error_TYPE != YAP_NO_ERROR && seekable) {
|
||||||
H = old_H;
|
H = old_H;
|
||||||
@ -759,23 +758,6 @@ p_read2 ( USES_REGS1 )
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static Term
|
|
||||||
StreamPosition(IOSTREAM *st)
|
|
||||||
{
|
|
||||||
Term t[4];
|
|
||||||
t[0] = MkIntegerTerm(st->posbuf.charno);
|
|
||||||
t[1] = MkIntegerTerm(st->posbuf.lineno);
|
|
||||||
t[2] = MkIntegerTerm(st->posbuf.linepos);
|
|
||||||
t[3] = MkIntegerTerm(st->posbuf.byteno);
|
|
||||||
return Yap_MkApplTerm(FunctorStreamPos,4,t);
|
|
||||||
}
|
|
||||||
|
|
||||||
Term
|
|
||||||
Yap_StreamPosition(IOSTREAM *st)
|
|
||||||
{
|
|
||||||
return StreamPosition(st);
|
|
||||||
}
|
|
||||||
|
|
||||||
#if HAVE_SELECT && FALSE
|
#if HAVE_SELECT && FALSE
|
||||||
/* stream_select(+Streams,+TimeOut,-Result) */
|
/* stream_select(+Streams,+TimeOut,-Result) */
|
||||||
static Int
|
static Int
|
||||||
|
39
C/write.c
39
C/write.c
@ -309,13 +309,14 @@ legalAtom(unsigned char *s) /* Is this a legal atom ? */
|
|||||||
return (s[1] == ']' && !s[2]);
|
return (s[1] == ']' && !s[2]);
|
||||||
} else if (ch == '{') {
|
} else if (ch == '{') {
|
||||||
return (s[1] == '}' && !s[2]);
|
return (s[1] == '}' && !s[2]);
|
||||||
// else if (ch == '/')
|
|
||||||
// return (*++s != '*');
|
|
||||||
} else if (Yap_chtype[ch] == SL) {
|
} else if (Yap_chtype[ch] == SL) {
|
||||||
return (!s[1]);
|
return (!s[1]);
|
||||||
} else if ((ch == ',' || ch == '.') && !s[1]) {
|
} else if ((ch == ',' || ch == '.') && !s[1]) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
} else {
|
} else {
|
||||||
|
if (ch == '/') {
|
||||||
|
if (s[1] == '*') return FALSE;
|
||||||
|
}
|
||||||
while (ch) {
|
while (ch) {
|
||||||
if (Yap_chtype[ch] != SY) {
|
if (Yap_chtype[ch] != SY) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -451,7 +452,7 @@ putAtom(Atom atom, int Quote_illegal, wrf writewch) /* writes an atom */
|
|||||||
if (lastw == atom_or_symbol && atom_or_symbol != separator /* solo */)
|
if (lastw == atom_or_symbol && atom_or_symbol != separator /* solo */)
|
||||||
wrputc(' ', writewch);
|
wrputc(' ', writewch);
|
||||||
lastw = atom_or_symbol;
|
lastw = atom_or_symbol;
|
||||||
if (!legalAtom(s) && Quote_illegal) {
|
if (Quote_illegal && !legalAtom(s)) {
|
||||||
wrputc('\'', writewch);
|
wrputc('\'', writewch);
|
||||||
while (*s) {
|
while (*s) {
|
||||||
wchar_t ch = *s++;
|
wchar_t ch = *s++;
|
||||||
@ -738,6 +739,38 @@ writeTerm(Term t, int p, int depth, int rinfixarg, struct write_globs *wglb, str
|
|||||||
} else if (IsAtomTerm(t)) {
|
} else if (IsAtomTerm(t)) {
|
||||||
putAtom(AtomOfTerm(t), wglb->Quote_illegal, wglb->writewch);
|
putAtom(AtomOfTerm(t), wglb->Quote_illegal, wglb->writewch);
|
||||||
} else if (IsPairTerm(t)) {
|
} else if (IsPairTerm(t)) {
|
||||||
|
if (wglb->Ignore_ops) {
|
||||||
|
Int sl = 0;
|
||||||
|
|
||||||
|
wrputs("'.'(",wglb->writewch);
|
||||||
|
lastw = separator;
|
||||||
|
if (wglb->keep_terms) {
|
||||||
|
/* garbage collection may be called */
|
||||||
|
sl = Yap_InitSlot(t);
|
||||||
|
}
|
||||||
|
writeTerm(HeadOfTerm(t), 999, depth + 1, FALSE, wglb, &nrwt);
|
||||||
|
restore_from_write(&nrwt, wglb);
|
||||||
|
if (wglb->keep_terms) {
|
||||||
|
/* garbage collection may be called */
|
||||||
|
t = Yap_GetFromSlot(sl);
|
||||||
|
Yap_RecoverSlots(1);
|
||||||
|
}
|
||||||
|
wrputs(",",wglb->writewch);
|
||||||
|
if (wglb->keep_terms) {
|
||||||
|
/* garbage collection may be called */
|
||||||
|
sl = Yap_InitSlot(t);
|
||||||
|
}
|
||||||
|
writeTerm(TailOfTerm(t), 999, depth + 1, FALSE, wglb, &nrwt);
|
||||||
|
restore_from_write(&nrwt, wglb);
|
||||||
|
if (wglb->keep_terms) {
|
||||||
|
/* garbage collection may be called */
|
||||||
|
t = Yap_GetFromSlot(sl);
|
||||||
|
Yap_RecoverSlots(1);
|
||||||
|
}
|
||||||
|
wrputc(')', wglb->writewch);
|
||||||
|
lastw = separator;
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (wglb->Use_portray) {
|
if (wglb->Use_portray) {
|
||||||
Term targs[1];
|
Term targs[1];
|
||||||
struct DB_TERM *old_EX = NULL;
|
struct DB_TERM *old_EX = NULL;
|
||||||
|
@ -344,10 +344,12 @@ setCurrentSourceLocation(IOSTREAM *s ARG_LD)
|
|||||||
|
|
||||||
#if __YAP_PROLOG__
|
#if __YAP_PROLOG__
|
||||||
void
|
void
|
||||||
Yap_setCurrentSourceLocation(IOSTREAM *s)
|
Yap_setCurrentSourceLocation(IOSTREAM **s)
|
||||||
{
|
{
|
||||||
GET_LD
|
GET_LD
|
||||||
setCurrentSourceLocation(s PASS_LD);
|
if (!*s)
|
||||||
|
*s = Suser_input;
|
||||||
|
setCurrentSourceLocation(*s PASS_LD);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1096,6 +1096,26 @@ pl_readline(term_t flag)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Term
|
||||||
|
StreamPosition(IOSTREAM *st)
|
||||||
|
{
|
||||||
|
Term t[4];
|
||||||
|
if (!st)
|
||||||
|
st = Suser_input;
|
||||||
|
t[0] = MkIntegerTerm(st->posbuf.charno);
|
||||||
|
t[1] = MkIntegerTerm(st->posbuf.lineno);
|
||||||
|
t[2] = MkIntegerTerm(st->posbuf.linepos);
|
||||||
|
t[3] = MkIntegerTerm(st->posbuf.byteno);
|
||||||
|
return Yap_MkApplTerm(FunctorStreamPos,4,t);
|
||||||
|
}
|
||||||
|
|
||||||
|
Term
|
||||||
|
Yap_StreamPosition(IOSTREAM *st)
|
||||||
|
{
|
||||||
|
return StreamPosition(st);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#if THREADS
|
#if THREADS
|
||||||
|
|
||||||
#define COUNT_MUTEX_INITIALIZER(name) \
|
#define COUNT_MUTEX_INITIALIZER(name) \
|
||||||
|
Reference in New Issue
Block a user