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

📄 dffctbin.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.21  06/15/03            */   /*                                                     */   /*             DEFFACTS BSAVE/BLOAD MODULE             */   /*******************************************************//*************************************************************//* Purpose: Implements the binary save/load feature for the  *//*    deffacts construct.                                    *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*                                                           *//* Contributing Programmer(s):                               *//*      Brian L. Donnell                                     *//*                                                           *//* Revision History:                                         *//*                                                           *//*************************************************************/#define _DFFCTBIN_SOURCE_#include "setup.h"#if DEFFACTS_CONSTRUCT && (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME)#include <stdio.h>#define _STDIO_INCLUDED_#include "memalloc.h"#include "dffctdef.h"#include "moduldef.h"#include "bload.h"#include "bsave.h"#include "envrnmnt.h"#include "dffctbin.h"/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if BLOAD_AND_BSAVE   static void                    BsaveFind(void *);   static void                    BsaveExpressions(void *,FILE *);   static void                    BsaveStorage(void *,FILE *);   static void                    BsaveBinaryItem(void *,FILE *);#endif   static void                    BloadStorage(void *);   static void                    BloadBinaryItem(void *);   static void                    UpdateDeffactsModule(void *,void *,long);   static void                    UpdateDeffacts(void *,void *,long);   static void                    ClearBload(void *);   static void                    DeallocateDeffactsBloadData(void *);/********************************************//* DeffactsBinarySetup: Installs the binary *//*   save/load feature for deffacts.        *//********************************************/globle void DeffactsBinarySetup(  void *theEnv)  {   AllocateEnvironmentData(theEnv,DFFCTBIN_DATA,sizeof(struct deffactsBinaryData),DeallocateDeffactsBloadData);#if BLOAD_AND_BSAVE   AddBinaryItem(theEnv,"deffacts",0,BsaveFind,BsaveExpressions,                             BsaveStorage,BsaveBinaryItem,                             BloadStorage,BloadBinaryItem,                             ClearBload);#endif#if (BLOAD || BLOAD_ONLY)   AddBinaryItem(theEnv,"deffacts",0,NULL,NULL,NULL,NULL,                             BloadStorage,BloadBinaryItem,                             ClearBload);#endif  }  /********************************************************//* DeallocateDeffactsBloadData: Deallocates environment *//*    data for the deffacts bsave functionality.        *//********************************************************/static void DeallocateDeffactsBloadData(  void *theEnv)  {   size_t space;   space = DeffactsBinaryData(theEnv)->NumberOfDeffacts * sizeof(struct deffacts);   if (space != 0) genfree(theEnv,(void *) DeffactsBinaryData(theEnv)->DeffactsArray,space);      space = DeffactsBinaryData(theEnv)->NumberOfDeffactsModules * sizeof(struct deffactsModule);   if (space != 0) genfree(theEnv,(void *) DeffactsBinaryData(theEnv)->ModuleArray,space);  }#if BLOAD_AND_BSAVE/*********************************************************//* BsaveFind: Counts the number of data structures which *//*   must be saved in the binary image for the deffacts  *//*   in the current environment.                         *//*********************************************************/static void BsaveFind(  void *theEnv)  {   struct deffacts *theDeffacts;   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,DeffactsBinaryData(theEnv)->NumberOfDeffactsModules);   SaveBloadCount(theEnv,DeffactsBinaryData(theEnv)->NumberOfDeffacts);   /*========================================*/   /* Set the count of deffacts and deffacts */   /* module data structures to zero.        */   /*========================================*/   DeffactsBinaryData(theEnv)->NumberOfDeffacts = 0;   DeffactsBinaryData(theEnv)->NumberOfDeffactsModules = 0;   /*===========================*/   /* Loop through each module. */   /*===========================*/   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 deffacts */      /* modules encountered.                          */      /*===============================================*/      EnvSetCurrentModule(theEnv,(void *) theModule);      DeffactsBinaryData(theEnv)->NumberOfDeffactsModules++;      /*===================================================*/      /* Loop through each deffacts in the current module. */      /*===================================================*/      for (theDeffacts = (struct deffacts *) EnvGetNextDeffacts(theEnv,NULL);           theDeffacts != NULL;           theDeffacts = (struct deffacts *) EnvGetNextDeffacts(theEnv,theDeffacts))        {         /*======================================================*/         /* Initialize the construct header for the binary save. */         /*======================================================*/         MarkConstructHeaderNeededItems(&theDeffacts->header,DeffactsBinaryData(theEnv)->NumberOfDeffacts++);         /*============================================================*/         /* Count the number of expressions contained in the deffacts' */         /* assertion list and mark any atomic values contained there  */         /* as in use.                                                 */         /*============================================================*/         ExpressionData(theEnv)->ExpressionCount += ExpressionSize(theDeffacts->assertList);         MarkNeededItems(theEnv,theDeffacts->assertList);        }     }  }/************************************************//* BsaveExpressions: Saves the expressions used *//*   by deffacts to the binary save file.       *//************************************************/static void BsaveExpressions(  void *theEnv,  FILE *fp)  {   struct deffacts *theDeffacts;   struct defmodule *theModule;   /*===========================*/   /* Loop through each module. */   /*===========================*/   for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);        theModule != NULL;        theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))     {      /*======================================================*/      /* Set the current module to the module being examined. */      /*======================================================*/      EnvSetCurrentModule(theEnv,(void *) theModule);      /*==================================================*/      /* Loop through each deffacts in the current module */      /* and save the assertion list expression.          */      /*==================================================*/      for (theDeffacts = (struct deffacts *) EnvGetNextDeffacts(theEnv,NULL);           theDeffacts != NULL;           theDeffacts = (struct deffacts *) EnvGetNextDeffacts(theEnv,theDeffacts))        { BsaveExpression(theEnv,theDeffacts->assertList,fp); }     }  }/******************************************************//* BsaveStorage: Writes out the storage requirements  *//*    for all deffacts 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 deffacts binary */   /* image: the deffacts data structure and the deffactsModule data  */   /* structure. The assertion list expressions are not save with the */   /* deffacts portion of the binary image.                           */   /*=================================================================*/   space = sizeof(long) * 2;   GenWrite(&space,sizeof(size_t),fp);   GenWrite(&DeffactsBinaryData(theEnv)->NumberOfDeffacts,sizeof(long int),fp);   GenWrite(&DeffactsBinaryData(theEnv)->NumberOfDeffactsModules,sizeof(long int),fp);  }/********************************************//* BsaveBinaryItem: Writes out all deffacts *//*   structures to the binary file.         *//********************************************/static void BsaveBinaryItem(  void *theEnv,  FILE *fp)  {   size_t space;

⌨️ 快捷键说明

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