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

📄 argacces.c

📁 NASA 开发使用的一个专家系统
💻 C
📖 第 1 页 / 共 3 页
字号:
   PrintCLIPS(WERROR,"Function ");   PrintCLIPS(WERROR,functionName);   PrintCLIPS(WERROR," was unable to open file ");   PrintCLIPS(WERROR,fileName);   PrintCLIPS(WERROR,".\n");  }  /************************************************************//* GetModuleName: Retrieves the nth argument passed to the  *//*   function call currently being evaluated and determines *//*   if it is a valid module name. If valid, the module     *//*   name is returned or NULL is returned to indicate all   *//*   modules.                                               *//************************************************************/globle struct defmodule *GetModuleName(functionName,whichArgument,error)  char *functionName;  int whichArgument;  int *error;  {   DATA_OBJECT result;   struct defmodule *theModule;      *error = CLIPS_FALSE;      /*========================*/   /* Retrieve the argument. */   /*========================*/      RtnUnknown(whichArgument,&result);   /*=================================*/   /* A module name must be a symbol. */   /*=================================*/      if (GetType(result) != SYMBOL)     {      ExpectedTypeError1(functionName,whichArgument,"defmodule name");      *error = CLIPS_TRUE;      return(NULL);     }      /*=======================================*/   /* Check to see that the symbol actually */   /* corresponds to a defined module.      */   /*=======================================*/            if ((theModule = (struct defmodule *) FindDefmodule(DOToString(result))) == NULL)     {      if (strcmp("*",DOToString(result)) != 0)         {         ExpectedTypeError1(functionName,1,"defmodule name");         *error = CLIPS_TRUE;        }      return(NULL);     }        /*=================================*/   /* Return a pointer to the module. */   /*=================================*/      return(theModule);  }  /****************************************************************//* GetConstructName: Retrieves the 1st argument passed to the   *//*   function call currently being evaluated and determines if  *//*   it is a valid name for a construct. Also checks that the   *//*   function is only passed a single argument. This routine    *//*   is used by functions such as ppdeftemplate, undefrule,     *//*   etc... to retrieve the construct name on which to operate. *//****************************************************************/globle char *GetConstructName(functionName,constructType)  char *functionName, *constructType;  {   DATA_OBJECT result;   if (RtnArgCount() != 1)     {      ExpectedCountError(functionName,EXACTLY,1);      return(NULL);     }   RtnUnknown(1,&result);   if (GetType(result) != SYMBOL)     {      ExpectedTypeError1(functionName,1,constructType);      return(NULL);     }   return(DOToString(result));  }/**************************************************************************//* NonexistantError: Prints the error message for a nonexistant argument. *//**************************************************************************/static VOID NonexistantError(accessFunction,functionName,argumentPosition)  char *accessFunction, *functionName;  int argumentPosition;  {   PrintErrorID("ARGACCES",3,CLIPS_FALSE);   PrintCLIPS(WERROR,"Function ");   PrintCLIPS(WERROR,accessFunction);   PrintCLIPS(WERROR," received a request from function ");   PrintCLIPS(WERROR,functionName);   PrintCLIPS(WERROR," for argument #");   PrintLongInteger(WERROR,(long int) argumentPosition);   PrintCLIPS(WERROR," which is non-existent\n");  } /*********************************************************//* ExpectedCountError: Prints the error message for an   *//*   incorrect number of arguments passed to a function. *//*********************************************************/globle VOID ExpectedCountError(functionName,countRelation,expectedNumber)  char *functionName;  int countRelation, expectedNumber;  {   PrintErrorID("ARGACCES",4,CLIPS_FALSE);   PrintCLIPS(WERROR,"Function ");   PrintCLIPS(WERROR,functionName);   if (countRelation == EXACTLY)     { PrintCLIPS(WERROR," expected exactly "); }   else if (countRelation == AT_LEAST)     { PrintCLIPS(WERROR," expected at least "); }   else if (countRelation == NO_MORE_THAN)     { PrintCLIPS(WERROR," expected no more than "); }   else      { PrintCLIPS(WERROR," generated an illegal argument check for "); }   PrintLongInteger(WERROR,(long int) expectedNumber);   PrintCLIPS(WERROR," argument(s)\n");  }  /*************************************************************//*  NAME         : CheckFunctionArgCount                     *//*  DESCRIPTION  : Checks the number of arguments against    *//*                 the system function restriction list      *//*  INPUTS       : 1) Name of the calling function           *//*                 2) The restriction list can be NULL       *//*                 3) The number of arguments                *//*  RETURNS      : TRUE if OK, FALSE otherwise               *//*  SIDE EFFECTS : EvaluationError set on errrors            *//*  NOTES        : Used to check generic function implicit   *//*                 method (system function) calls and system *//*                 function calls which have the sequence    *//*                 expansion operator in their argument list */ /*************************************************************/globle BOOLEAN CheckFunctionArgCount(functionName,restrictions,argumentCount)  char *functionName, *restrictions;  int argumentCount;  {   register int minArguments, maxArguments;   char theChar[2];      theChar[0] = '0';   theChar[1] = EOS;      /*=====================================================*/   /* If there are no restrictions, then there is no need */   /* to check for the correct number of arguments.       */   /*=====================================================*/      if (restrictions == NULL) return(TRUE);      /*===========================================*/   /* Determine the minimum number of arguments */   /* required by the function.                 */   /*===========================================*/      if (isdigit(restrictions[0]))     {      theChar[0] = restrictions[0];      minArguments = atoi(theChar);     }   else     { minArguments = -1; }        /*===========================================*/   /* Determine the maximum number of arguments */   /* required by the function.                 */   /*===========================================*/      if (isdigit(restrictions[1]))     {      theChar[0] = restrictions[1];      maxArguments = atoi(theChar);     }   else     { maxArguments = 10000; }        /*==============================================*/   /* If the function expects exactly N arguments, */   /* then check to see if there are N arguments.  */   /*==============================================*/      if (minArguments == maxArguments)     {      if (argumentCount != minArguments)        {         ExpectedCountError(functionName,EXACTLY,minArguments);         SetEvaluationError(CLIPS_TRUE);         return(CLIPS_FALSE);        }      return(CLIPS_TRUE);     }        /*==================================*/   /* Check to see if there were fewer */   /* arguments passed than expected.  */   /*==================================*/        if (argumentCount < minArguments)     {      ExpectedCountError(functionName,AT_LEAST,minArguments);      SetEvaluationError(TRUE);      return(FALSE);     }        /*=================================*/   /* Check to see if there were more */   /* arguments passed than expected. */   /*=================================*/      if (argumentCount > maxArguments)     {      ExpectedCountError(functionName,NO_MORE_THAN,maxArguments);      SetEvaluationError(TRUE);      return(FALSE);     }        /*===============================*/   /* The number of arguments falls */   /* within the expected range.    */   /*===============================*/      return(TRUE);  }  /*******************************************************************//* ExpectedTypeError1: Prints the error message for the wrong type *//*   of argument passed to a user or system defined function. The  *//*   expected type is passed as a string to this function.         *//*******************************************************************/globle VOID ExpectedTypeError1(functionName,whichArg,expectedType)  char *functionName;  int whichArg;  char *expectedType;  {   PrintErrorID("ARGACCES",5,CLIPS_FALSE);   PrintCLIPS(WERROR,"Function ");   PrintCLIPS(WERROR,functionName);   PrintCLIPS(WERROR," expected argument #");   PrintLongInteger(WERROR,(long int) whichArg);   PrintCLIPS(WERROR," to be of type ");   PrintCLIPS(WERROR,expectedType);   PrintCLIPS(WERROR,"\n");  }  /**************************************************************//* ExpectedTypeError2: Prints the error message for the wrong *//*   type of argument passed to a user or system defined      *//*   function. The expected type is derived by examining the  *//*   function's argument restriction list.                    *//**************************************************************/globle VOID ExpectedTypeError2(functionName,whichArg)  char *functionName;  int whichArg;  {   struct FunctionDefinition *theFunction;   char *theType;      theFunction = FindFunction(functionName);      if (theFunction == NULL) return;      theType = GetArgumentTypeName(GetNthRestriction(theFunction,whichArg));      ExpectedTypeError1(functionName,whichArg,theType);  }  /*******************************************************************//* ExpectedTypeError3: Prints the error message for the wrong type *//*   of argument passed to a user or system defined function when  *//*   the argument was requested by calling RtnLexeme, RtnLong, or  *//*   RtnDouble.                                                    *//*******************************************************************/static VOID ExpectedTypeError3(accessFunction,functionName,argumentPosition,type)  char *accessFunction, *functionName, *type;  int argumentPosition;  {   PrintErrorID("ARGACCES",6,CLIPS_FALSE);   PrintCLIPS(WERROR,"Function ");   PrintCLIPS(WERROR,accessFunction);   PrintCLIPS(WERROR," received a request from function ");   PrintCLIPS(WERROR,functionName);   PrintCLIPS(WERROR," for argument #");   PrintLongInteger(WERROR,(long int) argumentPosition);   PrintCLIPS(WERROR," which is not of type ");   PrintCLIPS(WERROR,type);   PrintCLIPS(WERROR,"\n");  }

⌨️ 快捷键说明

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