Merge 192.168.1.103:github/YAPDroid/app/src/yap
This commit is contained in:
commit
b645f60405
@ -209,8 +209,8 @@ bool YAP_get_blob(Term t, void **blob, size_t *len, blob_type_t **type) {
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *YAP_blob_data(Atom x, size_t *len, blob_type_t **type) {
|
void *YAP_blob_data(YAP_Atom at, size_t *len, blob_type_t **type) {
|
||||||
|
Atom x = at;
|
||||||
if (!IsBlob(x)) {
|
if (!IsBlob(x)) {
|
||||||
|
|
||||||
if (len)
|
if (len)
|
||||||
|
2032
C/c_interface.c
2032
C/c_interface.c
File diff suppressed because it is too large
Load Diff
@ -4911,17 +4911,17 @@ static Int cont_current_key_integer(USES_REGS1) {
|
|||||||
return Yap_unify(term, ARG1) && Yap_unify(term, ARG2);
|
return Yap_unify(term, ARG1) && Yap_unify(term, ARG2);
|
||||||
}
|
}
|
||||||
|
|
||||||
Term Yap_FetchTermFromDB(DBTerm *ref) {
|
Term Yap_FetchTermFromDB(void *ref) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
return GetDBTerm(ref, FALSE PASS_REGS);
|
return GetDBTerm(ref, FALSE PASS_REGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
Term Yap_FetchClauseTermFromDB(DBTerm *ref) {
|
Term Yap_FetchClauseTermFromDB(void *ref) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
return GetDBTerm(ref, TRUE PASS_REGS);
|
return GetDBTerm(ref, TRUE PASS_REGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
Term Yap_PopTermFromDB(DBTerm *ref) {
|
Term Yap_PopTermFromDB(void *ref) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
|
||||||
Term t = GetDBTerm(ref, FALSE PASS_REGS);
|
Term t = GetDBTerm(ref, FALSE PASS_REGS);
|
||||||
@ -5304,7 +5304,7 @@ static void ReleaseTermFromDB(DBTerm *ref USES_REGS) {
|
|||||||
FreeDBSpace((char *)ref);
|
FreeDBSpace((char *)ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Yap_ReleaseTermFromDB(DBTerm *ref) {
|
void Yap_ReleaseTermFromDB(void *ref) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
ReleaseTermFromDB(ref PASS_REGS);
|
ReleaseTermFromDB(ref PASS_REGS);
|
||||||
}
|
}
|
||||||
|
@ -386,10 +386,10 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
|
|||||||
Yap_RestartYap(1);
|
Yap_RestartYap(1);
|
||||||
}
|
}
|
||||||
LOCAL_ActiveError->errorNo = type;
|
LOCAL_ActiveError->errorNo = type;
|
||||||
LOCAL_ActiveError->errorAsText = Yap_LookupAtom(Yap_errorName(type));
|
LOCAL_ActiveError->errorAsText = Yap_errorName(type);
|
||||||
LOCAL_ActiveError->errorClass = Yap_errorClass(type);
|
LOCAL_ActiveError->errorClass = Yap_errorClass(type);
|
||||||
LOCAL_ActiveError->classAsText =
|
LOCAL_ActiveError->classAsText =
|
||||||
Yap_LookupAtom(Yap_errorClassName(LOCAL_ActiveError->errorClass));
|
Yap_errorClassName(LOCAL_ActiveError->errorClass);
|
||||||
LOCAL_ActiveError->errorLine = lineno;
|
LOCAL_ActiveError->errorLine = lineno;
|
||||||
LOCAL_ActiveError->errorFunction = function;
|
LOCAL_ActiveError->errorFunction = function;
|
||||||
LOCAL_ActiveError->errorFile = file;
|
LOCAL_ActiveError->errorFile = file;
|
||||||
|
6
C/exec.c
6
C/exec.c
@ -2039,10 +2039,10 @@ static Int jump_env(USES_REGS1) {
|
|||||||
// LOCAL_Error_TYPE = ERROR_EVENT;
|
// LOCAL_Error_TYPE = ERROR_EVENT;
|
||||||
Term t1 = ArgOfTerm(1, t);
|
Term t1 = ArgOfTerm(1, t);
|
||||||
if (IsApplTerm(t1) && IsAtomTerm((t2 = ArgOfTerm(1, t1)))) {
|
if (IsApplTerm(t1) && IsAtomTerm((t2 = ArgOfTerm(1, t1)))) {
|
||||||
LOCAL_ActiveError->errorAsText = AtomOfTerm(t2);
|
LOCAL_ActiveError->errorAsText = RepAtom(AtomOfTerm(t2))->StrOfAE;
|
||||||
LOCAL_ActiveError->classAsText = NameOfFunctor(FunctorOfTerm(t1));
|
LOCAL_ActiveError->classAsText = RepAtom(NameOfFunctor(FunctorOfTerm(t1)))->StrOfAE;
|
||||||
} else if (IsAtomTerm(t)) {
|
} else if (IsAtomTerm(t)) {
|
||||||
LOCAL_ActiveError->errorAsText = AtomOfTerm(t1);
|
LOCAL_ActiveError->errorAsText = RepAtom(AtomOfTerm(t1))->StrOfAE;
|
||||||
LOCAL_ActiveError->classAsText = NULL;
|
LOCAL_ActiveError->classAsText = NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
229
C/scanner.c
229
C/scanner.c
@ -689,12 +689,12 @@ static int send_error_message(char s[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static wchar_t read_quoted_char(int *scan_nextp,
|
static wchar_t read_quoted_char(int *scan_nextp,
|
||||||
struct stream_desc *inp_stream) {
|
struct stream_desc *st) {
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
/* escape sequence */
|
/* escape sequence */
|
||||||
do_switch:
|
do_switch:
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 10:
|
case 10:
|
||||||
return 0;
|
return 0;
|
||||||
@ -705,7 +705,7 @@ do_switch:
|
|||||||
case 'b':
|
case 'b':
|
||||||
return '\b';
|
return '\b';
|
||||||
case 'c':
|
case 'c':
|
||||||
while (chtype((ch = getchrq(inp_stream))) == BS)
|
while (chtype((ch = getchrq(st))) == BS)
|
||||||
;
|
;
|
||||||
{
|
{
|
||||||
if (ch == '\\') {
|
if (ch == '\\') {
|
||||||
@ -732,7 +732,7 @@ do_switch:
|
|||||||
wchar_t wc = '\0';
|
wchar_t wc = '\0';
|
||||||
|
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (ch >= '0' && ch <= '9') {
|
if (ch >= '0' && ch <= '9') {
|
||||||
wc += (ch - '0') << ((3 - i) * 4);
|
wc += (ch - '0') << ((3 - i) * 4);
|
||||||
} else if (ch >= 'a' && ch <= 'f') {
|
} else if (ch >= 'a' && ch <= 'f') {
|
||||||
@ -750,7 +750,7 @@ do_switch:
|
|||||||
wchar_t wc = '\0';
|
wchar_t wc = '\0';
|
||||||
|
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (ch >= '0' && ch <= '9') {
|
if (ch >= '0' && ch <= '9') {
|
||||||
wc += (ch - '0') << ((7 - i) * 4);
|
wc += (ch - '0') << ((7 - i) * 4);
|
||||||
} else if (ch >= 'a' && ch <= 'f') {
|
} else if (ch >= 'a' && ch <= 'f') {
|
||||||
@ -777,7 +777,7 @@ do_switch:
|
|||||||
if (trueGlobalPrologFlag(ISO_FLAG)) {
|
if (trueGlobalPrologFlag(ISO_FLAG)) {
|
||||||
return send_error_message("invalid escape sequence");
|
return send_error_message("invalid escape sequence");
|
||||||
} else {
|
} else {
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (ch == '?') { /* delete character */
|
if (ch == '?') { /* delete character */
|
||||||
return 127;
|
return 127;
|
||||||
} else if (ch >= 'a' && ch < 'z') { /* hexa */
|
} else if (ch >= 'a' && ch < 'z') { /* hexa */
|
||||||
@ -800,13 +800,13 @@ do_switch:
|
|||||||
/* follow ISO */
|
/* follow ISO */
|
||||||
{
|
{
|
||||||
unsigned char so_far = ch - '0';
|
unsigned char so_far = ch - '0';
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (ch >= '0' && ch < '8') { /* octal */
|
if (ch >= '0' && ch < '8') { /* octal */
|
||||||
so_far = so_far * 8 + (ch - '0');
|
so_far = so_far * 8 + (ch - '0');
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (ch >= '0' && ch < '8') { /* octal */
|
if (ch >= '0' && ch < '8') { /* octal */
|
||||||
so_far = so_far * 8 + (ch - '0');
|
so_far = so_far * 8 + (ch - '0');
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (ch != '\\') {
|
if (ch != '\\') {
|
||||||
return send_error_message("invalid octal escape sequence");
|
return send_error_message("invalid octal escape sequence");
|
||||||
}
|
}
|
||||||
@ -826,19 +826,19 @@ do_switch:
|
|||||||
/* hexadecimal character (YAP allows empty hexadecimal */
|
/* hexadecimal character (YAP allows empty hexadecimal */
|
||||||
{
|
{
|
||||||
unsigned char so_far = 0;
|
unsigned char so_far = 0;
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (my_isxdigit(ch, 'f', 'F')) { /* hexa */
|
if (my_isxdigit(ch, 'f', 'F')) { /* hexa */
|
||||||
so_far =
|
so_far =
|
||||||
so_far * 16 + (chtype(ch) == NU
|
so_far * 16 + (chtype(ch) == NU
|
||||||
? ch - '0'
|
? ch - '0'
|
||||||
: (my_isupper(ch) ? ch - 'A' : ch - 'a') + 10);
|
: (my_isupper(ch) ? ch - 'A' : ch - 'a') + 10);
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (my_isxdigit(ch, 'f', 'F')) { /* hexa */
|
if (my_isxdigit(ch, 'f', 'F')) { /* hexa */
|
||||||
so_far =
|
so_far =
|
||||||
so_far * 16 + (chtype(ch) == NU
|
so_far * 16 + (chtype(ch) == NU
|
||||||
? ch - '0'
|
? ch - '0'
|
||||||
: (my_isupper(ch) ? ch - 'A' : ch - 'a') + 10);
|
: (my_isupper(ch) ? ch - 'A' : ch - 'a') + 10);
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (ch == '\\') {
|
if (ch == '\\') {
|
||||||
return so_far;
|
return so_far;
|
||||||
} else {
|
} else {
|
||||||
@ -890,7 +890,7 @@ static int num_send_error_message(char s[]) {
|
|||||||
|
|
||||||
/* reads a number, either integer or float */
|
/* reads a number, either integer or float */
|
||||||
|
|
||||||
static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
static Term get_num(int *chp, int *chbuffp, StreamDesc *st, int sign) {
|
||||||
int ch = *chp;
|
int ch = *chp;
|
||||||
Int val = 0L, base = ch - '0';
|
Int val = 0L, base = ch - '0';
|
||||||
int might_be_float = TRUE, has_overflow = FALSE;
|
int might_be_float = TRUE, has_overflow = FALSE;
|
||||||
@ -899,7 +899,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
int max_size = 254, left = 254;
|
int max_size = 254, left = 254;
|
||||||
|
|
||||||
*sp++ = ch;
|
*sp++ = ch;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
/*
|
/*
|
||||||
* because of things like 00'2, 03'2 and even better 12'2, I need to
|
* because of things like 00'2, 03'2 and even better 12'2, I need to
|
||||||
* do this (have mercy)
|
* do this (have mercy)
|
||||||
@ -909,7 +909,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
if (--left == 0)
|
if (--left == 0)
|
||||||
number_overflow();
|
number_overflow();
|
||||||
base = 10 * base + ch - '0';
|
base = 10 * base + ch - '0';
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
if (ch == '\'') {
|
if (ch == '\'') {
|
||||||
if (base > 36) {
|
if (base > 36) {
|
||||||
@ -919,7 +919,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
if (--left == 0)
|
if (--left == 0)
|
||||||
number_overflow();
|
number_overflow();
|
||||||
*sp++ = ch;
|
*sp++ = ch;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
if (base == 0) {
|
if (base == 0) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
wchar_t ascii = ch;
|
wchar_t ascii = ch;
|
||||||
@ -927,11 +927,11 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
|
|
||||||
if (ch == '\\' &&
|
if (ch == '\\' &&
|
||||||
Yap_GetModuleEntry(CurrentModule)->flags & M_CHARESCAPE) {
|
Yap_GetModuleEntry(CurrentModule)->flags & M_CHARESCAPE) {
|
||||||
ascii = read_quoted_char(&scan_extra, inp_stream);
|
ascii = read_quoted_char(&scan_extra, st);
|
||||||
}
|
}
|
||||||
/* a quick way to represent ASCII */
|
/* a quick way to represent ASCII */
|
||||||
if (scan_extra)
|
if (scan_extra)
|
||||||
*chp = getchr(inp_stream);
|
*chp = getchr(st);
|
||||||
if (sign == -1) {
|
if (sign == -1) {
|
||||||
return MkIntegerTerm(-ascii);
|
return MkIntegerTerm(-ascii);
|
||||||
}
|
}
|
||||||
@ -951,7 +951,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
val = oval * base + chval;
|
val = oval * base + chval;
|
||||||
if (oval != (val - chval) / base) /* overflow */
|
if (oval != (val - chval) / base) /* overflow */
|
||||||
has_overflow = (has_overflow || TRUE);
|
has_overflow = (has_overflow || TRUE);
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ch == 'x' && base == 0) {
|
} else if (ch == 'x' && base == 0) {
|
||||||
@ -959,7 +959,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
if (--left == 0)
|
if (--left == 0)
|
||||||
number_overflow();
|
number_overflow();
|
||||||
*sp++ = ch;
|
*sp++ = ch;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
while (my_isxdigit(ch, 'F', 'f')) {
|
while (my_isxdigit(ch, 'F', 'f')) {
|
||||||
Int oval = val;
|
Int oval = val;
|
||||||
int chval =
|
int chval =
|
||||||
@ -971,17 +971,17 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
val = val * 16 + chval;
|
val = val * 16 + chval;
|
||||||
if (oval != (val - chval) / 16) /* overflow */
|
if (oval != (val - chval) / 16) /* overflow */
|
||||||
has_overflow = TRUE;
|
has_overflow = TRUE;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
*chp = ch;
|
*chp = ch;
|
||||||
} else if (ch == 'o' && base == 0) {
|
} else if (ch == 'o' && base == 0) {
|
||||||
might_be_float = FALSE;
|
might_be_float = FALSE;
|
||||||
base = 8;
|
base = 8;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
} else if (ch == 'b' && base == 0) {
|
} else if (ch == 'b' && base == 0) {
|
||||||
might_be_float = FALSE;
|
might_be_float = FALSE;
|
||||||
base = 2;
|
base = 2;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
} else {
|
} else {
|
||||||
val = base;
|
val = base;
|
||||||
base = 10;
|
base = 10;
|
||||||
@ -1002,7 +1002,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
val = val * base + ch - '0';
|
val = val * base + ch - '0';
|
||||||
if (val / base != oval || val - oval * base != ch - '0') /* overflow */
|
if (val / base != oval || val - oval * base != ch - '0') /* overflow */
|
||||||
has_overflow = TRUE;
|
has_overflow = TRUE;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
if (might_be_float && (ch == '.' || ch == 'e' || ch == 'E')) {
|
if (might_be_float && (ch == '.' || ch == 'e' || ch == 'E')) {
|
||||||
int has_dot = (ch == '.');
|
int has_dot = (ch == '.');
|
||||||
@ -1010,7 +1010,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
unsigned char *dp;
|
unsigned char *dp;
|
||||||
int dc;
|
int dc;
|
||||||
|
|
||||||
if (chtype(ch = getchr(inp_stream)) != NU) {
|
if (chtype(ch = getchr(st)) != NU) {
|
||||||
if (ch == 'e' || ch == 'E') {
|
if (ch == 'e' || ch == 'E') {
|
||||||
if (trueGlobalPrologFlag(ISO_FLAG))
|
if (trueGlobalPrologFlag(ISO_FLAG))
|
||||||
return num_send_error_message(
|
return num_send_error_message(
|
||||||
@ -1045,21 +1045,21 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
if (--left == 0)
|
if (--left == 0)
|
||||||
number_overflow();
|
number_overflow();
|
||||||
*sp++ = ch;
|
*sp++ = ch;
|
||||||
} while (chtype(ch = getchr(inp_stream)) == NU);
|
} while (chtype(ch = getchr(st)) == NU);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ch == 'e' || ch == 'E') {
|
if (ch == 'e' || ch == 'E') {
|
||||||
if (--left == 0)
|
if (--left == 0)
|
||||||
number_overflow();
|
number_overflow();
|
||||||
*sp++ = ch;
|
*sp++ = ch;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
if (ch == '-') {
|
if (ch == '-') {
|
||||||
if (--left == 0)
|
if (--left == 0)
|
||||||
number_overflow();
|
number_overflow();
|
||||||
*sp++ = '-';
|
*sp++ = '-';
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
} else if (ch == '+') {
|
} else if (ch == '+') {
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
if (chtype(ch) != NU) {
|
if (chtype(ch) != NU) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
@ -1071,7 +1071,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
if (--left == 0)
|
if (--left == 0)
|
||||||
number_overflow();
|
number_overflow();
|
||||||
*sp++ = ch;
|
*sp++ = ch;
|
||||||
} while (chtype(ch = getchr(inp_stream)) == NU);
|
} while (chtype(ch = getchr(st)) == NU);
|
||||||
}
|
}
|
||||||
*sp = '\0';
|
*sp = '\0';
|
||||||
*chp = ch;
|
*chp = ch;
|
||||||
@ -1257,7 +1257,7 @@ const char *Yap_tokText(void *tokptre) {
|
|||||||
return ".";
|
return ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void open_comment(int ch, StreamDesc *inp_stream USES_REGS) {
|
static void open_comment(int ch, StreamDesc *st USES_REGS) {
|
||||||
CELL *h0 = HR;
|
CELL *h0 = HR;
|
||||||
HR += 5;
|
HR += 5;
|
||||||
h0[0] = AbsAppl(h0 + 2);
|
h0[0] = AbsAppl(h0 + 2);
|
||||||
@ -1272,7 +1272,7 @@ static void open_comment(int ch, StreamDesc *inp_stream USES_REGS) {
|
|||||||
LOCAL_CommentsTail = h0 + 1;
|
LOCAL_CommentsTail = h0 + 1;
|
||||||
h0 += 2;
|
h0 += 2;
|
||||||
h0[0] = (CELL)FunctorMinus;
|
h0[0] = (CELL)FunctorMinus;
|
||||||
h0[1] = Yap_StreamPosition(inp_stream - GLOBAL_Stream);
|
h0[1] = Yap_StreamPosition(st - GLOBAL_Stream);
|
||||||
h0[2] = TermNil;
|
h0[2] = TermNil;
|
||||||
LOCAL_CommentsNextChar = h0 + 2;
|
LOCAL_CommentsNextChar = h0 + 2;
|
||||||
LOCAL_CommentsBuff = (wchar_t *)malloc(1024 * sizeof(wchar_t));
|
LOCAL_CommentsBuff = (wchar_t *)malloc(1024 * sizeof(wchar_t));
|
||||||
@ -1301,14 +1301,14 @@ static void close_comment(USES_REGS1) {
|
|||||||
|
|
||||||
// mark that we reached EOF,
|
// mark that we reached EOF,
|
||||||
// next token will be end_of_file)
|
// next token will be end_of_file)
|
||||||
static void mark_eof(struct stream_desc *inp_stream) {
|
static void mark_eof(struct stream_desc *st) {
|
||||||
inp_stream->status |= Push_Eof_Stream_f;
|
st->status |= Push_Eof_Stream_f;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define add_ch_to_buff(ch) \
|
#define add_ch_to_buff(ch) \
|
||||||
{ charp += put_utf8(charp, ch); }
|
{ charp += put_utf8(charp, ch); }
|
||||||
|
|
||||||
TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
||||||
Term *tposp) {
|
Term *tposp) {
|
||||||
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
@ -1324,14 +1324,15 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
LOCAL_AnonVarTable = NULL;
|
LOCAL_AnonVarTable = NULL;
|
||||||
l = NULL;
|
l = NULL;
|
||||||
p = NULL; /* Just to make lint happy */
|
p = NULL; /* Just to make lint happy */
|
||||||
ch = getchr(inp_stream);
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "i %d", st-GLOBAL_Stream);
|
||||||
|
ch = getchr(st);
|
||||||
while (chtype(ch) == BS) {
|
while (chtype(ch) == BS) {
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
*tposp = Yap_StreamPosition(inp_stream - GLOBAL_Stream);
|
*tposp = Yap_StreamPosition(st - GLOBAL_Stream);
|
||||||
Yap_setCurrentSourceLocation(inp_stream);
|
Yap_setCurrentSourceLocation(st);
|
||||||
LOCAL_StartLineCount = inp_stream->linecount;
|
LOCAL_StartLineCount = st->linecount;
|
||||||
LOCAL_StartLinePos = inp_stream->linepos;
|
LOCAL_StartLinePos = st->linepos;
|
||||||
do {
|
do {
|
||||||
int quote, isvar;
|
int quote, isvar;
|
||||||
unsigned char *charp, *mp;
|
unsigned char *charp, *mp;
|
||||||
@ -1350,22 +1351,22 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
p = t;
|
p = t;
|
||||||
restart:
|
restart:
|
||||||
while (chtype(ch) == BS) {
|
while (chtype(ch) == BS) {
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
t->TokPos = GetCurInpPos(inp_stream);
|
t->TokPos = GetCurInpPos(st);
|
||||||
|
|
||||||
switch (chtype(ch)) {
|
switch (chtype(ch)) {
|
||||||
|
|
||||||
case CC:
|
case CC:
|
||||||
if (store_comments) {
|
if (store_comments) {
|
||||||
open_comment(ch, inp_stream PASS_REGS);
|
open_comment(ch, st PASS_REGS);
|
||||||
continue_comment:
|
continue_comment:
|
||||||
while ((ch = getchr(inp_stream)) != 10 && chtype(ch) != EF) {
|
while ((ch = getchr(st)) != 10 && chtype(ch) != EF) {
|
||||||
extend_comment(ch PASS_REGS);
|
extend_comment(ch PASS_REGS);
|
||||||
}
|
}
|
||||||
extend_comment(ch PASS_REGS);
|
extend_comment(ch PASS_REGS);
|
||||||
if (chtype(ch) != EF) {
|
if (chtype(ch) != EF) {
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
if (chtype(ch) == CC) {
|
if (chtype(ch) == CC) {
|
||||||
extend_comment(ch PASS_REGS);
|
extend_comment(ch PASS_REGS);
|
||||||
goto continue_comment;
|
goto continue_comment;
|
||||||
@ -1373,7 +1374,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
}
|
}
|
||||||
close_comment(PASS_REGS1);
|
close_comment(PASS_REGS1);
|
||||||
} else {
|
} else {
|
||||||
while ((ch = getchr(inp_stream)) != 10 && chtype(ch) != EF)
|
while ((ch = getchr(st)) != 10 && chtype(ch) != EF)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
if (chtype(ch) != EF) {
|
if (chtype(ch) != EF) {
|
||||||
@ -1381,15 +1382,15 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
if (t == l) {
|
if (t == l) {
|
||||||
/* we found a comment before reading characters */
|
/* we found a comment before reading characters */
|
||||||
while (chtype(ch) == BS) {
|
while (chtype(ch) == BS) {
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
*tposp = Yap_StreamPosition(inp_stream - GLOBAL_Stream);
|
*tposp = Yap_StreamPosition(st - GLOBAL_Stream);
|
||||||
Yap_setCurrentSourceLocation(inp_stream);
|
Yap_setCurrentSourceLocation(st);
|
||||||
}
|
}
|
||||||
goto restart;
|
goto restart;
|
||||||
} else {
|
} else {
|
||||||
t->Tok = Ord(kind = eot_tok);
|
t->Tok = Ord(kind = eot_tok);
|
||||||
mark_eof(inp_stream);
|
mark_eof(st);
|
||||||
t->TokInfo = TermEof;
|
t->TokInfo = TermEof;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1398,14 +1399,14 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
case UL:
|
case UL:
|
||||||
case LC: {
|
case LC: {
|
||||||
int32_t och = ch;
|
int32_t och = ch;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
size_t sz = 512;
|
size_t sz = 512;
|
||||||
TokImage = Malloc(sz PASS_REGS);
|
TokImage = Malloc(sz PASS_REGS);
|
||||||
scan_name:
|
scan_name:
|
||||||
charp = (unsigned char *)TokImage;
|
charp = (unsigned char *)TokImage;
|
||||||
isvar = (chtype(och) != LC);
|
isvar = (chtype(och) != LC);
|
||||||
add_ch_to_buff(och);
|
add_ch_to_buff(och);
|
||||||
for (; chtype(ch) <= NU; ch = getchr(inp_stream)) {
|
for (; chtype(ch) <= NU; ch = getchr(st)) {
|
||||||
if (charp == TokImage + (sz - 1)) {
|
if (charp == TokImage + (sz - 1)) {
|
||||||
unsigned char *p0 = TokImage;
|
unsigned char *p0 = TokImage;
|
||||||
sz = Yap_Min(sz * 2, sz + MBYTE);
|
sz = Yap_Min(sz * 2, sz + MBYTE);
|
||||||
@ -1423,7 +1424,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
return CodeSpaceError(t, p, l);
|
return CodeSpaceError(t, p, l);
|
||||||
}
|
}
|
||||||
add_ch_to_buff(ch);
|
add_ch_to_buff(ch);
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
add_ch_to_buff('\0');
|
add_ch_to_buff('\0');
|
||||||
if (!isvar) {
|
if (!isvar) {
|
||||||
@ -1459,7 +1460,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
cha = ch;
|
cha = ch;
|
||||||
cherr = 0;
|
cherr = 0;
|
||||||
CHECK_SPACE();
|
CHECK_SPACE();
|
||||||
if ((t->TokInfo = get_num(&cha, &cherr, inp_stream, sign)) == 0L) {
|
if ((t->TokInfo = get_num(&cha, &cherr, st, sign)) == 0L) {
|
||||||
if (p) {
|
if (p) {
|
||||||
p->Tok = eot_tok;
|
p->Tok = eot_tok;
|
||||||
t->TokInfo = TermError;
|
t->TokInfo = TermError;
|
||||||
@ -1471,7 +1472,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
if (cherr) {
|
if (cherr) {
|
||||||
TokEntry *e;
|
TokEntry *e;
|
||||||
t->Tok = Number_tok;
|
t->Tok = Number_tok;
|
||||||
t->TokPos = GetCurInpPos(inp_stream);
|
t->TokPos = GetCurInpPos(st);
|
||||||
e = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
e = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
||||||
if (e == NULL) {
|
if (e == NULL) {
|
||||||
return TrailSpaceError(p, l);
|
return TrailSpaceError(p, l);
|
||||||
@ -1497,7 +1498,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
|
|
||||||
t->Tok = Ord(Var_tok);
|
t->Tok = Ord(Var_tok);
|
||||||
t->TokInfo = (Term)Yap_LookupVar("E");
|
t->TokInfo = (Term)Yap_LookupVar("E");
|
||||||
t->TokPos = GetCurInpPos(inp_stream);
|
t->TokPos = GetCurInpPos(st);
|
||||||
e2 = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
e2 = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
||||||
if (e2 == NULL) {
|
if (e2 == NULL) {
|
||||||
return TrailSpaceError(p, l);
|
return TrailSpaceError(p, l);
|
||||||
@ -1530,7 +1531,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
if (ch == '(')
|
if (ch == '(')
|
||||||
solo_flag = FALSE;
|
solo_flag = FALSE;
|
||||||
t->TokInfo = MkAtomTerm(AtomE);
|
t->TokInfo = MkAtomTerm(AtomE);
|
||||||
t->TokPos = GetCurInpPos(inp_stream);
|
t->TokPos = GetCurInpPos(st);
|
||||||
e2 = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
e2 = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
||||||
if (e2 == NULL) {
|
if (e2 == NULL) {
|
||||||
return TrailSpaceError(p, l);
|
return TrailSpaceError(p, l);
|
||||||
@ -1557,7 +1558,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
charp = TokImage;
|
charp = TokImage;
|
||||||
quote = ch;
|
quote = ch;
|
||||||
len = 0;
|
len = 0;
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
size_t sz = 1024;
|
size_t sz = 1024;
|
||||||
|
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
@ -1577,23 +1578,23 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (ch == quote) {
|
if (ch == quote) {
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (ch != quote)
|
if (ch != quote)
|
||||||
break;
|
break;
|
||||||
add_ch_to_buff(ch);
|
add_ch_to_buff(ch);
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
} else if (ch == '\\' &&
|
} else if (ch == '\\' &&
|
||||||
Yap_GetModuleEntry(CurrentModule)->flags & M_CHARESCAPE) {
|
Yap_GetModuleEntry(CurrentModule)->flags & M_CHARESCAPE) {
|
||||||
int scan_next = TRUE;
|
int scan_next = TRUE;
|
||||||
if ((ch = read_quoted_char(&scan_next, inp_stream))) {
|
if ((ch = read_quoted_char(&scan_next, st))) {
|
||||||
add_ch_to_buff(ch);
|
add_ch_to_buff(ch);
|
||||||
}
|
}
|
||||||
if (scan_next) {
|
if (scan_next) {
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
add_ch_to_buff(ch);
|
add_ch_to_buff(ch);
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
}
|
}
|
||||||
++len;
|
++len;
|
||||||
}
|
}
|
||||||
@ -1628,9 +1629,9 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
if (ch == '\0') {
|
if (ch == '\0') {
|
||||||
int pch;
|
int pch;
|
||||||
t->Tok = Ord(kind = eot_tok);
|
t->Tok = Ord(kind = eot_tok);
|
||||||
pch = Yap_peek(inp_stream - GLOBAL_Stream);
|
pch = Yap_peek(st - GLOBAL_Stream);
|
||||||
if (chtype(pch) == EF) {
|
if (chtype(pch) == EF) {
|
||||||
mark_eof(inp_stream);
|
mark_eof(st);
|
||||||
t->TokInfo = TermEof;
|
t->TokInfo = TermEof;
|
||||||
} else {
|
} else {
|
||||||
t->TokInfo = TermNewLine;
|
t->TokInfo = TermNewLine;
|
||||||
@ -1638,11 +1639,11 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
t->TokInfo = TermEof;
|
t->TokInfo = TermEof;
|
||||||
return l;
|
return l;
|
||||||
} else
|
} else
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
break;
|
break;
|
||||||
case SY: {
|
case SY: {
|
||||||
int pch;
|
int pch;
|
||||||
if (ch == '.' && (pch = Yap_peek(inp_stream - GLOBAL_Stream)) &&
|
if (ch == '.' && (pch = Yap_peek(st - GLOBAL_Stream)) &&
|
||||||
(chtype(pch) == BS || chtype(pch) == EF || pch == '%')) {
|
(chtype(pch) == BS || chtype(pch) == EF || pch == '%')) {
|
||||||
t->Tok = Ord(kind = eot_tok);
|
t->Tok = Ord(kind = eot_tok);
|
||||||
// consume...
|
// consume...
|
||||||
@ -1655,7 +1656,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
if (ch == '`')
|
if (ch == '`')
|
||||||
goto quoted_string;
|
goto quoted_string;
|
||||||
och = ch;
|
och = ch;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
if (och == '.') {
|
if (och == '.') {
|
||||||
if (chtype(ch) == BS || chtype(ch) == EF || ch == '%') {
|
if (chtype(ch) == BS || chtype(ch) == EF || ch == '%') {
|
||||||
t->Tok = Ord(kind = eot_tok);
|
t->Tok = Ord(kind = eot_tok);
|
||||||
@ -1664,7 +1665,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
if (chtype(ch) == EF) {
|
if (chtype(ch) == EF) {
|
||||||
mark_eof(inp_stream);
|
mark_eof(st);
|
||||||
t->TokInfo = TermEof;
|
t->TokInfo = TermEof;
|
||||||
} else {
|
} else {
|
||||||
t->TokInfo = TermNewLine;
|
t->TokInfo = TermNewLine;
|
||||||
@ -1675,12 +1676,12 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
if (och == '/' && ch == '*') {
|
if (och == '/' && ch == '*') {
|
||||||
if (store_comments) {
|
if (store_comments) {
|
||||||
CHECK_SPACE();
|
CHECK_SPACE();
|
||||||
open_comment('/', inp_stream PASS_REGS);
|
open_comment('/', st PASS_REGS);
|
||||||
while ((och != '*' || ch != '/') && chtype(ch) != EF) {
|
while ((och != '*' || ch != '/') && chtype(ch) != EF) {
|
||||||
och = ch;
|
och = ch;
|
||||||
CHECK_SPACE();
|
CHECK_SPACE();
|
||||||
extend_comment(ch PASS_REGS);
|
extend_comment(ch PASS_REGS);
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
if (chtype(ch) != EF) {
|
if (chtype(ch) != EF) {
|
||||||
CHECK_SPACE();
|
CHECK_SPACE();
|
||||||
@ -1690,7 +1691,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
} else {
|
} else {
|
||||||
while ((och != '*' || ch != '/') && chtype(ch) != EF) {
|
while ((och != '*' || ch != '/') && chtype(ch) != EF) {
|
||||||
och = ch;
|
och = ch;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (chtype(ch) == EF) {
|
if (chtype(ch) == EF) {
|
||||||
@ -1699,15 +1700,15 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
/* leave comments */
|
/* leave comments */
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
if (t == l) {
|
if (t == l) {
|
||||||
/* we found a comment before reading characters */
|
/* we found a comment before reading characters */
|
||||||
while (chtype(ch) == BS) {
|
while (chtype(ch) == BS) {
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
CHECK_SPACE();
|
CHECK_SPACE();
|
||||||
*tposp = Yap_StreamPosition(inp_stream - GLOBAL_Stream);
|
*tposp = Yap_StreamPosition(st - GLOBAL_Stream);
|
||||||
Yap_setCurrentSourceLocation(inp_stream);
|
Yap_setCurrentSourceLocation(st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
goto restart;
|
goto restart;
|
||||||
@ -1721,7 +1722,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
if (chtype(ch) == EF) {
|
if (chtype(ch) == EF) {
|
||||||
mark_eof(inp_stream);
|
mark_eof(st);
|
||||||
t->TokInfo = TermEof;
|
t->TokInfo = TermEof;
|
||||||
} else {
|
} else {
|
||||||
t->TokInfo = TermNl;
|
t->TokInfo = TermNl;
|
||||||
@ -1733,7 +1734,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
TokImage = Malloc(sz);
|
TokImage = Malloc(sz);
|
||||||
charp = TokImage;
|
charp = TokImage;
|
||||||
add_ch_to_buff(och);
|
add_ch_to_buff(och);
|
||||||
for (; chtype(ch) == SY; ch = getchr(inp_stream)) {
|
for (; chtype(ch) == SY; ch = getchr(st)) {
|
||||||
if (charp >= TokImage + (sz - 10)) {
|
if (charp >= TokImage + (sz - 10)) {
|
||||||
sz = Yap_Min(sz * 2, sz + MBYTE);
|
sz = Yap_Min(sz * 2, sz + MBYTE);
|
||||||
TokImage = Realloc(TokImage, sz);
|
TokImage = Realloc(TokImage, sz);
|
||||||
@ -1764,7 +1765,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
unsigned char chs[2];
|
unsigned char chs[2];
|
||||||
chs[0] = ch;
|
chs[0] = ch;
|
||||||
chs[1] = '\0';
|
chs[1] = '\0';
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
t->TokInfo = MkAtomTerm(Yap_ULookupAtom(chs));
|
t->TokInfo = MkAtomTerm(Yap_ULookupAtom(chs));
|
||||||
t->Tok = Ord(kind = Name_tok);
|
t->Tok = Ord(kind = Name_tok);
|
||||||
if (ch == '(')
|
if (ch == '(')
|
||||||
@ -1773,7 +1774,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
|
|
||||||
case BK:
|
case BK:
|
||||||
och = ch;
|
och = ch;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
{
|
{
|
||||||
unsigned char chs[10];
|
unsigned char chs[10];
|
||||||
TokImage = charp = chs;
|
TokImage = charp = chs;
|
||||||
@ -1783,12 +1784,12 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
}
|
}
|
||||||
if (och == '(') {
|
if (och == '(') {
|
||||||
while (chtype(ch) == BS) {
|
while (chtype(ch) == BS) {
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
if (ch == ')') {
|
if (ch == ')') {
|
||||||
t->TokInfo = TermEmptyBrackets;
|
t->TokInfo = TermEmptyBrackets;
|
||||||
t->Tok = Ord(kind = Name_tok);
|
t->Tok = Ord(kind = Name_tok);
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
solo_flag = FALSE;
|
solo_flag = FALSE;
|
||||||
break;
|
break;
|
||||||
} else if (!solo_flag) {
|
} else if (!solo_flag) {
|
||||||
@ -1797,12 +1798,12 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
}
|
}
|
||||||
} else if (och == '[') {
|
} else if (och == '[') {
|
||||||
while (chtype(ch) == BS) {
|
while (chtype(ch) == BS) {
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
};
|
};
|
||||||
if (ch == ']') {
|
if (ch == ']') {
|
||||||
t->TokInfo = TermNil;
|
t->TokInfo = TermNil;
|
||||||
t->Tok = Ord(kind = Name_tok);
|
t->Tok = Ord(kind = Name_tok);
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
solo_flag = FALSE;
|
solo_flag = FALSE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1827,26 +1828,26 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
cur_qq = qq;
|
cur_qq = qq;
|
||||||
}
|
}
|
||||||
t->TokInfo = (CELL)qq;
|
t->TokInfo = (CELL)qq;
|
||||||
if (inp_stream->status & Seekable_Stream_f) {
|
if (st->status & Seekable_Stream_f) {
|
||||||
qq->start.byteno = fseek(inp_stream->file, 0, 0);
|
qq->start.byteno = fseek(st->file, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
qq->start.byteno = inp_stream->charcount - 1;
|
qq->start.byteno = st->charcount - 1;
|
||||||
}
|
}
|
||||||
qq->start.lineno = inp_stream->linecount;
|
qq->start.lineno = st->linecount;
|
||||||
qq->start.linepos = inp_stream->linepos - 1;
|
qq->start.linepos = st->linepos - 1;
|
||||||
qq->start.charno = inp_stream->charcount - 1;
|
qq->start.charno = st->charcount - 1;
|
||||||
t->Tok = Ord(kind = QuasiQuotes_tok);
|
t->Tok = Ord(kind = QuasiQuotes_tok);
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
solo_flag = FALSE;
|
solo_flag = FALSE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
while (chtype(ch) == BS) {
|
while (chtype(ch) == BS) {
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
};
|
};
|
||||||
if (ch == '}') {
|
if (ch == '}') {
|
||||||
t->TokInfo = TermBraces;
|
t->TokInfo = TermBraces;
|
||||||
t->Tok = Ord(kind = Name_tok);
|
t->Tok = Ord(kind = Name_tok);
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
solo_flag = FALSE;
|
solo_flag = FALSE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1863,16 +1864,16 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
}
|
}
|
||||||
cur_qq = NULL;
|
cur_qq = NULL;
|
||||||
t->TokInfo = (CELL)qq;
|
t->TokInfo = (CELL)qq;
|
||||||
if (inp_stream->status & Seekable_Stream_f) {
|
if (st->status & Seekable_Stream_f) {
|
||||||
qq->mid.byteno = fseek(inp_stream->file, 0, 0);
|
qq->mid.byteno = fseek(st->file, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
qq->mid.byteno = inp_stream->charcount - 1;
|
qq->mid.byteno = st->charcount - 1;
|
||||||
}
|
}
|
||||||
qq->mid.lineno = inp_stream->linecount;
|
qq->mid.lineno = st->linecount;
|
||||||
qq->mid.linepos = inp_stream->linepos - 1;
|
qq->mid.linepos = st->linepos - 1;
|
||||||
qq->mid.charno = inp_stream->charcount - 1;
|
qq->mid.charno = st->charcount - 1;
|
||||||
t->Tok = Ord(kind = QuasiQuotes_tok);
|
t->Tok = Ord(kind = QuasiQuotes_tok);
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
sz = 1024;
|
sz = 1024;
|
||||||
TokImage = Malloc(sz);
|
TokImage = Malloc(sz);
|
||||||
if (!TokImage) {
|
if (!TokImage) {
|
||||||
@ -1885,11 +1886,11 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
charp = TokImage;
|
charp = TokImage;
|
||||||
quote = ch;
|
quote = ch;
|
||||||
len = 0;
|
len = 0;
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
|
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
if (ch == '|') {
|
if (ch == '|') {
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (ch != '}') {
|
if (ch != '}') {
|
||||||
} else {
|
} else {
|
||||||
charp += put_utf8((unsigned char *)charp, och);
|
charp += put_utf8((unsigned char *)charp, och);
|
||||||
@ -1899,13 +1900,13 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
}
|
}
|
||||||
} else if (chtype(ch) == EF) {
|
} else if (chtype(ch) == EF) {
|
||||||
Free(TokImage);
|
Free(TokImage);
|
||||||
mark_eof(inp_stream);
|
mark_eof(st);
|
||||||
t->Tok = Ord(kind = eot_tok);
|
t->Tok = Ord(kind = eot_tok);
|
||||||
t->TokInfo = TermOutOfHeapError;
|
t->TokInfo = TermOutOfHeapError;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
charp += put_utf8(charp, ch);
|
charp += put_utf8(charp, ch);
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
}
|
}
|
||||||
if (charp > (unsigned char *)AuxSp - 1024) {
|
if (charp > (unsigned char *)AuxSp - 1024) {
|
||||||
/* Not enough space to read in the string. */
|
/* Not enough space to read in the string. */
|
||||||
@ -1925,26 +1926,26 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
strncpy((char *)mp, (const char *)TokImage, len + 1);
|
strncpy((char *)mp, (const char *)TokImage, len + 1);
|
||||||
qq->text = (unsigned char *)mp;
|
qq->text = (unsigned char *)mp;
|
||||||
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
||||||
if (inp_stream->status & Seekable_Stream_f) {
|
if (st->status & Seekable_Stream_f) {
|
||||||
qq->end.byteno = fseek(inp_stream->file, 0, 0);
|
qq->end.byteno = fseek(st->file, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
qq->end.byteno = inp_stream->charcount - 1;
|
qq->end.byteno = st->charcount - 1;
|
||||||
}
|
}
|
||||||
qq->end.lineno = inp_stream->linecount;
|
qq->end.lineno = st->linecount;
|
||||||
qq->end.linepos = inp_stream->linepos - 1;
|
qq->end.linepos = st->linepos - 1;
|
||||||
qq->end.charno = inp_stream->charcount - 1;
|
qq->end.charno = st->charcount - 1;
|
||||||
if (!(t->TokInfo)) {
|
if (!(t->TokInfo)) {
|
||||||
return CodeSpaceError(t, p, l);
|
return CodeSpaceError(t, p, l);
|
||||||
}
|
}
|
||||||
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
||||||
solo_flag = FALSE;
|
solo_flag = FALSE;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
t->Tok = Ord(kind = Ponctuation_tok);
|
t->Tok = Ord(kind = Ponctuation_tok);
|
||||||
break;
|
break;
|
||||||
case EF:
|
case EF:
|
||||||
mark_eof(inp_stream);
|
mark_eof(st);
|
||||||
t->Tok = Ord(kind = eot_tok);
|
t->Tok = Ord(kind = eot_tok);
|
||||||
t->TokInfo = TermEof;
|
t->TokInfo = TermEof;
|
||||||
return l;
|
return l;
|
||||||
@ -1966,7 +1967,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
p->TokNext = e;
|
p->TokNext = e;
|
||||||
e->Tok = Error_tok;
|
e->Tok = Error_tok;
|
||||||
e->TokInfo = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
|
e->TokInfo = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
|
||||||
e->TokPos = GetCurInpPos(inp_stream);
|
e->TokPos = GetCurInpPos(st);
|
||||||
e->TokNext = NULL;
|
e->TokNext = NULL;
|
||||||
LOCAL_ErrorMessage = NULL;
|
LOCAL_ErrorMessage = NULL;
|
||||||
p = e;
|
p = e;
|
||||||
|
@ -1098,7 +1098,7 @@ bool set_clause_info(yamop *codeptr, PredEntry *pp) {
|
|||||||
LOCAL_ActiveError->prologPredArity = pp->ArityOfPE;
|
LOCAL_ActiveError->prologPredArity = pp->ArityOfPE;
|
||||||
}
|
}
|
||||||
LOCAL_ActiveError->prologPredModule =
|
LOCAL_ActiveError->prologPredModule =
|
||||||
(pp->ModuleOfPred ? pp->ModuleOfPred : TermProlog);
|
(pp->ModuleOfPred ? pp->ModuleOfPred : "prolog");
|
||||||
LOCAL_ActiveError->prologPredFile = pp->src.OwnerFile;
|
LOCAL_ActiveError->prologPredFile = pp->src.OwnerFile;
|
||||||
if (codeptr->opc == UNDEF_OPCODE) {
|
if (codeptr->opc == UNDEF_OPCODE) {
|
||||||
LOCAL_ActiveError->prologPredFirstLine = 0;
|
LOCAL_ActiveError->prologPredFirstLine = 0;
|
||||||
|
2
C/text.c
2
C/text.c
@ -487,7 +487,7 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
|
|||||||
#endif
|
#endif
|
||||||
if (inp->type & YAP_STRING_TERM) {
|
if (inp->type & YAP_STRING_TERM) {
|
||||||
// Yap_DebugPlWriteln(inp->val.t);
|
// Yap_DebugPlWriteln(inp->val.t);
|
||||||
char *s = (char *)Yap_TermToString(inp->val.t, ENC_ISO_UTF8, 0);
|
char *s = (char *) Yap_TermToBuffer(inp->val.t, ENC_ISO_UTF8, 0);
|
||||||
return inp->val.uc = (unsigned char *)s;
|
return inp->val.uc = (unsigned char *)s;
|
||||||
}
|
}
|
||||||
if (inp->type & YAP_STRING_CHARS) {
|
if (inp->type & YAP_STRING_CHARS) {
|
||||||
|
@ -501,7 +501,7 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) {
|
|||||||
#endif
|
#endif
|
||||||
if (inp->type & YAP_STRING_TERM) {
|
if (inp->type & YAP_STRING_TERM) {
|
||||||
// Yap_DebugPlWriteln(inp->val.t);
|
// Yap_DebugPlWriteln(inp->val.t);
|
||||||
char *s = (char *)Yap_TermToString(inp->val.t, lengp, ENC_ISO_UTF8, 0);
|
char *s = (char *) Yap_TermToBuffer(inp->val.t, lengp, ENC_ISO_UTF8, 0);
|
||||||
return inp->val.uc = (unsigned char *)s;
|
return inp->val.uc = (unsigned char *)s;
|
||||||
}
|
}
|
||||||
if (inp->type & YAP_STRING_CHARS) {
|
if (inp->type & YAP_STRING_CHARS) {
|
||||||
|
@ -87,7 +87,7 @@ static char *send_tracer_message(char *start, char *name, arity_t arity,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const char *sn = Yap_TermToString(args[i], LOCAL_encoding,
|
const char *sn = Yap_TermToBuffer(args[i], LOCAL_encoding,
|
||||||
Quote_illegal_f | Handle_vars_f);
|
Quote_illegal_f | Handle_vars_f);
|
||||||
size_t sz;
|
size_t sz;
|
||||||
if (sn == NULL) {
|
if (sn == NULL) {
|
||||||
|
@ -1255,7 +1255,7 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
Yap_CloseSlots(sls);
|
Yap_CloseSlots(sls);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *Yap_TermToString(Term t, encoding_t enc, int flags) {
|
char *Yap_TermToBuffer(Term t, encoding_t enc, int flags) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
int sno = Yap_open_buf_write_stream(enc, flags);
|
int sno = Yap_open_buf_write_stream(enc, flags);
|
||||||
const char *sf;
|
const char *sf;
|
||||||
|
12
C/yap-args.c
12
C/yap-args.c
@ -147,14 +147,14 @@ static int dump_runtime_variables(void) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
YAP_file_type_t Yap_InitDefaults(YAP_init_args *iap, char *saved_state,
|
X_API YAP_file_type_t Yap_InitDefaults(void *x, char *saved_state,
|
||||||
int argc, char *argv[]) {
|
int argc, char *argv[]) {
|
||||||
memset(iap, 0, sizeof(YAP_init_args));
|
YAP_init_args *iap = x;
|
||||||
|
memset(iap, 0, sizeof(YAP_init_args));
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
iap->boot_file_type = YAP_BOOT_PL;
|
iap->boot_file_type = YAP_BOOT_PL;
|
||||||
iap->SavedState = malloc(strlen(saved_state)+1);
|
iap->SavedState = NULL;
|
||||||
strcpy(iap->SavedState, saved_state);
|
iap->assetManager = NULL;
|
||||||
iap->assetManager = true;
|
|
||||||
#else
|
#else
|
||||||
iap->boot_file_type = YAP_QLY;
|
iap->boot_file_type = YAP_QLY;
|
||||||
iap->SavedState = saved_state;
|
iap->SavedState = saved_state;
|
||||||
@ -498,7 +498,7 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
|
|||||||
} else if (!strncmp("-home=", p, strlen("-home="))) {
|
} else if (!strncmp("-home=", p, strlen("-home="))) {
|
||||||
GLOBAL_Home = p + strlen("-home=");
|
GLOBAL_Home = p + strlen("-home=");
|
||||||
} else if (!strncmp("-cwd=", p, strlen("-cwd="))) {
|
} else if (!strncmp("-cwd=", p, strlen("-cwd="))) {
|
||||||
if (!ChDir(p + strlen("-cwd=")) ) {
|
if (!Yap_ChDir(p + strlen("-cwd=")) ) {
|
||||||
fprintf(stderr, " [ YAP unrecoverable error in setting cwd: %s ]\n",
|
fprintf(stderr, " [ YAP unrecoverable error in setting cwd: %s ]\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
}
|
}
|
||||||
|
18
CXX/yapdb.hh
18
CXX/yapdb.hh
@ -88,7 +88,9 @@ protected:
|
|||||||
PredEntry *ap;
|
PredEntry *ap;
|
||||||
|
|
||||||
/// auxiliary routine to find a predicate in the current module.
|
/// auxiliary routine to find a predicate in the current module.
|
||||||
PredEntry *getPred(YAPTerm &t, Term *&outp);
|
|
||||||
|
/// auxiliary routine to find a predicate in the current module.
|
||||||
|
PredEntry *getPred(YAPTerm &t, CELL *& outp);
|
||||||
|
|
||||||
PredEntry *asPred() { return ap; };
|
PredEntry *asPred() { return ap; };
|
||||||
|
|
||||||
@ -122,7 +124,7 @@ protected:
|
|||||||
///
|
///
|
||||||
/// It is just a call to getPred
|
/// It is just a call to getPred
|
||||||
inline YAPPredicate(Term t) {
|
inline YAPPredicate(Term t) {
|
||||||
CELL *v = NULL;
|
CELL *v = nullptr;
|
||||||
YAPTerm tt = YAPTerm(t);
|
YAPTerm tt = YAPTerm(t);
|
||||||
ap = getPred(tt, v);
|
ap = getPred(tt, v);
|
||||||
}
|
}
|
||||||
@ -131,7 +133,7 @@ protected:
|
|||||||
///
|
///
|
||||||
/// It is just a call to getPred
|
/// It is just a call to getPred
|
||||||
inline YAPPredicate(YAPTerm t) {
|
inline YAPPredicate(YAPTerm t) {
|
||||||
Term *v = nullptr;
|
CELL *v = nullptr;
|
||||||
ap = getPred(t, v);
|
ap = getPred(t, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,13 +277,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
class X_API YAPFLIP : public YAPPredicate {
|
class X_API YAPFLIP : public YAPPredicate {
|
||||||
public:
|
public:
|
||||||
YAPFLIP(CPredicate call, YAPAtom name, uintptr_t arity,
|
YAPFLIP(YAP_UserCPred call, YAPAtom name, YAP_Arity arity,
|
||||||
YAPModule module = YAPModule(), CPredicate retry = 0,
|
YAPModule module = YAPModule(), YAP_UserCPred retry = 0,
|
||||||
CPredicate cut = 0, size_t extra = 0, bool test = false)
|
YAP_UserCPred cut = 0, YAP_Arity extra = 0, bool test = false)
|
||||||
: YAPPredicate(name, arity, module) {
|
: YAPPredicate(name, arity, module) {
|
||||||
if (retry) {
|
if (retry) {
|
||||||
Yap_InitCPredBackCut(name.getName(), arity, extra, call, retry, cut,
|
YAP_UserBackCutCPredicate(name.getName(), call, retry, cut, arity, extra
|
||||||
UserCPredFlag);
|
);
|
||||||
} else {
|
} else {
|
||||||
if (test) {
|
if (test) {
|
||||||
YAP_UserCPredicate(name.getName(), call, arity);
|
YAP_UserCPredicate(name.getName(), call, arity);
|
||||||
|
32
CXX/yapi.cpp
32
CXX/yapi.cpp
@ -12,14 +12,14 @@ extern "C" {
|
|||||||
#include "YapInterface.h"
|
#include "YapInterface.h"
|
||||||
#include "blobs.h"
|
#include "blobs.h"
|
||||||
|
|
||||||
X_API char *Yap_TermToString(Term t, encoding_t encodingp,
|
X_API char *Yap_TermToBuffer(Term t, encoding_t encodingp,
|
||||||
int flags);
|
int flags);
|
||||||
|
|
||||||
X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, arity_t arity);
|
X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, arity_t arity);
|
||||||
X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, arity_t,
|
X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, arity_t,
|
||||||
YAP_Term);
|
YAP_Term);
|
||||||
X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred, YAP_UserCPred,
|
X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred, YAP_UserCPred,
|
||||||
arity_t, arity_t);
|
YAP_Arity, YAP_Arity);
|
||||||
|
|
||||||
#if YAP_PYTHON
|
#if YAP_PYTHON
|
||||||
X_API bool do_init_python(void);
|
X_API bool do_init_python(void);
|
||||||
@ -934,17 +934,11 @@ void YAPEngine::doInit(YAP_file_type_t BootMode)
|
|||||||
}
|
}
|
||||||
/* Begin preprocessor code */
|
/* Begin preprocessor code */
|
||||||
/* live */
|
/* live */
|
||||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "initialize_prolog");
|
|
||||||
#if __ANDROID__
|
|
||||||
Yap_AndroidBufp = (char *)malloc(Yap_AndroidMax = 4096);
|
|
||||||
Yap_AndroidBufp[0] = '\0';
|
|
||||||
Yap_AndroidSz = 0;
|
|
||||||
#endif
|
|
||||||
//yerror = YAPError();
|
//yerror = YAPError();
|
||||||
#if YAP_PYTHON
|
#if YAP_PYTHON
|
||||||
do_init_python();
|
do_init_python();
|
||||||
#endif
|
#endif
|
||||||
YAP_PredEntryPtr p = YAP_AtomToPred( YAP_LookupAtom("initialize_prolog") );
|
YAPPredicate p = YAPPredicate( YAPAtomTerm("initialize_prolog") );
|
||||||
YAPQuery initq = YAPQuery(YAPPredicate(p), nullptr);
|
YAPQuery initq = YAPQuery(YAPPredicate(p), nullptr);
|
||||||
if (initq.next())
|
if (initq.next())
|
||||||
{
|
{
|
||||||
@ -992,7 +986,7 @@ YAPEngine::YAPEngine(int argc, char *argv[],
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// auxiliary routine to find a predicate in the current module.
|
/// auxiliary routine to find a predicate in the current module.
|
||||||
PredEntry *YAPPredicate::getPred(YAPTerm &tt, Term *&outp)
|
PredEntry *YAPPredicate::getPred(YAPTerm &tt, CELL * &outp)
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
Term m = Yap_CurrentModule(), t = tt.term();
|
Term m = Yap_CurrentModule(), t = tt.term();
|
||||||
@ -1015,9 +1009,11 @@ YAPEngine::YAPEngine(int argc, char *argv[],
|
|||||||
else if (IsPairTerm(t))
|
else if (IsPairTerm(t))
|
||||||
{
|
{
|
||||||
Term ts[2];
|
Term ts[2];
|
||||||
ts[0] = t;
|
Functor FunctorConsult = Yap_MkFunctor(Yap_LookupAtom("consult"), 1);
|
||||||
ts[1] = m;
|
ts[1] = t;
|
||||||
t = Yap_MkApplTerm(FunctorCsult, 2, ts);
|
ts[0] = m;
|
||||||
|
t = Yap_MkApplTerm(FunctorModule, 2, ts);
|
||||||
|
t = Yap_MkApplTerm(FunctorConsult, 1, &t);
|
||||||
tt.put(t);
|
tt.put(t);
|
||||||
outp = RepAppl(t) + 1;
|
outp = RepAppl(t) + 1;
|
||||||
}
|
}
|
||||||
@ -1110,7 +1106,7 @@ YAPEngine::YAPEngine(int argc, char *argv[],
|
|||||||
if (LOCAL_ActiveError->prologPredLine)
|
if (LOCAL_ActiveError->prologPredLine)
|
||||||
{
|
{
|
||||||
s += "\n";
|
s += "\n";
|
||||||
s += LOCAL_ActiveError->prologPredFile->StrOfAE;
|
s += LOCAL_ActiveError->prologPredFile;
|
||||||
s += ":";
|
s += ":";
|
||||||
sprintf(buf, "%ld", (long int)LOCAL_ActiveError->prologPredLine);
|
sprintf(buf, "%ld", (long int)LOCAL_ActiveError->prologPredLine);
|
||||||
s += buf; // std::to_string(LOCAL_ActiveError->prologPredLine) ;
|
s += buf; // std::to_string(LOCAL_ActiveError->prologPredLine) ;
|
||||||
@ -1118,7 +1114,7 @@ YAPEngine::YAPEngine(int argc, char *argv[],
|
|||||||
s += ":0 ";
|
s += ":0 ";
|
||||||
s += LOCAL_ActiveError->prologPredModule;
|
s += LOCAL_ActiveError->prologPredModule;
|
||||||
s += ":";
|
s += ":";
|
||||||
s += (LOCAL_ActiveError->prologPredName)->StrOfAE;
|
s += (LOCAL_ActiveError->prologPredName);
|
||||||
s += "/";
|
s += "/";
|
||||||
sprintf(buf, "%ld", (long int)LOCAL_ActiveError->prologPredArity);
|
sprintf(buf, "%ld", (long int)LOCAL_ActiveError->prologPredArity);
|
||||||
s += // std::to_string(LOCAL_ActiveError->prologPredArity);
|
s += // std::to_string(LOCAL_ActiveError->prologPredArity);
|
||||||
@ -1126,13 +1122,13 @@ YAPEngine::YAPEngine(int argc, char *argv[],
|
|||||||
}
|
}
|
||||||
s += " error ";
|
s += " error ";
|
||||||
if (LOCAL_ActiveError->classAsText != nullptr)
|
if (LOCAL_ActiveError->classAsText != nullptr)
|
||||||
s += LOCAL_ActiveError->classAsText->StrOfAE;
|
s += LOCAL_ActiveError->classAsText;
|
||||||
s += ".";
|
s += ".";
|
||||||
s += LOCAL_ActiveError->errorAsText->StrOfAE;
|
s += LOCAL_ActiveError->errorAsText;
|
||||||
s += ".\n";
|
s += ".\n";
|
||||||
if (LOCAL_ActiveError->errorTerm)
|
if (LOCAL_ActiveError->errorTerm)
|
||||||
{
|
{
|
||||||
Term t = LOCAL_ActiveError->errorTerm->Entry;
|
Term t = Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm);
|
||||||
if (t)
|
if (t)
|
||||||
{
|
{
|
||||||
s += "error term is: ";
|
s += "error term is: ";
|
||||||
|
12
CXX/yapi.hh
12
CXX/yapi.hh
@ -85,8 +85,16 @@ X_API extern void YAP_UserCPredicate(const char *, YAP_UserCPred,
|
|||||||
X_API extern void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred,
|
X_API extern void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred,
|
||||||
YAP_Arity, YAP_Term);
|
YAP_Arity, YAP_Term);
|
||||||
|
|
||||||
X_API extern void UserBackCPredicate(const char *name, int *init(), int *cont(),
|
X_API extern void YAP_UserBackCPredicate(const char *name,
|
||||||
int arity, int extra);
|
YAP_UserCPred init,
|
||||||
|
YAP_UserCPred cont,
|
||||||
|
YAP_Arity arity, YAP_Arity extra);
|
||||||
|
|
||||||
|
X_API extern void YAP_UserBackCutCPredicate(const char *name,
|
||||||
|
YAP_UserCPred init,
|
||||||
|
YAP_UserCPred cont,
|
||||||
|
YAP_UserCPred cut,
|
||||||
|
YAP_Arity arity, YAP_Arity extra);
|
||||||
|
|
||||||
X_API extern YAP_Term YAP_ReadBuffer(const char *s, YAP_Term *tp);
|
X_API extern YAP_Term YAP_ReadBuffer(const char *s, YAP_Term *tp);
|
||||||
|
|
||||||
|
12
CXX/yapq.hh
12
CXX/yapq.hh
@ -185,17 +185,15 @@ public:
|
|||||||
virtual void run(char *s) {}
|
virtual void run(char *s) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
void YAP_init_args::YAP_init_args()
|
|
||||||
{
|
|
||||||
Yap_InitDefaults(this, NULL, 0, NULL);
|
|
||||||
} ;
|
|
||||||
|
|
||||||
/// @brief Setup all arguments to a new engine
|
/// @brief Setup all arguments to a new engine
|
||||||
struct X_API YAPEngineArgs: YAP_init_args {
|
struct X_API YAPEngineArgs: YAP_init_args {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
YAPEngineArgs(): yap_boot_params() {
|
YAPEngineArgs():yap_boot_params() {
|
||||||
#if YAP_PYTHON
|
char s[32];
|
||||||
|
strcpy(s, "startup.yss" );
|
||||||
|
Yap_InitDefaults(this,s,0,nullptr);
|
||||||
|
#if YAP_PYTHON
|
||||||
Embedded = true;
|
Embedded = true;
|
||||||
python_in_python = Py_IsInitialized();
|
python_in_python = Py_IsInitialized();
|
||||||
#endif
|
#endif
|
||||||
|
@ -241,7 +241,7 @@ public:
|
|||||||
char *os;
|
char *os;
|
||||||
|
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
if (!(os = Yap_TermToString(Yap_GetFromSlot(t), enc, Handle_vars_f))) {
|
if (!(os = Yap_TermToBuffer(Yap_GetFromSlot(t), enc, Handle_vars_f))) {
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -96,7 +96,7 @@ typedef struct ExtraAtomEntryStruct {
|
|||||||
#define USE_OFFSETS_IN_PROPS 0
|
#define USE_OFFSETS_IN_PROPS 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef SFLAGS PropFlags;
|
typedef u_short PropFlags;
|
||||||
|
|
||||||
/* basic property entry structure */
|
/* basic property entry structure */
|
||||||
typedef struct PropEntryStruct {
|
typedef struct PropEntryStruct {
|
||||||
|
96
H/YapTerm.h
96
H/YapTerm.h
@ -17,9 +17,6 @@
|
|||||||
#include "YapTermConfig.h"
|
#include "YapTermConfig.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
typedef void *Functor;
|
|
||||||
typedef void *Atom;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAVE_STDINT_H
|
#if HAVE_STDINT_H
|
||||||
@ -29,6 +26,22 @@ typedef void *Atom;
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* truth-values */
|
||||||
|
/* stdbool defines the booleam type, bool,
|
||||||
|
and the constants false and true */
|
||||||
|
#if HAVE_STDBOOL_H
|
||||||
|
#include <stdbool.h>
|
||||||
|
#else
|
||||||
|
#ifndef true
|
||||||
|
typedef int _Bool;
|
||||||
|
#define bool _Bool;
|
||||||
|
|
||||||
|
#define false 0
|
||||||
|
#define true 1
|
||||||
|
#endif
|
||||||
|
#endif /* HAVE_STDBOOL_H */
|
||||||
|
|
||||||
|
|
||||||
#define ALIGN_BY_TYPE(X, TYPE) \
|
#define ALIGN_BY_TYPE(X, TYPE) \
|
||||||
(((CELL)(X) + (sizeof(TYPE) - 1)) & ~(sizeof(TYPE) - 1))
|
(((CELL)(X) + (sizeof(TYPE) - 1)) & ~(sizeof(TYPE) - 1))
|
||||||
|
|
||||||
@ -45,59 +58,98 @@ typedef void *Atom;
|
|||||||
|
|
||||||
#if defined(PRIdPTR)
|
#if defined(PRIdPTR)
|
||||||
|
|
||||||
typedef intptr_t Int;
|
typedef intptr_t YAP_Int;
|
||||||
typedef uintptr_t UInt;
|
typedef uintptr_t YAP_UInt;
|
||||||
|
|
||||||
#elif defined(_WIN64)
|
#elif defined(_WIN64)
|
||||||
|
|
||||||
|
|
||||||
typedef int64_t Int;
|
typedef int64_t YAP_Int;
|
||||||
typedef uint64_t UInt;
|
typedef uint64_t YAP_UInt;
|
||||||
|
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
|
|
||||||
typedef int32_t Int;
|
typedef int32_t YAP_Int;
|
||||||
typedef uint32_t UInt;
|
typedef uint32_t YAP_UInt;
|
||||||
|
|
||||||
#elif SIZEOF_LONG_INT == SIZEOF_INT_P
|
#elif SIZEOF_LONG_INT == SIZEOF_INT_P
|
||||||
|
|
||||||
typedef long int Int;
|
typedef long int YAP_Int;
|
||||||
typedef unsigned long int UInt;
|
typedef unsigned long int YAP_UInt;
|
||||||
|
|
||||||
#elif SIZEOF_INT == SIZEOF_INT_P
|
#elif SIZEOF_INT == SIZEOF_INT_P
|
||||||
|
|
||||||
typedef int Int;
|
typedef int YAP_Int;
|
||||||
typedef unsigned int UInt;
|
typedef unsigned int YAP_UInt;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#error Yap require integer types of the same size as a pointer
|
#error Yap require integer types of the same size as a pointer
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* */ typedef short int Short;
|
/* */ typedef short int YAP_Short;
|
||||||
/* */ typedef unsigned short int UShort;
|
/* */ typedef unsigned short int YAP_UShort;
|
||||||
|
|
||||||
typedef UInt CELL;
|
typedef YAP_UInt YAP_CELL;
|
||||||
|
typedef YAP_UInt YAP_Term;
|
||||||
|
|
||||||
|
/* Type definitions */
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef TRUE
|
||||||
|
#define TRUE true
|
||||||
|
#endif
|
||||||
|
#ifndef FALSE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef bool YAP_Bool;
|
||||||
|
#define FALSE false
|
||||||
|
|
||||||
|
typedef YAP_Int YAP_handle_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef double YAP_Float;
|
||||||
|
|
||||||
|
typedef void *YAP_Atom;
|
||||||
|
|
||||||
|
typedef void *YAP_Functor;
|
||||||
|
|
||||||
|
#ifdef YAP_H
|
||||||
|
|
||||||
|
typedef YAP_Int Int;
|
||||||
|
typedef YAP_UInt UInt;
|
||||||
|
typedef YAP_Short Short;
|
||||||
|
typedef YAP_UShort UShort;
|
||||||
|
|
||||||
typedef uint16_t BITS16;
|
typedef uint16_t BITS16;
|
||||||
typedef int16_t SBITS16;
|
typedef int16_t SBITS16;
|
||||||
typedef uint32_t BITS32;
|
typedef uint32_t BITS32;
|
||||||
|
|
||||||
|
typedef YAP_CELL CELL;
|
||||||
|
|
||||||
|
typedef YAP_Term Term;
|
||||||
|
|
||||||
#define WordSize sizeof(BITS16)
|
#define WordSize sizeof(BITS16)
|
||||||
#define CellSize sizeof(CELL)
|
#define CellSize sizeof(CELL)
|
||||||
#define SmallSize sizeof(SMALLUNSGN)
|
#define SmallSize sizeof(SMALLUNSGN)
|
||||||
|
|
||||||
|
typedef YAP_Int Int;
|
||||||
|
typedef YAP_Float Float;
|
||||||
|
typedef YAP_handle_t yhandle_t;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "YapError.h"
|
||||||
|
|
||||||
|
#include "../os/encoding.h"
|
||||||
|
|
||||||
|
typedef encoding_t YAP_encoding_t;
|
||||||
|
|
||||||
#include "YapFormat.h"
|
#include "YapFormat.h"
|
||||||
|
|
||||||
/*************************************************************************************************
|
/*************************************************************************************************
|
||||||
type casting macros
|
type casting macros
|
||||||
*************************************************************************************************/
|
*************************************************************************************************/
|
||||||
|
|
||||||
typedef UInt Term;
|
|
||||||
|
|
||||||
typedef Int yhandle_t;
|
|
||||||
|
|
||||||
typedef double Float;
|
|
||||||
|
|
||||||
#if SIZEOF_INT < SIZEOF_INT_P
|
#if SIZEOF_INT < SIZEOF_INT_P
|
||||||
#define SHORT_INTS 1
|
#define SHORT_INTS 1
|
||||||
#else
|
#else
|
||||||
|
@ -416,7 +416,7 @@ extern AAssetManager *Yap_assetManager;
|
|||||||
extern void *Yap_openAssetFile(const char *path);
|
extern void *Yap_openAssetFile(const char *path);
|
||||||
extern bool Yap_isAsset(const char *path);
|
extern bool Yap_isAsset(const char *path);
|
||||||
#endif
|
#endif
|
||||||
extern const char *Yap_getcwd(const char *, size_t);
|
extern const char *Yap_getcwd( char *, size_t);
|
||||||
extern void Yap_cputime_interval(Int *, Int *);
|
extern void Yap_cputime_interval(Int *, Int *);
|
||||||
extern void Yap_systime_interval(Int *, Int *);
|
extern void Yap_systime_interval(Int *, Int *);
|
||||||
extern void Yap_InitSysbits(int wid);
|
extern void Yap_InitSysbits(int wid);
|
||||||
|
12
H/Yatom.h
12
H/Yatom.h
@ -1306,10 +1306,10 @@ void Yap_UpdateTimestamps(PredEntry *);
|
|||||||
void Yap_ErDBE(DBRef);
|
void Yap_ErDBE(DBRef);
|
||||||
DBTerm *Yap_StoreTermInDB(Term, int);
|
DBTerm *Yap_StoreTermInDB(Term, int);
|
||||||
DBTerm *Yap_StoreTermInDBPlusExtraSpace(Term, UInt, UInt *);
|
DBTerm *Yap_StoreTermInDBPlusExtraSpace(Term, UInt, UInt *);
|
||||||
Term Yap_FetchTermFromDB(DBTerm *);
|
Term Yap_FetchTermFromDB(void *);
|
||||||
Term Yap_FetchClauseTermFromDB(DBTerm *);
|
Term Yap_FetchClauseTermFromDB(void *);
|
||||||
Term Yap_PopTermFromDB(DBTerm *);
|
Term Yap_PopTermFromDB(void *);
|
||||||
void Yap_ReleaseTermFromDB(DBTerm *);
|
void Yap_ReleaseTermFromDB(void *);
|
||||||
|
|
||||||
/* init.c */
|
/* init.c */
|
||||||
Atom Yap_GetOp(OpEntry *, int *, int);
|
Atom Yap_GetOp(OpEntry *, int *, int);
|
||||||
@ -1598,8 +1598,8 @@ bool Yap_PutException(Term t);
|
|||||||
INLINE_ONLY inline EXTERN bool Yap_HasException(void) {
|
INLINE_ONLY inline EXTERN bool Yap_HasException(void) {
|
||||||
return LOCAL_BallTerm != NULL;
|
return LOCAL_BallTerm != NULL;
|
||||||
}
|
}
|
||||||
INLINE_ONLY inline EXTERN DBTerm *Yap_RefToException(void) {
|
INLINE_ONLY inline EXTERN void *Yap_RefToException(void) {
|
||||||
DBTerm *dbt = LOCAL_BallTerm;
|
void *dbt = LOCAL_BallTerm;
|
||||||
LOCAL_BallTerm = NULL;
|
LOCAL_BallTerm = NULL;
|
||||||
return dbt;
|
return dbt;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ typedef struct vfs {
|
|||||||
const char *suffix;
|
const char *suffix;
|
||||||
bool (*chDir)(struct vfs *me, const char *s);
|
bool (*chDir)(struct vfs *me, const char *s);
|
||||||
/** operations */
|
/** operations */
|
||||||
void *(*open)(int sno, const char *fname, const char *io_mode); /// open an object
|
void *(*open)(struct vfs *,int sno, const char *fname, const char *io_mode); /// open an object
|
||||||
/// in this space, usual w,r,a,b flags plus B (store in a buffer)
|
/// in this space, usual w,r,a,b flags plus B (store in a buffer)
|
||||||
bool (*close)(int sno); /// close the object
|
bool (*close)(int sno); /// close the object
|
||||||
int (*get_char)(int sno); /// get an octet to the stream
|
int (*get_char)(int sno); /// get an octet to the stream
|
||||||
@ -92,7 +92,7 @@ typedef struct vfs {
|
|||||||
const char *(*nextdir)(void *d); /// walk to the next entry in a directory object
|
const char *(*nextdir)(void *d); /// walk to the next entry in a directory object
|
||||||
bool (*closedir)(void *d);
|
bool (*closedir)(void *d);
|
||||||
; /// close access a directory object
|
; /// close access a directory object
|
||||||
bool (*stat)(const char *s,
|
bool (*stat)(struct vfs *,const char *s,
|
||||||
vfs_stat *); /// obtain size, age, permissions of a file.
|
vfs_stat *); /// obtain size, age, permissions of a file.
|
||||||
bool (*isdir)(struct vfs *,const char *s); /// verify whether is directory.
|
bool (*isdir)(struct vfs *,const char *s); /// verify whether is directory.
|
||||||
bool (*exists)(struct vfs *, const char *s); /// verify whether a file exists.
|
bool (*exists)(struct vfs *, const char *s); /// verify whether a file exists.
|
||||||
|
@ -50,23 +50,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef YAP_H
|
|
||||||
|
|
||||||
/* The YAP main types */
|
/* The YAP main types */
|
||||||
#include "YapTerm.h"
|
#include "YapTerm.h"
|
||||||
|
|
||||||
/**
|
|
||||||
This term can never be constructed as a valid term, so it is
|
|
||||||
used as a "BAD" term
|
|
||||||
*/
|
|
||||||
#define TermZERO ((Term)0)
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#include "YapConfig.h"
|
|
||||||
|
|
||||||
#endif /* YAP_H */
|
|
||||||
|
|
||||||
#if HAVE_STDINT_H
|
#if HAVE_STDINT_H
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#endif
|
#endif
|
||||||
@ -74,21 +61,6 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* truth-values */
|
|
||||||
/* stdbool defines the booleam type, bool,
|
|
||||||
and the constants false and true */
|
|
||||||
#if HAVE_STDBOOL_H
|
|
||||||
#include <stdbool.h>
|
|
||||||
#else
|
|
||||||
#ifndef true
|
|
||||||
typedef int _Bool;
|
|
||||||
#define bool _Bool;
|
|
||||||
|
|
||||||
#define false 0
|
|
||||||
#define true 1
|
|
||||||
#endif
|
|
||||||
#endif /* HAVE_STDBOOL_H */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
FALSE and TRUE are the pre-standard versions,
|
FALSE and TRUE are the pre-standard versions,
|
||||||
still widely used.
|
still widely used.
|
||||||
@ -103,79 +75,26 @@ typedef int _Bool;
|
|||||||
typedef bool YAP_Bool;
|
typedef bool YAP_Bool;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef YAP_H
|
|
||||||
|
|
||||||
/* if Yap.h is available, just reexport */
|
/**
|
||||||
|
This term can never be constructed as a valid term, so it is
|
||||||
|
used as a "BAD" term
|
||||||
|
*/
|
||||||
|
#define TermZERO ((Term)0)
|
||||||
|
|
||||||
#define YAP_CELL CELL
|
|
||||||
|
|
||||||
#define YAP_Term Term
|
#include "YapConfig.h"
|
||||||
|
|
||||||
#define YAP_Arity arity_t
|
|
||||||
|
|
||||||
#define YAP_Module Term
|
typedef void *YAP_PredEntryPtr;
|
||||||
|
|
||||||
#define YAP_Functor Functor
|
|
||||||
|
|
||||||
#define YAP_Atom Atom
|
|
||||||
|
|
||||||
#define YAP_Int Int
|
|
||||||
|
|
||||||
#define YAP_UInt UInt
|
|
||||||
|
|
||||||
#define YAP_Float Float
|
|
||||||
|
|
||||||
#define YAP_handle_t yhandle_t
|
|
||||||
|
|
||||||
#define YAP_PredEntryPtr struct pred_entry *
|
|
||||||
|
|
||||||
#define YAP_UserCPred CPredicate
|
|
||||||
|
|
||||||
#define YAP_agc_hook Agc_hook
|
|
||||||
|
|
||||||
#define YAP_encoding_t encoding_t
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* Type definitions */
|
|
||||||
#if defined(PRIdPTR)
|
|
||||||
typedef uintptr_t YAP_UInt;
|
|
||||||
typedef intptr_t YAP_Int;
|
|
||||||
#elif _WIN64
|
|
||||||
typedef int64_t YAP_Int;
|
|
||||||
typedef uint64_t YAP_UInt;
|
|
||||||
#elif _WIN32
|
|
||||||
typedef int32_t YAP_Int;
|
|
||||||
typedef uint32_t YAP_UInt;
|
|
||||||
#else
|
|
||||||
typedef long int YAP_Int;
|
|
||||||
typedef unsigned long int YAP_UInt;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef YAP_UInt YAP_CELL;
|
|
||||||
|
|
||||||
typedef YAP_CELL YAP_Term;
|
|
||||||
|
|
||||||
typedef size_t YAP_Arity;
|
typedef size_t YAP_Arity;
|
||||||
|
|
||||||
typedef YAP_Term YAP_Module;
|
typedef YAP_Term YAP_Module;
|
||||||
|
|
||||||
typedef struct FunctorEntry *YAP_Functor;
|
|
||||||
|
|
||||||
typedef struct AtomEntry *YAP_Atom;
|
|
||||||
|
|
||||||
typedef double YAP_Float;
|
|
||||||
|
|
||||||
#ifndef TRUE
|
|
||||||
#define TRUE 1
|
|
||||||
#endif
|
|
||||||
#ifndef FALSE
|
|
||||||
#define FALSE 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef YAP_Int YAP_handle_t;
|
typedef YAP_Int YAP_handle_t;
|
||||||
|
|
||||||
typedef struct YAP_pred_entry *YAP_PredEntryPtr;
|
typedef void *YAP_PredEntryPtr;
|
||||||
|
|
||||||
typedef YAP_Bool (*YAP_UserCPred)(void);
|
typedef YAP_Bool (*YAP_UserCPred)(void);
|
||||||
|
|
||||||
@ -187,8 +106,6 @@ typedef int (*YAP_agc_hook)(void *_Atom);
|
|||||||
|
|
||||||
typedef encoding_t YAP_encoding_t;
|
typedef encoding_t YAP_encoding_t;
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
#include <android/asset_manager.h>
|
#include <android/asset_manager.h>
|
||||||
#include <android/native_activity.h>
|
#include <android/native_activity.h>
|
||||||
@ -257,6 +174,10 @@ typedef enum {
|
|||||||
#define YAP_RECONSULT_MODE 1
|
#define YAP_RECONSULT_MODE 1
|
||||||
#define YAP_BOOT_MODE 2
|
#define YAP_BOOT_MODE 2
|
||||||
|
|
||||||
|
|
||||||
|
X_API YAP_file_type_t Yap_InitDefaults(void *init_args, char saved_state[],
|
||||||
|
int Argc, char *Argv[]);
|
||||||
|
|
||||||
typedef struct yap_boot_params {
|
typedef struct yap_boot_params {
|
||||||
//> boot type as suggested by the user
|
//> boot type as suggested by the user
|
||||||
YAP_file_type_t boot_file_type;
|
YAP_file_type_t boot_file_type;
|
||||||
@ -351,16 +272,8 @@ typedef struct yap_boot_params {
|
|||||||
int ErrorNo;
|
int ErrorNo;
|
||||||
//> errorstring
|
//> errorstring
|
||||||
char *ErrorCause;
|
char *ErrorCause;
|
||||||
#ifdef __cplusplus
|
|
||||||
void YAP_init_args();
|
|
||||||
#endif
|
|
||||||
} YAP_init_args;
|
} YAP_init_args;
|
||||||
|
|
||||||
#ifdef YAP_H
|
|
||||||
YAP_file_type_t Yap_InitDefaults(YAP_init_args *init_args, char saved_state[],
|
|
||||||
int Argc, char **Argv);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* this should be opaque to the user */
|
/* this should be opaque to the user */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned long b; //> choice-point at entry
|
unsigned long b; //> choice-point at entry
|
||||||
|
@ -176,48 +176,48 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi,
|
|||||||
/// go back t
|
/// go back t
|
||||||
} yap_error_stage_t;
|
} yap_error_stage_t;
|
||||||
|
|
||||||
/// a Prolo goal that caused a bug
|
/// a Prolog goal that caused a bug
|
||||||
|
|
||||||
typedef struct error_prolog_source {
|
typedef struct error_prolog_source {
|
||||||
YAP_Int prologPredCl;
|
intptr_t prologPredCl;
|
||||||
YAP_UInt prologPredLine;
|
uintptr_t prologPredLine;
|
||||||
YAP_UInt prologPredFirstLine;
|
uintptr_t prologPredFirstLine;
|
||||||
YAP_UInt prologPredLastLine;
|
uintptr_t prologPredLastLine;
|
||||||
YAP_Atom prologPredName;
|
const char * prologPredName;
|
||||||
YAP_UInt prologPredArity;
|
uintptr_t prologPredArity;
|
||||||
YAP_Term prologPredModule;
|
const char * prologPredModule;
|
||||||
YAP_Atom prologPredFile;
|
const char * prologPredFile;
|
||||||
struct DB_TERM *errorGoal;
|
void *errorGoal;
|
||||||
struct error_prolog_source *errorParent;
|
struct error_prolog_source *errorParent;
|
||||||
} error_prolog_source_t;
|
} error_prolog_source_t;
|
||||||
|
|
||||||
/// all we need to know about an error/throw
|
/// all we need to know about an error/throw
|
||||||
typedef struct yap_error_descriptor {
|
typedef struct error_descriptor {
|
||||||
enum yap_error_status status;
|
enum yap_error_status status;
|
||||||
yap_error_class_number errorClass;
|
yap_error_class_number errorClass;
|
||||||
YAP_Atom errorAsText;
|
const char * errorAsText;
|
||||||
YAP_Atom classAsText;
|
const char * classAsText;
|
||||||
yap_error_number errorNo;
|
yap_error_number errorNo;
|
||||||
YAP_Int errorLine;
|
intptr_t errorLine;
|
||||||
const char *errorFunction;
|
const char *errorFunction;
|
||||||
const char *errorFile;
|
const char *errorFile;
|
||||||
// struct error_prolog_source *errorSource;
|
// struct error_prolog_source *errorSource;
|
||||||
YAP_Int prologPredCl;
|
intptr_t prologPredCl;
|
||||||
YAP_UInt prologPredLine;
|
uintptr_t prologPredLine;
|
||||||
YAP_UInt prologPredFirstLine;
|
uintptr_t prologPredFirstLine;
|
||||||
YAP_UInt prologPredLastLine;
|
uintptr_t prologPredLastLine;
|
||||||
YAP_Atom prologPredName;
|
const char * prologPredName;
|
||||||
YAP_UInt prologPredArity;
|
uintptr_t prologPredArity;
|
||||||
YAP_Term prologPredModule;
|
const char * prologPredModule;
|
||||||
YAP_Atom prologPredFile;
|
const char * prologPredFile;
|
||||||
YAP_UInt prologParserLine;
|
uintptr_t prologParserLine;
|
||||||
YAP_UInt prologParserFirstLine;
|
uintptr_t prologParserFirstLine;
|
||||||
YAP_UInt prologParserLastLine;
|
uintptr_t prologParserLastLine;
|
||||||
YAP_Atom prologParserName;
|
const char * prologParserName;
|
||||||
YAP_Atom prologParserFile;
|
const char * prologParserFile;
|
||||||
YAP_Bool prologConsulting;
|
bool prologConsulting;
|
||||||
struct DB_TERM *errorTerm;
|
void *errorTerm;
|
||||||
YAP_Term rawErrorTerm, rawExtraErrorTerm;
|
uintptr_t rawErrorTerm, rawExtraErrorTerm;
|
||||||
char *errorMsg;
|
char *errorMsg;
|
||||||
size_t errorMsgLen;
|
size_t errorMsgLen;
|
||||||
struct yap_error_descriptor *top_error;
|
struct yap_error_descriptor *top_error;
|
||||||
|
@ -268,18 +268,19 @@ extern X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred,
|
|||||||
extern X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred,
|
extern X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred,
|
||||||
YAP_UserCPred, YAP_Arity, YAP_Arity);
|
YAP_UserCPred, YAP_Arity, YAP_Arity);
|
||||||
|
|
||||||
/* YAP_Int YAP_ListLength(YAP_Term t) */
|
|
||||||
extern X_API YAP_Int YAP_ListLength(YAP_Term);
|
|
||||||
|
|
||||||
extern X_API size_t YAP_UTF8_TextLength(YAP_Term t);
|
|
||||||
|
|
||||||
/* void UserBackCPredicate(char *name, int *init(), int *cont(), int *cut(),
|
/* void UserBackCPredicate(char *name, int *init(), int *cont(), int *cut(),
|
||||||
int
|
int
|
||||||
arity, int extra) */
|
arity, int extra) */
|
||||||
extern X_API void YAP_UserBackCutCPredicate(const char *, YAP_UserCPred,
|
extern X_API void YAP_UserBackCutCPredicate(const char *name, YAP_UserCPred,
|
||||||
YAP_UserCPred, YAP_UserCPred,
|
YAP_UserCPred, YAP_UserCPred,
|
||||||
YAP_Arity, YAP_Arity);
|
YAP_Arity, YAP_Arity);
|
||||||
|
|
||||||
|
/* YAP_Int YAP_ListLength(YAP_Term t) */
|
||||||
|
extern X_API YAP_Int YAP_ListLength(YAP_Term);
|
||||||
|
|
||||||
|
extern X_API size_t YAP_UTF8_TextLength(YAP_Term t);
|
||||||
|
|
||||||
/* void CallProlog(YAP_Term t) */
|
/* void CallProlog(YAP_Term t) */
|
||||||
extern X_API YAP_Int YAP_CallProlog(YAP_Term t);
|
extern X_API YAP_Int YAP_CallProlog(YAP_Term t);
|
||||||
|
|
||||||
@ -399,7 +400,7 @@ extern X_API YAP_Term YAP_ReadFromStream(int s);
|
|||||||
|
|
||||||
/// read a Prolog clause from a Prolog opened stream $s$. Similar to
|
/// read a Prolog clause from a Prolog opened stream $s$. Similar to
|
||||||
/// YAP_ReadFromStream() but takes /// default options from read_clause/3.
|
/// YAP_ReadFromStream() but takes /// default options from read_clause/3.
|
||||||
extern X_API YAP_Term YAP_ReadFromStream(int s);
|
extern X_API YAP_Term YAP_ReadClauseFromStream(int s);
|
||||||
|
|
||||||
extern X_API void YAP_Write(YAP_Term t, FILE *s, int);
|
extern X_API void YAP_Write(YAP_Term t, FILE *s, int);
|
||||||
|
|
||||||
|
@ -136,9 +136,9 @@ FILE *open_memstream(char **buf, size_t *len);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
|
//extern FILE * fmemopen(void *buf, size_t size, const char *mode);
|
||||||
#undef HAVE_FMEMOPEN
|
#define HAVE_FMEMOPEN 1
|
||||||
#undef HAVE_OPEN_MEMSTREAM
|
#define HAVE_OPEN_MEMSTREAM 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAVE_FMEMOPEN
|
#if HAVE_FMEMOPEN
|
||||||
|
@ -7,7 +7,10 @@ set (YAPOS_SOURCES
|
|||||||
console.c
|
console.c
|
||||||
files.c
|
files.c
|
||||||
fmem.c
|
fmem.c
|
||||||
fmemopen.c
|
# fmemopen.c
|
||||||
|
#android/fmemopen.c
|
||||||
|
# android/fopencookie.c
|
||||||
|
# android/open_memstream.c
|
||||||
format.c
|
format.c
|
||||||
iopreds.c
|
iopreds.c
|
||||||
mem.c
|
mem.c
|
||||||
|
271
os/assets.c
271
os/assets.c
@ -35,197 +35,190 @@ static char SccsId[] = "%W% %G%";
|
|||||||
|
|
||||||
|
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
|
|
||||||
#include <android/asset_manager.h>
|
#include <android/asset_manager.h>
|
||||||
#include <android/native_activity.h>
|
#include <android/native_activity.h>
|
||||||
|
|
||||||
AAssetManager * Yap_assetManager;
|
AAssetManager *Yap_assetManager;
|
||||||
|
|
||||||
jboolean Java_pt_up_yap_app_YAPDroid_setAssetManager(JNIEnv* env, jclass clazz, jobject assetManager)
|
jboolean
|
||||||
{
|
Java_pt_up_yap_app_YAPDroid_setAssetManager(JNIEnv *env, jclass clazz, jobject assetManager) {
|
||||||
Yap_assetManager = AAssetManager_fromJava(env, assetManager);
|
Yap_assetManager = AAssetManager_fromJava(env, assetManager);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
open_asset__( int sno, const char *fname, const char *io_mode)
|
open_asset__(VFS_t *me, int sno, const char *fname, const char *io_mode) {
|
||||||
{
|
int mode;
|
||||||
int mode;
|
const void *buf;
|
||||||
const void *buf;
|
if (strchr(io_mode, 'B'))
|
||||||
VFS_t *me = GLOBAL_Stream[sno].vfs;
|
mode = AASSET_MODE_BUFFER;
|
||||||
if (strstr(fname,"/assets") == fname) {
|
else {
|
||||||
// we're in
|
mode = AASSET_MODE_UNKNOWN;
|
||||||
if ( Yap_assetManager == NULL) {
|
}
|
||||||
PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, TermNil,
|
fname += strlen(me->prefix) + 1;
|
||||||
"asset manager",
|
AAsset *a = AAssetManager_open(Yap_assetManager, fname, mode);
|
||||||
fname);
|
if (!a)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
// try not to use it as an asset
|
||||||
if (strchr(io_mode, 'w') || strchr(io_mode, 'a')) {
|
off64_t sz = AAsset_getLength64(a), sz0 = 0;
|
||||||
PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, TermNil,
|
int fd;
|
||||||
"%s: no writing but flags are %s",
|
StreamDesc *st = GLOBAL_Stream + sno;
|
||||||
fname, io_mode);
|
if ((buf = AAsset_getBuffer(a))) {
|
||||||
return NULL;
|
// copy to memory
|
||||||
}
|
bool rc = Yap_set_stream_to_buf(st, buf, sz);
|
||||||
if (strchr(io_mode, 'B'))
|
if (rc) AAsset_close(a);
|
||||||
mode = AASSET_MODE_BUFFER;
|
st->vfs = NULL;
|
||||||
else {
|
st->vfs_handle = NULL;
|
||||||
mode = AASSET_MODE_UNKNOWN;
|
st->status = InMemory_Stream_f|Seekable_Stream_f|Input_Stream_f;
|
||||||
}
|
return st;
|
||||||
AAsset *a = AAssetManager_open( Yap_assetManager, fname, mode);
|
} else if ((fd = AAsset_openFileDescriptor64(a, &sz0, &sz)) >= 0) {
|
||||||
// try not to use it as an asset
|
// can use it as read-only file
|
||||||
off64_t sz = AAsset_getLength64(a), sz0 = 0;
|
st->file = fdopen(fd, "r");
|
||||||
int fd;
|
st->vfs = NULL;
|
||||||
StreamDesc *st = GLOBAL_Stream+sno;
|
st->vfs_handle = NULL;
|
||||||
if ((fd = AAsset_openFileDescriptor64(a, &sz0, &sz)) >= 0) {
|
st->status = Seekable_Stream_f|Input_Stream_f;
|
||||||
// can use it as red-only file
|
return st;
|
||||||
st->file = fdopen(fd, "r");
|
} else {
|
||||||
st->vfs = me;
|
// should be done, but if not
|
||||||
st->vfs_handle = a;
|
GLOBAL_Stream[sno].vfs_handle = a;
|
||||||
return a;
|
st->vfs = me;
|
||||||
} else if ((buf = AAsset_getBuffer(a))) {
|
st->status = Input_Stream_f;
|
||||||
// copy to memory
|
return a;
|
||||||
bool rc = Yap_set_stream_to_buf(st, buf, sz);
|
}
|
||||||
if (rc) AAsset_close(a);
|
|
||||||
return st;
|
|
||||||
}
|
|
||||||
// should be done, but if not
|
|
||||||
GLOBAL_Stream[sno].vfs_handle= a;
|
|
||||||
st->vfs = me;
|
|
||||||
return a;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
close_asset(int sno)
|
close_asset(int sno) {
|
||||||
{
|
AAsset_close(GLOBAL_Stream[sno].vfs_handle);
|
||||||
AAsset_close(GLOBAL_Stream[sno].vfs_handle);
|
return true;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int64_t seek64(int sno, int64_t offset, int whence)
|
static int64_t seek64(int sno, int64_t offset, int whence) {
|
||||||
{
|
return AAsset_seek64(GLOBAL_Stream[sno].vfs_handle, offset, whence);
|
||||||
return AAsset_seek64(GLOBAL_Stream[sno].vfs_handle, offset, whence);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int getc_asset(int sno)
|
static int getc_asset(int sno) {
|
||||||
{
|
int ch;
|
||||||
int ch;
|
if (AAsset_read(GLOBAL_Stream[sno].vfs_handle, &ch, 1))
|
||||||
if ( AAsset_read (GLOBAL_Stream[sno].vfs_handle, &ch, 1) )
|
return ch;
|
||||||
return ch;
|
return -1;
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void *opendir_a( VFS_t *me, const char *dirName)
|
static void *opendir_a(VFS_t *me, const char *dirName) {
|
||||||
{
|
dirName += strlen(me->prefix) + 1;
|
||||||
return (void *)AAssetManager_openDir (Yap_assetManager, dirName);
|
return (void *) AAssetManager_openDir(Yap_assetManager, dirName);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *readdir_a(void *dirHandle)
|
static const char *readdir_a(void *dirHandle) {
|
||||||
{
|
return AAssetDir_getNextFileName((AAssetDir *) dirHandle);
|
||||||
return AAssetDir_getNextFileName ((AAssetDir *)dirHandle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool closedir_a(void *dirHandle)
|
static bool closedir_a(void *dirHandle) {
|
||||||
{
|
AAssetDir_close((AAssetDir *) dirHandle);
|
||||||
AAssetDir_close ((AAssetDir *)dirHandle);
|
return true;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool stat_a(VFS_t *me, const char *fname, vfs_stat *out)
|
static bool stat_a(VFS_t *me, const char *fname, vfs_stat *out) {
|
||||||
{
|
struct stat bf;
|
||||||
struct stat bf;
|
fname += strlen(me->prefix) + 1;
|
||||||
if (stat( "/assets", &bf)) {
|
if (stat("/assets", &bf)) {
|
||||||
|
|
||||||
out->st_dev = bf.st_dev;
|
out->st_dev = bf.st_dev;
|
||||||
out->st_uid = bf.st_uid;
|
out->st_uid = bf.st_uid;
|
||||||
out->st_gid = bf.st_gid;
|
out->st_gid = bf.st_gid;
|
||||||
memcpy(&out->st_atimespec, (const void *)&out->st_atimespec, sizeof(struct timespec));
|
memcpy(&out->st_atimespec, (const void *) &out->st_atimespec, sizeof(struct timespec));
|
||||||
memcpy(&out->st_mtimespec,(const void *) &out->st_mtimespec, sizeof(struct timespec));
|
memcpy(&out->st_mtimespec, (const void *) &out->st_mtimespec, sizeof(struct timespec));
|
||||||
memcpy(&out->st_ctimespec, (const void *)&out->st_ctimespec, sizeof(struct timespec));
|
memcpy(&out->st_ctimespec, (const void *) &out->st_ctimespec, sizeof(struct timespec));
|
||||||
memcpy(&out->st_birthtimespec, (const void *)&out->st_birthtimespec, sizeof(struct timespec));
|
memcpy(&out->st_birthtimespec, (const void *) &out->st_birthtimespec,
|
||||||
}
|
sizeof(struct timespec));
|
||||||
AAsset *a = AAssetManager_open( Yap_assetManager , fname, AASSET_MODE_UNKNOWN);
|
}
|
||||||
|
AAsset *a = AAssetManager_open(Yap_assetManager, fname, AASSET_MODE_UNKNOWN);
|
||||||
// try not to use it as an asset
|
// try not to use it as an asset
|
||||||
out->st_size = AAsset_getLength64(a);
|
out->st_size = AAsset_getLength64(a);
|
||||||
AAsset_close(a);
|
AAsset_close(a);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
bool is_dir_a( VFS_t *me,const char *dirName)
|
bool is_dir_a(VFS_t *me, const char *dirName) {
|
||||||
{
|
bool rc;
|
||||||
bool rc;
|
dirName += strlen(me->prefix) + 1;
|
||||||
// try not to use it as an asset
|
// try not to use it as an asset
|
||||||
AAssetDir *d = AAssetManager_openDir ( Yap_assetManager, dirName);
|
AAssetDir *d = AAssetManager_openDir(Yap_assetManager, dirName);
|
||||||
if (d == NULL)
|
if (d == NULL)
|
||||||
return false;
|
return false;
|
||||||
rc = (AAssetDir_getNextFileName(d) != NULL);
|
rc = (AAssetDir_getNextFileName(d) != NULL);
|
||||||
AAssetDir_close(d);
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "isdir %s <%p>", dirName, d);
|
||||||
return rc;
|
AAssetDir_close(d);
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
VFS_t *exists_a(VFS_t *me, const char *dirName)
|
bool exists_a(VFS_t *me, const char *dirName) {
|
||||||
{
|
dirName += strlen(me->prefix) + 1;
|
||||||
// try not to use it as an asset
|
// try not to use it as an asset
|
||||||
AAsset *d = AAssetManager_open ( Yap_assetManager, dirName, AASSET_MODE_UNKNOWN);
|
AAsset *d = AAssetManager_open(Yap_assetManager, dirName, AASSET_MODE_UNKNOWN);
|
||||||
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exists %s <%p>", dirName, d);
|
||||||
if (d == NULL)
|
if (d == NULL)
|
||||||
return NULL;
|
return false;
|
||||||
AAsset_close(d);
|
AAsset_close(d);
|
||||||
return me;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool set_cwd (VFS_t *me, const char *dirName) {
|
extern char virtual_cwd[YAP_FILENAME_MAX + 1];
|
||||||
|
|
||||||
|
static bool set_cwd(VFS_t *me, const char *dirName) {
|
||||||
|
|
||||||
chdir("/assets");
|
chdir("/assets");
|
||||||
if (me->virtual_cwd)
|
strcpy(virtual_cwd, dirName);
|
||||||
free((void*)(me->virtual_cwd));
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid",
|
||||||
me->virtual_cwd = malloc( sizeof(dirName) + 1 );
|
"chdir %s", virtual_cwd);
|
||||||
return me!= NULL;
|
Yap_do_low_level_trace=1;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
VFS_t *
|
VFS_t *
|
||||||
Yap_InitAssetManager( void )
|
Yap_InitAssetManager(void) {
|
||||||
{
|
|
||||||
|
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
VFS_t *me;
|
VFS_t *me;
|
||||||
|
|
||||||
/* init standard VFS */
|
/* init standard VFS */
|
||||||
me = (VFS_t *)Yap_AllocCodeSpace(sizeof(struct vfs));
|
me = (VFS_t *) Yap_AllocCodeSpace(sizeof(struct vfs));
|
||||||
me->name = "/assets";
|
me->name = "/assets";
|
||||||
me->vflags = VFS_CAN_EXEC|VFS_CAN_SEEK|VFS_HAS_PREFIX; /// the main flags describing the operation of the Fs.
|
me->vflags = VFS_CAN_EXEC | VFS_CAN_SEEK |
|
||||||
me->prefix = "/assets";
|
VFS_HAS_PREFIX; /// the main flags describing the operation of the Fs.
|
||||||
/** operations */
|
me->prefix = "/assets";
|
||||||
me->open = open_asset__; /// open an object in this space
|
/** operations */
|
||||||
me->close= close_asset; /// close the object
|
me->open = open_asset__; /// open an object in this space
|
||||||
me->get_char = getc_asset; /// get an octet to the stream
|
me->close = close_asset; /// close the object
|
||||||
me->put_char = NULL; /// output an octet to the stream
|
me->get_char = getc_asset; /// get an octet to the stream
|
||||||
me->seek = seek64; /// jump around the stream
|
me->put_char = NULL; /// output an octet to the stream
|
||||||
me->opendir = opendir_a; /// open a directory object, if one exists
|
me->seek = seek64; /// jump around the stream
|
||||||
me->nextdir = readdir_a; /// open a directory object, if one exists
|
me->opendir = opendir_a; /// open a directory object, if one exists
|
||||||
me->closedir = closedir_a; /// close access a directory object
|
me->nextdir = readdir_a; /// open a directory object, if one exists
|
||||||
me->stat = stat_a; /// obtain size, age, permissions of a file.
|
me->closedir = closedir_a; /// close access a directory object
|
||||||
me->isdir = is_dir_a; /// obtain size, age, permissions of a file.
|
me->stat = stat_a; /// obtain size, age, permissions of a file.
|
||||||
me->exists = exists_a; /// obtain size, age, permissions of a file.
|
me->isdir = is_dir_a; /// obtain size, age, permissions of a file.
|
||||||
me->chdir = set_cwd; /// chnage working directory.
|
me->exists = exists_a; /// obtain size, age, permissions of a file.
|
||||||
me->enc = ENC_ISO_UTF8; /// how the file is encoded.
|
me->chdir = set_cwd; /// chnage working directory.
|
||||||
me->parsers = NULL; /// a set of parsers that can read the stream and generate a term
|
me->enc = ENC_ISO_UTF8; /// how the file is encoded.
|
||||||
me->writers = NULL;
|
me->parsers = NULL; /// a set of parsers that can read the stream and generate a term
|
||||||
LOCK(BGL);
|
me->writers = NULL;
|
||||||
me-> next = GLOBAL_VFS;
|
LOCK(BGL);
|
||||||
GLOBAL_VFS = me;
|
me->next = GLOBAL_VFS;
|
||||||
return me;
|
GLOBAL_VFS = me;
|
||||||
UNLOCK(BGL);
|
return me;
|
||||||
return me;
|
UNLOCK(BGL);
|
||||||
|
return me;
|
||||||
#else
|
#else
|
||||||
return NULL;
|
return NULL;
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,6 +20,11 @@
|
|||||||
#define ENCODING_H 1
|
#define ENCODING_H 1
|
||||||
|
|
||||||
#include "YapError.h"
|
#include "YapError.h"
|
||||||
|
#if HAVE_STRING_H
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ENC_OCTET = 0, /// binary files
|
ENC_OCTET = 0, /// binary files
|
||||||
|
@ -460,7 +460,7 @@ static Int exists_directory(USES_REGS1) {
|
|||||||
#if HAVE_STAT
|
#if HAVE_STAT
|
||||||
struct SYSTEM_STAT ss;
|
struct SYSTEM_STAT ss;
|
||||||
|
|
||||||
file_name = RepAtom(AtomOfTerm(tname))->StrOfAE;
|
file_name = Yap_VF(RepAtom(AtomOfTerm(tname))->StrOfAE);
|
||||||
if (SYSTEM_STAT(file_name, &ss) != 0) {
|
if (SYSTEM_STAT(file_name, &ss) != 0) {
|
||||||
/* ignore errors while checking a file */
|
/* ignore errors while checking a file */
|
||||||
return false;
|
return false;
|
||||||
@ -483,7 +483,7 @@ static Int is_absolute_file_name(USES_REGS1) { /* file_base_name(Stream,N) */
|
|||||||
int l = push_text_stack();
|
int l = push_text_stack();
|
||||||
const char *buf = Yap_TextTermToText(t PASS_REGS);
|
const char *buf = Yap_TextTermToText(t PASS_REGS);
|
||||||
if (buf) {
|
if (buf) {
|
||||||
rc = Yap_IsAbsolutePath(buf);
|
rc = Yap_IsAbsolutePath(buf, true);
|
||||||
} else {
|
} else {
|
||||||
at = AtomOfTerm(t);
|
at = AtomOfTerm(t);
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
|
22
os/fmem.c
22
os/fmem.c
@ -114,16 +114,18 @@ bool fill_pads(int sno, int sno0, int total, format_info *fg USES_REGS)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf, encoding_t enc,
|
bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf,
|
||||||
size_t nchars) {
|
size_t nchars USES_REGS) {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
// like any file stream.
|
// like any file stream.
|
||||||
st->file = f = fmemopen((void *)buf, nchars, "r");
|
st->file = f = fmemopen((char *)buf, nchars, "r");
|
||||||
st->status = Input_Stream_f | InMemory_Stream_f | Seekable_Stream_f;
|
st->status = Input_Stream_f | Seekable_Stream_f | InMemory_Stream_f;
|
||||||
st->vfs = NULL;
|
st->vfs = NULL;
|
||||||
st->encoding = enc;
|
st->encoding = LOCAL_encoding;
|
||||||
Yap_DefaultStreamOps(st);
|
Yap_DefaultStreamOps(st);
|
||||||
|
st->linecount = 0;
|
||||||
|
st->linepos = st->charcount = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,9 +200,7 @@ int Yap_open_buf_write_stream(encoding_t enc, memBufSource src) {
|
|||||||
// setbuf(st->file, NULL);
|
// setbuf(st->file, NULL);
|
||||||
st->status |= Seekable_Stream_f;
|
st->status |= Seekable_Stream_f;
|
||||||
#else
|
#else
|
||||||
st->file = fmemopen((void *)buf, nchars, "w");
|
st->file = fmemopen((void *)st->nbuf, st->nsize, "w");
|
||||||
st->nsize = nchars;
|
|
||||||
st->nbuf = buf;
|
|
||||||
if (!st->nbuf) {
|
if (!st->nbuf) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -292,17 +292,15 @@ void Yap_MemOps(StreamDesc *st) {
|
|||||||
st->stream_getc = PlGetc;
|
st->stream_getc = PlGetc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sssno;
|
|
||||||
|
|
||||||
bool Yap_CloseMemoryStream(int sno) {
|
bool Yap_CloseMemoryStream(int sno) {
|
||||||
sssno++;
|
if ((GLOBAL_Stream[sno].status & Output_Stream_f) && GLOBAL_Stream[sno].file) {
|
||||||
// if (sssno > 1720) Yap_do_low_level_trace=1;
|
|
||||||
if ((GLOBAL_Stream[sno].status & Output_Stream_f)) {
|
|
||||||
fflush(GLOBAL_Stream[sno].file);
|
fflush(GLOBAL_Stream[sno].file);
|
||||||
fclose(GLOBAL_Stream[sno].file);
|
fclose(GLOBAL_Stream[sno].file);
|
||||||
if (GLOBAL_Stream[sno].status & FreeOnClose_Stream_f)
|
if (GLOBAL_Stream[sno].status & FreeOnClose_Stream_f)
|
||||||
free(GLOBAL_Stream[sno].nbuf);
|
free(GLOBAL_Stream[sno].nbuf);
|
||||||
} else {
|
} else {
|
||||||
|
if (GLOBAL_Stream[sno].file)
|
||||||
fclose(GLOBAL_Stream[sno].file);
|
fclose(GLOBAL_Stream[sno].file);
|
||||||
if (GLOBAL_Stream[sno].status & FreeOnClose_Stream_f)
|
if (GLOBAL_Stream[sno].status & FreeOnClose_Stream_f)
|
||||||
free(GLOBAL_Stream[sno].nbuf);
|
free(GLOBAL_Stream[sno].nbuf);
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
* Copyright (C) 2007 Eric Blake
|
/* Copyright (C) 2007 Eric Blake
|
||||||
* Permission to use, copy, modify, and distribute this software
|
* Permission to use, copy, modify, and distribute this software
|
||||||
* is freely granted, provided that this notice is preserved.
|
* is freely granted, provided that this notice is preserved.
|
||||||
*
|
*
|
||||||
* Modifications for Android written Jul 2009 by Alan Viverette
|
* Modifications for Android written Jul 2009 by Alan Viverette
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if __ANDROID__
|
||||||
|
|
||||||
/*
|
/*
|
||||||
FUNCTION
|
FUNCTION
|
||||||
<fmemopen>>---open a stream around a fixed-length string
|
<fmemopen>>---open a stream around a fixed-length string
|
||||||
@ -69,7 +71,7 @@ Supporting OS subroutines required: <<sbrk>>.
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include "stdioext.h"
|
//#include "stdioext.h"
|
||||||
|
|
||||||
/* Describe details of an open memstream. */
|
/* Describe details of an open memstream. */
|
||||||
typedef struct fmemcookie {
|
typedef struct fmemcookie {
|
||||||
@ -172,13 +174,13 @@ fmemseek(void *cookie, fpos_t pos, int whence)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (c->writeonly && c->pos < c->eof)
|
if (c->writeonly && c->pos < c->eof)
|
||||||
{
|
{
|
||||||
c->buf[c->pos] = c->saved;
|
c->buf[c->pos] = c->saved;
|
||||||
c->saved = '\0';
|
c->saved = '\0';
|
||||||
}
|
}
|
||||||
c->pos = offset;
|
c->pos = offset;
|
||||||
if (c->writeonly && c->pos < c->eof)
|
if (c->writeonly && c->pos < c->eof)
|
||||||
{
|
{
|
||||||
c->saved = c->buf[c->pos];
|
c->saved = c->buf[c->pos];
|
||||||
c->buf[c->pos] = '\0';
|
c->buf[c->pos] = '\0';
|
||||||
@ -206,9 +208,9 @@ fmemopen(void *buf, size_t size, const char *mode)
|
|||||||
int flags;
|
int flags;
|
||||||
int dummy;
|
int dummy;
|
||||||
|
|
||||||
if ((flags = __sflags (mode, &dummy)) == 0)
|
if ((flags = __sflags (mode, &dummy)) == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!size || !(buf || flags & __SAPP))
|
if (!size || !(buf || flags & __SAPP))
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -225,7 +227,7 @@ fmemopen(void *buf, size_t size, const char *mode)
|
|||||||
c->max = size;
|
c->max = size;
|
||||||
/* 9 modes to worry about. */
|
/* 9 modes to worry about. */
|
||||||
/* w/a, buf or no buf: Guarantee a NUL after any file writes. */
|
/* w/a, buf or no buf: Guarantee a NUL after any file writes. */
|
||||||
c->writeonly = (flags & __SWR) != 0;
|
c->writeonly = (flags & __SWR) != 0;
|
||||||
c->saved = '\0';
|
c->saved = '\0';
|
||||||
if (!buf)
|
if (!buf)
|
||||||
{
|
{
|
||||||
@ -233,7 +235,7 @@ fmemopen(void *buf, size_t size, const char *mode)
|
|||||||
c->buf = (char *) (c + 1);
|
c->buf = (char *) (c + 1);
|
||||||
*(char *) buf = '\0';
|
*(char *) buf = '\0';
|
||||||
c->pos = c->eof = 0;
|
c->pos = c->eof = 0;
|
||||||
c->append = (flags & __SAPP) != 0;
|
c->append = (flags & __SAPP) != 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -244,7 +246,7 @@ fmemopen(void *buf, size_t size, const char *mode)
|
|||||||
/* a/a+ and buf: position and size at first NUL. */
|
/* a/a+ and buf: position and size at first NUL. */
|
||||||
buf = memchr (c->buf, '\0', size);
|
buf = memchr (c->buf, '\0', size);
|
||||||
c->eof = c->pos = buf ? (char *) buf - c->buf : size;
|
c->eof = c->pos = buf ? (char *) buf - c->buf : size;
|
||||||
if (!buf && c->writeonly)
|
if (!buf && c->writeonly)
|
||||||
/* a: guarantee a NUL within size even if no writes. */
|
/* a: guarantee a NUL within size even if no writes. */
|
||||||
c->buf[size - 1] = '\0';
|
c->buf[size - 1] = '\0';
|
||||||
c->append = 1;
|
c->append = 1;
|
||||||
@ -267,10 +269,12 @@ fmemopen(void *buf, size_t size, const char *mode)
|
|||||||
fp->_file = -1;
|
fp->_file = -1;
|
||||||
fp->_flags = flags;
|
fp->_flags = flags;
|
||||||
fp->_cookie = c;
|
fp->_cookie = c;
|
||||||
fp->_read = flags & (__SRD | __SRW) ? fmemread : NULL;
|
fp->_read = flags & (__SRD | __SRW) ? fmemread : NULL;
|
||||||
fp->_write = flags & (__SWR | __SRW) ? fmemwrite : NULL;
|
fp->_write = flags & (__SWR | __SRW) ? fmemwrite : NULL;
|
||||||
fp->_seek = fmemseek;
|
fp->_seek = fmemseek;
|
||||||
fp->_close = fmemclose;
|
fp->_close = fmemclose;
|
||||||
|
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
2658
os/iopreds.c
2658
os/iopreds.c
File diff suppressed because it is too large
Load Diff
@ -80,7 +80,7 @@ Int Yap_CloseSocket(int, socket_info, socket_domain);
|
|||||||
#endif /* USE_SOCKET */
|
#endif /* USE_SOCKET */
|
||||||
|
|
||||||
extern bool Yap_clearInput(int sno);
|
extern bool Yap_clearInput(int sno);
|
||||||
extern Term Yap_read_term(int inp_stream, Term opts, bool clauatse);
|
extern Term Yap_read_term(int inp_stream, Term opts, bool clause);
|
||||||
extern Term Yap_Parse(UInt prio, encoding_t enc, Term cmod);
|
extern Term Yap_Parse(UInt prio, encoding_t enc, Term cmod);
|
||||||
|
|
||||||
extern void init_read_data(ReadData _PL_rd, struct stream_desc *s);
|
extern void init_read_data(ReadData _PL_rd, struct stream_desc *s);
|
||||||
@ -216,7 +216,7 @@ INLINE_ONLY inline EXTERN void count_output_char(int ch, StreamDesc *s) {
|
|||||||
|
|
||||||
inline static Term StreamName(int i) { return (GLOBAL_Stream[i].user_name); }
|
inline static Term StreamName(int i) { return (GLOBAL_Stream[i].user_name); }
|
||||||
|
|
||||||
inline static Atom StreamFullName(int i) { return (GLOBAL_Stream[i].name); }
|
inline static Atom StreamFullName(int i) { return (Atom)(GLOBAL_Stream[i].name); }
|
||||||
|
|
||||||
inline static void console_count_output_char(int ch, StreamDesc *s) {
|
inline static void console_count_output_char(int ch, StreamDesc *s) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
@ -829,13 +829,13 @@ static parser_state_t initParser(Term opts, FEnv *fe, REnv *re, int inp_stream,
|
|||||||
return YAP_SCANNING;
|
return YAP_SCANNING;
|
||||||
}
|
}
|
||||||
|
|
||||||
static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream) {
|
static parser_state_t scan(REnv *re, FEnv *fe, int sno) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
/* preserve value of H after scanning: otherwise we may lose strings
|
/* preserve value of H after scanning: otherwise we may lose strings
|
||||||
and floats */
|
and floats */
|
||||||
LOCAL_tokptr = LOCAL_toktide =
|
LOCAL_tokptr = LOCAL_toktide =
|
||||||
|
|
||||||
Yap_tokenizer(GLOBAL_Stream + inp_stream, false, &fe->tpos);
|
Yap_tokenizer(GLOBAL_Stream + sno, false, &fe->tpos);
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
if (GLOBAL_Option[2]) {
|
if (GLOBAL_Option[2]) {
|
||||||
TokEntry *t = LOCAL_tokptr;
|
TokEntry *t = LOCAL_tokptr;
|
||||||
@ -857,7 +857,7 @@ static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream) {
|
|||||||
LOCAL_Error_TYPE = SYNTAX_ERROR;
|
LOCAL_Error_TYPE = SYNTAX_ERROR;
|
||||||
return YAP_PARSING_ERROR;
|
return YAP_PARSING_ERROR;
|
||||||
}
|
}
|
||||||
return scanEOF(fe, inp_stream);
|
return scanEOF(fe, sno);
|
||||||
}
|
}
|
||||||
|
|
||||||
static parser_state_t scanError(REnv *re, FEnv *fe, int inp_stream) {
|
static parser_state_t scanError(REnv *re, FEnv *fe, int inp_stream) {
|
||||||
@ -956,7 +956,7 @@ static parser_state_t parse(REnv *re, FEnv *fe, int inp_stream) {
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Term Yap_read_term(int inp_stream, Term opts, bool clause) {
|
Term Yap_read_term(int sno, Term opts, bool clause) {
|
||||||
FEnv fe;
|
FEnv fe;
|
||||||
REnv re;
|
REnv re;
|
||||||
#if EMACS
|
#if EMACS
|
||||||
@ -968,23 +968,23 @@ Term Yap_read_term(int inp_stream, Term opts, bool clause) {
|
|||||||
while (true) {
|
while (true) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case YAP_START_PARSING:
|
case YAP_START_PARSING:
|
||||||
state = initParser(opts, &fe, &re, inp_stream, clause);
|
state = initParser(opts, &fe, &re, sno, clause);
|
||||||
if (state == YAP_PARSING_FINISHED) {
|
if (state == YAP_PARSING_FINISHED) {
|
||||||
pop_text_stack(lvl);
|
pop_text_stack(lvl);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case YAP_SCANNING:
|
case YAP_SCANNING:
|
||||||
state = scan(&re, &fe, inp_stream);
|
state = scan(&re, &fe, sno);
|
||||||
break;
|
break;
|
||||||
case YAP_SCANNING_ERROR:
|
case YAP_SCANNING_ERROR:
|
||||||
state = scanError(&re, &fe, inp_stream);
|
state = scanError(&re, &fe, sno);
|
||||||
break;
|
break;
|
||||||
case YAP_PARSING:
|
case YAP_PARSING:
|
||||||
state = parse(&re, &fe, inp_stream);
|
state = parse(&re, &fe, sno);
|
||||||
break;
|
break;
|
||||||
case YAP_PARSING_ERROR:
|
case YAP_PARSING_ERROR:
|
||||||
state = parseError(&re, &fe, inp_stream);
|
state = parseError(&re, &fe, sno);
|
||||||
break;
|
break;
|
||||||
case YAP_PARSING_FINISHED: {
|
case YAP_PARSING_FINISHED: {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
@ -1021,17 +1021,17 @@ static Int
|
|||||||
|
|
||||||
static Int read_term(
|
static Int read_term(
|
||||||
USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */
|
USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */
|
||||||
int inp_stream;
|
int sno;
|
||||||
Term out;
|
Term out;
|
||||||
|
|
||||||
/* needs to change LOCAL_output_stream for write */
|
/* needs to change LOCAL_output_stream for write */
|
||||||
|
|
||||||
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
|
sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
|
||||||
if (inp_stream == -1) {
|
if (sno == -1) {
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
out = Yap_read_term(inp_stream, add_output(ARG2, ARG3), false);
|
out = Yap_read_term(sno, add_output(ARG2, ARG3), false);
|
||||||
UNLOCK(GLOBAL_Stream[inp_stream].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return out != 0L;
|
return out != 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1060,7 +1060,7 @@ static const param_t read_clause_defs[] = {READ_CLAUSE_DEFS()};
|
|||||||
#undef PAR
|
#undef PAR
|
||||||
|
|
||||||
static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
|
static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
|
||||||
int inp_stream) {
|
int sno) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
|
||||||
xarg *args = Yap_ArgListToVector(opts, read_clause_defs, READ_CLAUSE_END);
|
xarg *args = Yap_ArgListToVector(opts, read_clause_defs, READ_CLAUSE_END);
|
||||||
@ -1082,7 +1082,7 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
|
|||||||
fe->cmod = PROLOG_MODULE;
|
fe->cmod = PROLOG_MODULE;
|
||||||
}
|
}
|
||||||
re->bq = getBackQuotesFlag();
|
re->bq = getBackQuotesFlag();
|
||||||
fe->enc = GLOBAL_Stream[inp_stream].encoding;
|
fe->enc = GLOBAL_Stream[sno].encoding;
|
||||||
fe->sp = 0;
|
fe->sp = 0;
|
||||||
fe->qq = 0;
|
fe->qq = 0;
|
||||||
if (args[READ_CLAUSE_OUTPUT].used) {
|
if (args[READ_CLAUSE_OUTPUT].used) {
|
||||||
@ -1118,12 +1118,12 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
|
|||||||
fe->vp = 0;
|
fe->vp = 0;
|
||||||
}
|
}
|
||||||
fe->ce = Yap_CharacterEscapes(fe->cmod);
|
fe->ce = Yap_CharacterEscapes(fe->cmod);
|
||||||
re->seekable = (GLOBAL_Stream[inp_stream].status & Seekable_Stream_f) != 0;
|
re->seekable = (GLOBAL_Stream[sno].status & Seekable_Stream_f) != 0;
|
||||||
if (re->seekable) {
|
if (re->seekable) {
|
||||||
#if HAVE_FGETPOS
|
#if HAVE_FGETPOS
|
||||||
fgetpos(GLOBAL_Stream[inp_stream].file, &re->rpos);
|
fgetpos(GLOBAL_Stream[sno].file, &re->rpos);
|
||||||
#else
|
#else
|
||||||
re->cpos = GLOBAL_Stream[inp_stream].charcount;
|
re->cpos = GLOBAL_Stream[sno].charcount;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
re->prio = LOCAL_default_priority;
|
re->prio = LOCAL_default_priority;
|
||||||
@ -1166,15 +1166,15 @@ static Int read_clause2(USES_REGS1) {
|
|||||||
*/
|
*/
|
||||||
static Int read_clause(
|
static Int read_clause(
|
||||||
USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */
|
USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */
|
||||||
int inp_stream;
|
int sno;
|
||||||
Term out;
|
Term out;
|
||||||
|
|
||||||
/* needs to change LOCAL_output_stream for write */
|
/* needs to change LOCAL_output_stream for write */
|
||||||
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
|
sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
|
||||||
if (inp_stream < 0)
|
if (sno < 0)
|
||||||
return false;
|
return false;
|
||||||
out = Yap_read_term(inp_stream, add_output(ARG2, ARG3), true);
|
out = Yap_read_term(sno, add_output(ARG2, ARG3), true);
|
||||||
UNLOCK(GLOBAL_Stream[inp_stream].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return out != 0;
|
return out != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1191,20 +1191,20 @@ static Int read_clause(
|
|||||||
*/
|
*/
|
||||||
#if 0
|
#if 0
|
||||||
static Int start_mega(USES_REGS1) {
|
static Int start_mega(USES_REGS1) {
|
||||||
int inp_stream;
|
int sno;
|
||||||
Term out;
|
Term out;
|
||||||
Term t3 = Deref(ARG3);
|
Term t3 = Deref(ARG3);
|
||||||
yhandle_t h = Yap_InitSlot(ARG2);
|
yhandle_t h = Yap_InitSlot(ARG2);
|
||||||
TokENtry *tok;
|
TokENtry *tok;
|
||||||
arity_t srity = 0;
|
arity_t srity = 0;
|
||||||
/* needs to change LOCAL_output_stream for write */
|
/* needs to change LOCAL_output_stream for write */
|
||||||
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read_exo/3");
|
sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "read_exo/3");
|
||||||
if (inp_stream < 0)
|
if (sno < 0)
|
||||||
return false;
|
return false;
|
||||||
/* preserve value of H after scanning: otherwise we may lose strings
|
/* preserve value of H after scanning: otherwise we may lose strings
|
||||||
and floats */
|
and floats */
|
||||||
LOCAL_tokptr = LOCAL_toktide =
|
LOCAL_tokptr = LOCAL_toktide =
|
||||||
x Yap_tokenizer(GLOBAL_Stream + inp_stream, false, &tpos);
|
x Yap_tokenizer(GLOBAL_Stream + sno, false, &tpos);
|
||||||
if (tokptr->Tok == Name_tok && (next = tokptr->TokNext) != NULL &&
|
if (tokptr->Tok == Name_tok && (next = tokptr->TokNext) != NULL &&
|
||||||
next->Tok == Ponctuation_tok && next->TokInfo == TermOpenBracket) {
|
next->Tok == Ponctuation_tok && next->TokInfo == TermOpenBracket) {
|
||||||
bool start = true;
|
bool start = true;
|
||||||
@ -1253,16 +1253,16 @@ static Int source_location(USES_REGS1) {
|
|||||||
*/
|
*/
|
||||||
static Int read2(
|
static Int read2(
|
||||||
USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */
|
USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */
|
||||||
int inp_stream;
|
int sno;
|
||||||
Int out;
|
Int out;
|
||||||
|
|
||||||
/* needs to change LOCAL_output_stream for write */
|
/* needs to change LOCAL_output_stream for write */
|
||||||
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
|
sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
|
||||||
if (inp_stream == -1) {
|
if (sno == -1) {
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
out = Yap_read_term(inp_stream, add_output(ARG2, TermNil), false);
|
out = Yap_read_term(sno, add_output(ARG2, TermNil), false);
|
||||||
UNLOCK(GLOBAL_Stream[inp_stream].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -959,7 +959,8 @@ static void CloseStream(int sno) {
|
|||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
if (!(GLOBAL_Stream[sno].status &
|
if (GLOBAL_Stream[sno].file &&
|
||||||
|
!(GLOBAL_Stream[sno].status &
|
||||||
(Null_Stream_f | Socket_Stream_f | InMemory_Stream_f | Pipe_Stream_f)))
|
(Null_Stream_f | Socket_Stream_f | InMemory_Stream_f | Pipe_Stream_f)))
|
||||||
fclose(GLOBAL_Stream[sno].file);
|
fclose(GLOBAL_Stream[sno].file);
|
||||||
#if HAVE_SOCKET
|
#if HAVE_SOCKET
|
||||||
|
209
os/sysbits.c
209
os/sysbits.c
@ -34,13 +34,6 @@ static void FileError(yap_error_number type, Term where, const char *format,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Allocate a temporary buffer
|
|
||||||
static char *getFileNameBuffer(void) {
|
|
||||||
|
|
||||||
return Yap_AllocAtomSpace(YAP_FILENAME_MAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void freeFileNameBuffer(char *s) { Yap_FreeCodeSpace(s); }
|
|
||||||
|
|
||||||
static Int p_sh(USES_REGS1);
|
static Int p_sh(USES_REGS1);
|
||||||
static Int p_shell(USES_REGS1);
|
static Int p_shell(USES_REGS1);
|
||||||
@ -52,7 +45,6 @@ static Int p_putenv(USES_REGS1);
|
|||||||
static Term do_glob(const char *spec, bool ok_to);
|
static Term do_glob(const char *spec, bool ok_to);
|
||||||
#ifdef MACYAP
|
#ifdef MACYAP
|
||||||
|
|
||||||
static int chdir(char *);
|
|
||||||
/* #define signal skel_signal */
|
/* #define signal skel_signal */
|
||||||
#endif /* MACYAP */
|
#endif /* MACYAP */
|
||||||
static const char *expandVars(const char *spec, char *u);
|
static const char *expandVars(const char *spec, char *u);
|
||||||
@ -103,8 +95,9 @@ static bool is_directory(const char *FileName) {
|
|||||||
|
|
||||||
bool Yap_Exists(const char *f) {
|
bool Yap_Exists(const char *f) {
|
||||||
VFS_t *vfs;
|
VFS_t *vfs;
|
||||||
|
f = Yap_VFAlloc(f);
|
||||||
if ((vfs = vfs_owner(f))) {
|
if ((vfs = vfs_owner(f))) {
|
||||||
return vfs->exists(vfs,f) != NULL;
|
return vfs->exists(vfs,f);
|
||||||
}
|
}
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
if (_access(f, 0) == 0)
|
if (_access(f, 0) == 0)
|
||||||
@ -114,8 +107,9 @@ bool Yap_Exists(const char *f) {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
#elif HAVE_ACCESS
|
#elif HAVE_ACCESS
|
||||||
if (access(f, F_OK) == 0)
|
if (access(f, F_OK) == 0) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
if (errno == EINVAL) {
|
if (errno == EINVAL) {
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "bad flags to access");
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "bad flags to access");
|
||||||
}
|
}
|
||||||
@ -147,10 +141,13 @@ int Yap_dir_separator(int ch) { return dir_separator(ch); }
|
|||||||
char *libdir = NULL;
|
char *libdir = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool Yap_IsAbsolutePath(const char *p0) {
|
bool Yap_IsAbsolutePath(const char *p0, bool expand) {
|
||||||
// verify first if expansion is needed: ~/ or $HOME/
|
// verify first if expansion is needed: ~/ or $HOME/
|
||||||
const char *p = expandVars(p0, LOCAL_FileNameBuf);
|
const char *p = p0;
|
||||||
bool nrc;
|
bool nrc;
|
||||||
|
if (expand) {
|
||||||
|
p = expandVars(p0, LOCAL_FileNameBuf);
|
||||||
|
}
|
||||||
#if _WIN32 || __MINGW32__
|
#if _WIN32 || __MINGW32__
|
||||||
nrc = !PathIsRelative(p);
|
nrc = !PathIsRelative(p);
|
||||||
#else
|
#else
|
||||||
@ -266,7 +263,7 @@ static const char *PlExpandVars(const char *source, const char *root,
|
|||||||
pop_text_stack(lvl);
|
pop_text_stack(lvl);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (root && !Yap_IsAbsolutePath(source)) {
|
if (root && !Yap_IsAbsolutePath(source, false)) {
|
||||||
strncpy(result, root, YAP_FILENAME_MAX);
|
strncpy(result, root, YAP_FILENAME_MAX);
|
||||||
if (root[strlen(root) - 1] != '/')
|
if (root[strlen(root) - 1] != '/')
|
||||||
strncat(result, "/", YAP_FILENAME_MAX);
|
strncat(result, "/", YAP_FILENAME_MAX);
|
||||||
@ -346,7 +343,9 @@ static char *PrologPath(const char *Y, char *X) { return (char *)Y; }
|
|||||||
#define HAVE_REALPATH 1
|
#define HAVE_REALPATH 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool ChDir(const char *path) {
|
char virtual_cwd[YAP_FILENAME_MAX + 1];
|
||||||
|
|
||||||
|
bool Yap_ChDir(const char *path) {
|
||||||
bool rc = false;
|
bool rc = false;
|
||||||
char qp[FILENAME_MAX + 1];
|
char qp[FILENAME_MAX + 1];
|
||||||
const char *qpath = Yap_AbsoluteFile(path, qp, true);
|
const char *qpath = Yap_AbsoluteFile(path, qp, true);
|
||||||
@ -370,14 +369,15 @@ static char *PrologPath(const char *Y, char *X) { return (char *)Y; }
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char *myrealpath(const char *path, char *out) {
|
static const char *myrealpath(const char *path, char *out) {
|
||||||
if (!out)
|
int lvl = push_text_stack();
|
||||||
out = LOCAL_FileNameBuf;
|
#if _WIN32
|
||||||
#if _WIN32
|
|
||||||
DWORD retval = 0;
|
DWORD retval = 0;
|
||||||
|
|
||||||
// notice that the file does not need to exist
|
// notice that the file does not need to exist
|
||||||
retval = GetFullPathName(path, YAP_FILENAME_MAX, out, NULL);
|
retval = GetFullPathName(path, YAP_FILENAME_MAX, out, NULL);
|
||||||
|
pop_text_stack(lvl);
|
||||||
if (retval == 0) {
|
if (retval == 0) {
|
||||||
Yap_WinError("Generating a full path name for a file");
|
Yap_WinError("Generating a full path name for a file");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -388,12 +388,13 @@ static const char *myrealpath(const char *path, char *out) {
|
|||||||
char *rc = realpath(path, NULL);
|
char *rc = realpath(path, NULL);
|
||||||
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
|
pop_text_stack(lvl);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
// rc = NULL;
|
// rc = NULL;
|
||||||
if (errno == ENOENT || errno == EACCES) {
|
if (errno == ENOENT || errno == EACCES) {
|
||||||
char base[YAP_FILENAME_MAX + 1];
|
char *base= Malloc(YAP_FILENAME_MAX + 1);
|
||||||
strncpy(base, path, YAP_FILENAME_MAX - 1);
|
strncpy(base, path, YAP_FILENAME_MAX );
|
||||||
rc = realpath(dirname(base), out);
|
rc = realpath(dirname(base), out);
|
||||||
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
@ -417,6 +418,7 @@ static const char *myrealpath(const char *path, char *out) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
strcat(rc, b);
|
strcat(rc, b);
|
||||||
|
rc = pop_output_text_stack(lvl, rc);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -424,6 +426,7 @@ static const char *myrealpath(const char *path, char *out) {
|
|||||||
#endif
|
#endif
|
||||||
out = malloc(strlen(path) + 1);
|
out = malloc(strlen(path) + 1);
|
||||||
strcpy(out, path);
|
strcpy(out, path);
|
||||||
|
pop_text_stack(lvl);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -929,7 +932,7 @@ static Int make_directory(USES_REGS1) {
|
|||||||
#if defined(__MINGW32__) || _MSC_VER
|
#if defined(__MINGW32__) || _MSC_VER
|
||||||
if (_mkdir(fd) == -1) {
|
if (_mkdir(fd) == -1) {
|
||||||
#else
|
#else
|
||||||
if (mkdir(fd, 0777) == -1) {
|
if (mkdir(Yap_VFAlloc(fd), 0777) == -1) {
|
||||||
#endif
|
#endif
|
||||||
/* return an error number */
|
/* return an error number */
|
||||||
return false; // errno?
|
return false; // errno?
|
||||||
@ -938,7 +941,7 @@ static Int make_directory(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Int p_rmdir(USES_REGS1) {
|
static Int p_rmdir(USES_REGS1) {
|
||||||
const char *fd = AtomName(AtomOfTerm(ARG1));
|
const char *fd = Yap_VFAlloc(AtomName(AtomOfTerm(ARG1)));
|
||||||
#if defined(__MINGW32__) || _MSC_VER
|
#if defined(__MINGW32__) || _MSC_VER
|
||||||
if (_rmdir(fd) == -1) {
|
if (_rmdir(fd) == -1) {
|
||||||
#else
|
#else
|
||||||
@ -1136,7 +1139,14 @@ static int volume_header(char *file) {
|
|||||||
|
|
||||||
int Yap_volume_header(char *file) { return volume_header(file); }
|
int Yap_volume_header(char *file) { return volume_header(file); }
|
||||||
|
|
||||||
const char *Yap_getcwd(const char *cwd, size_t cwdlen) {
|
const char *Yap_getcwd(char *cwd, size_t cwdlen) {
|
||||||
|
if (virtual_cwd[0]) {
|
||||||
|
if (!cwd) {
|
||||||
|
cwd = malloc(cwdlen+1);
|
||||||
|
}
|
||||||
|
strcpy( cwd, virtual_cwd);
|
||||||
|
return cwd;
|
||||||
|
}
|
||||||
#if _WIN32 || defined(__MINGW32__)
|
#if _WIN32 || defined(__MINGW32__)
|
||||||
if (GetCurrentDirectory(cwdlen, (char *)cwd) == 0) {
|
if (GetCurrentDirectory(cwdlen, (char *)cwd) == 0) {
|
||||||
Yap_WinError("GetCurrentDirectory failed");
|
Yap_WinError("GetCurrentDirectory failed");
|
||||||
@ -1166,7 +1176,7 @@ static Int working_directory(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
if (t2 == TermEmptyAtom || t2 == TermDot)
|
if (t2 == TermEmptyAtom || t2 == TermDot)
|
||||||
return true;
|
return true;
|
||||||
return ChDir(RepAtom(AtomOfTerm(t2))->StrOfAE);
|
return Yap_ChDir(RepAtom(AtomOfTerm(t2))->StrOfAE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Yap_findFile(): tries to locate a file, no expansion should be performed/
|
/** Yap_findFile(): tries to locate a file, no expansion should be performed/
|
||||||
@ -1188,11 +1198,21 @@ 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 = iroot, *source = isource;
|
char *root, *source;
|
||||||
int rc = FAIL_RESTORE;
|
int rc = FAIL_RESTORE;
|
||||||
int try
|
int try = 0;
|
||||||
= 0;
|
|
||||||
bool abspath = false;
|
bool abspath = false;
|
||||||
|
int lvl = push_text_stack();
|
||||||
|
root = Malloc(YAP_FILENAME_MAX+1);
|
||||||
|
source= Malloc(YAP_FILENAME_MAX+1);
|
||||||
|
if (iroot && iroot[0])
|
||||||
|
strcpy(root, iroot);
|
||||||
|
else
|
||||||
|
root[0] = 0;
|
||||||
|
if (isource && isource[0])
|
||||||
|
strcpy(source, isource);
|
||||||
|
else
|
||||||
|
source[0] = 0;
|
||||||
//__android_log_print(ANDROID_LOG_ERROR, "YAPDroid " __FUNCTION__,
|
//__android_log_print(ANDROID_LOG_ERROR, "YAPDroid " __FUNCTION__,
|
||||||
// "try=%d %s %s", try, isource, iroot) ; }
|
// "try=%d %s %s", try, isource, iroot) ; }
|
||||||
while (rc == FAIL_RESTORE) {
|
while (rc == FAIL_RESTORE) {
|
||||||
@ -1201,21 +1221,28 @@ const char *Yap_findFile(const char *isource, const char *idef,
|
|||||||
// { CACHE_REGS
|
// { CACHE_REGS
|
||||||
switch (try ++) {
|
switch (try ++) {
|
||||||
case 0: // path or file name is given;
|
case 0: // path or file name is given;
|
||||||
root = iroot;
|
if (!source[0] && idef && idef[0]) {
|
||||||
if (idef || isource) {
|
strcpy(source, idef);
|
||||||
source = (isource ? isource : idef);
|
|
||||||
}
|
}
|
||||||
if (source) {
|
if (source[0]) {
|
||||||
abspath = Yap_IsAbsolutePath(source);
|
abspath = Yap_IsAbsolutePath(source, expand_root);
|
||||||
}
|
}
|
||||||
if (!abspath && !root && ftype == YAP_BOOT_PL) {
|
if (!abspath && !root[0] && ftype == YAP_BOOT_PL) {
|
||||||
root = YAP_PL_SRCDIR;
|
strcpy(root, YAP_PL_SRCDIR);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 1: // library directory is given in command line
|
case 1: // library directory is given in command line
|
||||||
if (in_lib && ftype == YAP_SAVED_STATE) {
|
if (in_lib && ftype == YAP_SAVED_STATE) {
|
||||||
root = iroot;
|
if (iroot && iroot[0])
|
||||||
source = (isource ? isource : idef);
|
strcpy(root, iroot);
|
||||||
|
else
|
||||||
|
root[0] = 0;
|
||||||
|
if (isource && isource[0])
|
||||||
|
strcpy(source, isource);
|
||||||
|
else if (idef && idef[0])
|
||||||
|
strcpy(source, idef);
|
||||||
|
else
|
||||||
|
source[0] = 0;
|
||||||
} else {
|
} else {
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
@ -1223,35 +1250,44 @@ const char *Yap_findFile(const char *isource, const char *idef,
|
|||||||
case 2: // use environment variable YAPLIBDIR
|
case 2: // use environment variable YAPLIBDIR
|
||||||
#if HAVE_GETENV
|
#if HAVE_GETENV
|
||||||
if (in_lib) {
|
if (in_lib) {
|
||||||
|
const char *eroot;
|
||||||
|
|
||||||
if (ftype == YAP_SAVED_STATE || ftype == YAP_OBJ) {
|
if (ftype == YAP_SAVED_STATE || ftype == YAP_OBJ) {
|
||||||
root = getenv("YAPLIBDIR");
|
eroot = getenv("YAPLIBDIR");
|
||||||
} else if (ftype == YAP_BOOT_PL) {
|
} else if (ftype == YAP_BOOT_PL) {
|
||||||
root = getenv("YAPSHAREDIR"
|
eroot = getenv("YAPSHAREDIR");
|
||||||
"/pl");
|
if (eroot == NULL) {
|
||||||
if (root == NULL) {
|
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
save_buffer = getFileNameBuffer();
|
strncpy(root, eroot, YAP_FILENAME_MAX);
|
||||||
strncpy(save_buffer, root, YAP_FILENAME_MAX);
|
strncat(root, "/pl", YAP_FILENAME_MAX);
|
||||||
strncat(save_buffer, "/pl", YAP_FILENAME_MAX);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
source = (isource ? isource : idef);
|
if (isource && isource[0])
|
||||||
|
strcpy(source, isource);
|
||||||
|
else if (idef && idef[0])
|
||||||
|
strcpy(source, idef);
|
||||||
|
else
|
||||||
|
source[0] = 0;
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
done = true;
|
done = true;
|
||||||
break;
|
break;
|
||||||
case 3: // use compilation variable YAPLIBDIR
|
case 3: // use compilation variable YAPLIBDIR
|
||||||
if (in_lib) {
|
if (in_lib) {
|
||||||
source = (isource ? isource : idef);
|
if (isource && isource[0])
|
||||||
|
strcpy(source, isource);
|
||||||
|
else if (idef && idef[0])
|
||||||
|
strcpy(source, idef);
|
||||||
|
else
|
||||||
|
source[0] = 0;
|
||||||
if (ftype == YAP_PL) {
|
if (ftype == YAP_PL) {
|
||||||
root = YAP_SHAREDIR;
|
strcpy(root,YAP_SHAREDIR);
|
||||||
} else if (ftype == YAP_BOOT_PL) {
|
} else if (ftype == YAP_BOOT_PL) {
|
||||||
root = malloc(YAP_FILENAME_MAX+1);
|
|
||||||
strcpy(root, YAP_SHAREDIR);
|
strcpy(root, YAP_SHAREDIR);
|
||||||
strcat(root,"/pl");
|
strcat(root,"/pl");
|
||||||
} else {
|
} else {
|
||||||
root = YAP_LIBDIR;
|
strcpy(root,YAP_LIBDIR);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
done = true;
|
done = true;
|
||||||
@ -1260,9 +1296,9 @@ const char *Yap_findFile(const char *isource, const char *idef,
|
|||||||
case 4: // WIN stuff: registry
|
case 4: // WIN stuff: registry
|
||||||
#if __WINDOWS
|
#if __WINDOWS
|
||||||
if (in_lib) {
|
if (in_lib) {
|
||||||
source = (ftype == YAP_PL || ftype == YAP_QLY ? "library" : "startup");
|
const char *key = (ftype == YAP_PL || ftype == YAP_QLY ? "library" : "startup");
|
||||||
source = Yap_RegistryGetString(source);
|
strcpy( source, Yap_RegistryGetString(source) );
|
||||||
root = NULL;
|
root[0] = 0;
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
done = true;
|
done = true;
|
||||||
@ -1278,44 +1314,50 @@ const char *Yap_findFile(const char *isource, const char *idef,
|
|||||||
const char *pt = Yap_FindExecutable();
|
const char *pt = Yap_FindExecutable();
|
||||||
|
|
||||||
if (pt) {
|
if (pt) {
|
||||||
if (ftype == YAP_BOOT_PL) {
|
if (ftype == YAP_BOOT_PL) {
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
root = "../../../files/Yap/pl";
|
strcpy(root, "../../../files/Yap/pl");
|
||||||
#else
|
#else
|
||||||
root = "../../share/Yap/pl";
|
root = "../../share/Yap/pl";
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
root = (ftype == YAP_SAVED_STATE || ftype == YAP_OBJ
|
strcpy(root, (ftype == YAP_SAVED_STATE || ftype == YAP_OBJ
|
||||||
? "../../lib/Yap"
|
? "../../lib/Yap"
|
||||||
: "../../share/Yap");
|
: "../../share/Yap"));
|
||||||
}
|
}
|
||||||
if (root == iroot) {
|
if (strcmp(root, iroot) == 0) {
|
||||||
done = true;
|
done = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!save_buffer)
|
if (!save_buffer) {
|
||||||
save_buffer = getFileNameBuffer();
|
save_buffer = Malloc(YAP_FILENAME_MAX + 1);
|
||||||
if (Yap_findFile(source, NULL, root, save_buffer, access, ftype,
|
|
||||||
|
save_buffer[0] = 0;
|
||||||
|
}
|
||||||
|
if (Yap_findFile(source, NULL, root, save_buffer, access, ftype,
|
||||||
expand_root, in_lib))
|
expand_root, in_lib))
|
||||||
root = save_buffer;
|
strcpy(root, save_buffer);
|
||||||
else
|
else
|
||||||
done = true;
|
done = true;
|
||||||
} else {
|
} else {
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
source = (isource ? isource : idef);
|
if (isource && isource[0])
|
||||||
|
strcpy(source, isource);
|
||||||
|
else if (idef && idef[0])
|
||||||
|
strcpy(source, idef);
|
||||||
|
else
|
||||||
|
source[0] = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 6: // default, try current directory
|
case 6: // default, try current directory
|
||||||
if (!isource && ftype == YAP_SAVED_STATE)
|
if (!isource && ftype == YAP_SAVED_STATE)
|
||||||
source = idef;
|
strcpy(source, idef);
|
||||||
root = NULL;
|
root[0] = 0;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (save_buffer)
|
pop_text_stack(lvl);
|
||||||
freeFileNameBuffer(save_buffer);
|
return NULL;
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (done)
|
if (done)
|
||||||
@ -1324,16 +1366,19 @@ const char *Yap_findFile(const char *isource, const char *idef,
|
|||||||
// "root= %s %s ", root, source) ; }
|
// "root= %s %s ", root, source) ; }
|
||||||
const char *work = PlExpandVars(source, root, result);
|
const char *work = PlExpandVars(source, root, result);
|
||||||
|
|
||||||
if (save_buffer)
|
|
||||||
freeFileNameBuffer(save_buffer);
|
|
||||||
|
|
||||||
// expand names in case you have
|
// expand names in case you have
|
||||||
// to add a prefix
|
// to add a prefix
|
||||||
if (!access || Yap_Exists(work)) {
|
if (!access || Yap_Exists(work)) {
|
||||||
|
work = pop_output_text_stack(lvl,work);
|
||||||
return work; // done
|
return work; // done
|
||||||
} else if (abspath)
|
} else if (abspath) {
|
||||||
return NULL;
|
pop_text_stack(lvl);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
pop_text_stack(lvl);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1422,7 +1467,7 @@ static Int p_sh(USES_REGS1) { /* sh */
|
|||||||
shell = (char *)getenv("SHELL");
|
shell = (char *)getenv("SHELL");
|
||||||
if (shell == NULL)
|
if (shell == NULL)
|
||||||
shell = "/bin/sh";
|
shell = "/bin/sh";
|
||||||
if (system(shell) < 0) {
|
if (system(Yap_VFAlloc(shell)) < 0) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil, "%s in sh/0",
|
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil, "%s in sh/0",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
@ -1628,10 +1673,12 @@ static Int p_mv(USES_REGS1) { /* rename(+OldName,+NewName) */
|
|||||||
} else if (!IsAtomTerm(t2)) {
|
} else if (!IsAtomTerm(t2)) {
|
||||||
Yap_Error(TYPE_ERROR_ATOM, t2, "second argument to rename/2 not atom");
|
Yap_Error(TYPE_ERROR_ATOM, t2, "second argument to rename/2 not atom");
|
||||||
} else {
|
} else {
|
||||||
oldname = (RepAtom(AtomOfTerm(t1)))->StrOfAE;
|
oldname = Yap_VFAlloc((RepAtom(AtomOfTerm(t1)))->StrOfAE);
|
||||||
newname = (RepAtom(AtomOfTerm(t2)))->StrOfAE;
|
newname = Yap_VFAlloc((RepAtom(AtomOfTerm(t2)))->StrOfAE);
|
||||||
if ((r = link(oldname, newname)) == 0 && (r = unlink(oldname)) != 0)
|
if ((r = link(oldname, newname)) == 0 && (r = unlink(oldname)) != 0)
|
||||||
unlink(newname);
|
unlink(newname);
|
||||||
|
free(oldname);
|
||||||
|
free(newname);
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, t2, "%s in rename(%s,%s)",
|
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, t2, "%s in rename(%s,%s)",
|
||||||
|
@ -678,7 +678,7 @@ static Int term_to_string(USES_REGS1) {
|
|||||||
Term t2 = Deref(ARG2), rc = false, t1 = Deref(ARG1);
|
Term t2 = Deref(ARG2), rc = false, t1 = Deref(ARG1);
|
||||||
const char *s;
|
const char *s;
|
||||||
if (IsVarTerm(t2)) {
|
if (IsVarTerm(t2)) {
|
||||||
s = Yap_TermToString(ARG1,LOCAL_encoding,
|
s = Yap_TermToBuffer(ARG1, LOCAL_encoding,
|
||||||
Quote_illegal_f | Handle_vars_f);
|
Quote_illegal_f | Handle_vars_f);
|
||||||
if (!s || !MkStringTerm(s)) {
|
if (!s || !MkStringTerm(s)) {
|
||||||
Yap_Error(RESOURCE_ERROR_HEAP, t1,
|
Yap_Error(RESOURCE_ERROR_HEAP, t1,
|
||||||
@ -699,7 +699,7 @@ static Int term_to_atom(USES_REGS1) {
|
|||||||
Term t2 = Deref(ARG2), ctl, rc = false;
|
Term t2 = Deref(ARG2), ctl, rc = false;
|
||||||
Atom at;
|
Atom at;
|
||||||
if (IsVarTerm(t2)) {
|
if (IsVarTerm(t2)) {
|
||||||
const char *s = Yap_TermToString(Deref(ARG1), LOCAL_encoding,
|
const char *s = Yap_TermToBuffer(Deref(ARG1), LOCAL_encoding,
|
||||||
Quote_illegal_f | Handle_vars_f);
|
Quote_illegal_f | Handle_vars_f);
|
||||||
if (!s || !(at = Yap_UTF8ToAtom((const unsigned char *)s))) {
|
if (!s || !(at = Yap_UTF8ToAtom((const unsigned char *)s))) {
|
||||||
Yap_Error(RESOURCE_ERROR_HEAP, t2,
|
Yap_Error(RESOURCE_ERROR_HEAP, t2,
|
||||||
|
42
os/yapio.h
42
os/yapio.h
@ -86,9 +86,9 @@ extern int Yap_PlGetWchar(void);
|
|||||||
extern int Yap_PlFGetchar(void);
|
extern int Yap_PlFGetchar(void);
|
||||||
extern int Yap_GetCharForSIGINT(void);
|
extern int Yap_GetCharForSIGINT(void);
|
||||||
extern Int Yap_StreamToFileNo(Term);
|
extern Int Yap_StreamToFileNo(Term);
|
||||||
extern int Yap_OpenStream(const char*, const char *);
|
extern int Yap_OpenStream(const char*, const char*);
|
||||||
extern int Yap_FileStream(FILE*, char *, Term, int);
|
extern int Yap_FileStream(FILE*, char *, Term, int);
|
||||||
extern char *Yap_TermToString(Term t, encoding_t encoding, int flags);
|
extern char *Yap_TermToBuffer(Term t, encoding_t encoding, int flags);
|
||||||
extern char *Yap_HandleToString(yhandle_t l, size_t sz, size_t *length,
|
extern char *Yap_HandleToString(yhandle_t l, size_t sz, size_t *length,
|
||||||
encoding_t *encoding, int flags);
|
encoding_t *encoding, int flags);
|
||||||
extern int Yap_GetFreeStreamD(void);
|
extern int Yap_GetFreeStreamD(void);
|
||||||
@ -103,7 +103,7 @@ extern int Yap_growheap_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **);
|
|||||||
extern int Yap_growstack_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **);
|
extern int Yap_growstack_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **);
|
||||||
extern int Yap_growtrail_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **);
|
extern int Yap_growtrail_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **);
|
||||||
|
|
||||||
extern bool Yap_IsAbsolutePath(const char *p);
|
extern bool Yap_IsAbsolutePath(const char *p, bool);
|
||||||
extern Atom Yap_TemporaryFile(const char *prefix, int *fd);
|
extern Atom Yap_TemporaryFile(const char *prefix, int *fd);
|
||||||
extern const char *Yap_AbsoluteFile(const char *spec, char *obuf, bool expand);
|
extern const char *Yap_AbsoluteFile(const char *spec, char *obuf, bool expand);
|
||||||
|
|
||||||
@ -156,12 +156,46 @@ INLINE_ONLY inline EXTERN Term MkCharTerm(Int c) {
|
|||||||
return MkAtomTerm(Yap_ULookupAtom(cs));
|
return MkAtomTerm(Yap_ULookupAtom(cs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
INLINE_ONLY inline EXTERN char *Yap_VF(const char *path){
|
||||||
|
char out[YAP_FILENAME_MAX+1], *p = (char *)path;
|
||||||
|
extern char virtual_cwd[];
|
||||||
|
|
||||||
|
if ( virtual_cwd[0] == 0 || Yap_IsAbsolutePath(path, false)) {
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
strcpy(out, virtual_cwd);
|
||||||
|
strcat(out, "/" );
|
||||||
|
strcat(out, p);
|
||||||
|
strcpy(p, out);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
INLINE_ONLY inline EXTERN char *Yap_VFAlloc(const char *path){
|
||||||
|
char *out;
|
||||||
|
extern char virtual_cwd[];
|
||||||
|
|
||||||
|
out = (char *)malloc(YAP_FILENAME_MAX+1);
|
||||||
|
if ( virtual_cwd[0] == 0 || !Yap_IsAbsolutePath(path, false)) {
|
||||||
|
return (char *)path;
|
||||||
|
}
|
||||||
|
strcpy(out, virtual_cwd);
|
||||||
|
strcat(out, "/" );
|
||||||
|
strcat(out, path);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
/// UT when yap started
|
/// UT when yap started
|
||||||
extern uint64_t Yap_StartOfWTimes;
|
extern uint64_t Yap_StartOfWTimes;
|
||||||
|
|
||||||
extern bool Yap_HandleSIGINT(void);
|
extern bool Yap_HandleSIGINT(void);
|
||||||
|
|
||||||
|
|
||||||
extern bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf, size_t nchars USES_REGS);
|
extern bool Yap_set_stream_to_buf(StreamDesc *st, const char *bufi,
|
||||||
|
size_t nchars USES_REGS);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -294,8 +294,8 @@ const char* jniStrError(int errnum, char* buf, size_t buflen) {
|
|||||||
// char *strerror_r(int errnum, char *buf, size_t n);
|
// char *strerror_r(int errnum, char *buf, size_t n);
|
||||||
return strerror_r(errnum, buf, buflen);
|
return strerror_r(errnum, buf, buflen);
|
||||||
#else
|
#else
|
||||||
int rc = strerror_r(errnum, buf, buflen);
|
char *rc = strerror_r(errnum, buf, buflen);
|
||||||
if (rc != 0) {
|
if (rc != NULL) {
|
||||||
// (POSIX only guarantees a value other than 0. The safest
|
// (POSIX only guarantees a value other than 0. The safest
|
||||||
// way to implement this function is to use C++ and overload on the
|
// way to implement this function is to use C++ and overload on the
|
||||||
// type of strerror_r to accurately distinguish GNU from POSIX.)
|
// type of strerror_r to accurately distinguish GNU from POSIX.)
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "streamer.h"
|
#include "streamer.h"
|
||||||
|
|
||||||
|
|
||||||
static AndroidStreamer * streamerInstance = 0;
|
static AndroidStreamer * streamerInstance = 0;
|
||||||
|
|
||||||
void setStreamer(AndroidStreamer* streamer) {
|
void setStreamer(AndroidStreamer* streamer) {
|
||||||
@ -21,24 +22,29 @@ extern "C" {
|
|||||||
#include <Yap.h>
|
#include <Yap.h>
|
||||||
#include <YapStreams.h>
|
#include <YapStreams.h>
|
||||||
#include <VFS.h>
|
#include <VFS.h>
|
||||||
|
#include <yapio.h>
|
||||||
|
#include <iopreds.h>
|
||||||
|
|
||||||
VFS_t andstream;
|
extern void Java_pt_up_yap_lib_streamerJNI_swig_1module_1init__(void);
|
||||||
|
|
||||||
|
static VFS_t andstream;
|
||||||
|
|
||||||
|
void Java_pt_up_yap_lib_streamerJNI_swig_1module_1init__(void) {
|
||||||
|
streamerInstance = 0;
|
||||||
|
} ;
|
||||||
|
|
||||||
static std::string buff0;
|
static std::string buff0;
|
||||||
int n;
|
|
||||||
|
|
||||||
static void *
|
static void *
|
||||||
and_open(const char *name, const char *io_mode) {
|
and_open(struct vfs *me, int sno, const char *name, const char *io_mode) {
|
||||||
if (!strcmp(name,"//android/user_output") ||
|
|
||||||
!strcmp(name,"//android/user_error"))
|
|
||||||
// we assume object is already open, so there is no need to open it.
|
// we assume object is already open, so there is no need to open it.
|
||||||
return streamerInstance;
|
GLOBAL_Stream[sno].vfs_handle = streamerInstance;
|
||||||
else
|
GLOBAL_Stream[sno].vfs = me;
|
||||||
return NULL;
|
GLOBAL_Stream[sno].status = Append_Stream_f | Output_Stream_f;
|
||||||
|
buff0.clear();
|
||||||
|
return streamerInstance;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
and_close(int sno) {
|
and_close(int sno) {
|
||||||
return true;
|
return true;
|
||||||
@ -46,10 +52,13 @@ and_close(int sno) {
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
and_put(int sno, int ch) {
|
and_put(int sno, int ch) {
|
||||||
buff0[n++] = ch;
|
buff0 += ch;
|
||||||
if (ch=='\n' || n == 128) { buff0[n] = '\0'; streamerInstance->display(buff0); n = 0; }
|
if (ch=='\n' || buff0.length() == 128) { //buff0+= '\0';
|
||||||
|
streamerInstance->display(buff0);
|
||||||
|
}
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
and_get(int sno) {
|
and_get(int sno) {
|
||||||
return EOF;
|
return EOF;
|
||||||
@ -62,9 +71,10 @@ static int64_t and_seek(int sno, int64_t where, int how) {
|
|||||||
static void
|
static void
|
||||||
and_flush(int sno) {
|
and_flush(int sno) {
|
||||||
|
|
||||||
buff0[n] = '\0';
|
buff0 += '\0';
|
||||||
streamerInstance->display(buff0); n = 0;
|
streamerInstance->display(buff0);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Created by vsc on 11-07-2017.
|
// Created by vsc on 11-07-2017.
|
||||||
@ -73,13 +83,11 @@ streamerInstance->display(buff0); n = 0;
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
AndroidStreamer::bind()
|
AndroidStreamer::bind() {
|
||||||
{
|
buff0 = *new std::string[256];
|
||||||
buff0 = * new std::string[256];
|
andstream.name = "/android/user_error";
|
||||||
n = 0;
|
andstream.vflags = VFS_CAN_WRITE | VFS_HAS_PREFIX;
|
||||||
andstream.name = "//android/user_error";
|
andstream.prefix = "/android";
|
||||||
andstream.vflags = VFS_CAN_WRITE|VFS_HAS_PREFIX;
|
|
||||||
andstream.prefix = "//android/";
|
|
||||||
andstream.suffix = NULL;
|
andstream.suffix = NULL;
|
||||||
andstream.open = and_open;
|
andstream.open = and_open;
|
||||||
andstream.close = and_close;
|
andstream.close = and_close;
|
||||||
@ -89,8 +97,6 @@ AndroidStreamer::bind()
|
|||||||
andstream.seek = and_seek;
|
andstream.seek = and_seek;
|
||||||
andstream.next = GLOBAL_VFS;
|
andstream.next = GLOBAL_VFS;
|
||||||
GLOBAL_VFS = &andstream;
|
GLOBAL_VFS = &andstream;
|
||||||
// NULL;
|
Yap_InitStdStream(StdOutStream, Output_Stream_f | Append_Stream_f, NULL, &andstream);
|
||||||
Yap_InitStdStream(StdOutStream, Output_Stream_f, NULL, &andstream);
|
Yap_InitStdStream(StdErrStream, Output_Stream_f | Append_Stream_f, NULL, &andstream);
|
||||||
Yap_InitStdStream(StdErrStream, Output_Stream_f, NULL, &andstream);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
%module(directors="1") streamer
|
%module(directors="1") streamer
|
||||||
%{
|
%{
|
||||||
#include "streamer.h"
|
#include "streamer.h"
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
%include "std_string.i"
|
%include "std_string.i"
|
||||||
@ -10,7 +11,3 @@
|
|||||||
%feature("director") AndroidStreamer;
|
%feature("director") AndroidStreamer;
|
||||||
|
|
||||||
%include "streamer.h"
|
%include "streamer.h"
|
||||||
|
|
||||||
|
|
||||||
%init %{
|
|
||||||
%}
|
|
||||||
|
Reference in New Issue
Block a user