From 0007cb896be2eef8df899213f6e58c21bde9b146 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Fri, 17 Jun 2016 16:29:23 +0100 Subject: [PATCH] print predicate indicator --- C/text.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/C/text.c b/C/text.c index 909d24c50..1896707a0 100644 --- a/C/text.c +++ b/C/text.c @@ -1657,6 +1657,63 @@ const char *Yap_TextTermToText(Term t, char *buf, size_t len, encoding_t enc) { return out.val.c; } +/** + * Convert from a predicate structure to an UTF-8 string of the form + * + * module:name/arity. + * + * The result is in very volatile memory. + * + * @param s the buffer + * + * @return the temporary string + */ +const char * Yap_PredIndicatorToUTF8String(PredEntry *ap) { + CACHE_REGS + char *s = LOCAL_FileNameBuf, *smax = s+YAP_FILENAME_MAX; + Atom at; + arity_t arity; + Functor f; + + Term tmod = ap->ModuleOfPred; + if (tmod) { + Yap_AtomToUTF8Text(AtomOfTerm(tmod), s); + s += strlen(s); + stpncpy(s, ":", smax-s); + s++; + } else { + s = stpncpy(s, "prolog:" , smax-s ); + } + // follows the actual functor + if (ap->ModuleOfPred == IDB_MODULE) { + if (ap->PredFlags & NumberDBPredFlag) { + Int key = ap->src.IndxId; + snprintf( s, smax-s, "%" PRIdPTR , key); + return LOCAL_FileNameBuf; + } else if (ap->PredFlags & AtomDBPredFlag) { + at = (Atom)(ap->FunctorOfPred); + if (!Yap_AtomToUTF8Text(at, s)) + return NULL; + } else { + f = ap->FunctorOfPred; + at = NameOfFunctor(f); + arity = ArityOfFunctor(f); + } + } else { + arity = ap->ArityOfPE; + if (arity) { + at = NameOfFunctor( ap->FunctorOfPred ); + } else { + at = (Atom)(ap->FunctorOfPred); + } + } + if (!Yap_AtomToUTF8Text(at, s)) + return NULL; + s += strlen(s); + snprintf( s, smax-s, "/%" PRIdPTR, arity ); + return LOCAL_FileNameBuf; +} + /** * Convert from a text buffer (8-bit) to a term that has the same type as * _Tguide_