atom_concat and empty atoms
This commit is contained in:
parent
8baaa70cec
commit
861f185ec6
@ -1333,7 +1333,7 @@ restart_aux:
|
||||
}
|
||||
|
||||
while (t1 != TermNil) {
|
||||
inpv[i].type = YAP_STRING_ATOM;
|
||||
inpv[i].type = YAP_STRING_ATOM,
|
||||
inpv[i].val.t = HeadOfTerm(t1);
|
||||
i++;
|
||||
t1 = TailOfTerm(t1);
|
||||
|
115
C/text.c
115
C/text.c
@ -83,9 +83,9 @@ void *pop_output_text_stack__(int i, void *export) {
|
||||
struct mblock *p = LOCAL_TextBuffer->first[lvl];
|
||||
while (p) {
|
||||
struct mblock *np = p->next;
|
||||
if (p+1 == export) {
|
||||
if (p + 1 == export) {
|
||||
size_t sz = p->sz;
|
||||
memcpy(p, p+1, sz);
|
||||
memcpy(p, p + 1, sz);
|
||||
export = p;
|
||||
} else {
|
||||
free(p);
|
||||
@ -309,9 +309,9 @@ static unsigned char *latin2utf8(seq_tv_t *inp) {
|
||||
}
|
||||
*pt++ = '\0';
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned char *wchar2utf8(seq_tv_t *inp) {
|
||||
static unsigned char *wchar2utf8(seq_tv_t *inp) {
|
||||
size_t sz = wcslen(inp->val.w) * 4;
|
||||
wchar_t *b0 = inp->val.w;
|
||||
unsigned char *buf = Malloc(sz + 1), *pt = buf;
|
||||
@ -322,36 +322,36 @@ static unsigned char *latin2utf8(seq_tv_t *inp) {
|
||||
pt += put_utf8(pt, ch);
|
||||
*pt++ = '\0';
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
static void *slice(size_t min, size_t max, const unsigned char *buf USES_REGS);
|
||||
static void *slice(size_t min, size_t max, const unsigned char *buf USES_REGS);
|
||||
|
||||
static unsigned char *Yap_ListOfCodesToBuffer(unsigned char *buf, Term t,
|
||||
static unsigned char *Yap_ListOfCodesToBuffer(unsigned char *buf, Term t,
|
||||
seq_tv_t *inp USES_REGS) {
|
||||
bool codes;
|
||||
unsigned char *nbuf = codes2buf(t, buf, &codes PASS_REGS);
|
||||
if (!codes)
|
||||
return NULL;
|
||||
return nbuf;
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned char *Yap_ListOfAtomsToBuffer(unsigned char *buf, Term t,
|
||||
static unsigned char *Yap_ListOfAtomsToBuffer(unsigned char *buf, Term t,
|
||||
seq_tv_t *inp USES_REGS) {
|
||||
bool codes;
|
||||
unsigned char *nbuf = codes2buf(t, buf, &codes PASS_REGS);
|
||||
if (codes)
|
||||
return NULL;
|
||||
return nbuf;
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned char *Yap_ListToBuffer(unsigned char *buf, Term t,
|
||||
seq_tv_t *inp USES_REGS) {
|
||||
unsigned char *nbuf = codes2buf(t, buf, NULL PASS_REGS);
|
||||
return nbuf;
|
||||
}
|
||||
}
|
||||
|
||||
#if USE_GEN_TYPE_ERROR
|
||||
static yap_error_number gen_type_error(int flags) {
|
||||
static yap_error_number gen_type_error(int flags) {
|
||||
if ((flags & (YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT |
|
||||
YAP_STRING_FLOAT | YAP_STRING_ATOMS_CODES | YAP_STRING_BIG)) ==
|
||||
(YAP_STRING_STRING | YAP_STRING_ATOM | YAP_STRING_INT | YAP_STRING_FLOAT |
|
||||
@ -372,12 +372,12 @@ static unsigned char *Yap_ListToBuffer(unsigned char *buf, Term t,
|
||||
if (flags & (YAP_STRING_CODES | YAP_STRING_ATOMS))
|
||||
return TYPE_ERROR_LIST;
|
||||
return TYPE_ERROR_NUMBER;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// static int cnt;
|
||||
// static int cnt;
|
||||
|
||||
unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
|
||||
unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
|
||||
|
||||
/* we know what the term is */
|
||||
if (!(inp->type & (YAP_STRING_CHARS | YAP_STRING_WCHARS))) {
|
||||
@ -499,9 +499,9 @@ static unsigned char *Yap_ListToBuffer(unsigned char *buf, Term t,
|
||||
return wchar2utf8(inp);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static Term write_strings(unsigned char *s0, seq_tv_t *out USES_REGS) {
|
||||
static Term write_strings(unsigned char *s0, seq_tv_t *out USES_REGS) {
|
||||
size_t min = 0, max = strlen((char *)s0);
|
||||
|
||||
if (out->type & (YAP_STRING_NCHARS | YAP_STRING_TRUNC)) {
|
||||
@ -529,9 +529,9 @@ static unsigned char *Yap_ListToBuffer(unsigned char *buf, Term t,
|
||||
out->val.t = t;
|
||||
|
||||
return out->val.t;
|
||||
}
|
||||
}
|
||||
|
||||
static Term write_atoms(void *s0, seq_tv_t *out USES_REGS) {
|
||||
static Term write_atoms(void *s0, seq_tv_t *out USES_REGS) {
|
||||
Term t = AbsPair(HR);
|
||||
char *s1 = (char *)s0;
|
||||
size_t sz = 0;
|
||||
@ -581,9 +581,9 @@ static unsigned char *Yap_ListToBuffer(unsigned char *buf, Term t,
|
||||
}
|
||||
out->val.t = t;
|
||||
return (t);
|
||||
}
|
||||
}
|
||||
|
||||
static Term write_codes(void *s0, seq_tv_t *out USES_REGS) {
|
||||
static Term write_codes(void *s0, seq_tv_t *out USES_REGS) {
|
||||
Term t;
|
||||
size_t sz = strlen(s0);
|
||||
if (sz == 0) {
|
||||
@ -618,9 +618,9 @@ static unsigned char *Yap_ListToBuffer(unsigned char *buf, Term t,
|
||||
}
|
||||
out->val.t = t;
|
||||
return (t);
|
||||
}
|
||||
}
|
||||
|
||||
static Atom write_atom(void *s0, seq_tv_t *out USES_REGS) {
|
||||
static Atom write_atom(void *s0, seq_tv_t *out USES_REGS) {
|
||||
unsigned char *s = s0;
|
||||
int32_t ch;
|
||||
size_t leng = strlen(s0);
|
||||
@ -635,9 +635,9 @@ static unsigned char *Yap_ListToBuffer(unsigned char *buf, Term t,
|
||||
memcpy(buf, s0, n + 1);
|
||||
return Yap_ULookupAtom(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void *write_buffer(unsigned char *s0, seq_tv_t *out USES_REGS) {
|
||||
void *write_buffer(unsigned char *s0, seq_tv_t *out USES_REGS) {
|
||||
size_t leng = strlen((char *)s0);
|
||||
size_t min = 0, max = leng;
|
||||
if (out->enc == ENC_ISO_UTF8) {
|
||||
@ -702,7 +702,7 @@ static unsigned char *Yap_ListToBuffer(unsigned char *buf, Term t,
|
||||
return NULL;
|
||||
}
|
||||
return out->val.c;
|
||||
}
|
||||
}
|
||||
|
||||
static size_t write_length(const unsigned char *s0, seq_tv_t *out USES_REGS) {
|
||||
return strlen_utf8(s0);
|
||||
@ -797,9 +797,9 @@ bool write_Text(unsigned char *inp, seq_tv_t *out USES_REGS) {
|
||||
default: { return true; }
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static size_t upcase(void *s0, seq_tv_t *out USES_REGS) {
|
||||
static size_t upcase(void *s0, seq_tv_t *out USES_REGS) {
|
||||
|
||||
unsigned char *s = s0;
|
||||
while (*s) {
|
||||
@ -810,9 +810,9 @@ bool write_Text(unsigned char *inp, seq_tv_t *out USES_REGS) {
|
||||
s += put_utf8(s, chr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
static size_t downcase(void *s0, seq_tv_t *out USES_REGS) {
|
||||
static size_t downcase(void *s0, seq_tv_t *out USES_REGS) {
|
||||
|
||||
unsigned char *s = s0;
|
||||
while (*s) {
|
||||
@ -823,9 +823,9 @@ bool write_Text(unsigned char *inp, seq_tv_t *out USES_REGS) {
|
||||
s += put_utf8(s, chr);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) {
|
||||
bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) {
|
||||
unsigned char *buf;
|
||||
bool rc;
|
||||
/*
|
||||
@ -888,9 +888,9 @@ bool write_Text(unsigned char *inp, seq_tv_t *out USES_REGS) {
|
||||
fprintf(stderr, "\n]\n"); */
|
||||
pop_text_stack(l);
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned char *concat(int n, void *sv[] USES_REGS) {
|
||||
static unsigned char *concat(int n, void *sv[] USES_REGS) {
|
||||
void *buf;
|
||||
unsigned char *buf0;
|
||||
size_t room = 0;
|
||||
@ -915,9 +915,9 @@ bool write_Text(unsigned char *inp, seq_tv_t *out USES_REGS) {
|
||||
#endif
|
||||
}
|
||||
return buf0;
|
||||
}
|
||||
}
|
||||
|
||||
static void *slice(size_t min, size_t max, const unsigned char *buf USES_REGS) {
|
||||
static void *slice(size_t min, size_t max, const unsigned char *buf USES_REGS) {
|
||||
unsigned char *nbuf = BaseMalloc((max - min) * 4 + 1);
|
||||
const unsigned char *ptr = skip_utf8(buf, min);
|
||||
unsigned char *nptr = nbuf;
|
||||
@ -929,11 +929,11 @@ bool write_Text(unsigned char *inp, seq_tv_t *out USES_REGS) {
|
||||
}
|
||||
nptr[0] = '\0';
|
||||
return nbuf;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Out must be an atom or a string
|
||||
bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) {
|
||||
//
|
||||
// Out must be an atom or a string
|
||||
bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) {
|
||||
void **bufv;
|
||||
unsigned char *buf;
|
||||
int i, j;
|
||||
@ -949,8 +949,8 @@ bool write_Text(unsigned char *inp, seq_tv_t *out USES_REGS) {
|
||||
if (!nbuf) {
|
||||
return NULL;
|
||||
}
|
||||
if (!nbuf[0])
|
||||
continue;
|
||||
// if (!nbuf[0])
|
||||
// continue;
|
||||
bufv[j++] = nbuf;
|
||||
}
|
||||
if (j == 0) {
|
||||
@ -964,7 +964,7 @@ bool write_Text(unsigned char *inp, seq_tv_t *out USES_REGS) {
|
||||
bool rc = write_Text(buf, out PASS_REGS);
|
||||
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
|
||||
@ -1041,9 +1041,9 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Function to convert a generic text term (string, atom, list of codes, list
|
||||
of<
|
||||
atoms) into a buff
|
||||
@ -1057,12 +1057,13 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
|
||||
*
|
||||
* @return the buffer, or NULL in case of failure. If so, Yap_Error may be
|
||||
called.
|
||||
*/
|
||||
const char *Yap_TextTermToText(Term t USES_REGS) {
|
||||
*/
|
||||
const char *Yap_TextTermToText(Term t USES_REGS) {
|
||||
seq_tv_t inp, out;
|
||||
inp.val.t = t;
|
||||
inp.type = Yap_TextType(t);
|
||||
inp.type = YAP_STRING_ATOM | YAP_STRING_STRING | YAP_STRING_ATOMS_CODES| YAP_STRING_TERM;
|
||||
inp.type = YAP_STRING_ATOM | YAP_STRING_STRING | YAP_STRING_ATOMS_CODES |
|
||||
YAP_STRING_TERM;
|
||||
inp.enc = ENC_ISO_UTF8;
|
||||
out.enc = ENC_ISO_UTF8;
|
||||
out.type = YAP_STRING_CHARS;
|
||||
@ -1070,9 +1071,9 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
|
||||
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
|
||||
return NULL;
|
||||
return out.val.c;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Convert from a predicate structure to an UTF-8 string of the form
|
||||
*
|
||||
* module:name/arity.
|
||||
@ -1083,7 +1084,7 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
|
||||
*
|
||||
* @return the temporary string
|
||||
*/
|
||||
const char *Yap_PredIndicatorToUTF8String(PredEntry *ap) {
|
||||
const char *Yap_PredIndicatorToUTF8String(PredEntry *ap) {
|
||||
CACHE_REGS
|
||||
Atom at;
|
||||
arity_t arity = 0;
|
||||
@ -1131,15 +1132,15 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
|
||||
at = (Atom)(ap->FunctorOfPred);
|
||||
}
|
||||
}
|
||||
if (!stpcpy(s,Yap_AtomToUTF8Text(at))) {
|
||||
if (!stpcpy(s, Yap_AtomToUTF8Text(at))) {
|
||||
return NULL;
|
||||
}
|
||||
s += strlen(s);
|
||||
snprintf(s, smax - s, "/%" PRIdPTR, arity);
|
||||
return s0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Convert from a text buffer (8-bit) to a term that has the same type as
|
||||
* _Tguide_
|
||||
*
|
||||
@ -1147,8 +1148,8 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
|
||||
≈ * @param tguide the guide
|
||||
*
|
||||
≈ * @return the term
|
||||
*/
|
||||
Term Yap_MkTextTerm(const char *s, int guide USES_REGS) {
|
||||
*/
|
||||
Term Yap_MkTextTerm(const char *s, int guide USES_REGS) {
|
||||
if (guide == YAP_STRING_ATOM) {
|
||||
return MkAtomTerm(Yap_LookupAtom(s));
|
||||
} else if (guide == YAP_STRING_STRING) {
|
||||
@ -1158,4 +1159,4 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
|
||||
} else {
|
||||
return Yap_CharsToListOfCodes(s, ENC_ISO_UTF8 PASS_REGS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
38
os/charsio.c
38
os/charsio.c
@ -1,19 +1,19 @@
|
||||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
* File: charcodes.c *
|
||||
* Last rev: 5/2/88 *
|
||||
* mods: *
|
||||
* comments: Character codes and character conversion *
|
||||
* *
|
||||
*************************************************************************/
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
* *
|
||||
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
||||
* *
|
||||
**************************************************************************
|
||||
* *
|
||||
* File: charcodes.c *
|
||||
* Last rev: 5/2/88 *
|
||||
* mods: *
|
||||
* comments: Character codes and character conversion *
|
||||
* *
|
||||
*************************************************************************/
|
||||
#ifdef SCCS
|
||||
static char SccsId[] = "%W% %G%";
|
||||
#endif
|
||||
@ -1102,9 +1102,10 @@ static Int peek_char(USES_REGS1) {
|
||||
unsigned char sinp[16];
|
||||
Int ch;
|
||||
|
||||
if (sno < 0)
|
||||
if (sno < 0)
|
||||
return false;
|
||||
if ((ch = Yap_peek(sno)) < 0) {
|
||||
Int ch = Yap_peek(sno);
|
||||
if (ch < 0) {
|
||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||
return Yap_unify_constant(ARG2, MkAtomTerm(AtomEof));
|
||||
}
|
||||
@ -1114,7 +1115,8 @@ if (sno < 0)
|
||||
return false;
|
||||
}
|
||||
sinp[off] = '\0';
|
||||
return Yap_unify_constant(ARG2, MkAtomTerm(Yap_ULookupAtom(sinp)));
|
||||
printf("%s\n", simp) return Yap_unify_constant(
|
||||
ARG2, MkAtomTerm(Yap_ULookupAtom(sinp)));
|
||||
}
|
||||
|
||||
/** @pred peek_char( - _C_) is iso
|
||||
|
Reference in New Issue
Block a user