static void BsaveBinaryItem( FILE *fp) { unsigned long int space; struct defrule *theDefrule; #if FUZZY_DEFTEMPLATES struct defrule *theDisjunct; #endif struct defmodule *theModule; struct defruleModule *theModuleItem; struct bsaveDefruleModule tempDefruleModule; #if CERTAINTY_FACTORS long int disjunctExpressionCountCF = 0L; #endif /*===============================================*/ /* Write out the space required by the defrules. */ /*===============================================*/ space = (NumberOfDefrules * sizeof(struct bsaveDefrule)) + (NumberOfJoins * sizeof(struct bsaveJoinNode)) + #if FUZZY_DEFTEMPLATES (NumberOfPatternFuzzyValues * sizeof(struct fzSlotLocator)) + #endif (NumberOfDefruleModules * sizeof(struct bsaveDefruleModule)); GenWrite(&space,(unsigned long) sizeof(unsigned long int),fp); /*===============================================*/ /* Write out each defrule module data structure. */ /*===============================================*/ NumberOfDefrules = 0; #if FUZZY_DEFTEMPLATES NumberOfPatternFuzzyValues = 0; #endif for (theModule = (struct defmodule *) GetNextDefmodule(NULL); theModule != NULL; theModule = (struct defmodule *) GetNextDefmodule(theModule)) { SetCurrentModule((void *) theModule); theModuleItem = (struct defruleModule *) GetModuleItem(NULL,FindModuleItem("defrule")->moduleIndex); AssignBsaveDefmdlItemHdrVals(&tempDefruleModule.header, &theModuleItem->header); GenWrite(&tempDefruleModule,(unsigned long) sizeof(struct bsaveDefruleModule),fp); } /*========================================*/ /* Write out each defrule data structure. */ /*========================================*/ for (theModule = (struct defmodule *) GetNextDefmodule(NULL); theModule != NULL; theModule = (struct defmodule *) GetNextDefmodule(theModule)) { SetCurrentModule((void *) theModule); for (theDefrule = (struct defrule *) GetNextDefrule(NULL); theDefrule != NULL; theDefrule = (struct defrule *) GetNextDefrule(theDefrule)) { BsaveDisjuncts(fp,theDefrule); } } #if FUZZY_DEFTEMPLATES /*====================================*/ /* Write out the PatternFuzzyValues . */ /*====================================*/ theModule = (struct defmodule *) GetNextDefmodule(NULL); while (theModule != NULL) { SetCurrentModule((VOID *) theModule); theDefrule = (struct defrule *) GetNextDefrule(NULL); while (theDefrule != NULL) { theDisjunct = theDefrule; while (theDisjunct != NULL) { int i; struct bsaveFzSlotLocator tempFZSlotLocator; for (i=0; i<theDisjunct->numberOfFuzzySlots; i++) { FUZZY_VALUE_HN *fvhnPtr; struct fzSlotLocator *fvSLPtr; fvSLPtr = theDisjunct->pattern_fv_arrayPtr + i; fvhnPtr = fvSLPtr->fvhnPtr; tempFZSlotLocator.patternNum = fvSLPtr->patternNum; tempFZSlotLocator.slotNum = fvSLPtr->slotNum; tempFZSlotLocator.fvhnPtr = fvhnPtr->bucket; GenWrite(&tempFZSlotLocator,(unsigned long) sizeof(struct bsaveFzSlotLocator),fp); } theDisjunct = theDisjunct->disjunct; } theDefrule = (struct defrule *) GetNextDefrule(theDefrule); } theModule = (struct defmodule *) GetNextDefmodule(theModule); } #endif /*=============================*/ /* Write out the Rete Network. */ /*=============================*/ MarkRuleNetwork(1); BsaveJoins(fp); /*=============================================================*/ /* If a binary image was already loaded when the bsave command */ /* was issued, then restore the counts indicating the number */ /* of defrules, defrule modules, and joins in the binary image */ /* (these were overwritten by the binary save). */ /*=============================================================*/ if (Bloaded()) { RestoreBloadCount(&NumberOfDefruleModules); RestoreBloadCount(&NumberOfDefrules); RestoreBloadCount(&NumberOfJoins); #if FUZZY_DEFTEMPLATES RestoreBloadCount(&NumberOfPatternFuzzyValues); #endif } }
static void BsaveBinaryItem( void *theEnv, FILE *fp) { unsigned long int space; struct defrule *theDefrule; struct defmodule *theModule; struct defruleModule *theModuleItem; struct bsaveDefruleModule tempDefruleModule; /*===============================================*/ /* Write out the space required by the defrules. */ /*===============================================*/ space = (DefruleBinaryData(theEnv)->NumberOfDefrules * sizeof(struct bsaveDefrule)) + (DefruleBinaryData(theEnv)->NumberOfJoins * sizeof(struct bsaveJoinNode)) + (DefruleBinaryData(theEnv)->NumberOfDefruleModules * sizeof(struct bsaveDefruleModule)); GenWrite(&space,(unsigned long) sizeof(unsigned long int),fp); /*===============================================*/ /* Write out each defrule module data structure. */ /*===============================================*/ DefruleBinaryData(theEnv)->NumberOfDefrules = 0; for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { EnvSetCurrentModule(theEnv,(void *) theModule); theModuleItem = (struct defruleModule *) GetModuleItem(theEnv,NULL,FindModuleItem(theEnv,"defrule")->moduleIndex); AssignBsaveDefmdlItemHdrVals(&tempDefruleModule.header, &theModuleItem->header); GenWrite(&tempDefruleModule,(unsigned long) sizeof(struct bsaveDefruleModule),fp); } /*========================================*/ /* Write out each defrule data structure. */ /*========================================*/ for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { EnvSetCurrentModule(theEnv,(void *) theModule); for (theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,NULL); theDefrule != NULL; theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,theDefrule)) { BsaveDisjuncts(theEnv,fp,theDefrule); } } /*=============================*/ /* Write out the Rete Network. */ /*=============================*/ MarkRuleNetwork(theEnv,1); BsaveJoins(theEnv,fp); /*=============================================================*/ /* If a binary image was already loaded when the bsave command */ /* was issued, then restore the counts indicating the number */ /* of defrules, defrule modules, and joins in the binary image */ /* (these were overwritten by the binary save). */ /*=============================================================*/ RestoreBloadCount(theEnv,&DefruleBinaryData(theEnv)->NumberOfDefruleModules); RestoreBloadCount(theEnv,&DefruleBinaryData(theEnv)->NumberOfDefrules); RestoreBloadCount(theEnv,&DefruleBinaryData(theEnv)->NumberOfJoins); }