📄 tmpltutl.c
字号:
slotPtr = slotPtr->next; i++; } return(NULL); } /*******************************************************//* FindSlotPosition: Finds the position of a specified *//* slot in a deftemplate structure. *//*******************************************************/globle int FindSlotPosition(theDeftemplate,name) struct deftemplate *theDeftemplate; SYMBOL_HN *name; { struct templateSlot *slotPtr; int position; for (slotPtr = theDeftemplate->slotList, position = 1; slotPtr != NULL; slotPtr = slotPtr->next, position++) { if (slotPtr->slotName == name) { return(position); } } return(0); } /*******************************************************************//* PrintTemplateFact: Prints a fact using the deftemplate format. *//* Returns CLIPS_TRUE if the fact was printed using this format, *//* otherwise CLIPS_FALSE. *//*******************************************************************/globle VOID PrintTemplateFact(logicalName,theFact) char *logicalName; struct fact *theFact; { struct field *sublist; int i; struct deftemplate *theDeftemplate; struct templateSlot *slotPtr; /*==============================*/ /* Initialize some information. */ /*==============================*/ theDeftemplate = theFact->whichDeftemplate; sublist = theFact->theProposition.theFields; /*=============================================*/ /* Print the relation name of the deftemplate. */ /*=============================================*/ PrintCLIPS(logicalName,"("); PrintCLIPS(logicalName,theDeftemplate->header.name->contents); if (theDeftemplate->slotList != NULL) PrintCLIPS(logicalName," "); /*===================================================*/ /* Print each of the field slots of the deftemplate. */ /*===================================================*/ slotPtr = theDeftemplate->slotList; i = 0; while (slotPtr != NULL) { /*===========================================*/ /* Print the closing parenthesis of the slot */ /* and the slot name. */ /*===========================================*/ PrintCLIPS(logicalName,"("); PrintCLIPS(logicalName,slotPtr->slotName->contents); /*======================================================*/ /* Print the value of the slot for a single field slot. */ /*======================================================*/ if (slotPtr->multislot == CLIPS_FALSE) { PrintCLIPS(logicalName," "); PrintAtom(logicalName,sublist[i].type,sublist[i].value); } /*==========================================================*/ /* Else print the value of the slot for a multi field slot. */ /*==========================================================*/ else { struct multifield *theSegment; theSegment = (struct multifield *) sublist[i].value; if (theSegment->multifieldLength > 0) { PrintCLIPS(logicalName," "); PrintMultifield(logicalName,sublist[i].value,0,theSegment->multifieldLength-1,CLIPS_FALSE); } } /*============================================*/ /* Print the closing parenthesis of the slot. */ /*============================================*/ i++; PrintCLIPS(logicalName,")"); slotPtr = slotPtr->next; if (slotPtr != NULL) PrintCLIPS(logicalName," "); } PrintCLIPS(logicalName,")"); }/***************************************************************************//* UpdateDeftemplateScope: Updates the scope flag of all the deftemplates. *//***************************************************************************/globle VOID UpdateDeftemplateScope() { struct deftemplate *theDeftemplate; int moduleCount; struct defmodule *theModule; struct defmoduleItemHeader *theItem; /*==================================*/ /* Loop through all of the modules. */ /*==================================*/ for (theModule = (struct defmodule *) GetNextDefmodule(NULL); theModule != NULL; theModule = (struct defmodule *) GetNextDefmodule(theModule)) { /*======================================================*/ /* Loop through each of the deftemplates in the module. */ /*======================================================*/ theItem = (struct defmoduleItemHeader *) GetModuleItem(theModule,DeftemplateModuleIndex); for (theDeftemplate = (struct deftemplate *) theItem->firstItem; theDeftemplate != NULL ; theDeftemplate = (struct deftemplate *) GetNextDeftemplate(theDeftemplate)) { /*=======================================*/ /* If the deftemplate can be seen by the */ /* current module, then it is in scope. */ /*=======================================*/ if (FindImportedConstruct("deftemplate",theModule, ValueToString(theDeftemplate->header.name), &moduleCount,CLIPS_TRUE,NULL) != NULL) { theDeftemplate->inScope = CLIPS_TRUE; } else { theDeftemplate->inScope = CLIPS_FALSE; } } } } /****************************************************************//* FindSlot: Finds a specified slot in a deftemplate structure. *//****************************************************************/globle struct templateSlot *FindSlot(theDeftemplate,name,whichOne) struct deftemplate *theDeftemplate; SYMBOL_HN *name; int *whichOne; { struct templateSlot *slotPtr; *whichOne = 1; slotPtr = theDeftemplate->slotList; while (slotPtr != NULL) { if (slotPtr->slotName == name) { return(slotPtr); } (*whichOne)++; slotPtr = slotPtr->next; } *whichOne = -1; return(NULL); } #if (! RUN_TIME) && (! BLOAD_ONLY)/************************************************************//* CreateImpliedDeftemplate: Creates an implied deftemplate *//* and adds it to the list of deftemplates. *//************************************************************/globle struct deftemplate *CreateImpliedDeftemplate(deftemplateName,setFlag) SYMBOL_HN *deftemplateName; int setFlag; { struct deftemplate *newDeftemplate; newDeftemplate = get_struct(deftemplate); newDeftemplate->header.name = deftemplateName; newDeftemplate->header.ppForm = NULL; newDeftemplate->slotList = NULL; newDeftemplate->implied = setFlag; newDeftemplate->numberOfSlots = 0; newDeftemplate->inScope = 1; newDeftemplate->patternNetwork = NULL; newDeftemplate->busyCount = 0; newDeftemplate->watch = CLIPS_FALSE; newDeftemplate->header.next = NULL;#if DEBUGGING_FUNCTIONS if (GetWatchItem("facts")) { SetDeftemplateWatch(ON,(VOID *) newDeftemplate); }#endif newDeftemplate->header.whichModule = (struct defmoduleItemHeader *) GetModuleItem(NULL,DeftemplateModuleIndex); AddConstructToModule(&newDeftemplate->header); InstallDeftemplate(newDeftemplate); return(newDeftemplate); } #endif#endif /* DEFTEMPLATE_CONSTRUCT */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -