?? dffnxbin.c
字號:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.22 06/15/04 */ /* */ /* */ /*******************************************************//*************************************************************//* 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 "memalloc.h"#include "cstrcbin.h"#include "envrnmnt.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 BLOAD_AND_BSAVEstatic void BsaveDeffunctionFind(void *);static void MarkDeffunctionItems(void *,struct constructHeader *,void *);static void BsaveDeffunctionExpressions(void *,FILE *);static void BsaveDeffunctionExpression(void *,struct constructHeader *,void *);static void BsaveStorageDeffunctions(void *,FILE *);static void BsaveDeffunctions(void *,FILE *);static void BsaveDeffunction(void *,struct constructHeader *,void *);#endifstatic void BloadStorageDeffunctions(void *);static void BloadDeffunctions(void *);static void UpdateDeffunctionModule(void *,void *,long);static void UpdateDeffunction(void *,void *,long);static void ClearDeffunctionBload(void *);static void DeallocateDeffunctionBloadData(void *);/* ========================================= ***************************************** 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( void *theEnv) { AllocateEnvironmentData(theEnv,DFFNXBIN_DATA,sizeof(struct deffunctionBinaryData),DeallocateDeffunctionBloadData);#if BLOAD_AND_BSAVE AddBinaryItem(theEnv,"deffunctions",0,BsaveDeffunctionFind,BsaveDeffunctionExpressions, BsaveStorageDeffunctions,BsaveDeffunctions, BloadStorageDeffunctions,BloadDeffunctions, ClearDeffunctionBload);#else AddBinaryItem(theEnv,"deffunctions",0,NULL,NULL,NULL,NULL, BloadStorageDeffunctions,BloadDeffunctions, ClearDeffunctionBload);#endif } /***********************************************************//* DeallocateDeffunctionBloadData: Deallocates environment *//* data for the deffunction bsave functionality. *//***********************************************************/static void DeallocateDeffunctionBloadData( void *theEnv) { size_t space;#if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME) space = DeffunctionBinaryData(theEnv)->DeffunctionCount * sizeof(struct deffunctionStruct); if (space != 0) genfree(theEnv,(void *) DeffunctionBinaryData(theEnv)->DeffunctionArray,space); space = DeffunctionBinaryData(theEnv)->ModuleCount * sizeof(struct deffunctionModule); if (space != 0) genfree(theEnv,(void *) DeffunctionBinaryData(theEnv)->ModuleArray,space);#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( void *theEnv, int theIndex) { return ((void *) &DeffunctionBinaryData(theEnv)->ModuleArray[theIndex]); }/* ========================================= ***************************************** 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( void *theEnv) { SaveBloadCount(theEnv,DeffunctionBinaryData(theEnv)->ModuleCount); SaveBloadCount(theEnv,DeffunctionBinaryData(theEnv)->DeffunctionCount); DeffunctionBinaryData(theEnv)->DeffunctionCount = 0L; DeffunctionBinaryData(theEnv)->ModuleCount = DoForAllConstructs(theEnv,MarkDeffunctionItems,DeffunctionData(theEnv)->DeffunctionModuleIndex, 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( void *theEnv, struct constructHeader *theDeffunction, void *userBuffer) {#if MAC_MCW || IBM_MCW || MAC_XCD#pragma unused(userBuffer)#endif MarkConstructHeaderNeededItems(theDeffunction,DeffunctionBinaryData(theEnv)->DeffunctionCount++); ExpressionData(theEnv)->ExpressionCount += ExpressionSize(((DEFFUNCTION *) theDeffunction)->code); MarkNeededItems(theEnv,((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( void *theEnv, FILE *fp) { DoForAllConstructs(theEnv,BsaveDeffunctionExpression,DeffunctionData(theEnv)->DeffunctionModuleIndex, 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( void *theEnv, struct constructHeader *theDeffunction, void *userBuffer) { BsaveExpression(theEnv,((DEFFUNCTION *) theDeffunction)->code,(FILE *) userBuffer); }/*********************************************************** NAME : BsaveStorageDeffunctions DESCRIPTION : Writes out number of each type of structure required for deffunctions Space required for counts (unsigned long)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -