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

📄 tmpltutl.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*******************************************************/   /*      "C" Language Integrated Production System      */   /*                                                     */   /*             CLIPS Version 6.05  04/09/97            */   /*                                                     */   /*            DEFTEMPLATE UTILITIES MODULE             */   /*******************************************************//*************************************************************//* Purpose: Provides utility routines for deftemplates.      *//*                                                           *//* Principal Programmer(s):                                  *//*      Gary D. Riley                                        *//*                                                           *//* Contributing Programmer(s):                               *//*      Brian L. Donnell                                     *//*                                                           *//* Revision History:                                         *//*                                                           *//*************************************************************/#define  _TMPLTUTL_SOURCE_#include "setup.h"#if DEFTEMPLATE_CONSTRUCT#include <stdio.h>#define _CLIPS_STDIO_#include <string.h>#include "extnfunc.h"#include "clipsmem.h"#include "constrct.h"#include "router.h"#include "argacces.h"#include "cstrnchk.h"#include "tmpltfun.h"#include "tmpltpsr.h"#include "modulutl.h"#include "watch.h"#include "tmpltbsc.h"#include "tmpltdef.h"#include "tmpltutl.h"/********************************************************//* InvalidDeftemplateSlotMessage: Generic error message *//*   for use when a specified slot name isn't defined   *//*   in its corresponding deftemplate.                  *//********************************************************/globle VOID InvalidDeftemplateSlotMessage(slotName,deftemplateName)  char *slotName;  char *deftemplateName;  {   PrintErrorID("TMPLTDEF",1,CLIPS_TRUE);   PrintCLIPS(WERROR,"Invalid slot ");   PrintCLIPS(WERROR,slotName);   PrintCLIPS(WERROR," not defined in corresponding deftemplate ");   PrintCLIPS(WERROR,deftemplateName);   PrintCLIPS(WERROR,".\n");  }  /**********************************************************//* SingleFieldSlotCardinalityError: Generic error message *//*   used when an attempt is made to placed a multifield  *//*   value into a single field slot.                      *//**********************************************************/globle VOID SingleFieldSlotCardinalityError(slotName)  char *slotName;  {   PrintErrorID("TMPLTDEF",2,CLIPS_TRUE);   PrintCLIPS(WERROR,"The single field slot ");   PrintCLIPS(WERROR,slotName);   PrintCLIPS(WERROR," can only contain a single field value.\n");  }  /**********************************************************************//* MultiIntoSingleFieldSlotError: Determines if a multifield value is *//*   being placed into a single field slot of a deftemplate fact.     *//**********************************************************************/globle VOID MultiIntoSingleFieldSlotError(theSlot,theDeftemplate)  struct templateSlot *theSlot;  struct deftemplate *theDeftemplate;  {   PrintErrorID("TMPLTFUN",2,CLIPS_TRUE);   PrintCLIPS(WERROR,"Attempted to assert a multifield value \n");   PrintCLIPS(WERROR,"into the single field slot ");   if (theSlot != NULL) PrintCLIPS(WERROR,theSlot->slotName->contents);   else PrintCLIPS(WERROR,"<<unknown>>");   PrintCLIPS(WERROR," of deftemplate ");   if (theDeftemplate != NULL) PrintCLIPS(WERROR,theDeftemplate->header.name->contents);   else PrintCLIPS(WERROR,"<<unknown>>");   PrintCLIPS(WERROR,".\n");      SetEvaluationError(CLIPS_TRUE);  }/**************************************************************//* CheckTemplateFact: Checks a fact to see if it violates any *//*   deftemplate type, allowed-..., or range specifications.  *//**************************************************************/globle VOID CheckTemplateFact(theFact)  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 == CLIPS_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,CLIPS_TRUE);         PrintCLIPS(WERROR,"Slot value ");         PrintDataObject(WERROR,&theData);         PrintCLIPS(WERROR," ");         ConstraintViolationErrorMessage(NULL,thePlace,CLIPS_FALSE,0,slotPtr->slotName,                                         0,rv,slotPtr->constraints,CLIPS_TRUE);         SetHaltExecution(CLIPS_TRUE);         return;        }     }   return;  }  /***********************************************************************//* CheckRHSSlotTypes: Checks the validity of a change to a slot as the *//*   result of an assert, modify, or duplicate command. This checking  *//*   is performed statically (i.e. when the command is being parsed).  *//***********************************************************************/globle BOOLEAN CheckRHSSlotTypes(rhsSlots,slotPtr,thePlace)  struct expr *rhsSlots;  struct templateSlot *slotPtr;  char *thePlace;  {   int rv;   char *theName;   if (GetStaticConstraintChecking() == CLIPS_FALSE) return(CLIPS_TRUE);      rv = ConstraintCheckExpressionChain(rhsSlots,slotPtr->constraints);      if (rv != NO_VIOLATION)        {         if (rv != CARDINALITY_VIOLATION) theName = "A literal slot value";         else theName = "Literal slot values";         ConstraintViolationErrorMessage(theName,thePlace,CLIPS_TRUE,0,                                         slotPtr->slotName,0,rv,slotPtr->constraints,CLIPS_TRUE);         return(0);        }           return(1);  }    /*********************************************************//* GetNthSlot: Given a deftemplate and an integer index, *//*   returns the nth slot of a deftemplate.              *//*********************************************************/globle struct templateSlot *GetNthSlot(theDeftemplate,position)  struct deftemplate *theDeftemplate;  int position;  {   struct templateSlot *slotPtr;   int i = 0;      slotPtr = theDeftemplate->slotList;   while (slotPtr != NULL)     {      if (i == position) return(slotPtr);

⌨️ 快捷键说明

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