globle void CheckTemplateFact( struct fact *theFact) { struct field *sublist; int i; struct deftemplate *theDeftemplate; struct templateSlot *slotPtr; DATA_OBJECT theData; char thePlace[20]; int rv; if (! GetDynamicConstraintChecking()) return; sublist = theFact->theProposition.theFields; /*========================================================*/ /* If the deftemplate corresponding to the first field of */ /* of the fact cannot be found, then the fact cannot be */ /* checked against the deftemplate format. */ /*========================================================*/ theDeftemplate = theFact->whichDeftemplate; if (theDeftemplate == NULL) return; if (theDeftemplate->implied) return; /*=============================================*/ /* Check each of the slots of the deftemplate. */ /*=============================================*/ i = 0; for (slotPtr = theDeftemplate->slotList; slotPtr != NULL; slotPtr = slotPtr->next) { /*================================================*/ /* Store the slot value in the appropriate format */ /* for a call to the constraint checking routine. */ /*================================================*/ if (slotPtr->multislot == FALSE) { theData.type = sublist[i].type; theData.value = sublist[i].value; i++; } else { theData.type = MULTIFIELD; theData.value = (void *) sublist[i].value; theData.begin = 0; theData.end = ((struct multifield *) sublist[i].value)->multifieldLength-1; i++; } /*=============================================*/ /* Call the constraint checking routine to see */ /* if a constraint violation occurred. */ /*=============================================*/ rv = ConstraintCheckDataObject(&theData,slotPtr->constraints); if (rv != NO_VIOLATION) { sprintf(thePlace,"fact f-%-5ld ",theFact->factIndex); PrintErrorID("CSTRNCHK",1,TRUE); PrintRouter(WERROR,"Slot value "); PrintDataObject(WERROR,&theData); PrintRouter(WERROR," "); ConstraintViolationErrorMessage(NULL,thePlace,FALSE,0,slotPtr->slotName, 0,rv,slotPtr->constraints,TRUE); SetHaltExecution(TRUE); return; } } return; }
void CheckTemplateFact( Environment *theEnv, Fact *theFact) { CLIPSValue *sublist; int i; Deftemplate *theDeftemplate; struct templateSlot *slotPtr; UDFValue theData; char thePlace[20]; ConstraintViolationType rv; if (! GetDynamicConstraintChecking(theEnv)) return; sublist = theFact->theProposition.contents; /*========================================================*/ /* If the deftemplate corresponding to the first field of */ /* of the fact cannot be found, then the fact cannot be */ /* checked against the deftemplate format. */ /*========================================================*/ theDeftemplate = theFact->whichDeftemplate; if (theDeftemplate == NULL) return; if (theDeftemplate->implied) return; /*=============================================*/ /* Check each of the slots of the deftemplate. */ /*=============================================*/ i = 0; for (slotPtr = theDeftemplate->slotList; slotPtr != NULL; slotPtr = slotPtr->next) { /*================================================*/ /* Store the slot value in the appropriate format */ /* for a call to the constraint checking routine. */ /*================================================*/ if (slotPtr->multislot == false) { theData.value = sublist[i].value; i++; } else { theData.value = (void *) sublist[i].value; theData.begin = 0; theData.range = sublist[i].multifieldValue->length; i++; } /*=============================================*/ /* Call the constraint checking routine to see */ /* if a constraint violation occurred. */ /*=============================================*/ rv = ConstraintCheckDataObject(theEnv,&theData,slotPtr->constraints); if (rv != NO_VIOLATION) { gensprintf(thePlace,"fact f-%lld",theFact->factIndex); PrintErrorID(theEnv,"CSTRNCHK",1,true); WriteString(theEnv,STDERR,"Slot value "); WriteUDFValue(theEnv,STDERR,&theData); ConstraintViolationErrorMessage(theEnv,NULL,thePlace,false,0,slotPtr->slotName, 0,rv,slotPtr->constraints,true); SetHaltExecution(theEnv,true); return; } } return; }