warnings and stream read wchar simplification
This commit is contained in:
parent
a82a72fc14
commit
304489c74f
@ -982,8 +982,7 @@ static Int doformat(volatile Term otail, volatile Term oargs,
|
|||||||
goto do_format_control_sequence_error;
|
goto do_format_control_sequence_error;
|
||||||
t = targs[targ++];
|
t = targs[targ++];
|
||||||
yhandle_t slf = Yap_StartSlots();
|
yhandle_t slf = Yap_StartSlots();
|
||||||
Yap_plwrite(t, GLOBAL_Stream + sno, 0,
|
Yap_plwrite(t, GLOBAL_Stream + sno, 0, Handle_vars_f | To_heap_f,
|
||||||
Handle_vars_f | To_heap_f,
|
|
||||||
GLOBAL_MaxPriority);
|
GLOBAL_MaxPriority);
|
||||||
Yap_CloseSlots(slf);
|
Yap_CloseSlots(slf);
|
||||||
break;
|
break;
|
||||||
@ -1200,7 +1199,7 @@ static Int with_output_to(USES_REGS1) {
|
|||||||
Term tin = Deref(ARG1);
|
Term tin = Deref(ARG1);
|
||||||
Functor f;
|
Functor f;
|
||||||
bool out;
|
bool out;
|
||||||
bool mem_stream = false;
|
bool my_mem_stream;
|
||||||
yhandle_t hdl = Yap_PushHandle(tin);
|
yhandle_t hdl = Yap_PushHandle(tin);
|
||||||
if (IsVarTerm(tin)) {
|
if (IsVarTerm(tin)) {
|
||||||
Yap_Error(INSTANTIATION_ERROR, tin, "with_output_to/3");
|
Yap_Error(INSTANTIATION_ERROR, tin, "with_output_to/3");
|
||||||
@ -1215,6 +1214,7 @@ static Int with_output_to(USES_REGS1) {
|
|||||||
/* needs to change LOCAL_c_output_stream for write */
|
/* needs to change LOCAL_c_output_stream for write */
|
||||||
output_stream = Yap_CheckStream(ARG1, Output_Stream_f, "format/3");
|
output_stream = Yap_CheckStream(ARG1, Output_Stream_f, "format/3");
|
||||||
my_mem_stream = false;
|
my_mem_stream = false;
|
||||||
|
f = NIL;
|
||||||
}
|
}
|
||||||
if (output_stream == -1) {
|
if (output_stream == -1) {
|
||||||
return false;
|
return false;
|
||||||
@ -1223,7 +1223,7 @@ static Int with_output_to(USES_REGS1) {
|
|||||||
out = Yap_Execute(Deref(ARG2) PASS_REGS);
|
out = Yap_Execute(Deref(ARG2) PASS_REGS);
|
||||||
LOCK(GLOBAL_Stream[output_stream].streamlock);
|
LOCK(GLOBAL_Stream[output_stream].streamlock);
|
||||||
LOCAL_c_output_stream = old_out;
|
LOCAL_c_output_stream = old_out;
|
||||||
if (mem_stream) {
|
if (my_mem_stream) {
|
||||||
Term tat;
|
Term tat;
|
||||||
Term inp = Yap_GetFromHandle(hdl);
|
Term inp = Yap_GetFromHandle(hdl);
|
||||||
if (out) {
|
if (out) {
|
||||||
|
100
os/getw.h
100
os/getw.h
@ -2,9 +2,9 @@
|
|||||||
/// compose a wide char from a sequence of getchars
|
/// compose a wide char from a sequence of getchars
|
||||||
/// this is a slow lane routine, called if no specialised code
|
/// this is a slow lane routine, called if no specialised code
|
||||||
/// isavailable.
|
/// isavailable.
|
||||||
static int GETW(int sno) {
|
extern int get_wchar(int sno) {
|
||||||
StreamDesc *st = GLOBAL_Stream + sno;
|
StreamDesc *st = GLOBAL_Stream + sno;
|
||||||
int ch = GETC();
|
int ch = st->stream_getc(sno);
|
||||||
|
|
||||||
if (ch == -1)
|
if (ch == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
@ -31,7 +31,7 @@ static int GETW(int sno) {
|
|||||||
buf[0] = ch;
|
buf[0] = ch;
|
||||||
int n = 1;
|
int n = 1;
|
||||||
while ((out = mbrtowc(&wch, buf, 1, &(mbstate))) != 1) {
|
while ((out = mbrtowc(&wch, buf, 1, &(mbstate))) != 1) {
|
||||||
int ch = buf[0] = GETC();
|
int ch = buf[0] = st->stream_getc(sno);
|
||||||
n++;
|
n++;
|
||||||
if (ch == -1)
|
if (ch == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
@ -49,7 +49,7 @@ static int GETW(int sno) {
|
|||||||
// if ((ch - 0xc2) > (0xf4-0xc2)) return UTF8PROC_ERROR_INVALIDUTF8;
|
// if ((ch - 0xc2) > (0xf4-0xc2)) return UTF8PROC_ERROR_INVALIDUTF8;
|
||||||
if (ch < 0xe0) { // 2-byte sequence
|
if (ch < 0xe0) { // 2-byte sequence
|
||||||
// Must have valid continuation character
|
// Must have valid continuation character
|
||||||
int c1 = buf[0] = GETC();
|
int c1 = buf[0] = st->stream_getc(sno);
|
||||||
if (c1 == -1)
|
if (c1 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
// if (!utf_cont(*str)) return UTF8PROC_ERROR_INVALIDUTF8;
|
// if (!utf_cont(*str)) return UTF8PROC_ERROR_INVALIDUTF8;
|
||||||
@ -62,22 +62,22 @@ static int GETW(int sno) {
|
|||||||
// Check for surrogate chars
|
// Check for surrogate chars
|
||||||
// if (ch == 0xed && *str > 0x9f)
|
// if (ch == 0xed && *str > 0x9f)
|
||||||
// return UTF8PROC_ERROR_INVALIDUTF8;
|
// return UTF8PROC_ERROR_INVALIDUTF8;
|
||||||
int c1 = GETC();
|
int c1 = st->stream_getc(sno);
|
||||||
if (c1 == -1)
|
if (c1 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
int c2 = GETC();
|
int c2 = st->stream_getc(sno);
|
||||||
if (c2 == -1)
|
if (c2 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
wch = ((ch & 0xf) << 12) | ((c1 & 0x3f) << 6) | (c2 & 0x3f);
|
wch = ((ch & 0xf) << 12) | ((c1 & 0x3f) << 6) | (c2 & 0x3f);
|
||||||
return post_process_read_wchar(wch, 3, st);
|
return post_process_read_wchar(wch, 3, st);
|
||||||
} else {
|
} else {
|
||||||
int c1 = GETC();
|
int c1 = st->stream_getc(sno);
|
||||||
if (c1 == -1)
|
if (c1 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
int c2 = GETC();
|
int c2 = st->stream_getc(sno);
|
||||||
if (c2 == -1)
|
if (c2 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
int c3 = GETC();
|
int c3 = st->stream_getc(sno);
|
||||||
if (c3 == -1)
|
if (c3 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
wch = ((ch & 7) << 18) | ((c1 & 0x3f) << 12) | ((c2 & 0x3f) << 6) |
|
wch = ((ch & 7) << 18) | ((c1 & 0x3f) << 12) | ((c2 & 0x3f) << 6) |
|
||||||
@ -89,15 +89,15 @@ static int GETW(int sno) {
|
|||||||
// little-endian: start with big shot
|
// little-endian: start with big shot
|
||||||
{
|
{
|
||||||
int wch;
|
int wch;
|
||||||
int c1 = GETC();
|
int c1 = st->stream_getc(sno);
|
||||||
if (c1 == -1)
|
if (c1 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
wch = (c1 << 8) + ch;
|
wch = (c1 << 8) + ch;
|
||||||
if (wch >= 0xd800 && wch < 0xdc00) {
|
if (wch >= 0xd800 && wch < 0xdc00) {
|
||||||
int c2 = GETC();
|
int c2 = st->stream_getc(sno);
|
||||||
if (c2 == -1)
|
if (c2 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
int c3 = GETC();
|
int c3 = st->stream_getc(sno);
|
||||||
if (c3 == -1)
|
if (c3 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
wch = wch + (((c3 << 8) + c2) << wch) + SURROGATE_OFFSET;
|
wch = wch + (((c3 << 8) + c2) << wch) + SURROGATE_OFFSET;
|
||||||
@ -110,15 +110,15 @@ static int GETW(int sno) {
|
|||||||
// little-endian: start with big shot
|
// little-endian: start with big shot
|
||||||
{
|
{
|
||||||
int wch;
|
int wch;
|
||||||
int c1 = GETC();
|
int c1 = st->stream_getc(sno);
|
||||||
if (c1 == -1)
|
if (c1 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
wch = (c1) + (ch << 8);
|
wch = (c1) + (ch << 8);
|
||||||
if (wch >= 0xd800 && wch < 0xdc00) {
|
if (wch >= 0xd800 && wch < 0xdc00) {
|
||||||
int c3 = GETC();
|
int c3 = st->stream_getc(sno);
|
||||||
if (c3 == -1)
|
if (c3 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
int c2 = GETC();
|
int c2 = st->stream_getc(sno);
|
||||||
if (c2 == -1)
|
if (c2 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
wch = (((c3 << 8) + c2) << 10) + wch + SURROGATE_OFFSET;
|
wch = (((c3 << 8) + c2) << 10) + wch + SURROGATE_OFFSET;
|
||||||
@ -131,7 +131,7 @@ static int GETW(int sno) {
|
|||||||
// little-endian: start with big shot
|
// little-endian: start with big shot
|
||||||
{
|
{
|
||||||
int wch;
|
int wch;
|
||||||
int c1 = GETC();
|
int c1 = st->stream_getc(sno);
|
||||||
if (c1 == -1)
|
if (c1 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
wch = (c1) + (ch << 8);
|
wch = (c1) + (ch << 8);
|
||||||
@ -142,7 +142,7 @@ static int GETW(int sno) {
|
|||||||
// little-endian: start with big shot
|
// little-endian: start with big shot
|
||||||
{
|
{
|
||||||
int wch;
|
int wch;
|
||||||
int c1 = GETC();
|
int c1 = st->stream_getc(sno);
|
||||||
if (c1 == -1)
|
if (c1 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
wch = (c1 << 8) + ch;
|
wch = (c1 << 8) + ch;
|
||||||
@ -155,19 +155,19 @@ static int GETW(int sno) {
|
|||||||
{
|
{
|
||||||
int wch = ch;
|
int wch = ch;
|
||||||
{
|
{
|
||||||
int c1 = GETC();
|
int c1 = st->stream_getc(sno);
|
||||||
if (c1 == -1)
|
if (c1 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
wch = wch + c1;
|
wch = wch + c1;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
int c1 = GETC();
|
int c1 = st->stream_getc(sno);
|
||||||
if (c1 == -1)
|
if (c1 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
wch = (wch << 8) + c1;
|
wch = (wch << 8) + c1;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
int c1 = GETC();
|
int c1 = st->stream_getc(sno);
|
||||||
if (c1 == -1)
|
if (c1 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
wch = (wch << 8) + c1;
|
wch = (wch << 8) + c1;
|
||||||
@ -179,19 +179,19 @@ static int GETW(int sno) {
|
|||||||
{
|
{
|
||||||
int wch = ch;
|
int wch = ch;
|
||||||
{
|
{
|
||||||
int c1 = GETC();
|
int c1 = st->stream_getc(sno);
|
||||||
if (c1 == -1)
|
if (c1 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
wch += c1 << 8;
|
wch += c1 << 8;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
int c1 = GETC();
|
int c1 = st->stream_getc(sno);
|
||||||
if (c1 == -1)
|
if (c1 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
wch += c1 << 16;
|
wch += c1 << 16;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
int c1 = GETC();
|
int c1 = st->stream_getc(sno);
|
||||||
if (c1 == -1)
|
if (c1 == -1)
|
||||||
return post_process_weof(st);
|
return post_process_weof(st);
|
||||||
wch += c1 << 24;
|
wch += c1 << 24;
|
||||||
@ -204,3 +204,57 @@ static int GETW(int sno) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int get_wchar_UTF8(int sno) {
|
||||||
|
StreamDesc *st = GLOBAL_Stream + sno;
|
||||||
|
int ch = st->stream_getc(sno);
|
||||||
|
|
||||||
|
if (ch == -1)
|
||||||
|
return post_process_weof(st);
|
||||||
|
else {
|
||||||
|
int wch;
|
||||||
|
unsigned char buf[8];
|
||||||
|
|
||||||
|
if (ch < 0x80) {
|
||||||
|
return post_process_read_wchar(ch, 1, st);
|
||||||
|
}
|
||||||
|
// if ((ch - 0xc2) > (0xf4-0xc2)) return UTF8PROC_ERROR_INVALIDUTF8;
|
||||||
|
if (ch < 0xe0) { // 2-byte sequence
|
||||||
|
// Must have valid continuation character
|
||||||
|
int c1 = buf[0] = st->stream_getc(sno);
|
||||||
|
if (c1 == -1)
|
||||||
|
return post_process_weof(st);
|
||||||
|
// if (!utf_cont(*str)) return UTF8PROC_ERROR_INVALIDUTF8;
|
||||||
|
wch = ((ch & 0x1f) << 6) | (c1 & 0x3f);
|
||||||
|
return post_process_read_wchar(wch, 2, st);
|
||||||
|
}
|
||||||
|
if (ch < 0xf0) { // 3-byte sequence
|
||||||
|
// if ((str + 1 >= end) || !utf_cont(*str) || !utf_cont(str[1]))
|
||||||
|
// return UTF8PROC_ERROR_INVALIDUTF8;
|
||||||
|
// Check for surrogate chars
|
||||||
|
// if (ch == 0xed && *str > 0x9f)
|
||||||
|
// return UTF8PROC_ERROR_INVALIDUTF8;
|
||||||
|
int c1 = st->stream_getc(sno);
|
||||||
|
if (c1 == -1)
|
||||||
|
return post_process_weof(st);
|
||||||
|
int c2 = st->stream_getc(sno);
|
||||||
|
if (c2 == -1)
|
||||||
|
return post_process_weof(st);
|
||||||
|
wch = ((ch & 0xf) << 12) | ((c1 & 0x3f) << 6) | (c2 & 0x3f);
|
||||||
|
return post_process_read_wchar(wch, 3, st);
|
||||||
|
} else {
|
||||||
|
int c1 = st->stream_getc(sno);
|
||||||
|
if (c1 == -1)
|
||||||
|
return post_process_weof(st);
|
||||||
|
int c2 = st->stream_getc(sno);
|
||||||
|
if (c2 == -1)
|
||||||
|
return post_process_weof(st);
|
||||||
|
int c3 = st->stream_getc(sno);
|
||||||
|
if (c3 == -1)
|
||||||
|
return post_process_weof(st);
|
||||||
|
wch = ((ch & 7) << 18) | ((c1 & 0x3f) << 12) | ((c2 & 0x3f) << 6) |
|
||||||
|
(c3 & 0x3f);
|
||||||
|
return post_process_read_wchar(wch, 4, st);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
20
os/iopreds.c
20
os/iopreds.c
@ -97,16 +97,9 @@ static char SccsId[] = "%W% %G%";
|
|||||||
#define S_ISDIR(x) (((x)&_S_IFDIR) == _S_IFDIR)
|
#define S_ISDIR(x) (((x)&_S_IFDIR) == _S_IFDIR)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#include "iopreds.h"
|
|
||||||
//#define GETW get_wchar_from_FILE
|
|
||||||
//#endif
|
|
||||||
#define GETC() fgetwc(st->file)
|
|
||||||
#include "getw.h"
|
|
||||||
|
|
||||||
#undef GETW
|
#include "iopreds.h"
|
||||||
#undef GETC
|
|
||||||
#define GETW get_wchar
|
|
||||||
#define GETC() st->stream_getc(sno)
|
|
||||||
#include "getw.h"
|
#include "getw.h"
|
||||||
|
|
||||||
static int get_wchar_from_file(int);
|
static int get_wchar_from_file(int);
|
||||||
@ -254,7 +247,7 @@ static void unix_upd_stream_info(StreamDesc *s) {
|
|||||||
void Yap_DefaultStreamOps(StreamDesc *st) {
|
void Yap_DefaultStreamOps(StreamDesc *st) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
st->stream_wputc = put_wchar;
|
st->stream_wputc = put_wchar;
|
||||||
st->stream_wgetc = get_wchar;
|
st->stream_wgetc = get_wchar_UTF8;
|
||||||
st->stream_putc = FilePutc;
|
st->stream_putc = FilePutc;
|
||||||
st->stream_getc = PlGetc;
|
st->stream_getc = PlGetc;
|
||||||
if (st->status & (Promptable_Stream_f)) {
|
if (st->status & (Promptable_Stream_f)) {
|
||||||
@ -664,10 +657,9 @@ int PlGetc(int sno) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// layered version
|
// layered version
|
||||||
static int get_wchar__(int sno) { return fgetwc(GLOBAL_Stream[sno].file); }
|
static inline int get_wchar_from_file(int sno) {
|
||||||
|
return post_process_read_wchar(fgetwc(GLOBAL_Stream[sno].file), 1,
|
||||||
static int get_wchar_from_file(int sno) {
|
GLOBAL_Stream + sno);
|
||||||
return post_process_read_wchar(get_wchar__(sno), 1, GLOBAL_Stream + sno);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef MB_LEN_MAX
|
#ifndef MB_LEN_MAX
|
||||||
|
@ -264,58 +264,76 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod) {
|
|||||||
t0[0] = TermNil;
|
t0[0] = TermNil;
|
||||||
}
|
}
|
||||||
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0);
|
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0);
|
||||||
} break;
|
}
|
||||||
case QuasiQuotes_tok: {
|
break;
|
||||||
|
case QuasiQuotes_tok:
|
||||||
|
{
|
||||||
Term t0[2];
|
Term t0[2];
|
||||||
t0[0] = MkAtomTerm(Yap_LookupAtom("<QQ>"));
|
t0[0] = MkAtomTerm(Yap_LookupAtom("<QQ>"));
|
||||||
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0);
|
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0);
|
||||||
} break;
|
}
|
||||||
case WQuasiQuotes_tok: {
|
break;
|
||||||
|
case WQuasiQuotes_tok:
|
||||||
|
{
|
||||||
Term t0[2];
|
Term t0[2];
|
||||||
t0[0] = MkAtomTerm(Yap_LookupAtom("<WideQQ>"));
|
t0[0] = MkAtomTerm(Yap_LookupAtom("<WideQQ>"));
|
||||||
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0);
|
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0);
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
case Number_tok:
|
case Number_tok:
|
||||||
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomNumber, 1), 1, &(tok->TokInfo));
|
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomNumber, 1), 1, &(tok->TokInfo));
|
||||||
break;
|
break;
|
||||||
case Var_tok: {
|
case Var_tok:
|
||||||
|
{
|
||||||
Term t[2];
|
Term t[2];
|
||||||
VarEntry *varinfo = (VarEntry *)info;
|
VarEntry *varinfo = (VarEntry *)info;
|
||||||
|
|
||||||
t[0] = MkIntTerm(0);
|
t[0] = MkIntTerm(0);
|
||||||
t[1] = Yap_CharsToString(varinfo->VarRep, ENC_ISO_LATIN1 PASS_REGS);
|
t[1] = Yap_CharsToString(varinfo->VarRep, ENC_ISO_LATIN1 PASS_REGS);
|
||||||
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomGVar, 2), 2, t);
|
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomGVar, 2), 2, t);
|
||||||
} break;
|
}
|
||||||
case String_tok: {
|
break;
|
||||||
|
case String_tok:
|
||||||
|
{
|
||||||
Term t0 = Yap_CharsToTDQ((char *)info, cmod, ENC_ISO_LATIN1 PASS_REGS);
|
Term t0 = Yap_CharsToTDQ((char *)info, cmod, ENC_ISO_LATIN1 PASS_REGS);
|
||||||
if (!t0) {
|
if (!t0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
|
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
|
||||||
} break;
|
}
|
||||||
case WString_tok: {
|
break;
|
||||||
|
case WString_tok:
|
||||||
|
{
|
||||||
Term t0 = Yap_WCharsToTDQ((wchar_t *)info, cmod PASS_REGS);
|
Term t0 = Yap_WCharsToTDQ((wchar_t *)info, cmod PASS_REGS);
|
||||||
if (!t0)
|
if (!t0)
|
||||||
return 0;
|
return 0;
|
||||||
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
|
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
|
||||||
} break;
|
}
|
||||||
case BQString_tok: {
|
break;
|
||||||
|
case BQString_tok:
|
||||||
|
{
|
||||||
Term t0 = Yap_CharsToTBQ((char *)info, cmod, ENC_ISO_LATIN1 PASS_REGS);
|
Term t0 = Yap_CharsToTBQ((char *)info, cmod, ENC_ISO_LATIN1 PASS_REGS);
|
||||||
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
|
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
|
||||||
} break;
|
}
|
||||||
case WBQString_tok: {
|
break;
|
||||||
|
case WBQString_tok:
|
||||||
|
{
|
||||||
Term t0 = Yap_WCharsToTBQ((wchar_t *)info, cmod PASS_REGS);
|
Term t0 = Yap_WCharsToTBQ((wchar_t *)info, cmod PASS_REGS);
|
||||||
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
|
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
|
||||||
} break;
|
}
|
||||||
case Error_tok: {
|
break;
|
||||||
|
case Error_tok:
|
||||||
|
{
|
||||||
ts[0] = MkAtomTerm(AtomError);
|
ts[0] = MkAtomTerm(AtomError);
|
||||||
} break;
|
}
|
||||||
|
break;
|
||||||
case eot_tok:
|
case eot_tok:
|
||||||
endline = MkIntegerTerm(tok->TokPos);
|
endline = MkIntegerTerm(tok->TokPos);
|
||||||
ts[0] = MkAtomTerm(Yap_LookupAtom("EOT"));
|
ts[0] = MkAtomTerm(Yap_LookupAtom("EOT"));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case Ponctuation_tok: {
|
case Ponctuation_tok:
|
||||||
|
{
|
||||||
char s[2];
|
char s[2];
|
||||||
s[1] = '\0';
|
s[1] = '\0';
|
||||||
if ((info) == 'l') {
|
if ((info) == 'l') {
|
||||||
@ -326,9 +344,13 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod) {
|
|||||||
ts[0] = MkAtomTerm(Yap_LookupAtom(s));
|
ts[0] = MkAtomTerm(Yap_LookupAtom(s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (tok->TokNext) {
|
||||||
tok = tok->TokNext;
|
tok = tok->TokNext;
|
||||||
if (!tok)
|
} else {
|
||||||
|
endline = MkIntegerTerm(tok->TokPos);
|
||||||
|
tok = NULL;
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
*tailp = MkPairTerm(ts[0], TermNil);
|
*tailp = MkPairTerm(ts[0], TermNil);
|
||||||
tailp = RepPair(*tailp) + 1;
|
tailp = RepPair(*tailp) + 1;
|
||||||
}
|
}
|
||||||
@ -939,7 +961,8 @@ Term Yap_read_term(int inp_stream, Term opts, int nargs) {
|
|||||||
case YAP_PARSING_ERROR:
|
case YAP_PARSING_ERROR:
|
||||||
state = parseError(&re, &fe, inp_stream);
|
state = parseError(&re, &fe, inp_stream);
|
||||||
break;
|
break;
|
||||||
case YAP_PARSING_FINISHED: {
|
case YAP_PARSING_FINISHED:
|
||||||
|
{
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
bool done;
|
bool done;
|
||||||
if (fe.reading_clause)
|
if (fe.reading_clause)
|
||||||
@ -1294,7 +1317,6 @@ X_API Term Yap_StringToTerm(const char *s, size_t len, encoding_t *encp,
|
|||||||
return rval;
|
return rval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @pred read_term_from_atom( +_Atom_ , - _T_ , + _Options_
|
* @pred read_term_from_atom( +_Atom_ , - _T_ , + _Options_
|
||||||
*
|
*
|
||||||
@ -1397,8 +1419,7 @@ static Int string_to_term(USES_REGS1) {
|
|||||||
len = strlen_utf8((const unsigned char *)s);
|
len = strlen_utf8((const unsigned char *)s);
|
||||||
}
|
}
|
||||||
encoding_t enc = ENC_ISO_UTF8;
|
encoding_t enc = ENC_ISO_UTF8;
|
||||||
rc = Yap_StringToTerm(s, len, &enc,
|
rc = Yap_StringToTerm(s, len, &enc, 1200, &ARG3);
|
||||||
1200, &ARG3);
|
|
||||||
if (!rc)
|
if (!rc)
|
||||||
return false;
|
return false;
|
||||||
return Yap_unify(rc, ARG2);
|
return Yap_unify(rc, ARG2);
|
||||||
@ -1420,8 +1441,7 @@ static Int atomic_to_term(USES_REGS1) {
|
|||||||
len = strlen_utf8((unsigned char *)s);
|
len = strlen_utf8((unsigned char *)s);
|
||||||
}
|
}
|
||||||
encoding_t enc = ENC_ISO_UTF8;
|
encoding_t enc = ENC_ISO_UTF8;
|
||||||
rc = Yap_StringToTerm(s, len, &enc,
|
rc = Yap_StringToTerm(s, len, &enc, 1200, &ARG3);
|
||||||
1200, &ARG3);
|
|
||||||
if (!rc)
|
if (!rc)
|
||||||
return false;
|
return false;
|
||||||
return Yap_unify(rc, ARG2);
|
return Yap_unify(rc, ARG2);
|
||||||
@ -1443,8 +1463,7 @@ static Int atom_to_term(USES_REGS1) {
|
|||||||
len = strlen_utf8((const unsigned char *)s);
|
len = strlen_utf8((const unsigned char *)s);
|
||||||
}
|
}
|
||||||
encoding_t enc = ENC_ISO_UTF8;
|
encoding_t enc = ENC_ISO_UTF8;
|
||||||
rc = Yap_StringToTerm(s, len, &enc,
|
rc = Yap_StringToTerm(s, len, &enc, 1200, &ARG3);
|
||||||
1200, &ARG3);
|
|
||||||
if (!rc)
|
if (!rc)
|
||||||
return false;
|
return false;
|
||||||
return Yap_unify(rc, ARG2);
|
return Yap_unify(rc, ARG2);
|
||||||
|
@ -248,11 +248,12 @@ has_reposition(int sno,
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *Yap_guessFileName(FILE *file, int sno, char *nameb, size_t max) {
|
char *Yap_guessFileName(FILE *file, int sno, char *nameb, size_t max) {
|
||||||
|
size_t maxs = max(255, max);
|
||||||
if (!nameb) {
|
if (!nameb) {
|
||||||
nameb = malloc(max(256, max));
|
nameb = malloc(maxs + 1);
|
||||||
}
|
}
|
||||||
if (!file) {
|
if (!file) {
|
||||||
strcpy(nameb, "memory buffer");
|
strncpy(nameb, "memory buffer", maxs);
|
||||||
return nameb;
|
return nameb;
|
||||||
}
|
}
|
||||||
int f = fileno(file);
|
int f = fileno(file);
|
||||||
@ -275,7 +276,7 @@ char *Yap_guessFileName(FILE *file, int sno, char *nameb, size_t max) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
else {
|
else {
|
||||||
int i;
|
int i;
|
||||||
unsigned char *ptr = nameb;
|
unsigned char *ptr = (unsigned char *)nameb;
|
||||||
for (i = 0; i < strlen(path); i++)
|
for (i = 0; i < strlen(path); i++)
|
||||||
ptr += put_utf8(ptr, path[i]);
|
ptr += put_utf8(ptr, path[i]);
|
||||||
*ptr = '\0';
|
*ptr = '\0';
|
||||||
|
@ -1181,7 +1181,7 @@ const char *Yap_findFile(const char *isource, const char *idef,
|
|||||||
YAP_file_type_t ftype, bool expand_root, bool in_lib) {
|
YAP_file_type_t ftype, bool expand_root, bool in_lib) {
|
||||||
|
|
||||||
char *save_buffer = NULL;
|
char *save_buffer = NULL;
|
||||||
const char *root, *source = isource;
|
const char *root = iroot, *source = isource;
|
||||||
int rc = FAIL_RESTORE;
|
int rc = FAIL_RESTORE;
|
||||||
int try
|
int try
|
||||||
= 0;
|
= 0;
|
||||||
|
Reference in New Issue
Block a user