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

📄 factbin.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.30  10/19/06            */   /*                                                     */   /*                FACT BSAVE/BLOAD MODULE              */   /*******************************************************//*************************************************************//* Purpose: Implements the binary save/load feature for the  *//*    fact pattern network.                                  *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*                                                           *//* Contributing Programmer(s):                               *//*      Brian L. Donnell                                     *//*                                                           *//* Revision History:                                         *//*                                                           *//*      6.30: Added support for hashed alpha memories.       *//*                                                           *//*************************************************************/#define _FACTBIN_SOURCE_#include "setup.h"#if DEFTEMPLATE_CONSTRUCT && (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME)#include <stdio.h>#define _STDIO_INCLUDED_#include "memalloc.h"#include "tmpltdef.h"#include "bload.h"#include "bsave.h"#include "reteutil.h"#include "rulebin.h"#include "moduldef.h"#include "envrnmnt.h"#include "factbin.h"/********************************************//* INTERNAL DATA STRUCTURES AND DEFINITIONS *//********************************************/struct bsaveFactPatternNode  {   struct bsavePatternNodeHeader header;   unsigned short whichSlot;   unsigned short whichField;   unsigned short leaveFields;   long networkTest;   long nextLevel;   long lastLevel;   long leftNode;   long rightNode;  };#define BSAVE_FIND         0#define BSAVE_PATTERNS     1/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if BLOAD_AND_BSAVE   static void                    BsaveDriver(void *,int,FILE *,struct factPatternNode *);   static void                    BsaveFind(void *);   static void                    BsaveStorage(void *,FILE *);   static void                    BsaveFactPatterns(void *,FILE *);   static void                    BsavePatternNode(void *,struct factPatternNode *,FILE *);#endif   static void                    BloadStorage(void *);   static void                    BloadBinaryItem(void *);   static void                    UpdateFactPatterns(void *,void *,long);   static void                    ClearBload(void *);   static void                    DeallocateFactBloadData(void *);/*****************************************************//* FactBinarySetup: Initializes the binary load/save *//*   feature for the fact pattern network.           *//*****************************************************/globle void FactBinarySetup(  void *theEnv)  {   AllocateEnvironmentData(theEnv,FACTBIN_DATA,sizeof(struct factBinaryData),DeallocateFactBloadData);   #if BLOAD_AND_BSAVE   AddBinaryItem(theEnv,"facts",0,BsaveFind,NULL,                            BsaveStorage,BsaveFactPatterns,                            BloadStorage,BloadBinaryItem,                            ClearBload);#endif#if BLOAD || BLOAD_ONLY   AddBinaryItem(theEnv,"facts",0,NULL,NULL,NULL,NULL,                            BloadStorage,BloadBinaryItem,                            ClearBload);#endif  }  /****************************************************//* DeallocateFactBloadData: Deallocates environment *//*    data for the fact bsave functionality.        *//****************************************************/static void DeallocateFactBloadData(  void *theEnv)  {   size_t space;   int i;      for (i = 0; i < FactBinaryData(theEnv)->NumberOfPatterns; i++)     { DestroyAlphaMemory(theEnv,&FactBinaryData(theEnv)->FactPatternArray[i].header,FALSE); }   space = FactBinaryData(theEnv)->NumberOfPatterns * sizeof(struct factPatternNode);   if (space != 0) genfree(theEnv,(void *) FactBinaryData(theEnv)->FactPatternArray,space);  }#if BLOAD_AND_BSAVE/*********************************************************//* BsaveFind: Counts the number of data structures which *//*   must be saved in the binary image for the fact      *//*   pattern network in the current environment.         *//*********************************************************/static void BsaveFind(  void *theEnv)  {   struct deftemplate *theDeftemplate;   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,FactBinaryData(theEnv)->NumberOfPatterns);   /*=======================================*/   /* Set the count of fact pattern network */   /* data structures to zero.              */   /*=======================================*/   FactBinaryData(theEnv)->NumberOfPatterns = 0L;   /*===========================*/   /* 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 deftemplate in the current module */      /* and count the number of data structures which must  */      /* be saved for its pattern network.                   */      /*=====================================================*/      for (theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,NULL);           theDeftemplate != NULL;           theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,theDeftemplate))        { BsaveDriver(theEnv,BSAVE_FIND,NULL,theDeftemplate->patternNetwork); }     }  }/**********************************************************//* BsaveDriver: Binary save driver routine which handles  *//*   both finding/marking the data structures to be saved *//*   and saving the data structures to a file.            *//**********************************************************/static void BsaveDriver(  void *theEnv,  int action,  FILE *fp,  struct factPatternNode *thePattern)  {   while (thePattern != NULL)     {      switch(action)        {         case BSAVE_FIND:           thePattern->bsaveID = FactBinaryData(theEnv)->NumberOfPatterns++;           break;         case BSAVE_PATTERNS:           BsavePatternNode(theEnv,thePattern,fp);           break;         default:           break;        }      if (thePattern->nextLevel == NULL)        {         while (thePattern->rightNode == NULL)           {            thePattern = thePattern->lastLevel;            if (thePattern == NULL) return;           }         thePattern = thePattern->rightNode;        }      else        { thePattern = thePattern->nextLevel; }     }  }/*********************************************************//* BsaveStorage: Writes out storage requirements for all *//*   factPatternNode data structures to the binary file  */

⌨️ 快捷键说明

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