#!/bin/bash APP_SVNID='$HeadURL$ $LastChangedRevision$' . $(ade-config ade_share_prefix)/include/ade.sh || { echo "${0##*/}: INTERNAL ERROR: failed to load ade.sh" >&2; exit 3; } ADESHF_DEFINED_ERRORS=( "KEY=ADESHF_ERR_MISC; FMT=\"%s\"" ) adeshf() { local OPTVAL RC TEMP ERRSTACK_REF CODE local -a DOLLARAT ERRSTACK_REF="$1" shift # Register application-specific errors ade_register_error_types ADESHF_DEFINED_ERRORS # Register adeshf's options (none) #ade_register_options "$ERRSTACK_REF" -o f: --longoptions=op-mode:,alert: --callback-template="handle_option_%s" || return $? ade_set_callbacks "$ERRSTACK_REF" adeshf_usage_help adeshf_version adeshf_paths || return $? # Process options ade_process_options "$ERRSTACK_REF" NEW_DOLLAR_AT "$@" || return $? set -- "${NEW_DOLLAR_AT[@]}" # Argument processing [ "X$1" != X -a "X$2" = X ] || ade_show_bad_usage "$ERRSTACK_REF" CODE="$1" # Guts ade_debug "$ERRSTACK_REF" 10 "main: calling \"$CODE\" ..." # Use eval to run the code, but do it in a function context, so that the # code is allowed to return without making adeshf() itself return. RC=0; eval "adeshf_code_wrapper() { $CODE }; adeshf_code_wrapper" || RC=$? # The eval returning 2 isn't a guarantee that the code failed to run: it # could have run but returned 2. We'll ignore that possibility for the # moment. if [ $RC = 2 ]; then ade_error "$ERRSTACK_REF" ADESHF_ERR_MISC "code failed to run; the error was displayed above" return $ADE_FAIL # Having got the syntax-error-in-code-made-eval-itself-return-failure case out # of the way, then we can examine the return code, assuming the return code # was returned by the code and not be the eval. elif [ $RC = $ADE_OK ]; then return $RC elif [ $RC = $ADE_FAIL ]; then ade_error "$ERRSTACK_REF" ADESHF_ERR_MISC "code ran but returned failure" return $RC else ade_error "$ERRSTACK_REF" ADESHF_ERR_MISC "code ran but returned a non-compliant return code; the return code was: $RC" return $ADE_FAIL fi return $ADE_OK } adeshf_usage_help() { local ERRSTACK_REF="$1"; shift local USAGE_TEXT_SHORT_REF="$1"; shift local USAGE_TEXT_LONG_REF="$1"; shift eval "$USAGE_TEXT_SHORT_REF=\"\"" eval "$USAGE_TEXT_LONG_REF=" return $ADE_OK } adeshf_paths() { local ERRSTACK_REF="$1"; shift local PATHLIST_REF=$1; shift eval "$PATHLIST_REF=\"\ \"" return $ADE_OK } adeshf_version() { local ERRSTACK_REF="$1"; shift local VERSION_REF=$1; shift ade_extract_version "$ERRSTACK_REF" "$APP_SVNID" "$VERSION_REF" return $ADE_OK } ade_main adeshf "$@"