📄 getenv.java
字号:
package jmathlib.toolbox.jmathlib.system;
import jmathlib.core.interpreter.*;
import jmathlib.core.functions.ExternalFunction;
import jmathlib.core.tokens.Token;
import jmathlib.core.tokens.CharToken;
import jmathlib.core.tokens.OperandToken;
/**External function to get a enviroment variable*/
public class getenv extends ExternalFunction
{
/**Returns an enviroment variable
@param operand[0] = the name of the variable
@param operand[1] = a default value (optional)
@return the enviroment value*/
public OperandToken evaluate(Token[] operands)
{
OperandToken result = null;
if(operands[0] instanceof CharToken)
{
String name = operands[0].toString();
String defaultVal = "";
if(operands.length > 1)
{
defaultVal = operands[1].toString();
}
String property = System.getProperty(name, defaultVal);
result = new CharToken(property);
}
else
Errors.throwMathLibException(ERR_INVALID_PARAMETER, new Object[] {"CharToken", operands[0].getClass().getName()});
return result;
}
}
/*
@GROUP
system
@SYNTAX
GETENV(variablename)
@DOC
Returns the value of the enviromental variable variablename.
@NOTES
@EXAMPLES
GETENV("HOME")= "/home/user"
@SEE
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -