From 163eda3dc000b25f5c71146b6d4473825da0a5c2 Mon Sep 17 00:00:00 2001 From: P. J. McDermott Date: Sun, 28 Feb 2016 23:28:51 -0500 Subject: eshtrans/eshrt: Add __check_args() --- (limited to 'eshtrans') 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}" -- cgit v0.9.1