void ClipsRuleMgr::getAllTemplatesFromClips() { void *firstT; firstT = EnvGetNextDeftemplate(m_theEnv, 0); cout<<"ClipsRuleMgr::GetAllTemplatesFromClips:first template name:"<<EnvGetDeftemplateName(m_theEnv, firstT)<<endl; while((firstT = EnvGetNextDeftemplate(m_theEnv,firstT)) != 0) { m_templateNames.push_back(EnvGetDeftemplateName(m_theEnv, firstT)); cout<<"ClipsRuleMgr::GetAllTemplatesFromClips:template name:"<<EnvGetDeftemplateName(m_theEnv, firstT)<<endl; } }
static void BsaveFind( void *theEnv, EXEC_STATUS) { struct deftemplate *theDeftemplate; struct defmodule *theModule; /*=======================================================*/ /* If a binary image is already loaded, then temporarily */ /* save the count values since these will be overwritten */ /* in the process of saving the binary image. */ /*=======================================================*/ SaveBloadCount(theEnv,execStatus,FactBinaryData(theEnv,execStatus)->NumberOfPatterns); /*=======================================*/ /* Set the count of fact pattern network */ /* data structures to zero. */ /*=======================================*/ FactBinaryData(theEnv,execStatus)->NumberOfPatterns = 0L; /*===========================*/ /* Loop through each module. */ /*===========================*/ for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,execStatus,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,execStatus,theModule)) { /*===============================*/ /* Set the current module to the */ /* module being examined. */ /*===============================*/ EnvSetCurrentModule(theEnv,execStatus,(void *) theModule); /*=====================================================*/ /* Loop through each deftemplate in the current module */ /* and count the number of data structures which must */ /* be saved for its pattern network. */ /*=====================================================*/ for (theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,execStatus,NULL); theDeftemplate != NULL; theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,execStatus,theDeftemplate)) { BsaveDriver(theEnv,execStatus,BSAVE_FIND,NULL,theDeftemplate->patternNetwork); } } }
static void BsaveFactPatterns( void *theEnv, EXEC_STATUS, FILE *fp) { size_t space; struct deftemplate *theDeftemplate; struct defmodule *theModule; /*========================================*/ /* Write out the amount of space taken up */ /* by the factPatternNode data structures */ /* in the binary image. */ /*========================================*/ space = FactBinaryData(theEnv,execStatus)->NumberOfPatterns * sizeof(struct bsaveFactPatternNode); GenWrite(&space,sizeof(size_t),fp); /*===========================*/ /* Loop through each module. */ /*===========================*/ for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,execStatus,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,execStatus,theModule)) { /*=====================================================*/ /* Loop through each deftemplate in the current module */ /* and save its fact pattern network to the file. */ /*=====================================================*/ EnvSetCurrentModule(theEnv,execStatus,(void *) theModule); for (theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,execStatus,NULL); theDeftemplate != NULL; theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,execStatus,theDeftemplate)) { BsaveDriver(theEnv,execStatus,BSAVE_PATTERNS,fp,theDeftemplate->patternNetwork); } } /*=============================================================*/ /* If a binary image was already loaded when the bsave command */ /* was issued, then restore the counts indicating the number */ /* of factPatternNode data structures in the binary image */ /* (these were overwritten by the binary save). */ /*=============================================================*/ RestoreBloadCount(theEnv,execStatus,&FactBinaryData(theEnv,execStatus)->NumberOfPatterns); }
Template::pointer Template::next( ) { void * nxt; if ( !m_cobj ) return Template::pointer(); nxt = EnvGetNextDeftemplate( m_environment.cobj(), m_cobj ); if ( nxt ) return Template::create( m_environment, nxt ); else return Template::pointer(); }
void UpdateDeftemplateScope( void *theEnv) { struct deftemplate *theDeftemplate; int moduleCount; struct defmodule *theModule; struct defmoduleItemHeader *theItem; /*==================================*/ /* Loop through all of the modules. */ /*==================================*/ for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { /*======================================================*/ /* Loop through each of the deftemplates in the module. */ /*======================================================*/ theItem = (struct defmoduleItemHeader *) GetModuleItem(theEnv,theModule,DeftemplateData(theEnv)->DeftemplateModuleIndex); for (theDeftemplate = (struct deftemplate *) theItem->firstItem; theDeftemplate != NULL ; theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,theDeftemplate)) { /*=======================================*/ /* If the deftemplate can be seen by the */ /* current module, then it is in scope. */ /*=======================================*/ if (FindImportedConstruct(theEnv,"deftemplate",theModule, ValueToString(theDeftemplate->header.name), &moduleCount,true,NULL) != NULL) { theDeftemplate->inScope = true; } else { theDeftemplate->inScope = false; } } } }
static void BsaveBinaryItem( void *theEnv, FILE *fp) { size_t space; struct deftemplate *theDeftemplate; struct bsaveDeftemplate tempDeftemplate; struct templateSlot *theSlot; struct bsaveTemplateSlot tempTemplateSlot; struct bsaveDeftemplateModule tempTemplateModule; struct defmodule *theModule; struct deftemplateModule *theModuleItem; /*============================================================*/ /* Write out the amount of space taken up by the deftemplate, */ /* deftemplateModule, and templateSlot data structures in the */ /* binary image. */ /*============================================================*/ space = (DeftemplateBinaryData(theEnv)->NumberOfDeftemplates * sizeof(struct bsaveDeftemplate)) + (DeftemplateBinaryData(theEnv)->NumberOfTemplateSlots * sizeof(struct bsaveTemplateSlot)) + (DeftemplateBinaryData(theEnv)->NumberOfTemplateModules * sizeof(struct bsaveDeftemplateModule)); GenWrite(&space,sizeof(size_t),fp); /*===================================================*/ /* Write out each deftemplate module data structure. */ /*===================================================*/ DeftemplateBinaryData(theEnv)->NumberOfDeftemplates = 0; for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { EnvSetCurrentModule(theEnv,(void *) theModule); theModuleItem = (struct deftemplateModule *) GetModuleItem(theEnv,NULL,FindModuleItem(theEnv,"deftemplate")->moduleIndex); AssignBsaveDefmdlItemHdrVals(&tempTemplateModule.header, &theModuleItem->header); GenWrite(&tempTemplateModule,sizeof(struct bsaveDeftemplateModule),fp); } /*============================================*/ /* Write out each deftemplate data structure. */ /*============================================*/ DeftemplateBinaryData(theEnv)->NumberOfTemplateSlots = 0; for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { EnvSetCurrentModule(theEnv,(void *) theModule); for (theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,NULL); theDeftemplate != NULL; theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,theDeftemplate)) { AssignBsaveConstructHeaderVals(&tempDeftemplate.header, &theDeftemplate->header); tempDeftemplate.implied = theDeftemplate->implied; tempDeftemplate.numberOfSlots = theDeftemplate->numberOfSlots; tempDeftemplate.patternNetwork = BsaveFactPatternIndex(theDeftemplate->patternNetwork); if (theDeftemplate->slotList != NULL) { tempDeftemplate.slotList = DeftemplateBinaryData(theEnv)->NumberOfTemplateSlots; } else tempDeftemplate.slotList = -1L; GenWrite(&tempDeftemplate,sizeof(struct bsaveDeftemplate),fp); DeftemplateBinaryData(theEnv)->NumberOfTemplateSlots += theDeftemplate->numberOfSlots; } } /*=============================================*/ /* Write out each templateSlot data structure. */ /*=============================================*/ for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { EnvSetCurrentModule(theEnv,(void *) theModule); for (theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,NULL); theDeftemplate != NULL; theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,theDeftemplate)) { for (theSlot = theDeftemplate->slotList; theSlot != NULL; theSlot = theSlot->next) { tempTemplateSlot.constraints = ConstraintIndex(theSlot->constraints); tempTemplateSlot.slotName = theSlot->slotName->bucket; tempTemplateSlot.multislot = theSlot->multislot; tempTemplateSlot.noDefault = theSlot->noDefault; tempTemplateSlot.defaultPresent = theSlot->defaultPresent; tempTemplateSlot.defaultDynamic = theSlot->defaultDynamic; tempTemplateSlot.defaultList = HashedExpressionIndex(theEnv,theSlot->defaultList); tempTemplateSlot.facetList = HashedExpressionIndex(theEnv,theSlot->facetList); if (theSlot->next != NULL) tempTemplateSlot.next = 0L; else tempTemplateSlot.next = -1L; GenWrite(&tempTemplateSlot,sizeof(struct bsaveTemplateSlot),fp); } } } /*=============================================================*/ /* If a binary image was already loaded when the bsave command */ /* was issued, then restore the counts indicating the number */ /* of deftemplates, deftemplate modules, and deftemplate slots */ /* in the binary image (these were overwritten by the binary */ /* save). */ /*=============================================================*/ RestoreBloadCount(theEnv,&DeftemplateBinaryData(theEnv)->NumberOfDeftemplates); RestoreBloadCount(theEnv,&DeftemplateBinaryData(theEnv)->NumberOfTemplateSlots); RestoreBloadCount(theEnv,&DeftemplateBinaryData(theEnv)->NumberOfTemplateModules); }
static void BsaveFind( void *theEnv) { struct deftemplate *theDeftemplate; struct templateSlot *theSlot; struct defmodule *theModule; /*=======================================================*/ /* If a binary image is already loaded, then temporarily */ /* save the count values since these will be overwritten */ /* in the process of saving the binary image. */ /*=======================================================*/ SaveBloadCount(theEnv,DeftemplateBinaryData(theEnv)->NumberOfDeftemplates); SaveBloadCount(theEnv,DeftemplateBinaryData(theEnv)->NumberOfTemplateSlots); SaveBloadCount(theEnv,DeftemplateBinaryData(theEnv)->NumberOfTemplateModules); /*==================================================*/ /* Set the count of deftemplates, deftemplate slots */ /* and deftemplate module data structures to zero. */ /*==================================================*/ DeftemplateBinaryData(theEnv)->NumberOfDeftemplates = 0; DeftemplateBinaryData(theEnv)->NumberOfTemplateSlots = 0; DeftemplateBinaryData(theEnv)->NumberOfTemplateModules = 0; /*===========================*/ /* Loop through each module. */ /*===========================*/ for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { /*============================================*/ /* Set the current module to the module being */ /* examined and increment the number of */ /* deftemplate modules encountered. */ /*============================================*/ EnvSetCurrentModule(theEnv,(void *) theModule); DeftemplateBinaryData(theEnv)->NumberOfTemplateModules++; /*======================================================*/ /* Loop through each deftemplate in the current module. */ /*======================================================*/ for (theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,NULL); theDeftemplate != NULL; theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,theDeftemplate)) { /*======================================================*/ /* Initialize the construct header for the binary save. */ /*======================================================*/ MarkConstructHeaderNeededItems(&theDeftemplate->header, DeftemplateBinaryData(theEnv)->NumberOfDeftemplates++); /*=============================================================*/ /* Loop through each slot in the deftemplate, incrementing the */ /* slot count and marking the slot names as needed symbols. */ /*=============================================================*/ for (theSlot = theDeftemplate->slotList; theSlot != NULL; theSlot = theSlot->next) { DeftemplateBinaryData(theEnv)->NumberOfTemplateSlots++; theSlot->slotName->neededSymbol = TRUE; } } } }
static void FindAndSetDeftemplatePatternNetwork( void *theEnv, struct factPatternNode *rootNode, struct factPatternNode *newRootNode) { struct deftemplate *theDeftemplate; struct defmodule *theModule; /*=======================================================*/ /* Save the current module since we will be changing it. */ /*=======================================================*/ SaveCurrentModule(theEnv); /*=======================================================*/ /* Loop through every module looking for the deftemplate */ /* associated with the specified root node. */ /*=======================================================*/ for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { /*======================================================*/ /* Set the current module to the module being examined. */ /*======================================================*/ EnvSetCurrentModule(theEnv,(void *) theModule); /*======================================================*/ /* Loop through every deftemplate in the current module */ /* searching for the deftemplate associated with the */ /* specified root node. */ /*======================================================*/ for (theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,NULL); theDeftemplate != NULL; theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,theDeftemplate)) { /*===========================================================*/ /* When the associated deftemplate is found, change its root */ /* node from the current value to the new value. Restore the */ /* current module before leaving this routine. */ /*===========================================================*/ if (theDeftemplate->patternNetwork == rootNode) { RestoreCurrentModule(theEnv); theDeftemplate->patternNetwork = newRootNode; return; } } } /*========================================================*/ /* If the deftemplate wasn't found, then we're presumably */ /* we're in the the middle of a clear and the deftemplate */ /* has already been deleted so there's no need to update */ /* the links to the fact pattern network. */ /*========================================================*/ RestoreCurrentModule(theEnv); }
/******************************************************************************* Name: UpdateWindowsMenu Description: Sets manager menu items to sensitive or unsensitive Arguments: None Returns: None *******************************************************************************/ static void UpdateWindowsMenu() { void *theEnv = GetCurrentEnvironment(); /* ==================================================== */ /* Refresh the manager window if nessessary */ /* ==================================================== */ if(list_change || list1_change ) RefreshMngrList(); /* =================================================================== */ /* Set the sensitive state to defrule manager item in the browse menu */ /* =================================================================== */ if(EnvGetNextDefrule(theEnv,NULL)) { XtSetArg(TheArgs[0], XtNsensitive, True); XtSetValues(defrule_manager, TheArgs, 1); } else { XtSetArg(TheArgs[0], XtNsensitive, False); XtSetValues(defrule_manager, TheArgs, 1); } /* ===================================-================================ */ /* Set the sensitive state to deffacts manager item in the browse menu */ /* ==================================================================== */ if(EnvGetNextDeffacts(theEnv,NULL)) { XtSetArg(TheArgs[0], XtNsensitive, True); XtSetValues(deffact_manager, TheArgs, 1); } else { XtSetArg(TheArgs[0], XtNsensitive, False); XtSetValues(deffact_manager, TheArgs, 1); } /* ======================================================================= */ /* Set the sensitive state to deftemplate manager item in the browse menu */ /* ======================================================================= */ if(EnvGetNextDeftemplate(theEnv,NULL)) { XtSetArg(TheArgs[0], XtNsensitive, True); XtSetValues(deftemplate_manager, TheArgs, 1); } else { XtSetArg(TheArgs[0], XtNsensitive, False); XtSetValues(deftemplate_manager, TheArgs, 1); } /* ======================================================================= */ /* Set the sensitive state to deffunction manager item in the browse menu */ /* ======================================================================= */ if(EnvGetNextDeffunction(theEnv,NULL)) { XtSetArg(TheArgs[0], XtNsensitive, True); XtSetValues(deffunction_manager, TheArgs, 1); } else { XtSetArg(TheArgs[0], XtNsensitive, False); XtSetValues(deffunction_manager, TheArgs, 1); } /* ===================================================================== */ /* Set the sensitive state to defglobal manager item in the browse menu */ /* ===================================================================== */ if(EnvGetNextDefglobal(theEnv,NULL)) { XtSetArg(TheArgs[0], XtNsensitive, True); XtSetValues(defglobal_manager,TheArgs,1); } else { XtSetArg(TheArgs[0], XtNsensitive, False); XtSetValues(defglobal_manager,TheArgs,1); } /* ====================================================================== */ /* Set the sensitive state to defgeneric manager item in the browse menu */ /* ====================================================================== */ if(EnvGetNextDefgeneric(theEnv,NULL)) { XtSetArg(TheArgs[0], XtNsensitive, True); XtSetValues(defgeneric_manager, TheArgs, 1); } else { XtSetArg(TheArgs[0], XtNsensitive, False); XtSetValues(defgeneric_manager, TheArgs, 1); } /* ======================================================================== */ /* Set the sensitive state to definstances manager item in the browse menu */ /* ======================================================================== */ if(EnvGetNextDefinstances(theEnv,NULL)) { XtSetArg(TheArgs[0], XtNsensitive, True); XtSetValues(definstances_manager, TheArgs, 1); } else { XtSetArg(TheArgs[0], XtNsensitive, False); XtSetValues(definstances_manager, TheArgs, 1); } /* ==================================================================== */ /* Set the sensitive state to defclass manager item in the browse menu */ /* ==================================================================== */ if(EnvGetNextDefclass(theEnv,NULL)) { XtSetArg(TheArgs[0], XtNsensitive, True); XtSetValues(defclass_manager, TheArgs, 1); } else { XtSetArg(TheArgs[0], XtNsensitive, False); XtSetValues(defclass_manager, TheArgs, 1); } /* =================================================================== */ /* Set the sensitive state to agenda manager item in the browse menu */ /* =================================================================== */ if(EnvGetNextActivation(theEnv,NULL)) { XtSetArg(TheArgs[0], XtNsensitive, True); XtSetValues(agenda_manager, TheArgs, 1); } else { XtSetArg(TheArgs[0], XtNsensitive, False); XtSetValues(agenda_manager, TheArgs, 1); } }
static int ConstructToCode( void *theEnv, char *fileName, char *pathName, char *fileNameBuffer, int fileID, FILE *headerFP, int imageID, int maxIndices) { int fileCount = 1; struct defmodule *theModule; struct deftemplate *theTemplate; struct templateSlot *slotPtr; int slotCount = 0, slotArrayCount = 0, slotArrayVersion = 1; int moduleCount = 0, moduleArrayCount = 0, moduleArrayVersion = 1; int templateArrayCount = 0, templateArrayVersion = 1; FILE *slotFile = NULL, *moduleFile = NULL, *templateFile = NULL; /*==================================================*/ /* Include the appropriate deftemplate header file. */ /*==================================================*/ fprintf(headerFP,"#include \"tmpltdef.h\"\n"); /*=============================================================*/ /* Loop through all the modules, all the deftemplates, and all */ /* the deftemplate slots writing their C code representation */ /* to the file as they are traversed. */ /*=============================================================*/ theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); while (theModule != NULL) { EnvSetCurrentModule(theEnv,(void *) theModule); moduleFile = OpenFileIfNeeded(theEnv,moduleFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, moduleArrayVersion,headerFP, (char*)"struct deftemplateModule",ModulePrefix(DeftemplateData(theEnv)->DeftemplateCodeItem), FALSE,NULL); if (moduleFile == NULL) { CloseDeftemplateFiles(theEnv,moduleFile,templateFile,slotFile,maxIndices); return(0); } DeftemplateModuleToCode(theEnv,moduleFile,theModule,imageID,maxIndices,moduleCount); moduleFile = CloseFileIfNeeded(theEnv,moduleFile,&moduleArrayCount,&moduleArrayVersion, maxIndices,NULL,NULL); /*=======================================================*/ /* Loop through each of the deftemplates in this module. */ /*=======================================================*/ theTemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,NULL); while (theTemplate != NULL) { templateFile = OpenFileIfNeeded(theEnv,templateFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, templateArrayVersion,headerFP, (char*)"struct deftemplate",ConstructPrefix(DeftemplateData(theEnv)->DeftemplateCodeItem), FALSE,NULL); if (templateFile == NULL) { CloseDeftemplateFiles(theEnv,moduleFile,templateFile,slotFile,maxIndices); return(0); } DeftemplateToCode(theEnv,templateFile,theTemplate,imageID,maxIndices, moduleCount,slotCount); templateArrayCount++; templateFile = CloseFileIfNeeded(theEnv,templateFile,&templateArrayCount,&templateArrayVersion, maxIndices,NULL,NULL); /*======================================================*/ /* Loop through each of the slots for this deftemplate. */ /*======================================================*/ slotPtr = theTemplate->slotList; while (slotPtr != NULL) { slotFile = OpenFileIfNeeded(theEnv,slotFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, slotArrayVersion,headerFP, (char*)"struct templateSlot",SlotPrefix(),FALSE,NULL); if (slotFile == NULL) { CloseDeftemplateFiles(theEnv,moduleFile,templateFile,slotFile,maxIndices); return(0); } SlotToCode(theEnv,slotFile,slotPtr,imageID,maxIndices,slotCount); slotCount++; slotArrayCount++; slotFile = CloseFileIfNeeded(theEnv,slotFile,&slotArrayCount,&slotArrayVersion, maxIndices,NULL,NULL); slotPtr = slotPtr->next; } theTemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,theTemplate); } theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule); moduleCount++; moduleArrayCount++; } CloseDeftemplateFiles(theEnv,moduleFile,templateFile,slotFile,maxIndices); return(1); }
globle void *GetNextDeftemplate( void *deftemplatePtr) { return EnvGetNextDeftemplate(GetCurrentEnvironment(),deftemplatePtr); }