Atom Yap_LookupMaybeWideAtomWithLength(wchar_t *atom, size_t len) { /* lookup atom in atom table */ wchar_t *p = atom, c; size_t len0 = 0; Atom at; int wide = FALSE; while ((c = *p++)) { if (c > 255) wide = TRUE; len0++; if (len0 == len) break; } if (p[0] == '\0' && wide) return LookupWideAtom(atom); else if (wide) { wchar_t *ptr, *ptr0; p = atom; ptr0 = ptr = (wchar_t *)Yap_AllocCodeSpace(sizeof(wchar_t)*(len+1)); if (!ptr) return NIL; while (len--) {*ptr++ = *p++;} ptr[0] = '\0'; at = LookupWideAtom(ptr0); Yap_FreeCodeSpace((char *)ptr0); return at; } else { char *ptr, *ptr0; /* not really a wide atom */ p = atom; ptr0 = ptr = Yap_AllocCodeSpace(len+1); if (!ptr) return NIL; while (len--) {*ptr++ = *p++;} ptr[0] = '\0'; at = LookupAtom(ptr0); Yap_FreeCodeSpace(ptr0); return at; } }
Atom Yap_LookupMaybeWideAtomWithLength( const wchar_t *atom, size_t len0) { /* lookup atom in atom table */ Atom at; int wide = FALSE; size_t i = 0; while (i < len0) { // primary support for atoms with null chars wchar_t c = atom[i]; if (c > 255) { wide = TRUE; break; } if (c == '\0') { len0 = i; break; } i++; } if (wide) { wchar_t *ptr0; ptr0 = (wchar_t *)Yap_AllocCodeSpace(sizeof(wchar_t) * (len0 + 1)); if (!ptr0) return NIL; memcpy(ptr0, atom, len0 * sizeof(wchar_t)); ptr0[len0] = '\0'; at = LookupWideAtom(ptr0); Yap_FreeCodeSpace((char *)ptr0); return at; } else { unsigned char *ptr0; ptr0 = Yap_AllocCodeSpace((len0 + 1)); if (!ptr0) return NIL; for (i = 0; i < len0; i++) ptr0[i] = atom[i]; ptr0[len0] = '\0'; at = LookupAtom(ptr0); Yap_FreeCodeSpace(ptr0); return at; } }
Atom Yap_LookupMaybeWideAtom(wchar_t *atom) { /* lookup atom in atom table */ wchar_t *p = atom, c; size_t len = 0; char *ptr, *ptr0; Atom at; while ((c = *p++)) { if (c > 255) return LookupWideAtom(atom); len++; } /* not really a wide atom */ p = atom; ptr0 = ptr = Yap_AllocCodeSpace(len+1); if (!ptr) return NIL; while ((*ptr++ = *p++)); at = LookupAtom(ptr0); Yap_FreeCodeSpace(ptr0); return at; }
Atom Yap_LookupWideAtom(const wchar_t *atom) { /* lookup atom in atom table */ return LookupWideAtom(atom); }