fix wide atom handling.

This commit is contained in:
Vitor Santos Costa 2011-08-12 11:52:47 -03:00
parent d70e53f243
commit 23be6ccdfc
3 changed files with 86 additions and 3 deletions

View File

@ -276,7 +276,6 @@ PutToken(const char *s, IOSTREAM *stream)
return TRUE;
}
static int
PutTokenN(const char *s, size_t len, IOSTREAM *stream)
{ if ( len > 0 )
@ -291,6 +290,63 @@ PutTokenN(const char *s, size_t len, IOSTREAM *stream)
return TRUE;
}
#if __YAP_PROLOG__
static bool
PutWideStringN(const wchar_t *str, size_t length, IOSTREAM *s)
{ size_t i;
const wchar_t *q = (const wchar_t *)str;
for(i=0; i<length; i++, q++)
{ if ( Sputcode(*q, s) == EOF )
return FALSE;
}
return TRUE;
}
static bool
PutWideString(const wchar_t *str, IOSTREAM *s)
{ const wchar_t *q = (const wchar_t *)str;
for( ; *q != EOS; q++ )
{ if ( Sputcode(*q, s) == EOF )
return FALSE;
}
return TRUE;
}
static int
PutWideToken(const wchar_t *s, IOSTREAM *stream)
{ if ( s[0] )
{ int rc;
TRY(rc=PutOpenToken(s[0]&0xff, stream));
TRY(PutWideString(s, stream));
return rc;
}
return TRUE;
}
static int
PutWideTokenN(const wchar_t *s, size_t len, IOSTREAM *stream)
{ if ( len > 0 )
{ int rc;
TRY(rc=PutOpenToken(s[0]&0xff, stream));
TRY(PutWideStringN(s, len, stream));
return rc;
}
return TRUE;
}
#endif
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
PutOpenBrace()/PutCloseBrace() are used to put additional braces around
@ -518,6 +574,11 @@ writeAtom(atom_t a, write_options *options)
case AT_SYMBOL:
case AT_SOLO:
case AT_SPECIAL:
#if __YAP_PROLOG__
if (isWideAtom(atom)) {
return PutWideToken(nameOfWideAtom(atom), options->out);
}
#endif
return PutToken(nameOfAtom(atom), options->out);
case AT_QUOTE:
case AT_FULLSTOP:
@ -532,8 +593,14 @@ writeAtom(atom_t a, write_options *options)
return rc;
}
}
} else
} else {
#if __YAP_PROLOG__
if (isWideAtom(atom)) {
return PutWideTokenN(nameOfWideAtom(atom), atomLength(atom), options->out);
}
#endif
return PutTokenN(nameOfAtom(atom), atomLength(atom), options->out);
}
}

View File

@ -1165,6 +1165,20 @@ Yap_dowrite(Term t, IOSTREAM *stream, int flags, int priority)
return res;
}
int
isWideAtom(atom_t atom)
{
Atom a = (Atom)atomValue(atom);
return IsWideAtom(a);
}
wchar_t *
nameOfWideAtom(atom_t atom)
{
Atom a = (Atom)atomValue(atom);
return RepAtom(a)->WStrOfAE;
}
#if THREADS
@ -1215,7 +1229,6 @@ error:
return rc;
}
int
recursiveMutexInit(recursiveMutex *m)
{

View File

@ -148,6 +148,9 @@ extern term_t Yap_CvtTerm(term_t ts);
#define clearNumber(n)
wchar_t *nameOfWideAtom(atom_t atom);
int isWideAtom(atom_t atom);
inline static int
charCode(Term w)
{ if ( IsAtomTerm(w) )