⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cstrccom.c

📁 一套美国国家宇航局人工智能中心NASA的专家系统工具源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
     {      theModule = (struct defmodule *) GetNextDefmodule(NULL);      allModules = CLIPS_TRUE;     }        /*================================*/   /* Count the number of constructs */   /* to be retrieved.               */   /*================================*/      loopModule = theModule;   while (loopModule != NULL)     {      SetCurrentModule((VOID *) loopModule);      theConstruct = NULL;      while ((theConstruct = (*constructClass->getNextItemFunction)(theConstruct)) != NULL)         { count++; }              if (allModules) loopModule = (struct defmodule *) GetNextDefmodule(loopModule);      else loopModule = NULL;     }      /*================================*/   /* Create the multifield value to */   /* store the construct names.     */   /*================================*/      SetpType(returnValue,MULTIFIELD);   SetpDOBegin(returnValue,1);   SetpDOEnd(returnValue,count);   theList = (struct multifield *) CreateMultifield((int) count);   SetpValue(returnValue,(VOID *) theList);      /*===========================*/   /* Store the construct names */   /* in the multifield value.  */   /*===========================*/      loopModule = theModule;   count = 1;   while (loopModule != NULL)     {      /*============================*/      /* Set the current module to  */      /* the module being examined. */      /*============================*/            SetCurrentModule((VOID *) loopModule);            /*===============================*/      /* Add each construct name found */      /* in the module to the list.    */      /*===============================*/            theConstruct = NULL;      while ((theConstruct = (*constructClass->getNextItemFunction)(theConstruct)) != NULL)         {         theName = (*constructClass->getConstructNameFunction)(theConstruct);         SetMFType(theList,count,SYMBOL);         if (allModules)           {            char buffer[512];                        strcpy(buffer,GetDefmoduleName(loopModule));            strcat(buffer,"::");            strcat(buffer,ValueToString(theName));            SetMFValue(theList,count,AddSymbol(buffer));           }         else           { SetMFValue(theList,count,AddSymbol(ValueToString(theName))); }         count++;        }        /*==================================*/      /* Move on to the next module (if   */      /* the list is to contain the names */      /* of constructs from all modules). */      /*==================================*/            if (allModules) loopModule = (struct defmodule *) GetNextDefmodule(loopModule);      else loopModule = NULL;     }      /*=============================*/   /* Restore the current module. */   /*=============================*/      RestoreCurrentModule();  }/***********************************************//* ListConstructCommand: Generic CLIPS Routine *//*   for listing the constructs in a module.   *//***********************************************/globle VOID ListConstructCommand(functionName,constructClass)  char *functionName;  struct construct *constructClass;  {   struct defmodule *theModule;   DATA_OBJECT result;   int numArgs;      /*============================================*/   /* Check for the correct number of arguments. */   /*============================================*/      if ((numArgs = ArgCountCheck(functionName,NO_MORE_THAN,1)) == -1) return;   /*====================================*/   /* If an argument was given, check to */   /* see that it's a valid module name. */   /*====================================*/   if (numArgs == 1)     {      /*======================================*/      /* Only symbols are valid module names. */      /*======================================*/      RtnUnknown(1,&result);      if (GetType(result) != SYMBOL)        {         ExpectedTypeError1(functionName,1,"defmodule name");         return;        }              /*===========================================*/      /* Verify that the named module exists or is */      /* the symbol * (for obtaining the construct */      /* list for all modules).                    */      /*===========================================*/      if ((theModule = (struct defmodule *) FindDefmodule(DOToString(result))) == NULL)        {         if (strcmp("*",DOToString(result)) != 0)            {            ExpectedTypeError1(functionName,1,"defmodule name");            return;           }                    theModule = NULL;        }     }      /*=====================================*/   /* Otherwise use the current module to */   /* generate the construct list.        */   /*=====================================*/   else     { theModule = ((struct defmodule *) GetCurrentModule()); }     /*=========================*/   /* Call the driver routine */   /* to list the constructs. */   /*=========================*/      ListConstruct(constructClass,WDISPLAY,theModule);  }  /*****************************************//* ListConstruct: Generic C Routine for  *//*   listing the constructs in a module. *//*****************************************/globle VOID ListConstruct(constructClass,logicalName,theModule)  char *logicalName;  struct construct *constructClass;  struct defmodule *theModule;  {   VOID *constructPtr;   SYMBOL_HN *constructName;   long count = 0;   int allModules = CLIPS_FALSE;           /*==========================*/   /* Save the current module. */   /*==========================*/      SaveCurrentModule();   /*=======================================*/   /* If the module specified is NULL, then */   /* list all constructs in all modules.   */   /*=======================================*/     if (theModule == NULL)     {       theModule = (struct defmodule *) GetNextDefmodule(NULL);      allModules = CLIPS_TRUE;     }        /*==================================*/   /* Loop through all of the modules. */   /*==================================*/      while (theModule != NULL)     {      /*========================================*/      /* If we're printing the construct in all */      /* modules, then preface each module      */      /* listing with the name of the module.   */      /*========================================*/                     if (allModules)         {         PrintCLIPS(logicalName,GetDefmoduleName(theModule));         PrintCLIPS(logicalName,":\n");        }              /*===============================*/      /* Set the current module to the */      /* module we're examining.       */      /*===============================*/            SetCurrentModule((VOID *) theModule);            /*===========================================*/      /* List all of the constructs in the module. */      /*===========================================*/            for (constructPtr = (*constructClass->getNextItemFunction)(NULL);           constructPtr != NULL;           constructPtr = (*constructClass->getNextItemFunction)(constructPtr))        {         if (HaltExecution == CLIPS_TRUE) return;           constructName = (*constructClass->getConstructNameFunction)(constructPtr);                    if (constructName != NULL)           {            if (allModules) PrintCLIPS(WDISPLAY,"   ");            PrintCLIPS(logicalName,ValueToString(constructName));            PrintCLIPS(logicalName,"\n");           }                     count++;        }              /*====================================*/      /* Move on to the next module (if the */      /* listing is to contain the names of */      /* constructs from all modules).      */      /*====================================*/            if (allModules) theModule = (struct defmodule *) GetNextDefmodule(theModule);      else theModule = NULL;     }   /*=================================================*/   /* Print the tally and restore the current module. */   /*=================================================*/      PrintTally(WDISPLAY,count,constructClass->constructName,                             constructClass->pluralName);      RestoreCurrentModule();  }  /**********************************************************//* SetNextConstruct: Sets the next field of one construct *//*   to point to another construct of the same type.      *//**********************************************************/globle VOID SetNextConstruct(theConstruct,targetConstruct)  struct constructHeader *theConstruct, *targetConstruct;  { theConstruct->next = targetConstruct; }  /********************************************************************//* GetConstructModuleItem: Returns the construct module for a given *//*   construct (note that this is a pointer to a data structure     *//*   like the deffactsModule, not a pointer to an environment       *//*   module which contains a number of types of constructs.         *//********************************************************************/globle struct defmoduleItemHeader *GetConstructModuleItem(theConstruct)  struct constructHeader *theConstruct;  { return(theConstruct->whichModule); }  /***************************************************************//* GetConstructPPForm: Returns the pretty print representation *//*   for the specified construct.                              *//***************************************************************/globle char *GetConstructPPForm(theConstruct)  struct constructHeader *theConstruct;  { return(theConstruct->ppForm); }/****************************************************//* GetNextConstructItem: Returns the next construct *//*   items from a list of constructs.               *//****************************************************/globle struct constructHeader *GetNextConstructItem(theConstruct,moduleIndex)  struct constructHeader *theConstruct;  int moduleIndex;  {      struct defmoduleItemHeader *theModuleItem;      if (theConstruct == NULL)     {      theModuleItem = (struct defmoduleItemHeader *)                       GetModuleItem(NULL,moduleIndex);      if (theModuleItem == NULL) return(NULL);      return(theModuleItem->firstItem);     }      return(theConstruct->next);  }/*******************************************************//* GetConstructModuleItemByIndex: Returns a pointer to *//*  the defmodule item for the specified construct. If *//*  theModule is NULL, then the construct module item  *//*  for the current module is returned, otherwise the  *//*  construct module item for the specified construct  *//*  is returned.                                       *//*******************************************************/globle struct defmoduleItemHeader *GetConstructModuleItemByIndex(theModule,moduleIndex)  struct defmodule *theModule;  int moduleIndex;  {    if (theModule != NULL)     {       return((struct defmoduleItemHeader *)             GetModuleItem(theModule,moduleIndex));     }        return((struct defmoduleItemHeader *)          GetModuleItem(((struct defmodule *) GetCurrentModule()),moduleIndex));  }  /******************************************//* FreeConstructHeaderModule: Deallocates *//*   the data structures associated with  *//*   the construct module item header.    */ /******************************************/globle VOID FreeConstructHeaderModule(theModuleItem,constructClass)  struct defmoduleItemHeader *theModuleItem;  struct construct *constructClass;  {   struct constructHeader *thisOne, *nextOne;      thisOne = theModuleItem->firstItem;      while (thisOne != NULL)     {       nextOne = thisOne->next;      (*constructClass->freeFunction)(thisOne);       thisOne = nextOne;     }  } /**********************************************//* DoForAllConstructs: Executes an action for *//*   all constructs of a specified class.     *//**********************************************/globle long DoForAllConstructs(actionFunction,moduleItemIndex,interruptable,userBuffer)#if ANSI_COMPILER  VOID (*actionFunction)(struct constructHeader *,VOID *);#else  VOID (*actionFunction)();#endif  int moduleItemIndex;  int interruptable;  VOID *userBuffer;  {   struct constructHeader *theConstruct;      struct defmoduleItemHeader *theModuleItem;   VOID *theModule;   long moduleCount = 0L;           /*==========================*/   /* Save the current module. */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -