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

📄 rulebin.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
   theBsaveHeader->stopNode = theHeader->stopNode;   theBsaveHeader->beginSlot = theHeader->beginSlot;   theBsaveHeader->endSlot = theHeader->endSlot;   theBsaveHeader->selector = theHeader->selector;  }#endif /* BLOAD_AND_BSAVE *//************************************************//* BloadStorage: Loads storage requirements for *//*   the defrules used by this binary image.    *//************************************************/static void BloadStorage(  void *theEnv)  {   size_t space;   /*=================================================*/   /* Determine the number of defrule, defruleModule, */   /* and joinNode data structures to be read.        */   /*=================================================*/   GenReadBinary(theEnv,&space,sizeof(size_t));   GenReadBinary(theEnv,&DefruleBinaryData(theEnv)->NumberOfDefruleModules,sizeof(long int));   GenReadBinary(theEnv,&DefruleBinaryData(theEnv)->NumberOfDefrules,sizeof(long int));   GenReadBinary(theEnv,&DefruleBinaryData(theEnv)->NumberOfJoins,sizeof(long int));   GenReadBinary(theEnv,&DefruleBinaryData(theEnv)->NumberOfLinks,sizeof(long int));   GenReadBinary(theEnv,&DefruleBinaryData(theEnv)->RightPrimeIndex,sizeof(long int));   GenReadBinary(theEnv,&DefruleBinaryData(theEnv)->LeftPrimeIndex,sizeof(long int));   /*===================================*/   /* Allocate the space needed for the */   /* defruleModule data structures.    */   /*===================================*/   if (DefruleBinaryData(theEnv)->NumberOfDefruleModules == 0)     {      DefruleBinaryData(theEnv)->ModuleArray = NULL;      DefruleBinaryData(theEnv)->DefruleArray = NULL;      DefruleBinaryData(theEnv)->JoinArray = NULL;     }   space = DefruleBinaryData(theEnv)->NumberOfDefruleModules * sizeof(struct defruleModule);   DefruleBinaryData(theEnv)->ModuleArray = (struct defruleModule *) genalloc(theEnv,space);   /*===============================*/   /* Allocate the space needed for */   /* the defrule data structures.  */   /*===============================*/   if (DefruleBinaryData(theEnv)->NumberOfDefrules == 0)     {      DefruleBinaryData(theEnv)->DefruleArray = NULL;      DefruleBinaryData(theEnv)->JoinArray = NULL;      return;     }   space = DefruleBinaryData(theEnv)->NumberOfDefrules * sizeof(struct defrule);   DefruleBinaryData(theEnv)->DefruleArray = (struct defrule *) genalloc(theEnv,space);   /*===============================*/   /* Allocate the space needed for */   /* the joinNode data structures. */   /*===============================*/   space = DefruleBinaryData(theEnv)->NumberOfJoins * sizeof(struct joinNode);   DefruleBinaryData(theEnv)->JoinArray = (struct joinNode *) genalloc(theEnv,space);   /*===============================*/   /* Allocate the space needed for */   /* the joinNode data structures. */   /*===============================*/   space = DefruleBinaryData(theEnv)->NumberOfLinks * sizeof(struct joinLink);   DefruleBinaryData(theEnv)->LinkArray = (struct joinLink *) genalloc(theEnv,space);  }/****************************************************//* BloadBinaryItem: Loads and refreshes the defrule *//*   constructs used by this binary image.          *//****************************************************/static void BloadBinaryItem(  void *theEnv)  {   size_t space;   /*======================================================*/   /* Read in the amount of space used by the binary image */   /* (this is used to skip the construct in the event it  */   /* is not available in the version being run).          */   /*======================================================*/   GenReadBinary(theEnv,&space,sizeof(size_t));   /*===========================================*/   /* Read in the defruleModule data structures */   /* and refresh the pointers.                 */   /*===========================================*/   BloadandRefresh(theEnv,DefruleBinaryData(theEnv)->NumberOfDefruleModules,                   sizeof(struct bsaveDefruleModule),UpdateDefruleModule);   /*=====================================*/   /* Read in the defrule data structures */   /* and refresh the pointers.           */   /*=====================================*/   BloadandRefresh(theEnv,DefruleBinaryData(theEnv)->NumberOfDefrules,                   sizeof(struct bsaveDefrule),UpdateDefrule);   /*======================================*/   /* Read in the joinNode data structures */   /* and refresh the pointers.            */   /*======================================*/   BloadandRefresh(theEnv,DefruleBinaryData(theEnv)->NumberOfJoins,                   sizeof(struct bsaveJoinNode),UpdateJoin);   /*======================================*/   /* Read in the joinLink data structures */   /* and refresh the pointers.            */   /*======================================*/   BloadandRefresh(theEnv,DefruleBinaryData(theEnv)->NumberOfLinks,                   sizeof(struct bsaveJoinLink),UpdateLink);                DefruleData(theEnv)->RightPrimeJoins = BloadJoinLinkPointer(DefruleBinaryData(theEnv)->RightPrimeIndex);   DefruleData(theEnv)->LeftPrimeJoins = BloadJoinLinkPointer(DefruleBinaryData(theEnv)->LeftPrimeIndex);  }/**********************************************//* UpdateDefruleModule: Bload refresh routine *//*   for defrule module data structures.      *//**********************************************/static void UpdateDefruleModule(  void *theEnv,  void *buf,  long obji)  {   struct bsaveDefruleModule *bdmPtr;   bdmPtr = (struct bsaveDefruleModule *) buf;   UpdateDefmoduleItemHeader(theEnv,&bdmPtr->header,&DefruleBinaryData(theEnv)->ModuleArray[obji].header,                             (int) sizeof(struct defrule),                             (void *) DefruleBinaryData(theEnv)->DefruleArray);   DefruleBinaryData(theEnv)->ModuleArray[obji].agenda = NULL;   DefruleBinaryData(theEnv)->ModuleArray[obji].groupings = NULL;  }/****************************************//* UpdateDefrule: Bload refresh routine *//*   for defrule data structures.       *//****************************************/static void UpdateDefrule(  void *theEnv,  void *buf,  long obji)  {   struct bsaveDefrule *br;   br = (struct bsaveDefrule *) buf;   UpdateConstructHeader(theEnv,&br->header,&DefruleBinaryData(theEnv)->DefruleArray[obji].header,                         (int) sizeof(struct defruleModule),(void *) DefruleBinaryData(theEnv)->ModuleArray,                         (int) sizeof(struct defrule),(void *) DefruleBinaryData(theEnv)->DefruleArray);   DefruleBinaryData(theEnv)->DefruleArray[obji].dynamicSalience = ExpressionPointer(br->dynamicSalience);   DefruleBinaryData(theEnv)->DefruleArray[obji].actions = ExpressionPointer(br->actions);   DefruleBinaryData(theEnv)->DefruleArray[obji].logicalJoin = BloadJoinPointer(br->logicalJoin);   DefruleBinaryData(theEnv)->DefruleArray[obji].lastJoin = BloadJoinPointer(br->lastJoin);   DefruleBinaryData(theEnv)->DefruleArray[obji].disjunct = BloadDefrulePointer(DefruleBinaryData(theEnv)->DefruleArray,br->disjunct);   DefruleBinaryData(theEnv)->DefruleArray[obji].salience = br->salience;   DefruleBinaryData(theEnv)->DefruleArray[obji].localVarCnt = br->localVarCnt;   DefruleBinaryData(theEnv)->DefruleArray[obji].complexity = br->complexity;   DefruleBinaryData(theEnv)->DefruleArray[obji].autoFocus = br->autoFocus;   DefruleBinaryData(theEnv)->DefruleArray[obji].executing = 0;   DefruleBinaryData(theEnv)->DefruleArray[obji].afterBreakpoint = 0;#if DEBUGGING_FUNCTIONS   DefruleBinaryData(theEnv)->DefruleArray[obji].watchActivation = AgendaData(theEnv)->WatchActivations;   DefruleBinaryData(theEnv)->DefruleArray[obji].watchFiring = DefruleData(theEnv)->WatchRules;#endif  }/*************************************//* UpdateJoin: Bload refresh routine *//*   for joinNode data structures.   *//*************************************/static void UpdateJoin(  void *theEnv,  void *buf,  long obji)  {   struct bsaveJoinNode *bj;   bj = (struct bsaveJoinNode *) buf;   DefruleBinaryData(theEnv)->JoinArray[obji].firstJoin = bj->firstJoin;   DefruleBinaryData(theEnv)->JoinArray[obji].logicalJoin = bj->logicalJoin;   DefruleBinaryData(theEnv)->JoinArray[obji].joinFromTheRight = bj->joinFromTheRight;   DefruleBinaryData(theEnv)->JoinArray[obji].patternIsNegated = bj->patternIsNegated;   DefruleBinaryData(theEnv)->JoinArray[obji].patternIsExists = bj->patternIsExists;   DefruleBinaryData(theEnv)->JoinArray[obji].depth = bj->depth;   DefruleBinaryData(theEnv)->JoinArray[obji].rhsType = bj->rhsType;   DefruleBinaryData(theEnv)->JoinArray[obji].networkTest = HashedExpressionPointer(bj->networkTest);   DefruleBinaryData(theEnv)->JoinArray[obji].secondaryNetworkTest = HashedExpressionPointer(bj->secondaryNetworkTest);   DefruleBinaryData(theEnv)->JoinArray[obji].leftHash = HashedExpressionPointer(bj->leftHash);   DefruleBinaryData(theEnv)->JoinArray[obji].rightHash = HashedExpressionPointer(bj->rightHash);   DefruleBinaryData(theEnv)->JoinArray[obji].nextLinks = BloadJoinLinkPointer(bj->nextLinks);   DefruleBinaryData(theEnv)->JoinArray[obji].lastLevel = BloadJoinPointer(bj->lastLevel);   if (bj->joinFromTheRight == TRUE)     { DefruleBinaryData(theEnv)->JoinArray[obji].rightSideEntryStructure =  (void *) BloadJoinPointer(bj->rightSideEntryStructure); }   else     { DefruleBinaryData(theEnv)->JoinArray[obji].rightSideEntryStructure = NULL; }   DefruleBinaryData(theEnv)->JoinArray[obji].rightMatchNode = BloadJoinPointer(bj->rightMatchNode);   DefruleBinaryData(theEnv)->JoinArray[obji].ruleToActivate = BloadDefrulePointer(DefruleBinaryData(theEnv)->DefruleArray,bj->ruleToActivate);   DefruleBinaryData(theEnv)->JoinArray[obji].initialize = 0;   DefruleBinaryData(theEnv)->JoinArray[obji].marked = 0;   DefruleBinaryData(theEnv)->JoinArray[obji].bsaveID = 0L;   DefruleBinaryData(theEnv)->JoinArray[obji].leftMemory = NULL;   DefruleBinaryData(theEnv)->JoinArray[obji].rightMemory = NULL;   AddBetaMemoriesToJoin(theEnv,&DefruleBinaryData(theEnv)->JoinArray[obji]);  }/*************************************//* UpdateLink: Bload refresh routine *//*   for joinLink data structures.   *//*************************************/static void UpdateLink(  void *theEnv,  void *buf,  long obji)  {   struct bsaveJoinLink *bj;   bj = (struct bsaveJoinLink *) buf;   DefruleBinaryData(theEnv)->LinkArray[obji].enterDirection = bj->enterDirection;   DefruleBinaryData(theEnv)->LinkArray[obji].next = BloadJoinLinkPointer(bj->next);   DefruleBinaryData(theEnv)->LinkArray[obji].join = BloadJoinPointer(bj->join);  }  /************************************************************//* UpdatePatternNodeHeader: Refreshes the values in pattern *//*   node headers from the loaded binary image.             *//************************************************************/globle void UpdatePatternNodeHeader(  void *theEnv,  struct patternNodeHeader *theHeader,  struct bsavePatternNodeHeader *theBsaveHeader)  {   struct joinNode *theJoin;   theHeader->singlefieldNode = theBsaveHeader->singlefieldNode;   theHeader->multifieldNode = theBsaveHeader->multifieldNode;   theHeader->stopNode = theBsaveHeader->stopNode;   theHeader->beginSlot = theBsaveHeader->beginSlot;   theHeader->endSlot = theBsaveHeader->endSlot;   theHeader->selector = theBsaveHeader->selector;   theHeader->initialize = 0;   theHeader->marked = 0;   theHeader->firstHash = NULL;   theHeader->lastHash = NULL;   theHeader->rightHash = HashedExpressionPointer(theBsaveHeader->rightHash);   theJoin = BloadJoinPointer(theBsaveHeader->entryJoin);   theHeader->entryJoin = theJoin;   while (theJoin != NULL)     {      theJoin->rightSideEntryStructure = (void *) theHeader;      theJoin = theJoin->rightMatchNode;     }  }/**************************************//* ClearBload: Defrule clear routine  *//*   when a binary load is in effect. *//**************************************/static void ClearBload(  void *theEnv)  {   size_t space;   long i;   struct patternParser *theParser = NULL;   struct patternEntity *theEntity = NULL;   void *theModule;   /*===========================================*/   /* Delete all known entities before removing */   /* the defrule data structures.              */   /*===========================================*/   GetNextPatternEntity(theEnv,&theParser,&theEntity);   while (theEntity != NULL)     {      (*theEntity->theInfo->base.deleteFunction)(theEnv,theEntity);      theEntity = NULL;      GetNextPatternEntity(theEnv,&theParser,&theEntity);     }   /*=========================================*/   /* Remove all activations from the agenda. */   /*=========================================*/   SaveCurrentModule(theEnv);   for (theModule = EnvGetNextDefmodule(theEnv,NULL);        theModule != NULL;        theModule = EnvGetNextDefmodule(theEnv,theModule))     {      EnvSetCurrentModule(theEnv,theModule);      RemoveAllActivations(theEnv);     }   RestoreCurrentModule(theEnv);   EnvClearFocusStack(theEnv);   /*==========================================================*/   /* Remove all partial matches from the beta memories in the */   /* join network. Alpha memories do not need to be examined  */   /* since all pattern entities have been deleted by now.     */   /*==========================================================*/   for (i = 0; i < DefruleBinaryData(theEnv)->NumberOfJoins; i++)     {       FlushBetaMemory(theEnv,&DefruleBinaryData(theEnv)->JoinArray[i],LHS);       ReturnLeftMemory(theEnv,&DefruleBinaryData(theEnv)->JoinArray[i]);      FlushBetaMemory(theEnv,&DefruleBinaryData(theEnv)->JoinArray[i],RHS);       ReturnRightMemory(theEnv,&DefruleBinaryData(theEnv)->JoinArray[i]);     }   /*================================================*/   /* Decrement the symbol count for each rule name. */   /*================================================*/   for (i = 0; i < DefruleBinaryData(theEnv)->NumberOfDefrules; i++)     { UnmarkConstructHeader(theEnv,&DefruleBinaryData(theEnv)->DefruleArray[i].header); }   /*==================================================*/   /* Return the space allocated for the bload arrays. */   /*==================================================*/   space = DefruleBinaryData(theEnv)->NumberOfDefruleModules * sizeof(struct defruleModule);   if (space != 0) genfree(theEnv,(void *) DefruleBinaryData(theEnv)->ModuleArray,space);   DefruleBinaryData(theEnv)->NumberOfDefruleModules = 0;      space = DefruleBinaryData(theEnv)->NumberOfDefrules * sizeof(struct defrule);   if (space != 0) genfree(theEnv,(void *) DefruleBinaryData(theEnv)->DefruleArray,space);   DefruleBinaryData(theEnv)->NumberOfDefrules = 0;      space = DefruleBinaryData(theEnv)->NumberOfJoins * sizeof(struct joinNode);   if (space != 0) genfree(theEnv,(void *) DefruleBinaryData(theEnv)->JoinArray,space);   DefruleBinaryData(theEnv)->NumberOfJoins = 0;   space = DefruleBinaryData(theEnv)->NumberOfLinks * sizeof(struct joinLink);   if (space != 0) genfree(theEnv,(void *) DefruleBinaryData(theEnv)->LinkArray,space);   DefruleBinaryData(theEnv)->NumberOfLinks = 0;   DefruleData(theEnv)->RightPrimeJoins = NULL;   DefruleData(theEnv)->LeftPrimeJoins = NULL;  }/*******************************************************//* BloadDefruleModuleReference: Returns the defrule    *//*   module pointer for using with the bload function. *//*******************************************************/globle void *BloadDefruleModuleReference(  void *theEnv,  int theIndex)  {   return ((void *) &DefruleBinaryData(theEnv)->ModuleArray[theIndex]);  }#endif /* DEFRULE_CONSTRUCT && (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME) */

⌨️ 快捷键说明

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