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

📄 factrete.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 3 页
字号:
#pragma argsused#endifgloble BOOLEAN FactPNConstant2(theValue,returnValue)  VOID *theValue;  DATA_OBJECT_PTR returnValue;  {#if MAC_MPW || MAC_MCW#pragma unused(returnValue)#endif   struct factConstantPN2Call *hack;   struct field *fieldPtr;   struct expr *theConstant;   struct multifield *segmentPtr;   /*==========================================*/   /* Retrieve the arguments for the function. */   /*==========================================*/      hack = (struct factConstantPN2Call *) ValueToBitMap(theValue);      /*==========================================================*/   /* Extract the value from the specified slot. Note that the */   /* test to determine the slot's type (multifield) should be */   /* unnecessary since this routine should only be used for   */   /* multifield slots.                                        */   /*==========================================================*/      fieldPtr = &CurrentPatternFact->theProposition.theFields[hack->whichSlot];      if (fieldPtr->type == MULTIFIELD)     {      segmentPtr = (struct multifield *) fieldPtr->value;      if (hack->fromBeginning)        { fieldPtr = &segmentPtr->theFields[hack->offset]; }      else        {          fieldPtr = &segmentPtr->theFields[segmentPtr->multifieldLength -                     (hack->offset + 1)];         }     }      /*====================================*/   /* Compare the value to the constant. */   /*====================================*/      theConstant = GetFirstArgument();   if (theConstant->type != fieldPtr->type) return(1 - hack->testForEquality);   if (theConstant->value != fieldPtr->value) return(1 - hack->testForEquality);   return(hack->testForEquality);  }  /**************************************************************//* FactJNGetVar1: Fact join network function for extracting a *//*   variable's value. This is the most generalized routine.  *//**************************************************************/globle BOOLEAN FactJNGetVar1(theValue,returnValue)  VOID *theValue;  DATA_OBJECT_PTR returnValue;  {   int theField, theSlot;   struct fact *factPtr;   struct field *fieldPtr;   struct multifieldMarker *marks;   struct multifield *segmentPtr;   int extent;   struct factGetVarJN1Call *hack;   /*==========================================*/   /* Retrieve the arguments for the function. */   /*==========================================*/      hack = (struct factGetVarJN1Call *) ValueToBitMap(theValue);      /*=====================================================*/   /* Get the pointer to the fact from the partial match. */   /*=====================================================*/        if (GlobalRHSBinds == NULL)     {       factPtr = (struct fact *) get_nth_pm_match(GlobalLHSBinds,hack->whichPattern)->matchingItem;      marks = get_nth_pm_match(GlobalLHSBinds,hack->whichPattern)->markers;     }   else if ((GlobalJoin->depth - 1) == hack->whichPattern)     {       factPtr = (struct fact *) get_nth_pm_match(GlobalRHSBinds,0)->matchingItem;      marks = get_nth_pm_match(GlobalRHSBinds,0)->markers;     }   else     {      factPtr = (struct fact *) get_nth_pm_match(GlobalLHSBinds,hack->whichPattern)->matchingItem;      marks = get_nth_pm_match(GlobalLHSBinds,hack->whichPattern)->markers;     }   /*==========================================================*/   /* Determine if we want to retrieve the fact address of the */   /* fact, rather than retrieving a field from the fact.      */   /*==========================================================*/   if (hack->factAddress)     {      returnValue->type = FACT_ADDRESS;      returnValue->value = (VOID *) factPtr;      return(CLIPS_TRUE);     }        /*=========================================================*/   /* Determine if we want to retrieve the entire slot value. */   /*=========================================================*/        if (hack->allFields)     {      theSlot = hack->whichSlot;      fieldPtr = &factPtr->theProposition.theFields[theSlot];      returnValue->type = fieldPtr->type;      returnValue->value = fieldPtr->value;      if (returnValue->type == MULTIFIELD)        {         returnValue->begin = 0;         returnValue->end = ((struct multifield *) fieldPtr->value)->multifieldLength - 1;        }              return(CLIPS_TRUE);     }      /*====================================================*/   /* If the slot being accessed is a single field slot, */   /* then just return the single value found in that    */   /* slot. The multifieldMarker data structures do not  */   /* have to be considered since access to a single     */   /* field slot is not affected by variable bindings    */   /* from multifield slots.                             */   /*====================================================*/      theField = hack->whichField;   theSlot = hack->whichSlot;   fieldPtr = &factPtr->theProposition.theFields[theSlot];   if (fieldPtr->type != MULTIFIELD)     {      returnValue->type = fieldPtr->type;      returnValue->value = fieldPtr->value;      return(CLIPS_TRUE);     }   /*==========================================================*/   /* Retrieve a value from a multifield slot. First determine */   /* the range of fields for the variable being retrieved.    */   /*==========================================================*/      extent = -1;   theField = AdjustFieldPosition(marks,theField,theSlot,&extent);       /*=============================================================*/   /* If a range of values are being retrieved (i.e. a multifield */   /* variable), then return the values as a multifield.          */   /*=============================================================*/      if (extent != -1)     {      returnValue->type = MULTIFIELD;      returnValue->value = (VOID *) fieldPtr->value;      returnValue->begin = theField;      returnValue->end = theField + extent - 1;      return(CLIPS_TRUE);     }   /*========================================================*/   /* Otherwise a single field value is being retrieved from */   /* a multifield slot. Just return the type and value.     */   /*========================================================*/      segmentPtr = (struct multifield *) factPtr->theProposition.theFields[theSlot].value;   fieldPtr = &segmentPtr->theFields[theField];   returnValue->type = fieldPtr->type;   returnValue->value = fieldPtr->value;      return(CLIPS_TRUE);  }  /*************************************************//* FactJNGetVar2: Fact join network function for *//*   extracting a variable's value. The value    *//*   extracted is from a single field slot.      *//*************************************************/globle BOOLEAN FactJNGetVar2(theValue,returnValue)  VOID *theValue;  DATA_OBJECT_PTR returnValue;  {   struct fact *factPtr;   struct factGetVarJN2Call *hack;   struct field *fieldPtr;   /*==========================================*/   /* Retrieve the arguments for the function. */   /*==========================================*/      hack = (struct factGetVarJN2Call *) ValueToBitMap(theValue);      /*=====================================================*/   /* Get the pointer to the fact from the partial match. */   /*=====================================================*/   if (GlobalRHSBinds == NULL)     { factPtr = (struct fact *) get_nth_pm_match(GlobalLHSBinds,hack->whichPattern)->matchingItem; }   else if ((GlobalJoin->depth - 1) == hack->whichPattern)     { factPtr = (struct fact *) get_nth_pm_match(GlobalRHSBinds,0)->matchingItem; }   else     { factPtr = (struct fact *) get_nth_pm_match(GlobalLHSBinds,hack->whichPattern)->matchingItem; }   /*============================================*/   /* Extract the value from the specified slot. */   /*============================================*/      fieldPtr = &factPtr->theProposition.theFields[hack->whichSlot];   returnValue->type = fieldPtr->type;   returnValue->value = fieldPtr->value;      return(CLIPS_TRUE);  }  /****************************************************************//* FactJNGetVar3: Fact join network function for extracting a   *//*   variable's value. The value extracted is from a multifield *//*   slot that contains at most one multifield variable.        *//****************************************************************/globle BOOLEAN FactJNGetVar3(theValue,returnValue)  VOID *theValue;  DATA_OBJECT_PTR returnValue;  {   struct fact *factPtr;   struct multifield *segmentPtr;   struct field *fieldPtr;   struct factGetVarJN3Call *hack;   /*==========================================*/   /* Retrieve the arguments for the function. */   /*==========================================*/      hack = (struct factGetVarJN3Call *) ValueToBitMap(theValue);      /*=====================================================*/   /* Get the pointer to the fact from the partial match. */   /*=====================================================*/   if (GlobalRHSBinds == NULL)     { factPtr = (struct fact *) get_nth_pm_match(GlobalLHSBinds,hack->whichPattern)->matchingItem; }   else if ((GlobalJoin->depth - 1) == hack->whichPattern)     { factPtr = (struct fact *) get_nth_pm_match(GlobalRHSBinds,0)->matchingItem; }   else     { factPtr = (struct fact *) get_nth_pm_match(GlobalLHSBinds,hack->whichPattern)->matchingItem; }      /*============================================================*/   /* Get the multifield value from which the data is retrieved. */   /*============================================================*/      segmentPtr = (struct multifield *) factPtr->theProposition.theFields[hack->whichSlot].value;   /*=========================================*/   /* If the beginning and end flags are set, */    /* then retrieve a multifield value.       */   /*=========================================*/      if (hack->fromBeginning && hack->fromEnd)     {      returnValue->type = MULTIFIELD;      returnValue->value = (VOID *) segmentPtr;      returnValue->begin = hack->beginOffset;      returnValue->end = segmentPtr->multifieldLength - (hack->endOffset + 1);      return(CLIPS_TRUE);     }        /*=====================================================*/   /* Return a single field value from a multifield slot. */   /*=====================================================*/      if (hack->fromBeginning)     { fieldPtr = &segmentPtr->theFields[hack->beginOffset]; }   else     { fieldPtr = &segmentPtr->theFields[segmentPtr->multifieldLength - (hack->endOffset + 1)]; }      returnValue->type = fieldPtr->type;   returnValue->value = fieldPtr->value;      return(CLIPS_TRUE);  }  /****************************************************//* FactSlotLength: Determines if the length of a    *//*  multifield slot falls within a specified range. *//****************************************************/globle BOOLEAN FactSlotLength(theValue,returnValue)  VOID *theValue;  DATA_OBJECT_PTR returnValue;  {   

⌨️ 快捷键说明

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