From ecaf6aa7139cb6a6ae0ba5760a25fbd423a40475 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Thu, 6 May 2010 10:58:25 +0100 Subject: [PATCH] lookup with max lentgth --- C/adtdefs.c | 40 ++++++++++++++++++++++++++++++++++++++++ H/Yapproto.h | 1 + 2 files changed, 41 insertions(+) diff --git a/C/adtdefs.c b/C/adtdefs.c index 161f3d717..f28dc250d 100644 --- a/C/adtdefs.c +++ b/C/adtdefs.c @@ -296,6 +296,46 @@ Yap_LookupMaybeWideAtom(wchar_t *atom) return at; } +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(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_LookupAtom(char *atom) { /* lookup atom in atom table */ diff --git a/H/Yapproto.h b/H/Yapproto.h index a6f8f7310..a93daf107 100644 --- a/H/Yapproto.h +++ b/H/Yapproto.h @@ -31,6 +31,7 @@ int STD_PROTO(Yap_HasOp,(Atom)); struct operator_entry *STD_PROTO(Yap_GetOpPropForAModuleHavingALock,(AtomEntry *, Term)); Atom STD_PROTO(Yap_LookupAtom,(char *)); Atom STD_PROTO(Yap_LookupMaybeWideAtom,(wchar_t *)); +Atom STD_PROTO(Yap_LookupMaybeWideAtomWithLength,(wchar_t *, size_t)); Atom STD_PROTO(Yap_FullLookupAtom,(char *)); void STD_PROTO(Yap_LookupAtomWithAddress,(char *,AtomEntry *)); Prop STD_PROTO(Yap_NewPredPropByFunctor,(struct FunctorEntryStruct *, Term));