📄 tmpltbin.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.05 04/09/97 */ /* */ /* DEFTEMPLATE BSAVE/BLOAD MODULE */ /*******************************************************//*************************************************************//* Purpose: Implements the binary save/load feature for the *//* deftemplate construct. *//* *//* Principal Programmer(s): *//* Gary D. Riley *//* *//* Contributing Programmer(s): *//* Brian L. Donnell *//* *//* Revision History: *//* *//*************************************************************/#define _TMPLTBIN_SOURCE_#include "setup.h"#if DEFTEMPLATE_CONSTRUCT && (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME)#include <stdio.h>#define _CLIPS_STDIO_#include "clipsmem.h"#include "bload.h"#include "bsave.h"#include "factbin.h"#include "cstrnbin.h"#include "factmngr.h"#include "tmpltpsr.h"#include "tmpltdef.h"#include "tmpltutl.h"#include "tmpltbin.h"/****************************************//* GLOBAL INTERNAL VARIABLE DEFINITIONS *//****************************************/ globle struct deftemplate HUGE_ADDR *DeftemplateArray; /***************************************//* LOCAL INTERNAL VARIABLE DEFINITIONS *//***************************************/ static long NumberOfDeftemplates; static long NumberOfTemplateSlots; static long NumberOfTemplateModules; static struct templateSlot HUGE_ADDR *SlotArray; static struct deftemplateModule HUGE_ADDR *ModuleArray;/***************************************//* LOCAL INTERNAL FUNCTION DEFINITIONS *//***************************************/#if ANSI_COMPILER#if BLOAD_AND_BSAVE static VOID BsaveFind(void); static VOID BsaveStorage(FILE *); static VOID BsaveBinaryItem(FILE *);#endif static VOID BloadStorage(void); static VOID BloadBinaryItem(void); static VOID UpdateDeftemplateModule(VOID *,long); static VOID UpdateDeftemplate(VOID *,long); static VOID UpdateDeftemplateSlot(VOID *,long); static VOID ClearBload(void);#else#if BLOAD_AND_BSAVE static VOID BsaveFind(); static VOID BsaveStorage(); static VOID BsaveBinaryItem();#endif static VOID BloadStorage(); static VOID BloadBinaryItem(); static VOID UpdateDeftemplateModule(); static VOID UpdateDeftemplate(); static VOID UpdateDeftemplateSlot(); static VOID ClearBload();#endif/***********************************************//* DeftemplateBinarySetup: Installs the binary *//* save/load feature for deftemplates. *//***********************************************/globle VOID DeftemplateBinarySetup() {#if BLOAD_AND_BSAVE AddBinaryItem("deftemplate",0,BsaveFind,NULL, BsaveStorage,BsaveBinaryItem, BloadStorage,BloadBinaryItem, ClearBload);#endif#if (BLOAD || BLOAD_ONLY) AddBinaryItem("deftemplate",0,NULL,NULL,NULL,NULL, BloadStorage,BloadBinaryItem, ClearBload);#endif }#if BLOAD_AND_BSAVE/**************************************************************//* BsaveFind: Counts the number of data structures which must *//* be saved in the binary image for the deftemplates in the *//* current environment. *//**************************************************************/static VOID BsaveFind() { struct deftemplate *theDeftemplate; struct templateSlot *theSlot; 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(NumberOfDeftemplates); SaveBloadCount(NumberOfTemplateSlots); SaveBloadCount(NumberOfTemplateModules); } /*==================================================*/ /* Set the count of deftemplates, deftemplate slots */ /* and deftemplate module data structures to zero. */ /*==================================================*/ NumberOfDeftemplates = 0; NumberOfTemplateSlots = 0; NumberOfTemplateModules = 0; /*===========================*/ /* 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 and increment the number of */ /* deftemplate modules encountered. */ /*============================================*/ SetCurrentModule((VOID *) theModule); NumberOfTemplateModules++; /*======================================================*/ /* Loop through each deftemplate in the current module. */ /*======================================================*/ for (theDeftemplate = (struct deftemplate *) GetNextDeftemplate(NULL); theDeftemplate != NULL; theDeftemplate = (struct deftemplate *) GetNextDeftemplate(theDeftemplate)) { /*======================================================*/ /* Initialize the construct header for the binary save. */ /*======================================================*/ MarkConstructHeaderNeededItems(&theDeftemplate->header, NumberOfDeftemplates++); /*=============================================================*/ /* Loop through each slot in the deftemplate, incrementing the */ /* slot count and marking the slot names as needed symbols. */ /*=============================================================*/ for (theSlot = theDeftemplate->slotList; theSlot != NULL; theSlot = theSlot->next) { NumberOfTemplateSlots++; theSlot->slotName->neededSymbol = CLIPS_TRUE; } } } }/*********************************************************//* BsaveStorage: Writes out the storage requirements for *//* all deftemplate structures to the binary file. *//*********************************************************/static VOID BsaveStorage(fp) FILE *fp; { unsigned long space; /*========================================================================*/ /* Three data structures are saved as part of a deftemplate binary image: */ /* the deftemplate data structure, the deftemplateModule data structure, */ /* and the templateSlot data structure. The data structures associated */ /* with default values and constraints are not save with the deftemplate */ /* portion of the binary image. */ /*========================================================================*/ space = sizeof(long) * 3; GenWrite(&space,(unsigned long) sizeof(long int),fp); GenWrite(&NumberOfDeftemplates,(unsigned long) sizeof(long int),fp); GenWrite(&NumberOfTemplateSlots,(unsigned long) sizeof(long int),fp); GenWrite(&NumberOfTemplateModules,(unsigned long) sizeof(long int),fp); }/***********************************************//* BsaveBinaryItem: Writes out all deftemplate *//* structures to the binary file. *//***********************************************/static VOID BsaveBinaryItem(fp) FILE *fp; { unsigned long space; struct deftemplate *theDeftemplate; struct bsaveDeftemplate tempDeftemplate; struct templateSlot *theSlot; struct bsaveTemplateSlot tempTemplateSlot; struct bsaveDeftemplateModule tempTemplateModule; struct defmodule *theModule; struct deftemplateModule *theModuleItem; /*============================================================*/ /* Write out the amount of space taken up by the deftemplate, */ /* deftemplateModule, and templateSlot data structures in the */ /* binary image. */ /*============================================================*/ space = (NumberOfDeftemplates * sizeof(struct bsaveDeftemplate)) + (NumberOfTemplateSlots * sizeof(struct bsaveTemplateSlot)) + (NumberOfTemplateModules * sizeof(struct bsaveDeftemplateModule)); GenWrite(&space,(unsigned long) sizeof(unsigned long int),fp); /*===================================================*/ /* Write out each deftemplate module data structure. */ /*===================================================*/ NumberOfDeftemplates = 0; for (theModule = (struct defmodule *) GetNextDefmodule(NULL); theModule != NULL; theModule = (struct defmodule *) GetNextDefmodule(theModule)) { SetCurrentModule((VOID *) theModule); theModuleItem = (struct deftemplateModule *) GetModuleItem(NULL,FindModuleItem("deftemplate")->moduleIndex); AssignBsaveDefmdlItemHdrVals(&tempTemplateModule.header, &theModuleItem->header); GenWrite(&tempTemplateModule,(unsigned long) sizeof(struct bsaveDeftemplateModule),fp); } /*============================================*/ /* Write out each deftemplate data structure. */ /*============================================*/ NumberOfTemplateSlots = 0; for (theModule = (struct defmodule *) GetNextDefmodule(NULL); theModule != NULL; theModule = (struct defmodule *) GetNextDefmodule(theModule)) { SetCurrentModule((VOID *) theModule); for (theDeftemplate = (struct deftemplate *) GetNextDeftemplate(NULL); theDeftemplate != NULL; theDeftemplate = (struct deftemplate *) GetNextDeftemplate(theDeftemplate)) { AssignBsaveConstructHeaderVals(&tempDeftemplate.header, &theDeftemplate->header); tempDeftemplate.implied = theDeftemplate->implied; tempDeftemplate.numberOfSlots = theDeftemplate->numberOfSlots; tempDeftemplate.patternNetwork = BsaveFactPatternIndex(theDeftemplate->patternNetwork); if (theDeftemplate->slotList != NULL) { tempDeftemplate.slotList = NumberOfTemplateSlots; } else tempDeftemplate.slotList = -1L; GenWrite(&tempDeftemplate,(unsigned long) sizeof(struct bsaveDeftemplate),fp); NumberOfTemplateSlots += theDeftemplate->numberOfSlots; } } /*=============================================*/ /* Write out each templateSlot data structure. */ /*=============================================*/ for (theModule = (struct defmodule *) GetNextDefmodule(NULL); theModule != NULL; theModule = (struct defmodule *) GetNextDefmodule(theModule)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -