⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rulebin.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
           (DefruleBinaryData(theEnv)->NumberOfLinks * sizeof(struct bsaveJoinLink)) +           (DefruleBinaryData(theEnv)->NumberOfDefruleModules * sizeof(struct bsaveDefruleModule));   GenWrite(&space,sizeof(size_t),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,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);   /*===========================*/   /* Write out the join links. */   /*===========================*/   MarkRuleNetwork(theEnv,1);   BsaveLinks(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);   RestoreBloadCount(theEnv,&DefruleBinaryData(theEnv)->NumberOfLinks);  }/************************************************************//* BsaveDisjuncts: Writes out all the disjunct defrule data *//*   structures for a specific rule to the binary file.     *//************************************************************/static void BsaveDisjuncts(  void *theEnv,  FILE *fp,  struct defrule *theDefrule)  {   struct defrule *theDisjunct;   struct bsaveDefrule tempDefrule;   long int disjunctExpressionCount = 0L;   int first;   /*=========================================*/   /* Loop through each disjunct of the rule. */   /*=========================================*/   for (theDisjunct = theDefrule, first = TRUE;        theDisjunct != NULL;        theDisjunct = theDisjunct->disjunct, first = FALSE)     {      DefruleBinaryData(theEnv)->NumberOfDefrules++;      /*======================================*/      /* Set header and miscellaneous values. */      /*======================================*/      AssignBsaveConstructHeaderVals(&tempDefrule.header,                                     &theDisjunct->header);      tempDefrule.salience = theDisjunct->salience;      tempDefrule.localVarCnt = theDisjunct->localVarCnt;      tempDefrule.complexity = theDisjunct->complexity;      tempDefrule.autoFocus = theDisjunct->autoFocus;      /*=======================================*/      /* Set dynamic salience data structures. */      /*=======================================*/      if (theDisjunct->dynamicSalience != NULL)        {         if (first)           {            tempDefrule.dynamicSalience = ExpressionData(theEnv)->ExpressionCount;            disjunctExpressionCount = ExpressionData(theEnv)->ExpressionCount;            ExpressionData(theEnv)->ExpressionCount += ExpressionSize(theDisjunct->dynamicSalience);           }         else           { tempDefrule.dynamicSalience = disjunctExpressionCount; }        }      else        { tempDefrule.dynamicSalience = -1L; }      /*==============================================*/      /* Set the index to the disjunct's RHS actions. */      /*==============================================*/      if (theDisjunct->actions != NULL)        {         tempDefrule.actions = ExpressionData(theEnv)->ExpressionCount;         ExpressionData(theEnv)->ExpressionCount += ExpressionSize(theDisjunct->actions);        }      else        { tempDefrule.actions = -1L; }      /*=================================*/      /* Set the index to the disjunct's */      /* logical join and last join.     */      /*=================================*/      tempDefrule.logicalJoin = BsaveJoinIndex(theDisjunct->logicalJoin);      tempDefrule.lastJoin = BsaveJoinIndex(theDisjunct->lastJoin);      /*=====================================*/      /* Set the index to the next disjunct. */      /*=====================================*/      if (theDisjunct->disjunct != NULL)        { tempDefrule.disjunct = DefruleBinaryData(theEnv)->NumberOfDefrules; }      else        { tempDefrule.disjunct = -1L; }      /*=================================*/      /* Write the disjunct to the file. */      /*=================================*/      GenWrite(&tempDefrule,sizeof(struct bsaveDefrule),fp);     }  }/********************************************//* BsaveJoins: Writes out all the join node *//*   data structures to the binary file.    *//********************************************/static void BsaveJoins(  void *theEnv,  FILE *fp)  {   struct defrule *rulePtr;   struct defmodule *theModule;   /*===========================*/   /* Loop through each module. */   /*===========================*/   for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);        theModule != NULL;        theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))     {      EnvSetCurrentModule(theEnv,(void *) theModule);      /*===========================================*/      /* Loop through each rule and its disjuncts. */      /*===========================================*/      rulePtr = (struct defrule *) EnvGetNextDefrule(theEnv,NULL);      while (rulePtr != NULL)        {         /*=========================================*/         /* Loop through each join of the disjunct. */         /*=========================================*/         BsaveTraverseJoins(theEnv,fp,rulePtr->lastJoin);                  /*=======================================*/         /* Move on to the next rule or disjunct. */         /*=======================================*/         if (rulePtr->disjunct != NULL) rulePtr = rulePtr->disjunct;         else rulePtr = (struct defrule *) EnvGetNextDefrule(theEnv,rulePtr);        }     }  }/**************************************************************//* BsaveTraverseJoins: Traverses the join network for a rule. *//**************************************************************/static void BsaveTraverseJoins(  void *theEnv,  FILE *fp,  struct joinNode *joinPtr)  {   for (;        joinPtr != NULL;        joinPtr = joinPtr->lastLevel)     {       if (joinPtr->marked) BsaveJoin(theEnv,fp,joinPtr);             if (joinPtr->joinFromTheRight)        { BsaveTraverseJoins(theEnv,fp,joinPtr->rightSideEntryStructure); }     }  }/********************************************//* BsaveJoin: Writes out a single join node *//*   data structure to the binary file.     *//********************************************/static void BsaveJoin(  void *theEnv,  FILE *fp,  struct joinNode *joinPtr)  {   struct bsaveJoinNode tempJoin;   joinPtr->marked = 0;   tempJoin.depth = joinPtr->depth;   tempJoin.rhsType = joinPtr->rhsType;   tempJoin.firstJoin = joinPtr->firstJoin;   tempJoin.logicalJoin = joinPtr->logicalJoin;   tempJoin.joinFromTheRight = joinPtr->joinFromTheRight;   tempJoin.patternIsNegated = joinPtr->patternIsNegated;   tempJoin.patternIsExists = joinPtr->patternIsExists;   if (joinPtr->joinFromTheRight)     { tempJoin.rightSideEntryStructure =  BsaveJoinIndex(joinPtr->rightSideEntryStructure); }   else     { tempJoin.rightSideEntryStructure =  -1L; }        tempJoin.lastLevel =  BsaveJoinIndex(joinPtr->lastLevel);   tempJoin.nextLinks =  BsaveJoinLinkIndex(joinPtr->nextLinks);   tempJoin.rightMatchNode =  BsaveJoinIndex(joinPtr->rightMatchNode);   tempJoin.networkTest = HashedExpressionIndex(theEnv,joinPtr->networkTest);   tempJoin.secondaryNetworkTest = HashedExpressionIndex(theEnv,joinPtr->secondaryNetworkTest);   tempJoin.leftHash = HashedExpressionIndex(theEnv,joinPtr->leftHash);   tempJoin.rightHash = HashedExpressionIndex(theEnv,joinPtr->rightHash);   if (joinPtr->ruleToActivate != NULL)     {      tempJoin.ruleToActivate =         GetDisjunctIndex(joinPtr->ruleToActivate);     }   else     { tempJoin.ruleToActivate = -1L; }   GenWrite(&tempJoin,(unsigned long) sizeof(struct bsaveJoinNode),fp);  }  /********************************************//* BsaveLinks: Writes out all the join link *//*   data structures to the binary file.    *//********************************************/static void BsaveLinks(  void *theEnv,  FILE *fp)  {   struct defrule *rulePtr;   struct defmodule *theModule;   struct joinLink *theLink;   for (theLink = DefruleData(theEnv)->LeftPrimeJoins;        theLink != NULL;        theLink = theLink->next)     { BsaveLink(theEnv,fp,theLink);  }   for (theLink = DefruleData(theEnv)->RightPrimeJoins;        theLink != NULL;        theLink = theLink->next)     { BsaveLink(theEnv,fp,theLink);  }   /*===========================*/   /* Loop through each module. */   /*===========================*/   for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);        theModule != NULL;        theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule))     {      EnvSetCurrentModule(theEnv,(void *) theModule);      /*===========================================*/      /* Loop through each rule and its disjuncts. */      /*===========================================*/      rulePtr = (struct defrule *) EnvGetNextDefrule(theEnv,NULL);      while (rulePtr != NULL)        {         /*=========================================*/         /* Loop through each join of the disjunct. */         /*=========================================*/         BsaveTraverseLinks(theEnv,fp,rulePtr->lastJoin);                  /*=======================================*/         /* Move on to the next rule or disjunct. */         /*=======================================*/         if (rulePtr->disjunct != NULL) rulePtr = rulePtr->disjunct;         else rulePtr = (struct defrule *) EnvGetNextDefrule(theEnv,rulePtr);        }     }  }/***************************************************//* BsaveTraverseLinks: Traverses the join network *//*   for a rule saving the join links.            *//**************************************************/static void BsaveTraverseLinks(  void *theEnv,  FILE *fp,  struct joinNode *joinPtr)  {   struct joinLink *theLink;      for (;        joinPtr != NULL;        joinPtr = joinPtr->lastLevel)     {       if (joinPtr->marked)         {         for (theLink = joinPtr->nextLinks;              theLink != NULL;              theLink = theLink->next)           { BsaveLink(theEnv,fp,theLink); }                  joinPtr->marked = 0;        }            if (joinPtr->joinFromTheRight)        { BsaveTraverseLinks(theEnv,fp,joinPtr->rightSideEntryStructure); }     }  }/********************************************//* BsaveLink: Writes out a single join link *//*   data structure to the binary file.     *//********************************************/static void BsaveLink(  void *theEnv,  FILE *fp,  struct joinLink *linkPtr)  {   struct bsaveJoinLink tempLink;   tempLink.enterDirection = linkPtr->enterDirection;   tempLink.join =  BsaveJoinIndex(linkPtr->join);   tempLink.next =  BsaveJoinLinkIndex(linkPtr->next);   GenWrite(&tempLink,(unsigned long) sizeof(struct bsaveJoinLink),fp);  }/***********************************************************//* AssignBsavePatternHeaderValues: Assigns the appropriate *//*   values to a bsave pattern header record.              *//***********************************************************/globle void AssignBsavePatternHeaderValues(  void *theEnv,  struct bsavePatternNodeHeader *theBsaveHeader,  struct patternNodeHeader *theHeader)  {   theBsaveHeader->multifieldNode = theHeader->multifieldNode;   theBsaveHeader->entryJoin = BsaveJoinIndex(theHeader->entryJoin);   theBsaveHeader->rightHash = HashedExpressionIndex(theEnv,theHeader->rightHash);   theBsaveHeader->singlefieldNode = theHeader->singlefieldNode;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -