globle void *GetNextFactInScope( void *vTheFact) { static long lastModuleIndex = -1; struct fact *theFact = (struct fact *) vTheFact; /*=======================================================*/ /* If fact passed as an argument is a NULL pointer, then */ /* we're just beginning a traversal of the fact list. If */ /* the module index has changed since that last time the */ /* fact list was traversed by this routine, then */ /* determine all of the deftemplates that are in scope */ /* of the current module. */ /*=======================================================*/ if (theFact == NULL) { theFact = FactList; if (lastModuleIndex != ModuleChangeIndex) { UpdateDeftemplateScope(); lastModuleIndex = ModuleChangeIndex; } } /*==================================================*/ /* Otherwise, if the fact passed as an argument has */ /* been retracted, then there's no way to determine */ /* the next fact, so return a NULL pointer. */ /*==================================================*/ else if (((struct fact *) theFact)->garbage) { return(NULL); } /*==================================================*/ /* Otherwise, start the search for the next fact in */ /* scope with the fact immediately following the */ /* fact passed as an argument. */ /*==================================================*/ else { theFact = theFact->nextFact; } /*================================================*/ /* Continue traversing the fact-list until a fact */ /* is found that's associated with a deftemplate */ /* that's in scope. */ /*================================================*/ while (theFact != NULL) { if (theFact->whichDeftemplate->inScope) return((void *) theFact); theFact = theFact->nextFact; } return(NULL); }
globle void EnvGetFactList( void *theEnv, DATA_OBJECT_PTR returnValue, void *vTheModule) { struct fact *theFact; unsigned long count; struct multifield *theList; struct defmodule *theModule = (struct defmodule *) vTheModule; /*==========================*/ /* Save the current module. */ /*==========================*/ SaveCurrentModule(theEnv); /*============================================*/ /* Count the number of facts to be retrieved. */ /*============================================*/ if (theModule == NULL) { for (theFact = (struct fact *) EnvGetNextFact(theEnv,NULL), count = 0; theFact != NULL; theFact = (struct fact *) EnvGetNextFact(theEnv,theFact), count++) { /* Do Nothing */ } } else { EnvSetCurrentModule(theEnv,(void *) theModule); UpdateDeftemplateScope(theEnv); for (theFact = (struct fact *) GetNextFactInScope(theEnv,NULL), count = 0; theFact != NULL; theFact = (struct fact *) GetNextFactInScope(theEnv,theFact), count++) { /* Do Nothing */ } } /*===========================================================*/ /* Create the multifield value to store the construct names. */ /*===========================================================*/ SetpType(returnValue,MULTIFIELD); SetpDOBegin(returnValue,1); SetpDOEnd(returnValue,(long) count); theList = (struct multifield *) EnvCreateMultifield(theEnv,count); SetpValue(returnValue,(void *) theList); /*==================================================*/ /* Store the fact pointers in the multifield value. */ /*==================================================*/ if (theModule == NULL) { for (theFact = (struct fact *) EnvGetNextFact(theEnv,NULL), count = 1; theFact != NULL; theFact = (struct fact *) EnvGetNextFact(theEnv,theFact), count++) { SetMFType(theList,count,FACT_ADDRESS); SetMFValue(theList,count,(void *) theFact); } } else { for (theFact = (struct fact *) GetNextFactInScope(theEnv,NULL), count = 1; theFact != NULL; theFact = (struct fact *) GetNextFactInScope(theEnv,theFact), count++) { SetMFType(theList,count,FACT_ADDRESS); SetMFValue(theList,count,(void *) theFact); } } /*=============================*/ /* Restore the current module. */ /*=============================*/ RestoreCurrentModule(theEnv); UpdateDeftemplateScope(theEnv); }