📄 dffnxbin.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.05 04/09/97 */ /* */ /* */ /*******************************************************//*************************************************************//* Purpose: Binary Load/Save Functions for Deffunctions *//* *//* Principal Programmer(s): *//* Brian L. Donnell *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//* *//*************************************************************/ /* ========================================= ***************************************** EXTERNAL DEFINITIONS ========================================= ***************************************** */#include "setup.h"#if DEFFUNCTION_CONSTRUCT && (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE)#include "bload.h"#include "bsave.h"#include "clipsmem.h"#include "cstrcbin.h"#include "modulbin.h"#define _DFFNXBIN_SOURCE_#include "dffnxbin.h"/* ========================================= ***************************************** CONSTANTS ========================================= ***************************************** */ /* ========================================= ***************************************** MACROS AND TYPES ========================================= ***************************************** */typedef struct bsaveDeffunctionModule { struct bsaveDefmoduleItemHeader header; } BSAVE_DEFFUNCTION_MODULE; typedef struct bsaveDeffunctionStruct { struct bsaveConstructHeader header; int minNumberOfParameters, maxNumberOfParameters, numberOfLocalVars; long name, code; } BSAVE_DEFFUNCTION; /* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTION HEADERS ========================================= ***************************************** */#if ANSI_COMPILER#if BLOAD_AND_BSAVEstatic VOID BsaveDeffunctionFind(void);static VOID MarkDeffunctionItems(struct constructHeader *,VOID *);static VOID BsaveDeffunctionExpressions(FILE *);static VOID BsaveDeffunctionExpression(struct constructHeader *,VOID *);static VOID BsaveStorageDeffunctions(FILE *);static VOID BsaveDeffunctions(FILE *);static VOID BsaveDeffunction(struct constructHeader *,VOID *);#endifstatic VOID BloadStorageDeffunctions(void);static VOID BloadDeffunctions(void);static VOID UpdateDeffunctionModule(VOID *,long);static VOID UpdateDeffunction(VOID *,long);static VOID ClearDeffunctionBload(void);#else#if BLOAD_AND_BSAVEstatic VOID BsaveDeffunctionFind();static VOID MarkDeffunctionItems();static VOID BsaveDeffunctionExpressions();static VOID BsaveDeffunctionExpression();static VOID BsaveStorageDeffunctions();static VOID BsaveDeffunctions();static VOID BsaveDeffunction();#endifstatic VOID BloadStorageDeffunctions();static VOID BloadDeffunctions();static VOID UpdateDeffunctionModule();static VOID UpdateDeffunction();static VOID ClearDeffunctionBload();#endif /* ========================================= ***************************************** EXTERNALLY VISIBLE GLOBAL VARIABLES ========================================= ***************************************** */globle DEFFUNCTION HUGE_ADDR *deffunctionArray = NULL;/* ========================================= ***************************************** INTERNALLY VISIBLE GLOBAL VARIABLES ========================================= ***************************************** */static long DeffunctionCount = 0L, ModuleCount = 0L;static DEFFUNCTION_MODULE HUGE_ADDR *ModuleArray;/* ========================================= ***************************************** EXTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** */ /*********************************************************** NAME : SetupDeffunctionsBload DESCRIPTION : Initializes data structures and routines for binary loads of deffunctions INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Routines defined and structures initialized NOTES : None ***********************************************************/globle VOID SetupDeffunctionsBload() {#if BLOAD_AND_BSAVE AddBinaryItem("deffunctions",0,BsaveDeffunctionFind,BsaveDeffunctionExpressions, BsaveStorageDeffunctions,BsaveDeffunctions, BloadStorageDeffunctions,BloadDeffunctions, ClearDeffunctionBload);#else AddBinaryItem("deffunctions",0,NULL,NULL,NULL,NULL, BloadStorageDeffunctions,BloadDeffunctions, ClearDeffunctionBload);#endif } /*************************************************** NAME : BloadDeffunctionModuleReference DESCRIPTION : Returns a pointer to the appropriate deffunction module INPUTS : The index of the module RETURNS : A pointer to the module SIDE EFFECTS : None NOTES : None ***************************************************/globle VOID *BloadDeffunctionModuleReference(index) int index; { return ((VOID *) &ModuleArray[index]); }/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** */#if BLOAD_AND_BSAVE/*************************************************************************** NAME : BsaveDeffunctionFind DESCRIPTION : For all deffunctions, this routine marks all the needed symbols. Also, it also counts the number of expression structures needed. Also, counts total number of deffunctions. INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : ExpressionCount (a global from BSAVE.C) is incremented for every expression needed Symbols are marked in their structures NOTES : Also sets bsaveIndex for each deffunction (assumes deffunctions will be bsaved in order of binary list) ***************************************************************************/static VOID BsaveDeffunctionFind() { if (Bloaded()) { SaveBloadCount(ModuleCount); SaveBloadCount(DeffunctionCount); } DeffunctionCount = 0L; ModuleCount = DoForAllConstructs(MarkDeffunctionItems,DeffunctionModuleIndex, CLIPS_FALSE,NULL); } /*************************************************** NAME : MarkDeffunctionItems DESCRIPTION : Marks the needed items for a deffunction bsave INPUTS : 1) The deffunction 2) User data buffer (ignored) RETURNS : Nothing useful SIDE EFFECTS : Needed items marked NOTES : None ***************************************************/#if IBM_TBC#pragma argsused#endifstatic VOID MarkDeffunctionItems(theDeffunction,userBuffer) struct constructHeader *theDeffunction; VOID *userBuffer; {#if MAC_MPW || MAC_MCW#pragma unused(userBuffer)#endif MarkConstructHeaderNeededItems(theDeffunction,DeffunctionCount++); ExpressionCount += ExpressionSize(((DEFFUNCTION *) theDeffunction)->code); MarkNeededItems(((DEFFUNCTION *) theDeffunction)->code); }/*************************************************** NAME : BsaveDeffunctionExpressions DESCRIPTION : Writes out all expressions needed by deffunctyions INPUTS : The file pointer of the binary file RETURNS : Nothing useful SIDE EFFECTS : File updated NOTES : None ***************************************************/static VOID BsaveDeffunctionExpressions(fp) FILE *fp; { DoForAllConstructs(BsaveDeffunctionExpression,DeffunctionModuleIndex, CLIPS_FALSE,(VOID *) fp); } /*************************************************** NAME : BsaveDeffunctionExpression DESCRIPTION : Saves the needed expressions for a deffunction bsave INPUTS : 1) The deffunction 2) Output data file pointer RETURNS : Nothing useful SIDE EFFECTS : Expressions saved NOTES : None ***************************************************/static VOID BsaveDeffunctionExpression(theDeffunction,userBuffer) struct constructHeader *theDeffunction; VOID *userBuffer; { BsaveExpression(((DEFFUNCTION *) theDeffunction)->code,(FILE *) userBuffer); }/***********************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -