?? dfinsbin.c
字號:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.22 06/15/04 */ /* */ /* */ /*******************************************************//*************************************************************//* Purpose: Binary Load/Save Functions for Definstances *//* *//* Principal Programmer(s): *//* Brian L. Donnell *//* *//* Contributing Programmer(s): *//* *//* Revision History: *//* *//*************************************************************//* ========================================= ***************************************** EXTERNAL DEFINITIONS ========================================= ***************************************** */#include "setup.h"#if DEFINSTANCES_CONSTRUCT && (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE)#include "bload.h"#include "bsave.h"#include "envrnmnt.h"#include "memalloc.h"#include "cstrcbin.h"#include "defins.h"#include "modulbin.h"#define _DFINSBIN_SOURCE_#include "dfinsbin.h"/* ========================================= ***************************************** CONSTANTS ========================================= ***************************************** *//* ========================================= ***************************************** MACROS AND TYPES ========================================= ***************************************** */typedef struct bsaveDefinstancesModule { struct bsaveDefmoduleItemHeader header; } BSAVE_DEFINSTANCES_MODULE;typedef struct bsaveDefinstances { struct bsaveConstructHeader header; long mkinstance; } BSAVE_DEFINSTANCES;/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTION HEADERS ========================================= ***************************************** */#if BLOAD_AND_BSAVEstatic void BsaveDefinstancesFind(void *);static void MarkDefinstancesItems(void *,struct constructHeader *,void *);static void BsaveDefinstancesExpressions(void *,FILE *);static void BsaveDefinstancesExpression(void *,struct constructHeader *,void *);static void BsaveStorageDefinstances(void *,FILE *);static void BsaveDefinstancesDriver(void *,FILE *);static void BsaveDefinstances(void *,struct constructHeader *,void *);#endifstatic void BloadStorageDefinstances(void *);static void BloadDefinstances(void *);static void UpdateDefinstancesModule(void *,void *,long);static void UpdateDefinstances(void *,void *,long);static void ClearDefinstancesBload(void *);static void DeallocateDefinstancesBinaryData(void *);/* ========================================= ***************************************** EXTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** *//*********************************************************** NAME : SetupDefinstancesBload DESCRIPTION : Initializes data structures and routines for binary loads of definstances INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Routines defined and structures initialized NOTES : None ***********************************************************/globle void SetupDefinstancesBload( void *theEnv) { AllocateEnvironmentData(theEnv,DFINSBIN_DATA,sizeof(struct definstancesBinaryData),DeallocateDefinstancesBinaryData);#if BLOAD_AND_BSAVE AddBinaryItem(theEnv,"definstances",0,BsaveDefinstancesFind,BsaveDefinstancesExpressions, BsaveStorageDefinstances,BsaveDefinstancesDriver, BloadStorageDefinstances,BloadDefinstances, ClearDefinstancesBload);#else AddBinaryItem(theEnv,"definstances",0,NULL,NULL,NULL,NULL, BloadStorageDefinstances,BloadDefinstances, ClearDefinstancesBload);#endif } /*************************************************************//* DeallocateDefinstancesBinaryData: Deallocates environment *//* data for the definstances binary functionality. *//*************************************************************/static void DeallocateDefinstancesBinaryData( void *theEnv) { size_t space;#if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME) space = DefinstancesBinaryData(theEnv)->DefinstancesCount * sizeof(struct definstances); if (space != 0) genfree(theEnv,(void *) DefinstancesBinaryData(theEnv)->DefinstancesArray,space); space = DefinstancesBinaryData(theEnv)->ModuleCount * sizeof(struct definstancesModule); if (space != 0) genfree(theEnv,(void *) DefinstancesBinaryData(theEnv)->ModuleArray,space);#endif }/*************************************************** NAME : BloadDefinstancesModuleRef DESCRIPTION : Returns a pointer to the appropriate definstances module INPUTS : The index of the module RETURNS : A pointer to the module SIDE EFFECTS : None NOTES : None ***************************************************/globle void *BloadDefinstancesModuleRef( void *theEnv, int theIndex) { return ((void *) &DefinstancesBinaryData(theEnv)->ModuleArray[theIndex]); }/* ========================================= ***************************************** INTERNALLY VISIBLE FUNCTIONS ========================================= ***************************************** */#if BLOAD_AND_BSAVE/*************************************************************************** NAME : BsaveDefinstancesFind DESCRIPTION : For all definstances, this routine marks all the needed symbols. Also, it also counts the number of expression structures needed. Also, counts total number of definstances. 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 definstances (assumes definstances will be bsaved in order of binary list) ***************************************************************************/static void BsaveDefinstancesFind( void *theEnv) { SaveBloadCount(theEnv,DefinstancesBinaryData(theEnv)->ModuleCount); SaveBloadCount(theEnv,DefinstancesBinaryData(theEnv)->DefinstancesCount); DefinstancesBinaryData(theEnv)->DefinstancesCount = 0L; DefinstancesBinaryData(theEnv)->ModuleCount = DoForAllConstructs(theEnv,MarkDefinstancesItems,DefinstancesData(theEnv)->DefinstancesModuleIndex, FALSE,NULL); }/*************************************************** NAME : MarkDefinstancesItems DESCRIPTION : Marks the needed items for a definstances bsave INPUTS : 1) The definstances 2) User data buffer (ignored) RETURNS : Nothing useful SIDE EFFECTS : Needed items marked NOTES : None ***************************************************/#if IBM_TBC#pragma argsused#endifstatic void MarkDefinstancesItems( void *theEnv, struct constructHeader *theDefinstances, void *userBuffer) {#if MAC_MCW || IBM_MCW || MAC_XCD#pragma unused(userBuffer)#endif MarkConstructHeaderNeededItems(theDefinstances,DefinstancesBinaryData(theEnv)->DefinstancesCount++); ExpressionData(theEnv)->ExpressionCount += ExpressionSize(((DEFINSTANCES *) theDefinstances)->mkinstance); MarkNeededItems(theEnv,((DEFINSTANCES *) theDefinstances)->mkinstance); }/*************************************************** NAME : BsaveDefinstancesExpressions 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 BsaveDefinstancesExpressions( void *theEnv, FILE *fp) { DoForAllConstructs(theEnv,BsaveDefinstancesExpression,DefinstancesData(theEnv)->DefinstancesModuleIndex, FALSE,(void *) fp); }/*************************************************** NAME : BsaveDefinstancesExpression DESCRIPTION : Saves the needed expressions for a definstances bsave INPUTS : 1) The definstances 2) Output data file pointer RETURNS : Nothing useful SIDE EFFECTS : Expressions saved NOTES : None ***************************************************/static void BsaveDefinstancesExpression( void *theEnv, struct constructHeader *theDefinstances, void *userBuffer) { BsaveExpression(theEnv,((DEFINSTANCES *) theDefinstances)->mkinstance,(FILE *) userBuffer); }/***********************************************************
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -