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

📄 globldef.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.24  06/05/06            */   /*                                                     */   /*                  DEFGLOBAL MODULE                   */   /*******************************************************//*************************************************************//* Purpose: Provides core routines for the creation and      *//*   maintenance of the defglobal construct.                 *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*                                                           *//* Contributing Programmer(s):                               *//*      Brian L. Donnell                                     *//*                                                           *//* Revision History:                                         *//*      6.23: Correction for FalseSymbol/TrueSymbol. DR0859  *//*                                                           *//*      6.24: Renamed BOOLEAN macro type to intBool.         *//*                                                           *//*            Corrected code to remove run-time program      *//*            compiler warning.                              *//*                                                           *//*************************************************************/#define _GLOBLDEF_SOURCE_#include "setup.h"#if DEFGLOBAL_CONSTRUCT#include <stdio.h>#define _STDIO_INCLUDED_#include "memalloc.h"#include "modulpsr.h"#include "multifld.h"#include "router.h"#include "strngrtr.h"#include "modulutl.h"#include "globlbsc.h"#include "globlpsr.h"#include "globlcom.h"#include "utility.h"#include "commline.h"#include "envrnmnt.h"#if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE#include "bload.h"#include "globlbin.h"#endif#if CONSTRUCT_COMPILER && (! RUN_TIME)#include "globlcmp.h"#endif#include "globldef.h"/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/   static void                   *AllocateModule(void *);   static void                    ReturnModule(void *,void *);   static void                    ReturnDefglobal(void *,void *);   static void                    InitializeDefglobalModules(void *);   static intBool                 GetDefglobalValue2(void *,void *,DATA_OBJECT_PTR);   static void                    IncrementDefglobalBusyCount(void *,void *);   static void                    DecrementDefglobalBusyCount(void *,void *);   static void                    DeallocateDefglobalData(void *);   static void                    DestroyDefglobalAction(void *,struct constructHeader *,void *);   static void                    DestroyDefglobal(void *,void *);/**************************************************************//* InitializeDefglobals: Initializes the defglobal construct. *//**************************************************************/globle void InitializeDefglobals(  void *theEnv)  {     struct entityRecord globalInfo = { "GBL_VARIABLE", GBL_VARIABLE,0,0,0,                                                       NULL,                                                       NULL,                                                       NULL,                                                       GetDefglobalValue2,                                                       NULL,NULL,                                                       NULL,NULL,NULL,NULL,NULL,NULL };   struct entityRecord defglobalPtrRecord = { "DEFGLOBAL_PTR", DEFGLOBAL_PTR,0,0,0,                                                       NULL,NULL,NULL,                                                       QGetDefglobalValue,                                                       NULL,                                                       DecrementDefglobalBusyCount,                                                       IncrementDefglobalBusyCount,                                                       NULL,NULL,NULL,NULL,NULL };      AllocateEnvironmentData(theEnv,DEFGLOBAL_DATA,sizeof(struct defglobalData),DeallocateDefglobalData);      memcpy(&DefglobalData(theEnv)->GlobalInfo,&globalInfo,sizeof(struct entityRecord));      memcpy(&DefglobalData(theEnv)->DefglobalPtrRecord,&defglobalPtrRecord,sizeof(struct entityRecord));      DefglobalData(theEnv)->ResetGlobals = TRUE;   DefglobalData(theEnv)->LastModuleIndex = -1;      InstallPrimitive(theEnv,&DefglobalData(theEnv)->GlobalInfo,GBL_VARIABLE);   InstallPrimitive(theEnv,&DefglobalData(theEnv)->DefglobalPtrRecord,DEFGLOBAL_PTR);   InitializeDefglobalModules(theEnv);   DefglobalBasicCommands(theEnv);   DefglobalCommandDefinitions(theEnv);   DefglobalData(theEnv)->DefglobalConstruct =      AddConstruct(theEnv,"defglobal","defglobals",ParseDefglobal,EnvFindDefglobal,                   GetConstructNamePointer,GetConstructPPForm,                   GetConstructModuleItem,EnvGetNextDefglobal,SetNextConstruct,                   EnvIsDefglobalDeletable,EnvUndefglobal,ReturnDefglobal);  }/****************************************************//* DeallocateDefglobalData: Deallocates environment *//*    data for the defglobal construct.             *//****************************************************/static void DeallocateDefglobalData(  void *theEnv)  {#if ! RUN_TIME   struct defglobalModule *theModuleItem;   void *theModule;   #if BLOAD || BLOAD_AND_BSAVE   if (Bloaded(theEnv)) return;#endif   DoForAllConstructs(theEnv,DestroyDefglobalAction,DefglobalData(theEnv)->DefglobalModuleIndex,FALSE,NULL);    for (theModule = EnvGetNextDefmodule(theEnv,NULL);        theModule != NULL;        theModule = EnvGetNextDefmodule(theEnv,theModule))     {      theModuleItem = (struct defglobalModule *)                      GetModuleItem(theEnv,(struct defmodule *) theModule,                                    DefglobalData(theEnv)->DefglobalModuleIndex);      rtn_struct(theEnv,defglobalModule,theModuleItem);     }#else   DoForAllConstructs(theEnv,DestroyDefglobalAction,DefglobalData(theEnv)->DefglobalModuleIndex,FALSE,NULL); #endif  }  /***************************************************//* DestroyDefglobalAction: Action used to remove   *//*   defglobals as a result of DestroyEnvironment. *//***************************************************/#if IBM_TBC#pragma argsused#endifstatic void DestroyDefglobalAction(  void *theEnv,  struct constructHeader *theConstruct,  void *buffer)  {#if MAC_MCW || IBM_MCW || MAC_XCD#pragma unused(buffer)#endif#if (! BLOAD_ONLY)   struct defglobal *theDefglobal = (struct defglobal *) theConstruct;      if (theDefglobal == NULL) return;   DestroyDefglobal(theEnv,theDefglobal);#else#if MAC_MCW || IBM_MCW || MAC_XCD#pragma unused(theEnv,theConstruct)#endif#endif  }/*********************************************************//* InitializeDefglobalModules: Initializes the defglobal *//*   construct for use with the defmodule construct.     *//*********************************************************/static void InitializeDefglobalModules(  void *theEnv)  {   DefglobalData(theEnv)->DefglobalModuleIndex = RegisterModuleItem(theEnv,"defglobal",                                    AllocateModule,                                    ReturnModule,#if BLOAD_AND_BSAVE || BLOAD || BLOAD_ONLY                                    BloadDefglobalModuleReference,#else                                    NULL,#endif#if CONSTRUCT_COMPILER && (! RUN_TIME)                                    DefglobalCModuleReference,#else                                    NULL,#endif                                    EnvFindDefglobal);#if (! BLOAD_ONLY) && (! RUN_TIME) && DEFMODULE_CONSTRUCT   AddPortConstructItem(theEnv,"defglobal",SYMBOL);#endif  }/*************************************************//* AllocateModule: Allocates a defglobal module. *//*************************************************/static void *AllocateModule(  void *theEnv)  {      return((void *) get_struct(theEnv,defglobalModule));   }/***********************************************//* ReturnModule: Deallocates a defglobal module. *//***********************************************/static void ReturnModule(  void *theEnv,  void *theItem)  {   FreeConstructHeaderModule(theEnv,(struct defmoduleItemHeader *) theItem,DefglobalData(theEnv)->DefglobalConstruct);   rtn_struct(theEnv,defglobalModule,theItem);  }/**************************************************************//* GetDefglobalModuleItem: Returns a pointer to the defmodule *//*  item for the specified defglobal or defmodule.            *//**************************************************************/globle struct defglobalModule *GetDefglobalModuleItem(  void *theEnv,  struct defmodule *theModule)  {   return((struct defglobalModule *) GetConstructModuleItemByIndex(theEnv,theModule,DefglobalData(theEnv)->DefglobalModuleIndex));  }/*****************************************************//* EnvFindDefglobal: Searches for a defglobal in the *//*   list of defglobals. Returns a pointer to the    *//*   defglobal if found, otherwise NULL.             *//*****************************************************/globle void *EnvFindDefglobal(  void *theEnv,  char *defglobalName)  {    return(FindNamedConstruct(theEnv,defglobalName,DefglobalData(theEnv)->DefglobalConstruct));   }/********************************************************************//* EnvGetNextDefglobal: If passed a NULL pointer, returns the first *//*   defglobal in the defglobal list. Otherwise returns the next    *//*   defglobal following the defglobal passed as an argument.       *//********************************************************************/globle void *EnvGetNextDefglobal(  void *theEnv,  void *defglobalPtr)  {    return((void *) GetNextConstructItem(theEnv,(struct constructHeader *) defglobalPtr,DefglobalData(theEnv)->DefglobalModuleIndex));   }/*********************************************************//* EnvIsDefglobalDeletable: Returns TRUE if a particular *//*   defglobal can be deleted, otherwise returns FALSE.  *//*********************************************************/globle intBool EnvIsDefglobalDeletable(  void *theEnv,  void *ptr)  {   if (! ConstructsDeletable(theEnv))     { return FALSE; }   if (((struct defglobal *) ptr)->busyCount) return(FALSE);   return(TRUE);  }/************************************************************//* ReturnDefglobal: Returns the data structures associated  *//*   with a defglobal construct to the pool of free memory. *//************************************************************/static void ReturnDefglobal(  void *theEnv,  void *vTheDefglobal)  {#if (MAC_MCW || IBM_MCW) && (RUN_TIME || BLOAD_ONLY)#pragma unused(theEnv,vTheDefglobal)#endif   #if (! BLOAD_ONLY) && (! RUN_TIME)   struct defglobal *theDefglobal = (struct defglobal *) vTheDefglobal;      if (theDefglobal == NULL) return;   /*====================================*/   /* Return the global's current value. */   /*====================================*/   ValueDeinstall(theEnv,&theDefglobal->current);   if (theDefglobal->current.type == MULTIFIELD)     { ReturnMultifield(theEnv,(struct multifield *) theDefglobal->current.value); }   /*================================================*/   /* Return the expression representing the initial */   /* value of the defglobal when it was defined.    */   /*================================================*/   RemoveHashedExpression(theEnv,theDefglobal->initial);   /*===============================*/   /* Release items stored in the   */   /* defglobal's construct header. */   /*===============================*/   DeinstallConstructHeader(theEnv,&theDefglobal->header);   /*======================================*/   /* Return the defglobal data structure. */   /*======================================*/   rtn_struct(theEnv,defglobal,theDefglobal);   /*===========================================*/   /* Set the variable indicating that a change */   /* has been made to a global variable.       */   /*===========================================*/   DefglobalData(theEnv)->ChangeToGlobals = TRUE;#endif  }  /************************************************************//* DestroyDefglobal: Returns the data structures associated  *//*   with a defglobal construct to the pool of free memory. *//************************************************************/static void DestroyDefglobal(  void *theEnv,  void *vTheDefglobal)  {#if (MAC_MCW || IBM_MCW) && BLOAD_ONLY#pragma unused(theEnv,vTheDefglobal)#endif   #if (! BLOAD_ONLY)   struct defglobal *theDefglobal = (struct defglobal *) vTheDefglobal;      if (theDefglobal == NULL) return;   /*====================================*/   /* Return the global's current value. */   /*====================================*/   if (theDefglobal->current.type == MULTIFIELD)     { ReturnMultifield(theEnv,(struct multifield *) theDefglobal->current.value); }     #if (! RUN_TIME)   /*===============================*/   /* Release items stored in the   */   /* defglobal's construct header. */   /*===============================*/   DeinstallConstructHeader(theEnv,&theDefglobal->header);   /*======================================*/   /* Return the defglobal data structure. */   /*======================================*/   rtn_struct(theEnv,defglobal,theDefglobal);#endif#endif  }  /************************************************//* QSetDefglobalValue: Lowest level routine for *//*   setting a defglobal's value.               *//************************************************/globle void QSetDefglobalValue(  void *theEnv,  struct defglobal *theGlobal,  DATA_OBJECT_PTR vPtr,  int resetVar)  {   /*====================================================*/   /* If the new value passed for the defglobal is NULL, */   /* then reset the defglobal to the initial value it   */   /* had when it was defined.                           */   /*====================================================*/   if (resetVar)     {      EvaluateExpression(theEnv,theGlobal->initial,vPtr);      if (EvaluationData(theEnv)->EvaluationError)        {         vPtr->type = SYMBOL;         vPtr->value = EnvFalseSymbol(theEnv);        }     }   /*==========================================*/   /* If globals are being watch, then display */   /* the change to the global variable.       */   /*==========================================*/#if DEBUGGING_FUNCTIONS

⌨️ 快捷键说明

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