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

📄 dffctbin.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.05  04/09/97            */   /*                                                     */   /*             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 _CLIPS_STDIO_#include "clipsmem.h"#include "dffctdef.h"#include "moduldef.h"#include "bload.h"#include "bsave.h"#include "dffctbin.h"/***************************************//* LOCAL INTERNAL VARIABLE DEFINITIONS *//***************************************/   static struct deffacts HUGE_ADDR        *DeffactsArray = NULL;   static long                              NumberOfDeffacts = 0;   static struct deffactsModule HUGE_ADDR  *ModuleArray;   static long                              NumberOfDeffactsModules;/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if ANSI_COMPILER#if BLOAD_AND_BSAVE   static VOID                    BsaveFind(void);   static VOID                    BsaveExpressions(FILE *);   static VOID                    BsaveStorage(FILE *);   static VOID                    BsaveBinaryItem(FILE *);#endif   static VOID                    BloadStorage(void);   static VOID                    BloadBinaryItem(void);   static VOID                    UpdateDeffactsModule(VOID *,long);   static VOID                    UpdateDeffacts(VOID *,long);   static VOID                    ClearBload(void);#else#if BLOAD_AND_BSAVE   static VOID                    BsaveFind();   static VOID                    BsaveExpressions();   static VOID                    BsaveStorage();   static VOID                    BsaveBinaryItem();#endif   static VOID                    BloadStorage();   static VOID                    BloadBinaryItem();   static VOID                    UpdateDeffactsModule();   static VOID                    UpdateDeffacts();   static VOID                    ClearBload();#endif/********************************************//* DeffactsBinarySetup: Installs the binary *//*   save/load feature for deffacts.        *//********************************************/globle VOID DeffactsBinarySetup()  {#if BLOAD_AND_BSAVE   AddBinaryItem("deffacts",0,BsaveFind,BsaveExpressions,                             BsaveStorage,BsaveBinaryItem,                             BloadStorage,BloadBinaryItem,                             ClearBload);#endif#if (BLOAD || BLOAD_ONLY)   AddBinaryItem("deffacts",0,NULL,NULL,NULL,NULL,                             BloadStorage,BloadBinaryItem,                             ClearBload);#endif  }#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()  {   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.            */   /*=======================================================*/      if (Bloaded())     {      SaveBloadCount(NumberOfDeffactsModules);      SaveBloadCount(NumberOfDeffacts);     }      /*========================================*/   /* Set the count of deffacts and deffacts */   /* module data structures to zero.        */   /*========================================*/      NumberOfDeffacts = 0;   NumberOfDeffactsModules = 0;      /*===========================*/   /* Loop through each module. */   /*===========================*/      for (theModule = (struct defmodule *) GetNextDefmodule(NULL);        theModule != NULL;        theModule = (struct defmodule *) GetNextDefmodule(theModule))     {      /*===============================================*/      /* Set the current module to the module being    */      /* examined and increment the number of deffacts */      /* modules encountered.                          */      /*===============================================*/            SetCurrentModule((VOID *) theModule);      NumberOfDeffactsModules++;            /*===================================================*/      /* Loop through each deffacts in the current module. */      /*===================================================*/            for (theDeffacts = (struct deffacts *) GetNextDeffacts(NULL);           theDeffacts != NULL;           theDeffacts = (struct deffacts *) GetNextDeffacts(theDeffacts))        {         /*======================================================*/         /* Initialize the construct header for the binary save. */         /*======================================================*/                  MarkConstructHeaderNeededItems(&theDeffacts->header,NumberOfDeffacts++);                  /*============================================================*/         /* Count the number of expressions contained in the deffacts' */         /* assertion list and mark any atomic values contained there  */         /* as in use.                                                 */         /*============================================================*/                  ExpressionCount += ExpressionSize(theDeffacts->assertList);         MarkNeededItems(theDeffacts->assertList);        }     }  }/************************************************//* BsaveExpressions: Saves the expressions used *//*   by deffacts to the binary save file.       *//************************************************/static VOID BsaveExpressions(fp)  FILE *fp;  {   struct deffacts *theDeffacts;   struct defmodule *theModule;   /*===========================*/   /* Loop through each module. */   /*===========================*/      for (theModule = (struct defmodule *) GetNextDefmodule(NULL);        theModule != NULL;        theModule = (struct defmodule *) GetNextDefmodule(theModule))     {      /*======================================================*/      /* Set the current module to the module being examined. */      /*======================================================*/      SetCurrentModule((VOID *) theModule);            /*==================================================*/      /* Loop through each deffacts in the current module */      /* and save the assertion list expression.          */      /*==================================================*/            for (theDeffacts = (struct deffacts *) GetNextDeffacts(NULL);           theDeffacts != NULL;           theDeffacts = (struct deffacts *) GetNextDeffacts(theDeffacts))        { BsaveExpression(theDeffacts->assertList,fp); }     }  }/******************************************************//* BsaveStorage: Writes out the storage requirements  *//*    for all deffacts structures to the binary file. *//******************************************************/static VOID BsaveStorage(fp)  FILE *fp;  {   unsigned long 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,(unsigned long) sizeof(unsigned long int),fp);   GenWrite(&NumberOfDeffacts,(unsigned long) sizeof(long int),fp);   GenWrite(&NumberOfDeffactsModules,(unsigned long) sizeof(long int),fp);  }  /********************************************//* BsaveBinaryItem: Writes out all deffacts *//*   structures to the binary file.         *//********************************************/static VOID BsaveBinaryItem(fp)

⌨️ 快捷键说明

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