📄 rulebin.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.05 04/09/97 */ /* */ /* DEFRULE BSAVE/BLOAD MODULE */ /*******************************************************//*************************************************************//* Purpose: Implements the binary save/load feature for the *//* defrule construct. *//* *//* Principal Programmer(s): *//* Gary D. Riley *//* *//* Contributing Programmer(s): *//* Brian L. Donnell *//* Barry Cameron *//* *//* Revision History: *//* *//*************************************************************/#define _RULEBIN_SOURCE_#include "setup.h"#if DEFRULE_CONSTRUCT && (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME)#include <stdio.h>#define _CLIPS_STDIO_#include <string.h>#include "clipsmem.h"#include "bload.h"#include "bsave.h"#include "reteutil.h"#include "agenda.h"#include "engine.h"#include "rulebsc.h"#include "pattern.h"#include "moduldef.h"#include "rulebin.h"/***************************************//* LOCAL INTERNAL VARIABLE DEFINITIONS *//***************************************/ static long NumberOfDefruleModules; static long NumberOfDefrules; static long NumberOfJoins; static struct defruleModule HUGE_ADDR *ModuleArray; static struct defrule HUGE_ADDR *DefruleArray; static struct joinNode HUGE_ADDR *JoinArray;/***************************************//* 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 *); static VOID BsaveJoins(FILE *); static VOID BsaveJoin(FILE *,struct joinNode *); static VOID BsaveDisjuncts(FILE *,struct defrule *);#endif static VOID BloadStorage(void); static VOID BloadBinaryItem(void); static VOID UpdateDefruleModule(VOID *,long); static VOID UpdateDefrule(VOID *,long); static VOID UpdateJoin(VOID *,long); static VOID ClearBload(void);#else#if BLOAD_AND_BSAVE static VOID BsaveFind(); static VOID BsaveExpressions(); static VOID BsavePatternExpressions(); static VOID BsaveStorage(); static VOID BsaveBinaryItem(); static VOID BsaveJoins(); static VOID BsaveJoin(); static VOID BsaveDisjuncts();#endif static VOID BloadStorage(); static VOID BloadBinaryItem(); static VOID UpdateDefruleModule(); static VOID UpdateDefrule(); static VOID UpdateJoin(); static VOID ClearBload();#endif/*****************************************************//* DefruleBinarySetup: Installs the binary save/load *//* feature for the defrule construct. *//*****************************************************/globle VOID DefruleBinarySetup() {#if BLOAD_AND_BSAVE AddBinaryItem("defrule",20,BsaveFind,BsaveExpressions, BsaveStorage,BsaveBinaryItem, BloadStorage,BloadBinaryItem, ClearBload);#endif#if BLOAD || BLOAD_ONLY AddBinaryItem("defrule",20,NULL,NULL,NULL,NULL, BloadStorage,BloadBinaryItem, ClearBload);#endif } #if BLOAD_AND_BSAVE/*************************************************************//* BsaveFind: Determines the amount of memory needed to save *//* the defrule and joinNode data structures in addition to *//* the memory needed for their associated expressions. *//*************************************************************/static VOID BsaveFind() { struct defrule *theDefrule, *theDisjunct; 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(NumberOfDefruleModules); SaveBloadCount(NumberOfDefrules); SaveBloadCount(NumberOfJoins); } /*====================================================*/ /* Set the binary save ID for defrule data structures */ /* and count the number of each type. */ /*====================================================*/ TagRuleNetwork(&NumberOfDefruleModules,&NumberOfDefrules,&NumberOfJoins); /*===========================*/ /* 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 defrule in the current module. */ /*==================================================*/ for (theDefrule = (struct defrule *) GetNextDefrule(NULL); theDefrule != NULL; theDefrule = (struct defrule *) GetNextDefrule(theDefrule)) { /*================================================*/ /* Initialize the construct header for the binary */ /* save. The binary save ID has already been set. */ /*================================================*/ MarkConstructHeaderNeededItems(&theDefrule->header,theDefrule->header.bsaveID); /*===========================================*/ /* Count and mark data structures associated */ /* with dynamic salience. */ /*===========================================*/ #if DYNAMIC_SALIENCE ExpressionCount += ExpressionSize(theDefrule->dynamicSalience); MarkNeededItems(theDefrule->dynamicSalience);#endif /*==========================================*/ /* Loop through each disjunct of the rule */ /* counting and marking the data structures */ /* associated with RHS actions. */ /*==========================================*/ for (theDisjunct = theDefrule; theDisjunct != NULL; theDisjunct = theDisjunct->disjunct) { ExpressionCount += ExpressionSize(theDisjunct->actions); MarkNeededItems(theDisjunct->actions); } } } /*===============================*/ /* Reset the bsave tags assigned */ /* to defrule data structures. */ /*===============================*/ MarkRuleNetwork(1); }/************************************************//* BsaveExpressions: Saves the expressions used *//* by defrules to the binary save file. *//************************************************/static VOID BsaveExpressions(fp) FILE *fp; { struct defrule *theDefrule, *theDisjunct; 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 defrule in the current module. */ /*==================================================*/ for (theDefrule = (struct defrule *) GetNextDefrule(NULL); theDefrule != NULL; theDefrule = (struct defrule *) GetNextDefrule(theDefrule)) { /*===========================================*/ /* Save the dynamic salience of the defrule. */ /*===========================================*/ #if DYNAMIC_SALIENCE BsaveExpression(theDefrule->dynamicSalience,fp);#endif /*===================================*/ /* Loop through each disjunct of the */ /* defrule and save its RHS actions. */ /*===================================*/ for (theDisjunct = theDefrule; theDisjunct != NULL; theDisjunct = theDisjunct->disjunct) { BsaveExpression(theDisjunct->actions,fp); } } } /*==============================*/ /* Set the marked flag for each */ /* join in the join network. */ /*==============================*/ MarkRuleNetwork(1); } /*****************************************************//* BsaveStorage: Writes out storage requirements for *//* all defrule structures to the binary file *//*****************************************************/static VOID BsaveStorage(fp) FILE *fp; { unsigned long space; space = sizeof(long) * 3; GenWrite(&space,(unsigned long) sizeof(unsigned long int),fp); GenWrite(&NumberOfDefruleModules,(unsigned long) sizeof(long int),fp); GenWrite(&NumberOfDefrules,(unsigned long) sizeof(long int),fp); GenWrite(&NumberOfJoins,(unsigned long) sizeof(long int),fp); }/*******************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -