extend C-interface to check if a variable is AttVar and to fetch all the

attributes.
This commit is contained in:
Vitor Santos Costa 2009-02-09 22:45:50 +00:00
parent bde2b57f07
commit 33b4a02fae
2 changed files with 35 additions and 1 deletions

View File

@ -333,6 +333,7 @@
#include "Yap.h"
#include "clause.h"
#include "yapio.h"
#include "attvar.h"
#if HAVE_STDARG_H
#include <stdarg.h>
#endif
@ -355,6 +356,9 @@
#ifdef CUT_C
#include "cut_c.h"
#endif /* CUT_C */
#if HAVE_MALLOC_H
#include <malloc.h>
#endif
#if !HAVE_STRNCPY
#define strncpy(X,Y,Z) strcpy(X,Y)
@ -504,6 +508,8 @@ X_API char *STD_PROTO(YAP_cwd,(void));
X_API Term STD_PROTO(YAP_OpenList,(int));
X_API Term STD_PROTO(YAP_ExtendList,(Term, Term));
X_API int STD_PROTO(YAP_CloseList,(Term, Term));
X_API int STD_PROTO(YAP_IsAttVar,(Term));
X_API Term STD_PROTO(YAP_AttsOfVar,(Term));
static int (*do_getf)(void);
@ -2430,7 +2436,7 @@ YAP_cwd(void)
if (!Yap_getcwd(Yap_FileNameBuf, YAP_FILENAME_MAX))
return FALSE;
len = strlen(Yap_FileNameBuf);
buf = malloc(+1);
buf = Yap_AllocCodeSpace(len+1);
if (!buf)
return NULL;
strncpy(buf, Yap_FileNameBuf, len);
@ -2478,3 +2484,27 @@ YAP_CloseList(Term t0, Term tail)
return FALSE;
return TRUE;
}
X_API Int
YAP_IsAttVar(Term t)
{
t = Deref(t);
if (!IsVarTerm(t))
return FALSE;
return (VarOfTerm(t) < H0);
}
X_API Term
YAP_AttsOfVar(Term t)
{
attvar_record *attv;
t = Deref(t);
if (!IsVarTerm(t))
return TermNil;
if (VarOfTerm(t) >= H0)
return TermNil;
attv = (attvar_record *)VarOfTerm(t);
return attv->Atts;
}

View File

@ -476,6 +476,10 @@ extern X_API YAP_Term PROTO(YAP_OpenList,(int));
extern X_API YAP_Term PROTO(YAP_ExtendList,(YAP_Term, YAP_Term));
extern X_API int PROTO(YAP_CloseList,(YAP_Term, YAP_Term));
/* attributed variables */
extern X_API int PROTO(YAP_IsAttVar,(YAP_Term));
extern X_API YAP_Term PROTO(YAP_AttsOfVar,(YAP_Term));
#define YAP_InitCPred(N,A,F) YAP_UserCPredicate(N,F,A)
__END_DECLS