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

📄 moduldef.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
  {   struct defmodule *newDefmodule;   struct moduleItem *theItem;   int i;   struct defmoduleItemHeader *theHeader;   /*=======================================*/   /* Allocate the defmodule data structure */   /* and name it the MAIN module.          */   /*=======================================*/      newDefmodule = get_struct(defmodule);   newDefmodule->name = (SYMBOL_HN *) AddSymbol("MAIN");   IncrementSymbolCount(newDefmodule->name);   newDefmodule->next = NULL;   newDefmodule->ppForm = NULL;   newDefmodule->importList = NULL;   newDefmodule->exportList = NULL;   newDefmodule->bsaveID = 0L;      /*==================================*/   /* Initialize the array for storing */   /* the module's construct lists.    */   /*==================================*/      if (NumberOfModuleItems == 0) newDefmodule->itemsArray = NULL;   else      {      newDefmodule->itemsArray = (struct defmoduleItemHeader **)                                  gm2((int) sizeof(VOID *) * NumberOfModuleItems);      for (i = 0, theItem = ListOfModuleItems;           (i < NumberOfModuleItems) && (theItem != NULL);            i++, theItem = theItem->next)        {          if (theItem->allocateFunction == NULL)           { newDefmodule->itemsArray[i] = NULL; }         else           {             newDefmodule->itemsArray[i] = (struct defmoduleItemHeader *)                                          (*theItem->allocateFunction)();             theHeader = (struct defmoduleItemHeader *) newDefmodule->itemsArray[i];            theHeader->theModule = newDefmodule;            theHeader->firstItem = NULL;            theHeader->lastItem = NULL;           }        }     }      /*=======================================*/   /* Add the module to the list of modules */   /* and make it the current module.       */   /*=======================================*/   #if (! BLOAD_ONLY) && (! RUN_TIME) && DEFMODULE_CONSTRUCT   SetNumberOfDefmodules(1L);#endif   LastDefmodule = newDefmodule;   ListOfDefmodules = newDefmodule;   SetCurrentModule((VOID *) newDefmodule);  }/*********************************************************************//* SetListOfDefmodules: Sets the list of defmodules to the specified *//*   value. Normally used when initializing a run-time module or     *//*   when bloading a binary file to install the list of defmodules.  *//*********************************************************************/globle VOID SetListOfDefmodules(defmodulePtr)  VOID *defmodulePtr;  {   ListOfDefmodules = (struct defmodule *) defmodulePtr;      LastDefmodule = ListOfDefmodules;   if (LastDefmodule == NULL) return;   while (LastDefmodule->next != NULL) LastDefmodule = LastDefmodule->next;  }  /*******************************************************************//* GetNextDefmodule: If passed a NULL pointer, returns the first   *//*   defmodule in the ListOfDefmodules. Otherwise returns the next *//*   defmodule following the defmodule passed as an argument.      *//*******************************************************************/globle VOID *GetNextDefmodule(defmodulePtr)  VOID *defmodulePtr;  {   if (defmodulePtr == NULL)     { return((VOID *) ListOfDefmodules); }   else     { return((VOID *) (((struct defmodule *) defmodulePtr)->next)); }  }/**************************************//* GetDefmoduleName: Returns the name *//*   of the specified defmodule.      *//**************************************/globle char *GetDefmoduleName(defmodulePtr)  VOID *defmodulePtr;  { return(ValueToString(((struct defmodule *) defmodulePtr)->name)); }  /************************************************//* GetDefmodulePPForm: Returns the pretty print *//*   representation of the specified defmodule. *//************************************************/globle char *GetDefmodulePPForm(defmodulePtr)  VOID *defmodulePtr;  { return(((struct defmodule *) defmodulePtr)->ppForm); }  #if (! RUN_TIME)  /***********************************************//* RemoveAllDefmodules: Removes all defmodules *//*   from the current environment.             *//***********************************************/globle VOID RemoveAllDefmodules()  {   struct defmodule *nextDefmodule;        while (ListOfDefmodules != NULL)     {      nextDefmodule = ListOfDefmodules->next;      ReturnDefmodule(ListOfDefmodules);      ListOfDefmodules = nextDefmodule;     }      CurrentModule = NULL;   LastDefmodule = NULL;  }      /************************************************************//* ReturnDefmodule: Returns the data structures associated  *//*   with a defmodule construct to the pool of free memory. *//************************************************************/static VOID ReturnDefmodule(theDefmodule)  struct defmodule *theDefmodule;  {   int i;   struct moduleItem *theItem;   struct portItem *theSpec, *nextSpec;      /*=====================================================*/   /* Set the current module to the module being deleted. */   /*=====================================================*/      if (theDefmodule == NULL) return;   SetCurrentModule((VOID *) theDefmodule);      /*============================================*/   /* Call the free functions for the constructs */   /* belonging to this module.                  */   /*============================================*/      if (theDefmodule->itemsArray != NULL)     {          for (i = 0, theItem = ListOfModuleItems;           (i < NumberOfModuleItems) && (theItem != NULL);            i++, theItem = theItem->next)        {          if (theItem->freeFunction != NULL)           { (*theItem->freeFunction)(theDefmodule->itemsArray[i]); }        }      rm(theDefmodule->itemsArray,(int) sizeof(VOID *) * NumberOfModuleItems);    }           /*======================================================*/   /* Decrement the symbol count for the defmodule's name. */   /*======================================================*/      DecrementSymbolCount(theDefmodule->name);      /*====================================*/   /* Free the items in the import list. */   /*====================================*/      theSpec = theDefmodule->importList;   while (theSpec != NULL)     {       nextSpec = theSpec->next;      if (theSpec->moduleName != NULL) DecrementSymbolCount(theSpec->moduleName);      if (theSpec->constructType != NULL) DecrementSymbolCount(theSpec->constructType);      if (theSpec->constructName != NULL) DecrementSymbolCount(theSpec->constructName);      rtn_struct(portItem,theSpec);      theSpec = nextSpec;     }   /*====================================*/   /* Free the items in the export list. */   /*====================================*/      theSpec = theDefmodule->exportList;   while (theSpec != NULL)     {       nextSpec = theSpec->next;      if (theSpec->moduleName != NULL) DecrementSymbolCount(theSpec->moduleName);      if (theSpec->constructType != NULL) DecrementSymbolCount(theSpec->constructType);      if (theSpec->constructName != NULL) DecrementSymbolCount(theSpec->constructName);      rtn_struct(portItem,theSpec);      theSpec = nextSpec;     }        /*=========================================*/   /* Free the defmodule pretty print string. */   /*=========================================*/      if (theDefmodule->ppForm != NULL)     {      rm(theDefmodule->ppForm,         (int) sizeof(char) * ((int) strlen(theDefmodule->ppForm) + 1));     }           /*======================================*/   /* Return the defmodule data structure. */   /*======================================*/      rtn_struct(defmodule,theDefmodule);  }#endif /* (! RUN_TIME) *//**********************************************************************//* FindDefmodule: Searches for a defmodule in the list of defmodules. *//*   Returns a pointer to the defmodule if found, otherwise NULL.     *//**********************************************************************/globle VOID *FindDefmodule(defmoduleName)  char *defmoduleName;  {   struct defmodule *defmodulePtr;   SYMBOL_HN *findValue;   if ((findValue = (SYMBOL_HN *) FindSymbol(defmoduleName)) == NULL) return(NULL);   defmodulePtr = ListOfDefmodules;   while (defmodulePtr != NULL)     {      if (defmodulePtr->name == findValue)        { return((VOID *) defmodulePtr); }      defmodulePtr = defmodulePtr->next;     }   return(NULL);  }  /*************************************************//* GetCurrentModuleCommand: CLIPS access routine *//*   for the get-current-module command.         *//*************************************************/globle SYMBOL_HN *GetCurrentModuleCommand()  {   struct defmodule *theModule;      ArgCountCheck("get-current-module",EXACTLY,0);      theModule = (struct defmodule *) GetCurrentModule();      if (theModule == NULL) return((SYMBOL_HN *) CLIPSFalseSymbol);      return((SYMBOL_HN *) AddSymbol(ValueToString(theModule->name)));  }/*************************************************//* SetCurrentModuleCommand: CLIPS access routine *//*   for the set-current-module command.         *//*************************************************/globle SYMBOL_HN *SetCurrentModuleCommand()  {   DATA_OBJECT argPtr;   char *argument;   struct defmodule *theModule;   SYMBOL_HN *defaultReturn;   /*=====================================================*/   /* Check for the correct number and type of arguments. */   /*=====================================================*/      theModule = ((struct defmodule *) GetCurrentModule());   if (theModule == NULL) return((SYMBOL_HN *) CLIPSFalseSymbol);      defaultReturn = (SYMBOL_HN *) AddSymbol(ValueToString(((struct defmodule *) GetCurrentModule())->name));      if (ArgCountCheck("set-current-module",EXACTLY,1) == -1)     { return(defaultReturn); }   if (ArgTypeCheck("set-current-module",1,SYMBOL,&argPtr) == CLIPS_FALSE)     { return(defaultReturn); }   argument = DOToString(argPtr);   /*================================================*/   /* Set the current module to the specified value. */   /*================================================*/      theModule = (struct defmodule *) FindDefmodule(argument);      if (theModule == NULL)     {      CantFindItemErrorMessage("defmodule",argument);      return(defaultReturn);     }        SetCurrentModule((VOID *) theModule);      /*================================*/   /* Return the new current module. */   /*================================*/      return((SYMBOL_HN *) defaultReturn);  }  /*************************************************//* AddAfterModuleChangeFunction: Adds a function *//*   to the list of functions to be called after *//*   a module change occurs.                     *//*************************************************/globle VOID AddAfterModuleChangeFunction(name,func,priority)  char *name;  VOID (*func)(VOID_ARG);  int priority;  {   AfterModuleChangeFunctions =      AddFunctionToCallList(name,priority,func,AfterModuleChangeFunctions);  }    /************************************************//* IllegalModuleSpecifierMessage: Error message *//*   for the illegal use of a module specifier. *//************************************************/globle VOID IllegalModuleSpecifierMessage()  {   PrintErrorID("MODULDEF",1,CLIPS_TRUE);   PrintCLIPS(WERROR,"Illegal use of the module specifier.\n");  }      

⌨️ 快捷键说明

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