diff options
author | kate.ward <kate.ward@forestent.com> | 2013-01-05 13:57:46 +0000 |
---|---|---|
committer | kate.ward <kate.ward@forestent.com> | 2013-01-05 13:57:46 +0000 |
commit | b075920c3109938f9b4a6ec8715031fcc9ee74f6 (patch) | |
tree | 0fc9eb32b0afa1c810e4f57ee72e1ab546cccc60 /source/1.0/src/shflags | |
parent | da1f85666887139f0473809fe09756c9fcc1ee30 (diff) | |
download | shflags-b075920c3109938f9b4a6ec8715031fcc9ee74f6.tar.gz |
added built-in and expr functions to do math
Diffstat (limited to 'source/1.0/src/shflags')
-rw-r--r-- | source/1.0/src/shflags | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/source/1.0/src/shflags b/source/1.0/src/shflags index 1955839..814f450 100644 --- a/source/1.0/src/shflags +++ b/source/1.0/src/shflags @@ -118,9 +118,11 @@ fi # can we use built-ins? ( echo "${FLAGS_TRUE#0}"; ) >/dev/null 2>&1 if [ $? -eq ${FLAGS_TRUE} ]; then + __FLAGS_FX_MATH='_flags_mathBuiltin' __FLAGS_FX_VALID_FLOAT='_flags_validFloatBuiltin' __FLAGS_FX_VALID_INT='_flags_validIntBuiltin' else + __FLAGS_FX_MATH='_flags_mathExpr' __FLAGS_FX_VALID_FLOAT='_flags_validFloatExpr' __FLAGS_FX_VALID_INT='_flags_validIntExpr' fi @@ -756,7 +758,7 @@ _flags_parseGetopt() # properly give user access to non-flag arguments mixed in between flag # arguments. Its usage was replaced by FLAGS_ARGV, and it is being kept only # for backwards compatibility reasons. - FLAGS_ARGC=`${FLAGS_EXPR_CMD} $# - 1 - ${_flags_argc_}` + FLAGS_ARGC=`${__FLAGS_FX_MATH} $# - 1 - ${_flags_argc_}` # handle options. note options with values must do an additional shift while true; do @@ -883,6 +885,31 @@ _flags_parseGetopt() return ${flags_return} } +# Perform some path using built-ins. +# +# Args: +# $@: string: math expression to evaluate +# Returns: +# string: the result +_flags_mathBuiltin() +{ + # Variable assignment is needed as workaround for Solaris Bourne shell, which + # cannot parse a bare $((expression)). + _flags_expr_='$(($@))' + eval echo ${_flags_expr_} +} + +# Perform some path using expr. +# +# Args: +# $@: string: math expression to evaluate +# Returns: +# string: the result +_flags_mathExpr() +{ + eval ${FLAGS_EXPR_CMD} $@ +} + #------------------------------------------------------------------------------ # public functions # |