📄 strngfun.c
字号:
if (EnvArgTypeCheck(theEnv,"eval",1,SYMBOL_OR_STRING,&theArg) == FALSE) { SetpType(returnValue,SYMBOL); SetpValue(returnValue,EnvFalseSymbol(theEnv)); return; } /*======================*/ /* Evaluate the string. */ /*======================*/ EnvEval(theEnv,DOToString(theArg),returnValue); }/*****************************//* EnvEval: C access routine *//* for the eval function. *//*****************************/globle int EnvEval( void *theEnv, char *theString, DATA_OBJECT_PTR returnValue) { struct expr *top; int ov; static int depth = 0; char logicalNameBuffer[20]; struct BindInfo *oldBinds; /*======================================================*/ /* Evaluate the string. Create a different logical name */ /* for use each time the eval function is called. */ /*======================================================*/ depth++; gensprintf(logicalNameBuffer,"Eval-%d",depth); if (OpenStringSource(theEnv,logicalNameBuffer,theString,0) == 0) { SetpType(returnValue,SYMBOL); SetpValue(returnValue,EnvFalseSymbol(theEnv)); depth--; return(FALSE); } /*================================================*/ /* Save the current parsing state before routines */ /* are called to parse the eval string. */ /*================================================*/ ov = GetPPBufferStatus(theEnv); SetPPBufferStatus(theEnv,FALSE); oldBinds = GetParsedBindNames(theEnv); SetParsedBindNames(theEnv,NULL); /*========================================================*/ /* Parse the string argument passed to the eval function. */ /*========================================================*/ top = ParseAtomOrExpression(theEnv,logicalNameBuffer,NULL); /*============================*/ /* Restore the parsing state. */ /*============================*/ SetPPBufferStatus(theEnv,ov); ClearParsedBindNames(theEnv); SetParsedBindNames(theEnv,oldBinds); /*===========================================*/ /* Return if an error occured while parsing. */ /*===========================================*/ if (top == NULL) { SetEvaluationError(theEnv,TRUE); CloseStringSource(theEnv,logicalNameBuffer); SetpType(returnValue,SYMBOL); SetpValue(returnValue,EnvFalseSymbol(theEnv)); depth--; return(FALSE); } /*==============================================*/ /* The sequence expansion operator must be used */ /* within the argument list of a function call. */ /*==============================================*/ if ((top->type == MF_GBL_VARIABLE) || (top->type == MF_VARIABLE)) { PrintErrorID(theEnv,"MISCFUN",1,FALSE); EnvPrintRouter(theEnv,WERROR,"expand$ must be used in the argument list of a function call.\n"); SetEvaluationError(theEnv,TRUE); CloseStringSource(theEnv,logicalNameBuffer); SetpType(returnValue,SYMBOL); SetpValue(returnValue,EnvFalseSymbol(theEnv)); ReturnExpression(theEnv,top); depth--; return(FALSE); } /*=======================================*/ /* The expression to be evaluated cannot */ /* contain any local variables. */ /*=======================================*/ if (ExpressionContainsVariables(top,FALSE)) { PrintErrorID(theEnv,"STRNGFUN",2,FALSE); EnvPrintRouter(theEnv,WERROR,"Some variables could not be accessed by the eval function.\n"); SetEvaluationError(theEnv,TRUE); CloseStringSource(theEnv,logicalNameBuffer); SetpType(returnValue,SYMBOL); SetpValue(returnValue,EnvFalseSymbol(theEnv)); ReturnExpression(theEnv,top); depth--; return(FALSE); } /*====================================*/ /* Evaluate the expression and return */ /* the memory used to parse it. */ /*====================================*/ ExpressionInstall(theEnv,top); EvaluateExpression(theEnv,top,returnValue); ExpressionDeinstall(theEnv,top); depth--; ReturnExpression(theEnv,top); CloseStringSource(theEnv,logicalNameBuffer); /*==========================================*/ /* Perform periodic cleanup if the eval was */ /* issued from an embedded controller. */ /*==========================================*/ if ((EvaluationData(theEnv)->CurrentEvaluationDepth == 0) && (! CommandLineData(theEnv)->EvaluatingTopLevelCommand) && (EvaluationData(theEnv)->CurrentExpression == NULL)) { ValueInstall(theEnv,returnValue); PeriodicCleanup(theEnv,TRUE,FALSE); ValueDeinstall(theEnv,returnValue); } if (GetEvaluationError(theEnv)) return(FALSE); return(TRUE); }#else/*************************************************//* EvalFunction: This is the non-functional stub *//* provided for use with a run-time version. *//*************************************************/globle void EvalFunction( void *theEnv, DATA_OBJECT_PTR returnValue) { PrintErrorID(theEnv,"STRNGFUN",1,FALSE); EnvPrintRouter(theEnv,WERROR,"Function eval does not work in run time modules.\n"); SetpType(returnValue,SYMBOL); SetpValue(returnValue,EnvFalseSymbol(theEnv)); }/*****************************************************//* EnvEval: This is the non-functional stub provided *//* for use with a run-time version. *//*****************************************************/globle int EnvEval( void *theEnv, char *theString, DATA_OBJECT_PTR returnValue) {#if (MAC_MCW || IBM_MCW) && (RUN_TIME || BLOAD_ONLY)#pragma unused(theString)#endif PrintErrorID(theEnv,"STRNGFUN",1,FALSE); EnvPrintRouter(theEnv,WERROR,"Function eval does not work in run time modules.\n"); SetpType(returnValue,SYMBOL); SetpValue(returnValue,EnvFalseSymbol(theEnv)); return(FALSE); }#endif#if (! RUN_TIME) && (! BLOAD_ONLY)/***************************************//* BuildFunction: H/L access routine *//* for the build function. *//***************************************/globle int BuildFunction( void *theEnv) { DATA_OBJECT theArg; /*==============================================*/ /* Function build expects exactly one argument. */ /*==============================================*/ if (EnvArgCountCheck(theEnv,"build",EXACTLY,1) == -1) return(FALSE); /*==================================================*/ /* The argument should be of type SYMBOL or STRING. */ /*==================================================*/ if (EnvArgTypeCheck(theEnv,"build",1,SYMBOL_OR_STRING,&theArg) == FALSE) { return(FALSE); } /*======================*/ /* Build the construct. */ /*======================*/ return(EnvBuild(theEnv,DOToString(theArg))); }/******************************//* EnvBuild: C access routine *//* for the build function. *//******************************/globle int EnvBuild( void *theEnv, char *theString) { char *constructType; struct token theToken; int errorFlag; /*====================================================*/ /* No additions during defrule join network activity. */ /*====================================================*/#if DEFRULE_CONSTRUCT if (EngineData(theEnv)->JoinOperationInProgress) return(FALSE);#endif /*===========================================*/ /* Create a string source router so that the */ /* string can be used as an input source. */ /*===========================================*/ if (OpenStringSource(theEnv,"build",theString,0) == 0) { return(FALSE); } /*================================*/ /* The first token of a construct */ /* must be a left parenthesis. */ /*================================*/ GetToken(theEnv,"build",&theToken); if (theToken.type != LPAREN) { CloseStringSource(theEnv,"build"); return(FALSE); } /*==============================================*/ /* The next token should be the construct type. */ /*==============================================*/ GetToken(theEnv,"build",&theToken); if (theToken.type != SYMBOL) { CloseStringSource(theEnv,"build"); return(FALSE); } constructType = ValueToString(theToken.value); /*======================*/ /* Parse the construct. */ /*======================*/ errorFlag = ParseConstruct(theEnv,constructType,"build"); /*=================================*/ /* Close the string source router. */ /*=================================*/ CloseStringSource(theEnv,"build"); /*=========================================*/ /* If an error occured while parsing the */ /* construct, then print an error message. */ /*=========================================*/ if (errorFlag == 1) { EnvPrintRouter(theEnv,WERROR,"\nERROR:\n"); PrintInChunks(theEnv,WERROR,GetPPBuffer(theEnv)); EnvPrintRouter(theEnv,WERROR,"\n"); } DestroyPPBuffer(theEnv); /*===========================================*/ /* Perform periodic cleanup if the build was */ /* issued from an embedded controller. */ /*===========================================*/ if ((EvaluationData(theEnv)->CurrentEvaluationDepth == 0) && (! CommandLineData(theEnv)->EvaluatingTopLevelCommand) && (EvaluationData(theEnv)->CurrentExpression == NULL)) { PeriodicCleanup(theEnv,TRUE,FALSE); } /*===============================================*/ /* Return TRUE if the construct was successfully */ /* parsed, otherwise return FALSE. */ /*===============================================*/ if (errorFlag == 0) return(TRUE); return(FALSE); }#else/**************************************************//* BuildFunction: This is the non-functional stub *//* provided for use with a run-time version. *//**************************************************/globle int BuildFunction( void *theEnv) { PrintErrorID(theEnv,"STRNGFUN",1,FALSE); EnvPrintRouter(theEnv,WERROR,"Function build does not work in run time modules.\n"); return(FALSE); }/******************************************************//* EnvBuild: This is the non-functional stub provided *//* for use with a run-time version. *//******************************************************/globle int EnvBuild( void *theEnv, char *theString) { #if (MAC_MCW || IBM_MCW) && (RUN_TIME || BLOAD_ONLY)#pragma unused(theString)#endif PrintErrorID(theEnv,"STRNGFUN",1,FALSE); EnvPrintRouter(theEnv,WERROR,"Function build does not work in run time modules.\n"); return(FALSE); }#endif /* (! RUN_TIME) && (! BLOAD_ONLY) */#endif /* STRING_FUNCTIONS */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -