fix write2atom and indent

This commit is contained in:
Vitor Santos Costa 2016-08-21 10:28:38 -05:00
parent 2aaca174e5
commit e50d722e66

View File

@ -51,7 +51,7 @@ void *otr__ = TR; void * ost__ = LOCAL_ScannerStack; TR =(tr_fr_ptr)LOCAL_Scanne
#define unprotect_stack(s) \ #define unprotect_stack(s) \
TR = ov__, LOCAL_ScannerStack = ocur__ TR = ov__, LOCAL_ScannerStack = ocur__
//LOCAL_ScannerStack = ov__, TR = ot__ //LOCAL_ScannerStack = ov__, TR = ot__
static bool alloc_ovfl(size_t sz) { static bool alloc_ovfl(size_t sz) {
@ -428,7 +428,7 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) {
} }
if (inp->type & YAP_STRING_WCHARS) { if (inp->type & YAP_STRING_WCHARS) {
//printf("%S\n",inp->val.w); //printf("%S\n",inp->val.w);
return wchar2utf8(inp, lengp); return wchar2utf8(inp, lengp);
} }
return NULL; return NULL;
} }
@ -578,7 +578,7 @@ static Atom write_atom(void *s0, seq_tv_t *out, size_t leng USES_REGS) {
utf8proc_int32_t chr; utf8proc_int32_t chr;
while (*s && get_utf8(s, -1, &chr) == 1) s++; while (*s && get_utf8(s, -1, &chr) == 1) s++;
if (*s == '\0') if (*s == '\0')
return out->val.a = Yap_LookupAtom((char*)s0); return out->val.a = Yap_LookupAtom((char *) s0);
s = s0; s = s0;
size_t l = strlen(s0); size_t l = strlen(s0);
wchar_t *wbuf = Malloc(sizeof(wchar_t) * ((l + 1))), *wptr = wbuf; wchar_t *wbuf = Malloc(sizeof(wchar_t) * ((l + 1))), *wptr = wbuf;
@ -593,11 +593,11 @@ static Atom write_atom(void *s0, seq_tv_t *out, size_t leng USES_REGS) {
continue; continue;
} }
s++; s++;
*wptr++ = chr; *wptr++ = chr;
} }
*wptr++ = '\0'; *wptr++ = '\0';
at = Yap_LookupMaybeWideAtom(wbuf); at = Yap_LookupMaybeWideAtom(wbuf);
out->val.a = at; out->val.a = at;
return at; return at;
} }
@ -620,7 +620,7 @@ size_t write_buffer(unsigned char *s0, seq_tv_t *out, size_t leng USES_REGS) {
unsigned char *buf = out->val.uc; unsigned char *buf = out->val.uc;
if (!buf) if (!buf)
return -1; return -1;
while (*cp ) { while (*cp) {
utf8proc_int32_t chr; utf8proc_int32_t chr;
int off = get_utf8(cp, -1, &chr); int off = get_utf8(cp, -1, &chr);
if (off <= 0) if (off <= 0)
@ -673,11 +673,11 @@ static size_t write_length(const unsigned char *s0, seq_tv_t *out,
return leng; return leng;
} }
static Term write_number( unsigned char *s, seq_tv_t *out, int size static Term write_number(unsigned char *s, seq_tv_t *out, int size
USES_REGS) { USES_REGS) {
Term t; Term t;
mark_stack(); mark_stack();
t = Yap_StringToNumberTerm((char *)s, &out->enc); t = Yap_StringToNumberTerm((char *) s, &out->enc);
restore_stack(); restore_stack();
return t; return t;
} }
@ -686,8 +686,8 @@ static Term string_to_term(void *s, seq_tv_t *out, size_t leng USES_REGS) {
Term o; Term o;
mark_stack(); mark_stack();
o = out->val.t = o = out->val.t =
Yap_StringToTerm(s, strlen(s) + 1, &out->enc, Yap_StringToTerm(s, strlen(s) + 1, &out->enc,
GLOBAL_MaxPriority, NULL); GLOBAL_MaxPriority, NULL);
restore_stack(); restore_stack();
return o; return o;
} }
@ -699,28 +699,26 @@ bool write_Text(unsigned char *inp, seq_tv_t *out, size_t leng USES_REGS) {
return out->val.t != 0; return out->val.t != 0;
} }
if (out->type & if (out->type &
(YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG)) { (YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG)) {
if ( if (
(out->val.t = write_number(inp, out, leng PASS_REGS)) != (out->val.t = write_number(inp, out, leng PASS_REGS)) !=
0L) { 0L) {
//Yap_DebugPlWriteln(out->val.t); //Yap_DebugPlWriteln(out->val.t);
return true; return true;
} }
if (!(out->type & YAP_STRING_ATOM)) if (!(out->type & YAP_STRING_ATOM))
return false; return false;
} }
if (out->type & (YAP_STRING_ATOM)) { if (out->type & (YAP_STRING_ATOM)) {
if ( if (
write_atom(inp, out, leng PASS_REGS) != NIL) { write_atom(inp, out, leng PASS_REGS) != NIL) {
Atom at = out->val.a; Atom at = out->val.a;
if (at != NIL) //Yap_DebugPlWriteln(out->val.t);
out->val.t = MkAtomTerm(at); return at != NIL;
//Yap_DebugPlWriteln(out->val.t);
return at != NIL;
}
} }
}
switch (out->type & YAP_TYPE_MASK) { switch (out->type & YAP_TYPE_MASK) {
case YAP_STRING_CHARS: { case YAP_STRING_CHARS: {
@ -837,7 +835,7 @@ bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) {
} }
} }
rc = write_Text(buf, out, leng PASS_REGS); rc = write_Text(buf, out, leng PASS_REGS);
unprotect_stack(out); unprotect_stack(out);
/* fprintf(stderr, " -> "); /* fprintf(stderr, " -> ");
if (!rc) fprintf(stderr, "NULL"); if (!rc) fprintf(stderr, "NULL");
@ -906,7 +904,7 @@ bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) {
unsigned char *buf; unsigned char *buf;
size_t leng; size_t leng;
int i; int i;
init_alloc(__LINE__); init_alloc(__LINE__);
bufv = Malloc(tot * sizeof(unsigned char *)); bufv = Malloc(tot * sizeof(unsigned char *));
if (!bufv) { if (!bufv) {
unprotect_stack(NULL); unprotect_stack(NULL);
@ -933,7 +931,7 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
seq_tv_t outv[] USES_REGS) { seq_tv_t outv[] USES_REGS) {
unsigned char *buf; unsigned char *buf;
size_t l; size_t l;
init_alloc(__LINE__); init_alloc(__LINE__);
inp->type |= YAP_STRING_IN_TMP; inp->type |= YAP_STRING_IN_TMP;
buf = Yap_readText(inp, &l PASS_REGS); buf = Yap_readText(inp, &l PASS_REGS);
if (!buf) { if (!buf) {
@ -964,7 +962,7 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
unprotect_stack(NULL); unprotect_stack(NULL);
return false; return false;
} }
unprotect_stack((outv+1)); unprotect_stack((outv + 1));
return rc; return rc;
} else /* if (outv[1].val.t) */ { } else /* if (outv[1].val.t) */ {
buf1 = Yap_readText(outv + 1, &l1 PASS_REGS); buf1 = Yap_readText(outv + 1, &l1 PASS_REGS);
@ -981,7 +979,7 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
} }
buf0 = slice(0, l0, buf PASS_REGS); buf0 = slice(0, l0, buf PASS_REGS);
bool rc = write_Text(buf0, outv, l0 PASS_REGS); bool rc = write_Text(buf0, outv, l0 PASS_REGS);
unprotect_stack((rc ? NULL : outv+0)); unprotect_stack((rc ? NULL : outv + 0));
return rc; return rc;
} }
} }
@ -991,9 +989,9 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
if (i == 0) if (i == 0)
next = 0; next = 0;
else else
next = cuts[i-1]; next = cuts[i - 1];
void *bufi = slice(next, cuts[i], buf PASS_REGS); void *bufi = slice(next, cuts[i], buf PASS_REGS);
if (!write_Text(bufi, outv + i, cuts[i]-next PASS_REGS)) { if (!write_Text(bufi, outv + i, cuts[i] - next PASS_REGS)) {
unprotect_stack(NULL); unprotect_stack(NULL);
return false; return false;
} }