globle intBool FactJNGetVar2( void *theEnv, 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 (hack->lhs) { factPtr = (struct fact *) get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->matchingItem; } else if (hack->rhs) { factPtr = (struct fact *) get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,hack->whichPattern)->matchingItem; } else if (EngineData(theEnv)->GlobalRHSBinds == NULL) { factPtr = (struct fact *) get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->matchingItem; } else if (((unsigned short) (EngineData(theEnv)->GlobalJoin->depth - 1)) == hack->whichPattern) { factPtr = (struct fact *) get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,0)->matchingItem; } else { factPtr = (struct fact *) get_nth_pm_match(EngineData(theEnv)->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(TRUE); }
globle void PrintPartialMatch( char *logicalName, struct partialMatch *list) { struct patternEntity *matchingItem; short int i; for (i = 0; i < (int) list->bcount;) { if (get_nth_pm_match(list,i)->matchingItem != NULL) { matchingItem = get_nth_pm_match(list,i)->matchingItem; if (matchingItem != NULL) (*matchingItem->theInfo->base.shortPrintFunction)(logicalName,matchingItem); } i++; if (i < (int) list->bcount) PrintRouter(logicalName,","); } }
bool FactJNGetVar2( Environment *theEnv, void *theValue, UDFValue *returnValue) { Fact *factPtr; struct factGetVarJN2Call *hack; CLIPSValue *fieldPtr; /*==========================================*/ /* Retrieve the arguments for the function. */ /*==========================================*/ hack = (struct factGetVarJN2Call *) ((CLIPSBitMap *) theValue)->contents; /*=====================================================*/ /* Get the pointer to the fact from the partial match. */ /*=====================================================*/ if (hack->lhs) { factPtr = (Fact *) get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->matchingItem; } else if (hack->rhs) { factPtr = (Fact *) get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,hack->whichPattern)->matchingItem; } else if (EngineData(theEnv)->GlobalRHSBinds == NULL) { factPtr = (Fact *) get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->matchingItem; } else if ((EngineData(theEnv)->GlobalJoin->depth - 1) == hack->whichPattern) { factPtr = (Fact *) get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,0)->matchingItem; } else { factPtr = (Fact *) get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->matchingItem; } /*============================================*/ /* Extract the value from the specified slot. */ /*============================================*/ if ((factPtr->basisSlots != NULL) && (! EngineData(theEnv)->JoinOperationInProgress)) { fieldPtr = &factPtr->basisSlots->contents[hack->whichSlot]; } else { fieldPtr = &factPtr->theProposition.contents[hack->whichSlot]; } returnValue->value = fieldPtr->value; return true; }
/**************************************************** NAME : GetPatternObjectAndMarks DESCRIPTION : Finds the instance and multfiield markers corresponding to a specified pattern in the join network INPUTS : 1) The index of the desired pattern 2) A buffer to hold the instance address 3) A buffer to hold the list of multifield markers RETURNS : Nothing useful SIDE EFFECTS : Buffers set NOTES : None ****************************************************/ static void GetPatternObjectAndMarks( void *theEnv, int pattern, int lhs, int rhs, INSTANCE_TYPE **theInstance, struct multifieldMarker **theMarkers) { if (lhs) { *theInstance = (INSTANCE_TYPE *) get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,pattern)->matchingItem; *theMarkers = get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,pattern)->markers; } else if (rhs) { *theInstance = (INSTANCE_TYPE *) get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,pattern)->matchingItem; *theMarkers = get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,pattern)->markers; } else if (EngineData(theEnv)->GlobalRHSBinds == NULL) { *theInstance = (INSTANCE_TYPE *) get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,pattern)->matchingItem; *theMarkers = get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,pattern)->markers; } else if ((((int) EngineData(theEnv)->GlobalJoin->depth) - 1) == pattern) { *theInstance = (INSTANCE_TYPE *) get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,0)->matchingItem; *theMarkers = get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,0)->markers; } else { *theInstance = (INSTANCE_TYPE *) get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,pattern)->matchingItem; *theMarkers = get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,pattern)->markers; } }
globle intBool FactJNGetVar3( void *theEnv, 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 (hack->lhs) { factPtr = (struct fact *) get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->matchingItem; } else if (hack->rhs) { factPtr = (struct fact *) get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,hack->whichPattern)->matchingItem; } else if (EngineData(theEnv)->GlobalRHSBinds == NULL) { factPtr = (struct fact *) get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->matchingItem; } else if (((unsigned short) (EngineData(theEnv)->GlobalJoin->depth - 1)) == hack->whichPattern) { factPtr = (struct fact *) get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,0)->matchingItem; } else { factPtr = (struct fact *) get_nth_pm_match(EngineData(theEnv)->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 = (long) (segmentPtr->multifieldLength - (hack->endOffset + 1)); return(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(TRUE); }
globle intBool FactJNGetVar1( void *theEnv, void *theValue, DATA_OBJECT_PTR returnValue) { unsigned short theField, theSlot; struct fact *factPtr; struct field *fieldPtr; struct multifieldMarker *marks; struct multifield *segmentPtr; long 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 (hack->lhs) { factPtr = (struct fact *) get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->matchingItem; marks = get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->markers; } else if (hack->rhs) { factPtr = (struct fact *) get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,hack->whichPattern)->matchingItem; marks = get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,hack->whichPattern)->markers; } else if (EngineData(theEnv)->GlobalRHSBinds == NULL) { factPtr = (struct fact *) get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->matchingItem; marks = get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->markers; } else if ((((unsigned short) (EngineData(theEnv)->GlobalJoin->depth - 1))) == hack->whichPattern) { factPtr = (struct fact *) get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,0)->matchingItem; marks = get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,0)->markers; } else { factPtr = (struct fact *) get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->matchingItem; marks = get_nth_pm_match(EngineData(theEnv)->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(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) { SetpDOBegin(returnValue,1); SetpDOEnd(returnValue,((struct multifield *) fieldPtr->value)->multifieldLength); } return(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(TRUE); } /*==========================================================*/ /* Retrieve a value from a multifield slot. First determine */ /* the range of fields for the variable being retrieved. */ /*==========================================================*/ extent = -1; theField = AdjustFieldPosition(theEnv,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(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(TRUE); }
bool FactJNGetVar3( Environment *theEnv, void *theValue, UDFValue *returnValue) { Fact *factPtr; Multifield *segmentPtr; CLIPSValue *fieldPtr; struct factGetVarJN3Call *hack; /*==========================================*/ /* Retrieve the arguments for the function. */ /*==========================================*/ hack = (struct factGetVarJN3Call *) ((CLIPSBitMap *) theValue)->contents; /*=====================================================*/ /* Get the pointer to the fact from the partial match. */ /*=====================================================*/ if (hack->lhs) { factPtr = (Fact *) get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->matchingItem; } else if (hack->rhs) { factPtr = (Fact *) get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,hack->whichPattern)->matchingItem; } else if (EngineData(theEnv)->GlobalRHSBinds == NULL) { factPtr = (Fact *) get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->matchingItem; } else if ((EngineData(theEnv)->GlobalJoin->depth - 1) == hack->whichPattern) { factPtr = (Fact *) get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,0)->matchingItem; } else { factPtr = (Fact *) get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->matchingItem; } /*============================================================*/ /* Get the multifield value from which the data is retrieved. */ /*============================================================*/ if ((factPtr->basisSlots != NULL) && (! EngineData(theEnv)->JoinOperationInProgress)) { segmentPtr = factPtr->basisSlots->contents[hack->whichSlot].multifieldValue; } else { segmentPtr = factPtr->theProposition.contents[hack->whichSlot].multifieldValue; } /*=========================================*/ /* If the beginning and end flags are set, */ /* then retrieve a multifield value. */ /*=========================================*/ if (hack->fromBeginning && hack->fromEnd) { returnValue->value = segmentPtr; returnValue->begin = hack->beginOffset; returnValue->range = segmentPtr->length - (hack->endOffset + hack->beginOffset); return true; } /*=====================================================*/ /* Return a single field value from a multifield slot. */ /*=====================================================*/ if (hack->fromBeginning) { fieldPtr = &segmentPtr->contents[hack->beginOffset]; } else { fieldPtr = &segmentPtr->contents[segmentPtr->length - (hack->endOffset + 1)]; } returnValue->value = fieldPtr->value; return true; }
bool FactJNGetVar1( Environment *theEnv, void *theValue, UDFValue *returnValue) { size_t adjustedField; unsigned short theField, theSlot; Fact *factPtr; CLIPSValue *fieldPtr; struct multifieldMarker *marks; Multifield *segmentPtr; size_t extent; struct factGetVarJN1Call *hack; Multifield *theSlots = NULL; /*==========================================*/ /* Retrieve the arguments for the function. */ /*==========================================*/ hack = (struct factGetVarJN1Call *) ((CLIPSBitMap *) theValue)->contents; /*=====================================================*/ /* Get the pointer to the fact from the partial match. */ /*=====================================================*/ if (hack->lhs) { factPtr = (Fact *) get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->matchingItem; marks = get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->markers; } else if (hack->rhs) { factPtr = (Fact *) get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,hack->whichPattern)->matchingItem; marks = get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,hack->whichPattern)->markers; } else if (EngineData(theEnv)->GlobalRHSBinds == NULL) { factPtr = (Fact *) get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->matchingItem; marks = get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->markers; } else if ((EngineData(theEnv)->GlobalJoin->depth - 1) == hack->whichPattern) { factPtr = (Fact *) get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,0)->matchingItem; marks = get_nth_pm_match(EngineData(theEnv)->GlobalRHSBinds,0)->markers; } else { factPtr = (Fact *) get_nth_pm_match(EngineData(theEnv)->GlobalLHSBinds,hack->whichPattern)->matchingItem; marks = get_nth_pm_match(EngineData(theEnv)->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->value = factPtr; return true; } if ((factPtr->basisSlots != NULL) && (! EngineData(theEnv)->JoinOperationInProgress)) { theSlots = factPtr->basisSlots; } else { theSlots = &factPtr->theProposition; } /*=========================================================*/ /* Determine if we want to retrieve the entire slot value. */ /*=========================================================*/ if (hack->allFields) { theSlot = hack->whichSlot; fieldPtr = &theSlots->contents[theSlot]; returnValue->value = fieldPtr->value; if (returnValue->header->type == MULTIFIELD_TYPE) { returnValue->begin = 0; returnValue->range = fieldPtr->multifieldValue->length; } return 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 = &theSlots->contents[theSlot]; if (fieldPtr->header->type != MULTIFIELD_TYPE) { returnValue->value = fieldPtr->value; return true; } /*==========================================================*/ /* Retrieve a value from a multifield slot. First determine */ /* the range of fields for the variable being retrieved. */ /*==========================================================*/ extent = SIZE_MAX; adjustedField = AdjustFieldPosition(theEnv,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 != SIZE_MAX) { returnValue->value = fieldPtr->value; returnValue->begin = adjustedField; returnValue->range = extent; return true; } /*========================================================*/ /* Otherwise a single field value is being retrieved from */ /* a multifield slot. Just return the type and value. */ /*========================================================*/ segmentPtr = theSlots->contents[theSlot].multifieldValue; fieldPtr = &segmentPtr->contents[adjustedField]; returnValue->value = fieldPtr->value; return true; }