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

📄 factcom.c

📁 clips源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
   /* Check for the correct number of arguments. */   /*============================================*/   if (EnvArgCountCheck(theEnv,"fact-index",EXACTLY,1) == -1) return(-1LL);   /*========================*/   /* Evaluate the argument. */   /*========================*/   EnvRtnUnknown(theEnv,1,&item);   /*======================================*/   /* The argument must be a fact address. */   /*======================================*/   if (GetType(item) != FACT_ADDRESS)     {      ExpectedTypeError1(theEnv,"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(-1LL);   return (EnvFactIndex(theEnv,GetValue(item)));  }#if DEBUGGING_FUNCTIONS/**************************************//* FactsCommand: H/L access routine   *//*   for the facts command.           *//**************************************/globle void FactsCommand(  void *theEnv)  {   int argumentCount;   long long 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 = EnvArgCountCheck(theEnv,"facts",NO_MORE_THAN,4)) == -1) return;   /*==================================*/   /* The default module for the facts */   /* command is the current module.   */   /*==================================*/   theModule = ((struct defmodule *) EnvGetCurrentModule(theEnv));   /*==========================================*/   /* If no arguments were specified, then use */   /* the default values to list the facts.    */   /*==========================================*/   if (argumentCount == 0)     {      EnvFacts(theEnv,WDISPLAY,theModule,start,end,max);      return;     }   /*========================================================*/   /* Since there are one or more arguments, see if a module */   /* or start index was specified as the first argument.    */   /*========================================================*/   EnvRtnUnknown(theEnv,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 *) EnvFindDefmodule(theEnv,ValueToString(theValue.value));      if ((theModule == NULL) && (strcmp(ValueToString(theValue.value),"*") != 0))        {         SetEvaluationError(theEnv,TRUE);         CantFindItemErrorMessage(theEnv,"defmodule",ValueToString(theValue.value));         return;        }      if ((start = GetFactsArgument(theEnv,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(theEnv,"facts",1,"symbol or positive number");         SetHaltExecution(theEnv,TRUE);         SetEvaluationError(theEnv,TRUE);         return;        }      argOffset = 0;     }   /*==========================================*/   /* Otherwise the first argument is invalid. */   /*==========================================*/   else     {      ExpectedTypeError1(theEnv,"facts",1,"symbol or positive number");      SetHaltExecution(theEnv,TRUE);      SetEvaluationError(theEnv,TRUE);      return;     }   /*==========================*/   /* Get the other arguments. */   /*==========================*/   if ((end = GetFactsArgument(theEnv,2 + argOffset,argumentCount)) == INVALID) return;   if ((max = GetFactsArgument(theEnv,3 + argOffset,argumentCount)) == INVALID) return;   /*=================*/   /* List the facts. */   /*=================*/   EnvFacts(theEnv,WDISPLAY,theModule,start,end,max);  }/*****************************************************//* EnvFacts: C access routine for the facts command. *//*****************************************************/globle void EnvFacts(  void *theEnv,  char *logicalName,  void *vTheModule,  long long start,  long long end,  long long max)  {   struct fact *factPtr;   long count = 0;   struct defmodule *oldModule, *theModule = (struct defmodule *) vTheModule;   int allModules = FALSE;   /*==========================*/   /* Save the current module. */   /*==========================*/   oldModule = ((struct defmodule *) EnvGetCurrentModule(theEnv));   /*=========================================================*/   /* Determine if facts from all modules are to be displayed */   /* or just facts from the current module.                  */   /*=========================================================*/   if (theModule == NULL) allModules = TRUE;   else EnvSetCurrentModule(theEnv,(void *) theModule);   /*=====================================*/   /* Get the first fact to be displayed. */   /*=====================================*/   if (allModules) factPtr = (struct fact *) EnvGetNextFact(theEnv,NULL);   else factPtr = (struct fact *) GetNextFactInScope(theEnv,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(theEnv) == TRUE)        {         EnvSetCurrentModule(theEnv,(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(theEnv,logicalName,count,"fact","facts");         EnvSetCurrentModule(theEnv,(void *) oldModule);         return;        }      /*================================================*/      /* If the maximum number of facts to be displayed */      /* has been reached, then stop displaying facts.  */      /*================================================*/      if (max == 0)        {         PrintTally(theEnv,logicalName,count,"fact","facts");         EnvSetCurrentModule(theEnv,(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(theEnv,logicalName,factPtr);         EnvPrintRouter(theEnv,logicalName,"\n");         count++;         if (max > 0) max--;        }      /*========================================*/      /* Proceed to the next fact to be listed. */      /*========================================*/      if (allModules) factPtr = (struct fact *) EnvGetNextFact(theEnv,factPtr);      else factPtr = (struct fact *) GetNextFactInScope(theEnv,factPtr);     }   /*===================================================*/   /* Print the total of the number of facts displayed. */   /*===================================================*/   PrintTally(theEnv,logicalName,count,"fact","facts");   /*=============================*/   /* Restore the current module. */   /*=============================*/   EnvSetCurrentModule(theEnv,(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 long GetFactsArgument(  void *theEnv,  int whichOne,  int argumentCount)  {   long long factIndex;   DATA_OBJECT theValue;   if (whichOne > argumentCount) return(UNSPECIFIED);   if (EnvArgTypeCheck(theEnv,"facts",whichOne,INTEGER,&theValue) == FALSE) return(INVALID);   factIndex = DOToLong(theValue);   if (factIndex < 0)     {      ExpectedTypeError1(theEnv,"facts",whichOne,"positive number");      SetHaltExecution(theEnv,TRUE);      SetEvaluationError(theEnv,TRUE);      return(INVALID);     }   return(factIndex);  }#endif /* DEBUGGING_FUNCTIONS *//**********************************************//* AssertStringFunction: H/L access routine   *//*   for the assert-string function.          *//**********************************************/globle void AssertStringFunction(  void *theEnv,  DATA_OBJECT_PTR returnValue)  {   DATA_OBJECT argPtr;   struct fact *theFact;   /*===================================================*/   /* Set the default return value to the symbol FALSE. */   /*===================================================*/   SetpType(returnValue,SYMBOL);   SetpValue(returnValue,EnvFalseSymbol(theEnv));   /*=====================================================*/   /* Check for the correct number and type of arguments. */   /*=====================================================*/   if (EnvArgCountCheck(theEnv,"assert-string",EXACTLY,1) == -1) return;   if (EnvArgTypeCheck(theEnv,"assert-string",1,STRING,&argPtr) == FALSE)     { return; }   /*==========================================*/   /* Call the driver routine for converting a */   /* string to a fact and then assert it.     */   /*==========================================*/   theFact = (struct fact *) EnvAssertString(theEnv,DOToString(argPtr));   if (theFact != NULL)     {      SetpType(returnValue,FACT_ADDRESS);      SetpValue(returnValue,(void *) theFact);     }   return;  }/******************************************//* SaveFactsCommand: H/L access routine   *//*   for the save-facts command.          *//******************************************/globle int SaveFactsCommand(  void *theEnv)  {   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 = EnvArgCountCheck(theEnv,"save-facts",AT_LEAST,1)) == -1) return(FALSE);   /*=================================================*/   /* Get the file name to which facts will be saved. */   /*=================================================*/   if ((fileName = GetFileName(theEnv,"save-facts",1)) == NULL) return(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 (EnvArgTypeCheck(theEnv,"save-facts",2,SYMBOL,&theValue) == FALSE) return(FALSE);      argument = DOToString(theValue);      if (strcmp(argument,"local") == 0)        { saveCode = LOCAL_SAVE; }      else if (strcmp(argument,"visible") == 0)        { saveCode = VISIBLE_SAVE; }      else        {         ExpectedTypeError1(theEnv,"save-facts",2,"symbol with value local or visible");         return(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 (EnvSaveFacts(theEnv,fileName,saveCode,theList) == FALSE)     { return(FALSE); }   return(TRUE);  }/******************************************//* LoadFactsCommand: H/L access routine   *//*   for the load-facts command.          *//******************************************/globle int LoadFactsCommand(  void *theEnv)  {   char *fileName;   /*============================================*/   /* Check for the correct number of arguments. */   /*============================================*/   if (EnvArgCountCheck(theEnv,"load-facts",EXACTLY,1) == -1) return(FALSE);   /*====================================================*/   /* Get the file name from which facts will be loaded. */   /*====================================================*/   if ((fileName = GetFileName(theEnv,"load-facts",1)) == NULL) return(FALSE);   /*====================================*/   /* Call the LoadFacts driver routine. */   /*====================================*/   if (EnvLoadFacts(theEnv,fileName) == FALSE) return(FALSE);   return(TRUE);  }/**************************************************************//* EnvSaveFacts: C access routine for the save-facts command. *//**************************************************************/globle intBool EnvSaveFacts(  void *theEnv,  char *fileName,  int saveCode,  struct expr *theList)

⌨️ 快捷键说明

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