argacces.c

来自「clips源代码」· C语言 代码 · 共 1,029 行 · 第 1/3 页

C
1,029
字号
   /*=================================*/   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(  void *theEnv,  char *functionName,  char *constructType)  {   DATA_OBJECT result;   if (EnvRtnArgCount(theEnv) != 1)     {      ExpectedCountError(theEnv,functionName,EXACTLY,1);      return(NULL);     }   EnvRtnUnknown(theEnv,1,&result);   if (GetType(result) != SYMBOL)     {      ExpectedTypeError1(theEnv,functionName,1,constructType);      return(NULL);     }   return(DOToString(result));  }/**************************************************************************//* NonexistantError: Prints the error message for a nonexistant argument. *//**************************************************************************/static void NonexistantError(  void *theEnv,  char *accessFunction,  char *functionName,  int argumentPosition)  {   PrintErrorID(theEnv,"ARGACCES",3,FALSE);   EnvPrintRouter(theEnv,WERROR,"Function ");   EnvPrintRouter(theEnv,WERROR,accessFunction);   EnvPrintRouter(theEnv,WERROR," received a request from function ");   EnvPrintRouter(theEnv,WERROR,functionName);   EnvPrintRouter(theEnv,WERROR," for argument #");   PrintLongInteger(theEnv,WERROR,(long int) argumentPosition);   EnvPrintRouter(theEnv,WERROR," which is non-existent\n");  }/*********************************************************//* ExpectedCountError: Prints the error message for an   *//*   incorrect number of arguments passed to a function. *//*********************************************************/globle void ExpectedCountError(  void *theEnv,  char *functionName,  int countRelation,  int expectedNumber)  {   PrintErrorID(theEnv,"ARGACCES",4,FALSE);   EnvPrintRouter(theEnv,WERROR,"Function ");   EnvPrintRouter(theEnv,WERROR,functionName);   if (countRelation == EXACTLY)     { EnvPrintRouter(theEnv,WERROR," expected exactly "); }   else if (countRelation == AT_LEAST)     { EnvPrintRouter(theEnv,WERROR," expected at least "); }   else if (countRelation == NO_MORE_THAN)     { EnvPrintRouter(theEnv,WERROR," expected no more than "); }   else     { EnvPrintRouter(theEnv,WERROR," generated an illegal argument check for "); }   PrintLongInteger(theEnv,WERROR,(long int) expectedNumber);   EnvPrintRouter(theEnv,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 intBool CheckFunctionArgCount(  void *theEnv,  char *functionName,  char *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(theEnv,functionName,EXACTLY,minArguments);         SetEvaluationError(theEnv,TRUE);         return(FALSE);        }      return(TRUE);     }   /*==================================*/   /* Check to see if there were fewer */   /* arguments passed than expected.  */   /*==================================*/   if (argumentCount < minArguments)     {      ExpectedCountError(theEnv,functionName,AT_LEAST,minArguments);      SetEvaluationError(theEnv,TRUE);      return(FALSE);     }   /*=================================*/   /* Check to see if there were more */   /* arguments passed than expected. */   /*=================================*/   if (argumentCount > maxArguments)     {      ExpectedCountError(theEnv,functionName,NO_MORE_THAN,maxArguments);      SetEvaluationError(theEnv,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(  void *theEnv,  char *functionName,  int whichArg,  char *expectedType)  {   PrintErrorID(theEnv,"ARGACCES",5,FALSE);   EnvPrintRouter(theEnv,WERROR,"Function ");   EnvPrintRouter(theEnv,WERROR,functionName);   EnvPrintRouter(theEnv,WERROR," expected argument #");   PrintLongInteger(theEnv,WERROR,(long int) whichArg);   EnvPrintRouter(theEnv,WERROR," to be of type ");   EnvPrintRouter(theEnv,WERROR,expectedType);   EnvPrintRouter(theEnv,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(  void *theEnv,  char *functionName,  int whichArg)  {   struct FunctionDefinition *theFunction;   char *theType;   theFunction = FindFunction(theEnv,functionName);   if (theFunction == NULL) return;   theType = GetArgumentTypeName(GetNthRestriction(theFunction,whichArg));   ExpectedTypeError1(theEnv,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(  void *theEnv,  char *accessFunction,  char *functionName,  int argumentPosition,  char *type)  {   PrintErrorID(theEnv,"ARGACCES",6,FALSE);   EnvPrintRouter(theEnv,WERROR,"Function ");   EnvPrintRouter(theEnv,WERROR,accessFunction);   EnvPrintRouter(theEnv,WERROR," received a request from function ");   EnvPrintRouter(theEnv,WERROR,functionName);   EnvPrintRouter(theEnv,WERROR," for argument #");   PrintLongInteger(theEnv,WERROR,(long int) argumentPosition);   EnvPrintRouter(theEnv,WERROR," which is not of type ");   EnvPrintRouter(theEnv,WERROR,type);   EnvPrintRouter(theEnv,WERROR,"\n");  }/***************************************************//* GetFactOrInstanceArgument: Utility routine for  *//*   retrieving a fact or instance argument        *//***************************************************/void *GetFactOrInstanceArgument(  void *theEnv,  int thePosition,  DATA_OBJECT *item,  char *functionName)  {#if DEFTEMPLATE_CONSTRUCT || OBJECT_SYSTEM   void *ptr;#endif   /*==============================*/   /* Retrieve the first argument. */   /*==============================*/   EnvRtnUnknown(theEnv,thePosition,item);   /*==================================================*/   /* Fact and instance addresses are valid arguments. */   /*==================================================*/   if ((GetpType(item) == FACT_ADDRESS) ||       (GetpType(item) == INSTANCE_ADDRESS))     { return(GetpValue(item)); }   /*==================================================*/   /* An integer is a valid argument if it corresponds */   /* to the fact index of an existing fact.           */   /*==================================================*/#if DEFTEMPLATE_CONSTRUCT   else if (GetpType(item) == INTEGER)     {      if ((ptr = (void *) FindIndexedFact(theEnv,DOPToLong(item))) == NULL)        {         char tempBuffer[20];         gensprintf(tempBuffer,"f-%lld",DOPToLong(item));         CantFindItemErrorMessage(theEnv,"fact",tempBuffer);        }      return(ptr);     }#endif   /*================================================*/   /* Instance names and symbols are valid arguments */   /* if they correspond to an existing instance.    */   /*================================================*/#if OBJECT_SYSTEM   else if ((GetpType(item) == INSTANCE_NAME) || (GetpType(item) == SYMBOL))     {      if ((ptr = (void *) FindInstanceBySymbol(theEnv,(SYMBOL_HN *) GetpValue(item))) == NULL)        {         CantFindItemErrorMessage(theEnv,"instance",ValueToString(GetpValue(item)));        }      return(ptr);     }#endif   /*========================================*/   /* Any other type is an invalid argument. */   /*========================================*/   ExpectedTypeError2(theEnv,functionName,thePosition);   return(NULL);  }/****************************************************//* IllegalLogicalNameMessage: Generic error message *//*   for illegal logical names.                     *//****************************************************/void IllegalLogicalNameMessage(  void *theEnv,  char *theFunction)  {   PrintErrorID(theEnv,"IOFUN",1,FALSE);   EnvPrintRouter(theEnv,WERROR,"Illegal logical name used for ");   EnvPrintRouter(theEnv,WERROR,theFunction);   EnvPrintRouter(theEnv,WERROR," function.\n");  }

⌨️ 快捷键说明

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