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

📄 globlbin.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.21  06/15/03            */   /*                                                     */   /*            DEFGLOBAL BSAVE/BLOAD MODULE             */   /*******************************************************//*************************************************************//* Purpose: Implements the binary save/load feature for the  *//*    defglobal construct.                                   *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*                                                           *//* Contributing Programmer(s):                               *//*      Brian L. Donnell                                     *//*                                                           *//* Revision History:                                         *//*                                                           *//*************************************************************/#define _GLOBLBIN_SOURCE_#include "setup.h"#if DEFGLOBAL_CONSTRUCT && (BLOAD || BLOAD_AND_BSAVE || BLOAD_ONLY) && (! RUN_TIME)#include <stdio.h>#define _STDIO_INCLUDED_#include "memalloc.h"#include "multifld.h"#include "globldef.h"#include "bload.h"#include "bsave.h"#include "moduldef.h"#include "globlbsc.h"#include "envrnmnt.h"#include "globlbin.h"/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if BLOAD_AND_BSAVE   static void                    BsaveFind(void *);   static void                    BsaveStorage(void *,FILE *);   static void                    BsaveBinaryItem(void *,FILE *);#endif   static void                    BloadStorageDefglobals(void *);   static void                    BloadBinaryItem(void *);   static void                    UpdateDefglobalModule(void *,void *,long);   static void                    UpdateDefglobal(void *,void *,long);   static void                    ClearBload(void *);   static void                    DeallocateDefglobalBloadData(void *);/*********************************************//* DefglobalBinarySetup: Installs the binary *//*   save/load feature for the defglobals.   *//*********************************************/globle void DefglobalBinarySetup(  void *theEnv)  {   AllocateEnvironmentData(theEnv,GLOBLBIN_DATA,sizeof(struct defglobalBinaryData),DeallocateDefglobalBloadData);#if (BLOAD_AND_BSAVE || BLOAD)   AddAfterBloadFunction(theEnv,"defglobal",ResetDefglobals,50);#endif#if BLOAD_AND_BSAVE   AddBinaryItem(theEnv,"defglobal",0,BsaveFind,NULL,                             BsaveStorage,BsaveBinaryItem,                             BloadStorageDefglobals,BloadBinaryItem,                             ClearBload);#endif#if (BLOAD || BLOAD_ONLY)   AddBinaryItem(theEnv,"defglobal",0,NULL,NULL,NULL,NULL,                             BloadStorageDefglobals,BloadBinaryItem,                             ClearBload);#endif  }/*********************************************************//* DeallocateDefglobalBloadData: Deallocates environment *//*    data for the defglobal bsave functionality.        *//*********************************************************/static void DeallocateDefglobalBloadData(  void *theEnv)  {#if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME)   size_t space;   long i;   for (i = 0; i < DefglobalBinaryData(theEnv)->NumberOfDefglobals; i++)     {      if (DefglobalBinaryData(theEnv)->DefglobalArray[i].current.type == MULTIFIELD)        { ReturnMultifield(theEnv,(struct multifield *) DefglobalBinaryData(theEnv)->DefglobalArray[i].current.value); }     }   space = DefglobalBinaryData(theEnv)->NumberOfDefglobals * sizeof(struct defglobal);   if (space != 0)      { genfree(theEnv,(void *) DefglobalBinaryData(theEnv)->DefglobalArray,space); }   space =  DefglobalBinaryData(theEnv)->NumberOfDefglobalModules * sizeof(struct defglobalModule);   if (space != 0)      { genfree(theEnv,(void *) DefglobalBinaryData(theEnv)->ModuleArray,space); }#endif  }#if BLOAD_AND_BSAVE/****************************************************//* BsaveFind:  Counts the number of data structures *//*   which must be saved in the binary image for    *//*   the defglobals in the current environment.     *//****************************************************/static void BsaveFind(  void *theEnv)  {   struct defglobal *defglobalPtr;   struct defmodule *theModule;   /*=======================================================*/   /* If a binary image is already loaded, then temporarily */   /* save the count values since these will be overwritten */   /* in the process of saving the binary image.            */   /*=======================================================*/   SaveBloadCount(theEnv,DefglobalBinaryData(theEnv)->NumberOfDefglobalModules);   SaveBloadCount(theEnv,DefglobalBinaryData(theEnv)->NumberOfDefglobals);   /*============================================*/   /* Set the count of defglobals and defglobals */   /* module data structures to zero.            */   /*============================================*/   DefglobalBinaryData(theEnv)->NumberOfDefglobals = 0;   DefglobalBinaryData(theEnv)->NumberOfDefglobalModules = 0;   for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);        theModule != NULL;        theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))     {      /*================================================*/      /* Set the current module to the module being     */      /* examined and increment the number of defglobal */      /* modules encountered.                           */      /*================================================*/      EnvSetCurrentModule(theEnv,(void *) theModule);      DefglobalBinaryData(theEnv)->NumberOfDefglobalModules++;      /*====================================================*/      /* Loop through each defglobal in the current module. */      /*====================================================*/      for (defglobalPtr = (struct defglobal *) EnvGetNextDefglobal(theEnv,NULL);           defglobalPtr != NULL;           defglobalPtr = (struct defglobal *) EnvGetNextDefglobal(theEnv,defglobalPtr))        {         /*======================================================*/         /* Initialize the construct header for the binary save. */         /*======================================================*/         MarkConstructHeaderNeededItems(&defglobalPtr->header,DefglobalBinaryData(theEnv)->NumberOfDefglobals++);        }     }  }/*****************************************************//* BsaveStorage: Writes out storage requirements for *//*   all defglobal structures to the binary file     *//*****************************************************/static void BsaveStorage(  void *theEnv,  FILE *fp)  {   size_t space;   /*===========================================================*/   /* Only two data structures are saved as part of a defglobal */   /* binary image: the defglobal data structure and the        */   /* defglobalModule data structure.                           */   /*===========================================================*/   space = sizeof(long) * 2;   GenWrite(&space,sizeof(size_t),fp);   GenWrite(&DefglobalBinaryData(theEnv)->NumberOfDefglobals,sizeof(long int),fp);   GenWrite(&DefglobalBinaryData(theEnv)->NumberOfDefglobalModules,sizeof(long int),fp);  }/*********************************************//* BsaveBinaryItem: Writes out all defglobal *//*   structures to the binary file           *//*********************************************/static void BsaveBinaryItem(  void *theEnv,  FILE *fp)  {   size_t space;   struct defglobal *theDefglobal;   struct bsaveDefglobal newDefglobal;   struct defmodule *theModule;   struct bsaveDefglobalModule tempDefglobalModule;   struct defglobalModule *theModuleItem;   /*==========================================================*/   /* Write out the amount of space taken up by the defglobal  */   /* and defglobalModule data structures in the binary image. */   /*==========================================================*/   space = DefglobalBinaryData(theEnv)->NumberOfDefglobals * sizeof(struct bsaveDefglobal) +           (DefglobalBinaryData(theEnv)->NumberOfDefglobalModules * sizeof(struct bsaveDefglobalModule));   GenWrite(&space,sizeof(size_t),fp);   /*=================================================*/   /* Write out each defglobal module data structure. */   /*=================================================*/   DefglobalBinaryData(theEnv)->NumberOfDefglobals = 0;   for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);        theModule != NULL;        theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))     {      EnvSetCurrentModule(theEnv,(void *) theModule);

⌨️ 快捷键说明

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