📄 modulutl.c
字号:
AddSymbol(findName),count, searchCurrent,notYetDefinedInModule); /*=============================*/ /* Restore the current module. */ /*=============================*/ RestoreCurrentModule(); /*====================================*/ /* Return a pointer to the construct. */ /*====================================*/ return(rv); }/*********************************************************//* AmbiguousReferenceErrorMessage: Error message printed *//* when a reference to a specific construct can be *//* imported from more than one module. *//*********************************************************/globle VOID AmbiguousReferenceErrorMessage(constructName,findName) char *constructName; char *findName; { PrintCLIPS(WERROR,"Ambiguous reference to "); PrintCLIPS(WERROR,constructName); PrintCLIPS(WERROR," "); PrintCLIPS(WERROR,findName); PrintCLIPS(WERROR,".\nIt is imported from more than one module.\n"); }/****************************************************//* MarkModulesAsUnvisited: Used for initializing a *//* search through the module heirarchies. Sets *//* the visited flag of each module to FALSE. *//****************************************************/globle VOID MarkModulesAsUnvisited() { struct defmodule *theModule; CurrentModule->visitedFlag = CLIPS_FALSE; for (theModule = (struct defmodule *) GetNextDefmodule(NULL); theModule != NULL; theModule = (struct defmodule *) GetNextDefmodule(theModule)) { theModule->visitedFlag = CLIPS_FALSE; } } /***********************************************************//* SearchImportedConstructModules: Low level routine which *//* searches a module and other modules from which it *//* imports constructs for a specified construct. *//***********************************************************/static VOID *SearchImportedConstructModules(constructType,matchModule,theModuleItem, findName,count,searchCurrent, notYetDefinedInModule) struct symbolHashNode *constructType; struct defmodule *matchModule; struct moduleItem *theModuleItem; struct symbolHashNode *findName; int *count; int searchCurrent; struct defmodule *notYetDefinedInModule; { struct defmodule *theModule; struct portItem *theImportList, *theExportList; VOID *rv, *arv = NULL; int searchModule, exported; struct defmodule *currentModule; /*=========================================*/ /* Start the search in the current module. */ /* If the current module has already been */ /* visited, then return. */ /*=========================================*/ currentModule = ((struct defmodule *) GetCurrentModule()); if (currentModule->visitedFlag) return(NULL); /*=======================================================*/ /* The searchCurrent flag indicates whether the current */ /* module should be included in the search. In addition, */ /* if matchModule is non-NULL, the current module will */ /* only be searched if it is the specific module from */ /* which we want the construct imported. */ /*=======================================================*/ if ((searchCurrent) && ((matchModule == NULL) || (currentModule == matchModule))) { /*===============================================*/ /* Look for the construct in the current module. */ /*===============================================*/ rv = (*theModuleItem->findFunction)(ValueToString(findName)); /*========================================================*/ /* If we're in the process of defining the construct in */ /* the module we're searching then go ahead and increment */ /* the count indicating the number of modules in which */ /* the construct was found. */ /*========================================================*/ if (notYetDefinedInModule == currentModule) { (*count)++; arv = rv; } /*=========================================================*/ /* Otherwise, if the construct is in the specified module, */ /* increment the count only if the construct actually */ /* belongs to the module. [Some constructs, like the COOL */ /* system classes, can be found in any module, but they */ /* actually belong to the MAIN module.] */ /*=========================================================*/ else if (rv != NULL) { if (((struct constructHeader *) rv)->whichModule->theModule == currentModule) { (*count)++; } arv = rv; } } /*=====================================*/ /* Mark the current module as visited. */ /*=====================================*/ currentModule->visitedFlag = CLIPS_TRUE; /*===================================*/ /* Search through all of the modules */ /* imported by the current module. */ /*===================================*/ theModule = ((struct defmodule *) GetCurrentModule()); theImportList = theModule->importList; while (theImportList != NULL) { /*===================================================*/ /* Determine if the module should be searched (based */ /* upon whether the entire module, all constructs of */ /* a specific type, or specifically named constructs */ /* are imported). */ /*===================================================*/ searchModule = CLIPS_FALSE; if ((theImportList->constructType == NULL) || (theImportList->constructType == constructType)) { if ((theImportList->constructName == NULL) || (theImportList->constructName == findName)) { searchModule = CLIPS_TRUE; } } /*=================================*/ /* Determine if the module exists. */ /*=================================*/ if (searchModule) { theModule = (struct defmodule *) FindDefmodule(ValueToString(theImportList->moduleName)); if (theModule == NULL) searchModule = CLIPS_FALSE; } /*=======================================================*/ /* Determine if the construct is exported by the module. */ /*=======================================================*/ if (searchModule) { exported = CLIPS_FALSE; theExportList = theModule->exportList; while ((theExportList != NULL) && (! exported)) { if ((theExportList->constructType == NULL) || (theExportList->constructType == constructType)) { if ((theExportList->constructName == NULL) || (theExportList->constructName == findName)) { exported = CLIPS_TRUE; } } theExportList = theExportList->next; } if (! exported) searchModule = CLIPS_FALSE; } /*=================================*/ /* Search in the specified module. */ /*=================================*/ if (searchModule) { SetCurrentModule((VOID *) theModule); if ((rv = SearchImportedConstructModules(constructType,matchModule, theModuleItem,findName, count,CLIPS_TRUE, notYetDefinedInModule)) != NULL) { arv = rv; } } /*====================================*/ /* Move on to the next imported item. */ /*====================================*/ theImportList = theImportList->next; } /*=========================*/ /* Return a pointer to the */ /* last construct found. */ /*=========================*/ return(arv); }/***************************************//* ListItemsDriver: Driver routine for *//* listing items in a module. *//***************************************/globle VOID ListItemsDriver(logicalName,theModule,singleName,pluralName, nextFunction,nameFunction,printFunction, doItFunction) char *logicalName; struct defmodule *theModule; char *singleName,*pluralName;#if ANSI_COMPILER VOID *(*nextFunction)(VOID *); char *(*nameFunction)(VOID *); VOID (*printFunction)(char *,VOID *); int (*doItFunction)(VOID *);#else VOID *(*nextFunction)(); char *(*nameFunction)(); VOID (*printFunction)(); int (*doItFunction)();#endif { VOID *constructPtr; char *constructName; long count = 0; int allModules = CLIPS_FALSE; int doIt; /*==========================*/ /* Save the current module. */ /*==========================*/ SaveCurrentModule(); /*======================*/ /* Print out the items. */ /*======================*/ if (theModule == NULL) { theModule = (struct defmodule *) GetNextDefmodule(NULL); allModules = CLIPS_TRUE; } while (theModule != NULL) { if (allModules) { PrintCLIPS(logicalName,GetDefmoduleName(theModule)); PrintCLIPS(logicalName,":\n"); } SetCurrentModule((VOID *) theModule); constructPtr = (*nextFunction)(NULL); while (constructPtr != NULL) { if (HaltExecution == CLIPS_TRUE) return; if (doItFunction == NULL) doIt = CLIPS_TRUE; else doIt = (*doItFunction)(constructPtr); if (! doIt) {} else if (nameFunction != NULL) { constructName = (*nameFunction)(constructPtr); if (constructName != NULL) { if (allModules) PrintCLIPS(logicalName," "); PrintCLIPS(logicalName,constructName); PrintCLIPS(logicalName,"\n"); } } else if (printFunction != NULL) { if (allModules) PrintCLIPS(logicalName," "); (*printFunction)(logicalName,constructPtr); PrintCLIPS(logicalName,"\n"); } constructPtr = (*nextFunction)(constructPtr); count++; } if (allModules) theModule = (struct defmodule *) GetNextDefmodule(theModule); else theModule = NULL; } /*=================================================*/ /* Print the tally and restore the current module. */ /*=================================================*/ if (singleName != NULL) PrintTally(logicalName,count,singleName,pluralName); RestoreCurrentModule(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -