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

📄 globldef.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
/*   defglobals. Returns a pointer to the defglobal if found, *//*   otherwise NULL.                                          *//**************************************************************/globle struct defglobal *QFindDefglobal(defglobalName)  SYMBOL_HN *defglobalName;  {   struct defglobal *theDefglobal;   for (theDefglobal = (struct defglobal *) GetNextDefglobal(NULL);        theDefglobal != NULL;        theDefglobal = (struct defglobal *) GetNextDefglobal(theDefglobal))     { if (defglobalName == theDefglobal->header.name) return (theDefglobal); }   return(NULL);  }  /*********************************************************************//* GetDefglobalValueForm: Returns the pretty print representation of *//*   the current value of the specified defglobal. For example, if   *//*   the current value of ?*x* is 5, the string "?*x* = 5" would be  *//*   returned.                                                       *//*********************************************************************/globle VOID GetDefglobalValueForm(buffer,bufferLength,vTheGlobal)  char *buffer;  int bufferLength;  VOID *vTheGlobal;  {   struct defglobal *theGlobal = (struct defglobal *) vTheGlobal;   OpenStringDestination("GlobalValueForm",buffer,bufferLength);   PrintCLIPS("GlobalValueForm","?*");   PrintCLIPS("GlobalValueForm",ValueToString(theGlobal->header.name));   PrintCLIPS("GlobalValueForm","* = ");   PrintDataObject("GlobalValueForm",&theGlobal->current);   CloseStringDestination("GlobalValueForm");  }  /*********************************************************//* GetGlobalsChanged: Returns the defglobal change flag. *//*********************************************************/globle int GetGlobalsChanged()  { return(ChangeToGlobals); }/******************************************************//* SetGlobalsChanged: Sets the defglobal change flag. *//******************************************************/globle VOID SetGlobalsChanged(value)  int value;  { ChangeToGlobals = value; }  /**********************************************************//* GetDefglobalValue2: Returns the value of the specified *//*   global variable in the supplied DATA_OBJECT.         *//**********************************************************/static BOOLEAN GetDefglobalValue2(theValue,vPtr)  VOID *theValue;  DATA_OBJECT_PTR vPtr;  {    struct defglobal *theGlobal;   int count;      /*===========================================*/   /* Search for the specified defglobal in the */   /* modules visible to the current module.    */   /*===========================================*/      theGlobal = (struct defglobal *)               FindImportedConstruct("defglobal",NULL,ValueToString(theValue),               &count,CLIPS_TRUE,NULL);                  /*=============================================*/   /* If it wasn't found, print an error message. */   /*=============================================*/   if (theGlobal == NULL)     {      PrintErrorID("GLOBLDEF",1,CLIPS_FALSE);      PrintCLIPS(WERROR,"Global variable ?*");      PrintCLIPS(WERROR,ValueToString(theValue));      PrintCLIPS(WERROR,"* is unbound.\n");      vPtr->type = SYMBOL;      vPtr->value = CLIPSFalseSymbol;      SetEvaluationError(CLIPS_TRUE);      return(CLIPS_FALSE);     }        /*========================================================*/   /* The current implementation of the defmodules shouldn't */   /* allow a construct to be defined which would cause an   */   /* ambiguous reference, but we'll check for it anyway.    */   /*========================================================*/        if (count > 1)      {      AmbiguousReferenceErrorMessage("defglobal",ValueToString(theValue));      vPtr->type = SYMBOL;      vPtr->value = CLIPSFalseSymbol;      SetEvaluationError(CLIPS_TRUE);      return(CLIPS_FALSE);     }      /*=================================*/   /* Get the value of the defglobal. */   /*=================================*/      QGetDefglobalValue(theGlobal,vPtr);        return(CLIPS_TRUE);  }/***************************************************************//* QGetDefglobalValue: Returns the value of a global variable. *//***************************************************************/static int QGetDefglobalValue(vTheGlobal,vPtr)  VOID *vTheGlobal;  DATA_OBJECT_PTR vPtr;  {   struct defglobal *theGlobal = (struct defglobal *) vTheGlobal;      /*===============================================*/   /* Transfer values which can be copied directly. */   /*===============================================*/      vPtr->type = theGlobal->current.type;   vPtr->value = theGlobal->current.value;   vPtr->begin = theGlobal->current.begin;   vPtr->end = theGlobal->current.end;   /*===========================================================*/   /* If the global contains a multifield value, return a copy  */   /* of the value so that routines which use this value are    */   /* not affected if the value of the global is later changed. */   /*===========================================================*/   if (vPtr->type == MULTIFIELD)     {      vPtr->value = CreateMultifield(vPtr->end + 1);      CopyMemory(struct field,vPtr->end + 1,                                &((struct multifield *) vPtr->value)->theFields[0],                                &((struct multifield *) theGlobal->current.value)->theFields[theGlobal->current.begin]);     }        return(TRUE);  }  /*********************************************************//* GetDefglobalValue: Returns the value of the specified *//*   global variable in the supplied DATA_OBJECT.        *//*********************************************************/globle BOOLEAN GetDefglobalValue(variableName,vPtr)  char *variableName;  DATA_OBJECT_PTR vPtr;  {   struct defglobal *theDefglobal;   if ((theDefglobal = (struct defglobal *) FindDefglobal(variableName)) == NULL)     { return(CLIPS_FALSE); }      QGetDefglobalValue(theDefglobal,vPtr);            return(CLIPS_TRUE);  }/***************************************************************//* SetDefglobalValue: Sets the value of the specified global   *//*   variable to the value stored in the supplied DATA_OBJECT. *//***************************************************************/globle BOOLEAN SetDefglobalValue(variableName,vPtr)  char *variableName;  DATA_OBJECT_PTR vPtr;  {   struct defglobal *theGlobal;   if ((theGlobal = QFindDefglobal(AddSymbol(variableName))) == NULL)     { return(CLIPS_FALSE); }     QSetDefglobalValue(theGlobal,vPtr,CLIPS_FALSE);      return(CLIPS_TRUE);  }  /**********************************************************//* DecrementDefglobalBusyCount: Decrements the busy count *//*   of a defglobal data structure.                       *//**********************************************************/static VOID DecrementDefglobalBusyCount(vTheGlobal)  VOID *vTheGlobal;  {   struct defglobal *theGlobal = (struct defglobal *) vTheGlobal;      if (! ClearInProgress) theGlobal->busyCount--;  }/**********************************************************//* IncrementDefglobalBusyCount: Increments the busy count *//*   of a defglobal data structure.                       *//**********************************************************/static VOID IncrementDefglobalBusyCount(vTheGlobal)  VOID *vTheGlobal;  {   struct defglobal *theGlobal = (struct defglobal *) vTheGlobal;      theGlobal->busyCount++;  } /***********************************************************************//* UpdateDefglobalScope: Updates the scope flag of all the defglobals. *//***********************************************************************/globle VOID UpdateDefglobalScope()  {   struct defglobal *theDefglobal;   int moduleCount;   struct defmodule *theModule;   struct defmoduleItemHeader *theItem;      /*============================*/   /* Loop through every module. */   /*============================*/      for (theModule = (struct defmodule *) GetNextDefmodule(NULL);        theModule != NULL;        theModule = (struct defmodule *) GetNextDefmodule(theModule))     {      /*============================================================*/      /* Loop through every defglobal in the module being examined. */      /*============================================================*/            theItem = (struct defmoduleItemHeader *)                GetModuleItem(theModule,DefglobalModuleIndex);            for (theDefglobal = (struct defglobal *) theItem->firstItem;           theDefglobal != NULL ;           theDefglobal = (struct defglobal *) GetNextDefglobal(theDefglobal))        {           /*====================================================*/         /* If the defglobal is visible to the current module, */         /* then mark it as being in scope, otherwise mark it  */         /* as being out of scope.                             */         /*====================================================*/                  if (FindImportedConstruct("defglobal",theModule,                                   ValueToString(theDefglobal->header.name),                                   &moduleCount,CLIPS_TRUE,NULL) != NULL)           { theDefglobal->inScope = CLIPS_TRUE; }         else           { theDefglobal->inScope = CLIPS_FALSE; }        }       }  }  /*******************************************************//* GetNextDefglobalInScope: Returns the next defglobal *//*   that is scope of the current module. Works in a   *//*   similar fashion to GetNextDefglobal, but skips    *//*   defglobals that are out of scope.                 *//*******************************************************/globle VOID *GetNextDefglobalInScope(vTheGlobal)  VOID *vTheGlobal;  {             static struct defmodule *theDefmodule = NULL;   static long lastModuleIndex = -1;   struct defglobal *theGlobal = (struct defglobal *) vTheGlobal;   struct defmoduleItemHeader *theItem;      /*=======================================*/   /* If we're beginning the search for the */   /* first defglobal in scope, then ...    */   /*=======================================*/      if (theGlobal == NULL)     {             /*==============================================*/      /* If the current module has been changed since */      /* the last time the scopes were computed, then */      /* recompute the scopes.                        */      /*==============================================*/            if (lastModuleIndex != ModuleChangeIndex)        {         UpdateDefglobalScope();         lastModuleIndex = ModuleChangeIndex;        }              /*==========================================*/      /* Get the first module and first defglobal */      /* to start the search with.                */      /*==========================================*/            theDefmodule = (struct defmodule *) GetNextDefmodule(NULL);      theItem = (struct defmoduleItemHeader *)                GetModuleItem(theDefmodule,DefglobalModuleIndex);      theGlobal = (struct defglobal *) theItem->firstItem;     }        /*==================================================*/   /* Otherwise, see if the last defglobal returned by */   /* this function has a defglobal following it.      */   /*==================================================*/      else     { theGlobal = (struct defglobal *) GetNextDefglobal(theGlobal); }      /*======================================*/   /* Continue looping through the modules */   /* until a defglobal in scope is found. */   /*======================================*/      while (theDefmodule != NULL)     {      /*=====================================================*/      /* Loop through the defglobals in the module currently */      /* being examined to see if one is in scope.           */      /*=====================================================*/            for (;           theGlobal != NULL;           theGlobal = (struct defglobal *) GetNextDefglobal(theGlobal))        { if (theGlobal->inScope) return((VOID *) theGlobal); }              /*================================================*/      /* If a global in scope couldn't be found in this */      /* module, then move on to the next module.       */      /*================================================*/            theDefmodule = (struct defmodule *) GetNextDefmodule(theDefmodule);      theItem = (struct defmoduleItemHeader *)                GetModuleItem(theDefmodule,DefglobalModuleIndex);      theGlobal = (struct defglobal *) theItem->firstItem;     }        /*====================================*/   /* All the globals in scope have been */   /* traversed and there are none left. */   /*====================================*/      return(NULL);  }#endif /* DEFGLOBAL_CONSTRUCT */

⌨️ 快捷键说明

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