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

📄 factcom.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 3 页
字号:
   /*============================================*/   /* Check for the correct number of arguments. */   /*============================================*/      if (ArgCountCheck("fact-index",EXACTLY,1) == -1) return(-1L);   /*========================*/   /* Evaluate the argument. */   /*========================*/      RtnUnknown(1,&item);   /*======================================*/   /* The argument must be a fact address. */   /*======================================*/      if (GetType(item) != FACT_ADDRESS)     {      ExpectedTypeError1("fact-index",1,"fact-address");      return(-1L);     }        /*================================================*/   /* Return the fact index associated with the fact */   /* address. If the fact has been retracted, then  */   /* return -1 for the fact index.                  */   /*================================================*/   if (((struct fact *) GetValue(item))->garbage) return(-1L);      return (FactIndex(GetValue(item)));   }#if DEBUGGING_FUNCTIONS/**************************************//* FactsCommand: CLIPS access routine *//*   for the facts command.           *//**************************************/globle VOID FactsCommand()  {   int argumentCount;   long int start = UNSPECIFIED, end = UNSPECIFIED, max = UNSPECIFIED;   struct defmodule *theModule;   DATA_OBJECT theValue;   int argOffset;   /*=========================================================*/   /* Determine the number of arguments to the facts command. */   /*=========================================================*/      if ((argumentCount = ArgCountCheck("facts",NO_MORE_THAN,4)) == -1) return;      /*==================================*/   /* The default module for the facts */   /* command is the current module.   */   /*==================================*/      theModule = ((struct defmodule *) GetCurrentModule());      /*==========================================*/   /* If no arguments were specified, then use */   /* the default values to list the facts.    */   /*==========================================*/      if (argumentCount == 0)     {      Facts(WDISPLAY,theModule,(long) start,(long) end,(long) max);      return;     }        /*========================================================*/   /* Since there are one or more arguments, see if a module */   /* or start index was specified as the first argument.    */   /*========================================================*/      RtnUnknown(1,&theValue);      /*===============================================*/   /* If the first argument is a symbol, then check */   /* to see that a valid module was specified.     */   /*===============================================*/      if (theValue.type == SYMBOL)     {      theModule = (struct defmodule *) FindDefmodule(ValueToString(theValue.value));      if ((theModule == NULL) && (strcmp(ValueToString(theValue.value),"*") != 0))        {         SetEvaluationError(CLIPS_TRUE);         CantFindItemErrorMessage("defmodule",ValueToString(theValue.value));         return;        }              if ((start = GetFactsArgument(2,argumentCount)) == INVALID) return;              argOffset = 1;     }      /*================================================*/   /* Otherwise if the first argument is an integer, */   /* check to see that a valid index was specified. */   /*================================================*/      else if (theValue.type == INTEGER)     {         start = DOToLong(theValue);      if (start < 0)        {         ExpectedTypeError1("facts",1,"symbol or positive number");         SetHaltExecution(CLIPS_TRUE);         SetEvaluationError(CLIPS_TRUE);         return;        }      argOffset = 0;     }      /*==========================================*/   /* Otherwise the first argument is invalid. */   /*==========================================*/      else     {        ExpectedTypeError1("facts",1,"symbol or positive number");      SetHaltExecution(CLIPS_TRUE);      SetEvaluationError(CLIPS_TRUE);      return;     }   /*==========================*/   /* Get the other arguments. */   /*==========================*/      if ((end = GetFactsArgument(2 + argOffset,argumentCount)) == INVALID) return;   if ((max = GetFactsArgument(3 + argOffset,argumentCount)) == INVALID) return;   /*=================*/   /* List the facts. */   /*=================*/      Facts(WDISPLAY,theModule,(long) start,(long) end,(long) max);  }/**************************************************//* Facts: C access routine for the facts command. *//**************************************************/globle VOID Facts(logicalName,vTheModule,start,end,max)  char *logicalName;  VOID *vTheModule;  long start, end, max;  {   struct fact *factPtr;   long count = 0;   struct defmodule *oldModule, *theModule = (struct defmodule *) vTheModule;   int allModules = CLIPS_FALSE;   /*==========================*/   /* Save the current module. */   /*==========================*/      oldModule = ((struct defmodule *) GetCurrentModule());      /*=========================================================*/   /* Determine if facts from all modules are to be displayed */   /* or just facts from the current module.                  */   /*=========================================================*/      if (theModule == NULL) allModules = CLIPS_TRUE;   else SetCurrentModule((VOID *) theModule);      /*=====================================*/   /* Get the first fact to be displayed. */   /*=====================================*/      if (allModules) factPtr = (struct fact *) GetNextFact(NULL);   else factPtr = (struct fact *) GetNextFactInScope(NULL);      /*===============================*/   /* Display facts until there are */   /* no more facts to display.     */   /*===============================*/      while (factPtr != NULL)     {      /*==================================================*/      /* Abort the display of facts if the Halt Execution */      /* flag has been set (normally by user action).     */      /*==================================================*/            if (GetHaltExecution() == CLIPS_TRUE)         {         SetCurrentModule((VOID *) oldModule);         return;        }              /*===============================================*/      /* If the maximum fact index of facts to display */      /* has been reached, then stop displaying facts. */      /*===============================================*/            if ((factPtr->factIndex > end) && (end != UNSPECIFIED))        {         PrintTally(logicalName,count,"fact","facts");         SetCurrentModule((VOID *) oldModule);         return;        }      /*================================================*/      /* If the maximum number of facts to be displayed */      /* has been reached, then stop displaying facts.  */      /*================================================*/            if (max == 0)        {         PrintTally(logicalName,count,"fact","facts");         SetCurrentModule((VOID *) oldModule);         return;        }      /*======================================================*/      /* If the index of the fact is greater than the minimum */      /* starting fact index, then display the fact.          */      /*======================================================*/            if (factPtr->factIndex >= start)        {         PrintFactWithIdentifier(WDISPLAY,factPtr);         PrintCLIPS(logicalName,"\n");         count++;         if (max > 0) max--;        }      /*========================================*/      /* Proceed to the next fact to be listed. */      /*========================================*/            if (allModules) factPtr = (struct fact *) GetNextFact(factPtr);      else factPtr = (struct fact *) GetNextFactInScope(factPtr);     }   /*===================================================*/   /* Print the total of the number of facts displayed. */   /*===================================================*/      PrintTally(logicalName,count,"fact","facts");      /*=============================*/   /* Restore the current module. */   /*=============================*/      SetCurrentModule((VOID *) oldModule);  }  /****************************************************************//* GetFactsArgument: Returns an argument for the facts command. *//*  A return value of -1 indicates that no value was specified. *//*  A return value of -2 indicates that the value specified is  *//*  invalid.                                                    *//****************************************************************/static long int GetFactsArgument(whichOne,argumentCount)  int whichOne, argumentCount;  {   long int factIndex;   DATA_OBJECT theValue;   if (whichOne > argumentCount) return(UNSPECIFIED);   if (ArgTypeCheck("facts",whichOne,INTEGER,&theValue) == CLIPS_FALSE) return(INVALID);      factIndex = DOToLong(theValue);      if (factIndex < 0)     {      ExpectedTypeError1("facts",whichOne,"positive number");      SetHaltExecution(CLIPS_TRUE);      SetEvaluationError(CLIPS_TRUE);      return(INVALID);     }        return(factIndex);  }#endif /* DEBUGGING_FUNCTIONS *//**********************************************//* AssertStringFunction: CLIPS access routine *//*   for the assert-string function.          *//**********************************************/globle VOID AssertStringFunction(returnValue)  DATA_OBJECT_PTR returnValue;  {   DATA_OBJECT argPtr;   struct fact *theFact;      /*===================================================*/   /* Set the default return value to the symbol FALSE. */   /*===================================================*/   SetpType(returnValue,SYMBOL);   SetpValue(returnValue,CLIPSFalseSymbol);   /*=====================================================*/   /* Check for the correct number and type of arguments. */   /*=====================================================*/      if (ArgCountCheck("assert-string",EXACTLY,1) == -1) return;   if (ArgTypeCheck("assert-string",1,STRING,&argPtr) == CLIPS_FALSE)     { return; }   /*==========================================*/   /* Call the driver routine for converting a */   /* string to a fact and then assert it.     */   /*==========================================*/      theFact = (struct fact *) AssertString(DOToString(argPtr));   if (theFact != NULL)     {      SetpType(returnValue,FACT_ADDRESS);      SetpValue(returnValue,(VOID *) theFact);     }        return;  }/******************************************//* SaveFactsCommand: CLIPS access routine *//*   for the save-facts command.          *//******************************************/globle int SaveFactsCommand()  {   char *fileName;   int numArgs, saveCode = LOCAL_SAVE;   char *argument;   DATA_OBJECT theValue;   struct expr *theList = NULL;   /*============================================*/   /* Check for the correct number of arguments. */   /*============================================*/      if ((numArgs = ArgCountCheck("save-facts",AT_LEAST,1)) == -1) return(CLIPS_FALSE);      /*=================================================*/   /* Get the file name to which facts will be saved. */   /*=================================================*/      if ((fileName = GetFileName("save-facts",1)) == NULL) return(CLIPS_FALSE);      /*=============================================================*/   /* If specified, the second argument to save-facts indicates   */   /* whether just facts local to the current module or all facts */   /* visible to the current module will be saved.                */   /*=============================================================*/      if (numArgs > 1)     {      if (ArgTypeCheck("save-facts",2,SYMBOL,&theValue) == CLIPS_FALSE) return(CLIPS_FALSE);      argument = DOToString(theValue);      if (strcmp(argument,"local") == 0)        { saveCode = LOCAL_SAVE; }      else if (strcmp(argument,"visible") == 0)        { saveCode = VISIBLE_SAVE; }      else        {         ExpectedTypeError1("save-facts",2,"symbol with value local or visible");         return(CLIPS_FALSE);        }     }      /*======================================================*/   /* Subsequent arguments indicate that only those facts  */   /* associated with the specified deftemplates should be */   /* saved to the file.                                   */   /*======================================================*/      if (numArgs > 2) theList = GetFirstArgument()->nextArg->nextArg;   /*====================================*/   /* Call the SaveFacts driver routine. */   /*====================================*/      if (SaveFacts(fileName,saveCode,theList) == CLIPS_FALSE)     { return(CLIPS_FALSE); }   return(CLIPS_TRUE);  }/******************************************//* LoadFactsCommand: CLIPS access routine *//*   for the load-facts command.          *//******************************************/globle int LoadFactsCommand()  {   char *fileName;   /*============================================*/   /* Check for the correct number of arguments. */   /*============================================*/      if (ArgCountCheck("load-facts",EXACTLY,1) == -1) return(CLIPS_FALSE);   /*====================================================*/   /* Get the file name from which facts will be loaded. */   /*====================================================*/   if ((fileName = GetFileName("load-facts",1)) == NULL) return(CLIPS_FALSE);   /*====================================*/   /* Call the LoadFacts driver routine. */   /*====================================*/      if (LoadFacts(fileName) == CLIPS_FALSE) return(CLIPS_FALSE);   return(CLIPS_TRUE);  }/***********************************************************//* SaveFacts: C access routine for the save-facts command. *//***********************************************************/globle BOOLEAN SaveFacts(fileName,saveCode,theList)  char *fileName;  int saveCode;  struct expr *theList;  {   int tempValue1, tempValue2, tempValue3;

⌨️ 快捷键说明

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