diff options
author | P. J. McDermott <pj@pehjota.net> | 2016-02-28 23:28:51 (EST) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2016-02-28 23:28:51 (EST) |
commit | 163eda3dc000b25f5c71146b6d4473825da0a5c2 (patch) | |
tree | 9a7f3ecf070c097d22b657ade40769e86c4e8432 /eshtrans/eshrt | |
parent | 1778852e86d710c5d28d46031b59e186a429dd38 (diff) | |
download | eggshell-163eda3dc000b25f5c71146b6d4473825da0a5c2.zip eggshell-163eda3dc000b25f5c71146b6d4473825da0a5c2.tar.gz eggshell-163eda3dc000b25f5c71146b6d4473825da0a5c2.tar.bz2 |
eshtrans/eshrt: Add __check_args()
Diffstat (limited to 'eshtrans/eshrt')
-rw-r--r-- | eshtrans/eshrt/eshrtbegin.esh | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/eshtrans/eshrt/eshrtbegin.esh b/eshtrans/eshrt/eshrtbegin.esh index fcc2df1..1848c45 100644 --- a/eshtrans/eshrt/eshrtbegin.esh +++ b/eshtrans/eshrt/eshrtbegin.esh @@ -33,6 +33,11 @@ __prev_vars='' __var='' __val='' __fn_frame=0 +__paramc='' +__paramv='' +__param='' +__i=0 +__err=false __fn_begin_hooks='' __fn_end_hooks='' __init_funcs='' @@ -230,6 +235,44 @@ __static() done } +__check_args() +{ + __fn="${1}" + __paramc="${2}" + __paramv="${3}" + shift 3 + + if [ ${#} -ne ${__paramc} ]; then + printf 'Error: Incorrect number of arguments to function %s\n' \ + "${__fn}()" >&2 + exit 1 + fi + unset IFS + __i=0 + for __param in ${__paramv}; do + __i=$((${__i} + 1)) + __err=false + case "${__param%:*}" in + 'bool') + case "${1}" in 'true'|'false');; *) __err=true;; + esac + ;; + 'int') + case "${1}" in *[!0-9]*) __err=true;; esac + ;; + esac + if ${__err}; then + printf 'Error: Argument %d of %s() %s (%s %s)\n' \ + ${__i} "${__fn}" 'has incorrect type' \ + 'expecting' "${__param%:*}" >&2 + exit 1 + else + __local "${__param#*:}=${1}" + fi + shift 1 + done +} + __fn_begin_hook() { __fn_begin_hooks="${__fn_begin_hooks} ${1}" |