📄 modulbin.c
字号:
/*******************************************************/ /* "C" Language Integrated Production System */ /* */ /* CLIPS Version 6.05 04/09/97 */ /* */ /* DEFMODULE BSAVE/BLOAD MODULE */ /*******************************************************//*************************************************************//* Purpose: Implements the binary save/load feature for the *//* defmodule construct. *//* *//* Principal Programmer(s): *//* Gary D. Riley *//* *//* Contributing Programmer(s): *//* Brian L. Donnell *//* *//* Revision History: *//* *//*************************************************************/#define _MODULBIN_SOURCE_#include "setup.h"#if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME)#include <stdio.h>#define _CLIPS_STDIO_#include "clipsmem.h"#include "constrct.h"#include "moduldef.h"#include "bload.h"#include "bsave.h"#include "modulbin.h" /***************************************//* LOCAL INTERNAL VARIABLE DEFINITIONS *//***************************************/ static long NumberOfDefmodules = 0; static long NumberOfPortItems = 0; static struct portItem HUGE_ADDR *PortItemArray = NULL;/****************************************//* GLOBAL INTERNAL VARIABLE DEFINITIONS *//****************************************/ globle struct defmodule HUGE_ADDR *DefmoduleArray = NULL; /***************************************//* 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 UpdateDefmodule(VOID *,long); static VOID UpdatePortItem(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 UpdateDefmodule(); static VOID UpdatePortItem(); static VOID ClearBload();#endif/*********************************************//* DefmoduleBinarySetup: Installs the binary *//* save/load feature for defmodules. *//*********************************************/globle VOID DefmoduleBinarySetup() { AddBeforeBloadFunction("defmodule",RemoveAllDefmodules,2000);#if BLOAD_AND_BSAVE AddBinaryItem("defmodule",0,BsaveFind,NULL, BsaveStorage,BsaveBinaryItem, BloadStorage,BloadBinaryItem, ClearBload);#endif AddAbortBloadFunction("defmodule",CreateMainModule,0);#if (BLOAD || BLOAD_ONLY) AddBinaryItem("defmodule",0,NULL,NULL,NULL,NULL, BloadStorage,BloadBinaryItem, ClearBload);#endif }/**************************************************************//* UpdateDefmoduleItemHeader: Updates the values in defmodule *//* item headers for the loaded binary image. *//**************************************************************/globle VOID UpdateDefmoduleItemHeader(theBsaveHeader,theHeader,itemSize,itemArray) struct bsaveDefmoduleItemHeader *theBsaveHeader; struct defmoduleItemHeader *theHeader; int itemSize; VOID *itemArray; { long firstOffset,lastOffset; theHeader->theModule = ModulePointer(theBsaveHeader->theModule); if (theBsaveHeader->firstItem == -1L) { theHeader->firstItem = NULL; theHeader->lastItem = NULL; } else { firstOffset = itemSize * theBsaveHeader->firstItem; lastOffset = itemSize * theBsaveHeader->lastItem; theHeader->firstItem = (struct constructHeader *) &((char HUGE_ADDR *) itemArray)[firstOffset]; theHeader->lastItem = (struct constructHeader *) &((char HUGE_ADDR *) itemArray)[lastOffset]; } }#if BLOAD_AND_BSAVE/*********************************************************//* AssignBsaveDefmdlItemHdrVals: Assigns the appropriate *//* values to a bsave defmodule item header record. *//*********************************************************/globle VOID AssignBsaveDefmdlItemHdrVals(theBsaveHeader,theHeader) struct bsaveDefmoduleItemHeader *theBsaveHeader; struct defmoduleItemHeader *theHeader; { theBsaveHeader->theModule = theHeader->theModule->bsaveID; if (theHeader->firstItem == NULL) { theBsaveHeader->firstItem = -1L; theBsaveHeader->lastItem = -1L; } else { theBsaveHeader->firstItem = theHeader->firstItem->bsaveID; theBsaveHeader->lastItem = theHeader->lastItem->bsaveID; } }/**********************************************************//* BsaveFind: Counts the number of data structures which *//* must be saved in the binary image for the defmodules *//* in the current environment. *//**********************************************************/static VOID BsaveFind() { struct defmodule *defmodulePtr; struct portItem *theList; /*=======================================================*/ /* 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(NumberOfDefmodules); SaveBloadCount(NumberOfPortItems); } /*==========================================*/ /* Set the count of defmodule and defmodule */ /* port items data structures to zero. */ /*==========================================*/ NumberOfDefmodules = 0; NumberOfPortItems = 0; /*===========================*/ /* Loop through each module. */ /*===========================*/ for (defmodulePtr = (struct defmodule *) GetNextDefmodule(NULL); defmodulePtr != NULL; defmodulePtr = (struct defmodule *) GetNextDefmodule(defmodulePtr)) { /*==============================================*/ /* Increment the number of modules encountered. */ /*==============================================*/ NumberOfDefmodules++; /*===========================*/ /* Mark the defmodule's name */ /* as being a needed symbol. */ /*===========================*/ defmodulePtr->name->neededSymbol = CLIPS_TRUE; /*==============================================*/ /* Loop through each of the port items in the */ /* defmodule's import list incrementing the */ /* number of port items encountered and marking */ /* needed symbols. */ /*==============================================*/ for (theList = defmodulePtr->importList; theList != NULL; theList = theList->next) { NumberOfPortItems++; if (theList->moduleName != NULL) { theList->moduleName->neededSymbol = CLIPS_TRUE; } if (theList->constructType != NULL) { theList->constructType->neededSymbol = CLIPS_TRUE; } if (theList->constructName != NULL) { theList->constructName->neededSymbol = CLIPS_TRUE; } } /*==============================================*/ /* Loop through each of the port items in the */ /* defmodule's export list incrementing the */ /* number of port items encountered and marking */ /* needed symbols. */ /*==============================================*/ for (theList = defmodulePtr->exportList; theList != NULL; theList = theList->next) { NumberOfPortItems++; if (theList->moduleName != NULL) { theList->moduleName->neededSymbol = CLIPS_TRUE; } if (theList->constructType != NULL) { theList->constructType->neededSymbol = CLIPS_TRUE; } if (theList->constructName != NULL) { theList->constructName->neededSymbol = CLIPS_TRUE; } } } }/*********************************************************//* BsaveStorage: Writes out the storage requirements for *//* all defmodule structures to the binary file. *//*********************************************************/static VOID BsaveStorage(fp) FILE *fp; { unsigned long space; space = sizeof(long) * 2; GenWrite(&space,(unsigned long) sizeof(unsigned long int),fp); GenWrite(&NumberOfDefmodules,(unsigned long) sizeof(long int),fp); GenWrite(&NumberOfPortItems,(unsigned long) sizeof(long int),fp); } /*********************************************//* BsaveBinaryItem: Writes out all defmodule *//* structures to the binary file. *//*********************************************/static VOID BsaveBinaryItem(fp) FILE *fp; { unsigned long int space; struct defmodule *defmodulePtr; struct bsaveDefmodule newDefmodule; struct bsavePortItem newPortItem; struct portItem *theList; /*=========================================================*/ /* Write out the amount of space taken up by the defmodule */ /* and port item data structures in the binary image. */ /*=========================================================*/ space = NumberOfDefmodules * sizeof(struct bsaveDefmodule); space += NumberOfPortItems * sizeof(struct bsavePortItem); GenWrite(&space,(unsigned long) sizeof(unsigned long int),fp); /*==========================================*/ /* Write out each defmodule data structure. */ /*==========================================*/ NumberOfDefmodules = 0; NumberOfPortItems = 0; for (defmodulePtr = (struct defmodule *) GetNextDefmodule(NULL); defmodulePtr != NULL; defmodulePtr = (struct defmodule *) GetNextDefmodule(defmodulePtr)) { newDefmodule.name = (unsigned long) defmodulePtr->name->bucket; NumberOfDefmodules++; if (defmodulePtr->next != NULL) { newDefmodule.next = NumberOfDefmodules; } else { newDefmodule.next = -1L; } if (defmodulePtr->importList == NULL) { newDefmodule.importList = -1L; } else { newDefmodule.importList = NumberOfPortItems; for (theList = defmodulePtr->importList;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -