?? tmpltutl.c
字號:
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 TRUE if the fact was printed using this format, *//* otherwise FALSE. *//*******************************************************************/globle void PrintTemplateFact( void *theEnv, char *logicalName, struct fact *theFact, int seperateLines, int ignoreDefaults) { struct field *sublist; int i; struct deftemplate *theDeftemplate; struct templateSlot *slotPtr; DATA_OBJECT tempDO; int slotPrinted = FALSE; /*==============================*/ /* Initialize some information. */ /*==============================*/ theDeftemplate = theFact->whichDeftemplate; sublist = theFact->theProposition.theFields; /*=============================================*/ /* Print the relation name of the deftemplate. */ /*=============================================*/ EnvPrintRouter(theEnv,logicalName,"("); EnvPrintRouter(theEnv,logicalName,theDeftemplate->header.name->contents); /*===================================================*/ /* Print each of the field slots of the deftemplate. */ /*===================================================*/ slotPtr = theDeftemplate->slotList; i = 0; while (slotPtr != NULL) { /*=================================================*/ /* If we're ignoring slots with their original */ /* default value, check to see if the fact's slot */ /* value differs from the deftemplate default. */ /*=================================================*/ if (ignoreDefaults && (slotPtr->defaultDynamic == FALSE)) { DeftemplateSlotDefault(theEnv,theDeftemplate,slotPtr,&tempDO,TRUE); if (slotPtr->multislot == FALSE) { if ((GetType(tempDO) == sublist[i].type) && (GetValue(tempDO) == sublist[i].value)) { i++; slotPtr = slotPtr->next; continue; } } else if (MultifieldsEqual((struct multifield*) GetValue(tempDO), (struct multifield *) sublist[i].value)) { i++; slotPtr = slotPtr->next; continue; } } /*===========================================*/ /* Print the opening parenthesis of the slot */ /* and the slot name. */ /*===========================================*/ if (! slotPrinted) { slotPrinted = TRUE; EnvPrintRouter(theEnv,logicalName," "); } if (seperateLines) { EnvPrintRouter(theEnv,logicalName,"\n "); } EnvPrintRouter(theEnv,logicalName,"("); EnvPrintRouter(theEnv,logicalName,slotPtr->slotName->contents); /*======================================================*/ /* Print the value of the slot for a single field slot. */ /*======================================================*/ if (slotPtr->multislot == FALSE) { EnvPrintRouter(theEnv,logicalName," "); PrintAtom(theEnv,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) { EnvPrintRouter(theEnv,logicalName," "); PrintMultifield(theEnv,logicalName,(struct multifield *) sublist[i].value, 0,(long) theSegment->multifieldLength-1,FALSE); } } /*============================================*/ /* Print the closing parenthesis of the slot. */ /*============================================*/ i++; EnvPrintRouter(theEnv,logicalName,")"); slotPtr = slotPtr->next; if (slotPtr != NULL) EnvPrintRouter(theEnv,logicalName," "); } EnvPrintRouter(theEnv,logicalName,")"); }/***************************************************************************//* UpdateDeftemplateScope: Updates the scope flag of all the deftemplates. *//***************************************************************************/globle 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; } } } }/****************************************************************//* FindSlot: Finds a specified slot in a deftemplate structure. *//****************************************************************/globle struct templateSlot *FindSlot( struct deftemplate *theDeftemplate, SYMBOL_HN *name, short *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( void *theEnv, SYMBOL_HN *deftemplateName, int setFlag) { struct deftemplate *newDeftemplate; newDeftemplate = get_struct(theEnv,deftemplate); newDeftemplate->header.name = deftemplateName; newDeftemplate->header.ppForm = NULL; newDeftemplate->header.usrData = NULL; newDeftemplate->slotList = NULL; newDeftemplate->implied = setFlag; newDeftemplate->numberOfSlots = 0; newDeftemplate->inScope = 1; newDeftemplate->patternNetwork = NULL; newDeftemplate->factList = NULL; newDeftemplate->lastFact = NULL; newDeftemplate->busyCount = 0; newDeftemplate->watch = FALSE; newDeftemplate->header.next = NULL;#if DEBUGGING_FUNCTIONS if (EnvGetWatchItem(theEnv,"facts")) { EnvSetDeftemplateWatch(theEnv,ON,(void *) newDeftemplate); }#endif newDeftemplate->header.whichModule = (struct defmoduleItemHeader *) GetModuleItem(theEnv,NULL,DeftemplateData(theEnv)->DeftemplateModuleIndex); AddConstructToModule(&newDeftemplate->header); InstallDeftemplate(theEnv,newDeftemplate); return(newDeftemplate); }#endif#endif /* DEFTEMPLATE_CONSTRUCT */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -