From cc38daccc0e83bd521ce4b8eb68b1d7e6a9e822b Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sun, 14 Apr 2019 13:39:09 -0400 Subject: src/main.sh: Move init(), fini(), etc. below main() --- diff --git a/src/main.sh b/src/main.sh index 3aa9e08..0c4ca77 100644 --- a/src/main.sh +++ b/src/main.sh @@ -41,6 +41,59 @@ conf_key= lock= exit_status= +_get_options() +{ + local opt= + + unset OPTARG + while getopts "${OPTSTRING}" opt; do + if [ "x${opt}" != 'x?' ]; then + eval "opt_${opt}=\"\${OPTARG:-true}\"" + fi + unset OPTARG + done + + return 0 +} + +main() +{ + local cmd= + local status= + + if [ -f "$(dirname -- "${0}")/.builddirstamp" ]; then + in_place=true + builddir="$(dirname -- "${0}")" + else + in_place=false + builddir='' + fi + + load_locale + + _get_options "${@}" + shift $((${OPTIND} - 1)) + + base_dir="${opt_b:-.}" + + if ${opt_h:-false}; then + cmd='help' + elif ${opt_V:-false}; then + cmd='version' + elif [ ${#} -lt 1 ]; then + cmd_help_main >&2 + exit 1 + else + cmd="${1}" + shift 1 + fi + + run_cmd "${cmd}" "${@}" + status=${?} + + return ${status} +} + _lock() { mkdir -p -- "${base_dir}/.db" @@ -89,21 +142,6 @@ _init_sigs() done } -_get_options() -{ - local opt= - - unset OPTARG - while getopts "${OPTSTRING}" opt; do - if [ "x${opt}" != 'x?' ]; then - eval "opt_${opt}=\"\${OPTARG:-true}\"" - fi - unset OPTARG - done - - return 0 -} - _get_conf() { local old_dir= @@ -153,41 +191,3 @@ fini() collect_garbage _unlock } - -main() -{ - local cmd= - local status= - - if [ -f "$(dirname -- "${0}")/.builddirstamp" ]; then - in_place=true - builddir="$(dirname -- "${0}")" - else - in_place=false - builddir='' - fi - - load_locale - - _get_options "${@}" - shift $((${OPTIND} - 1)) - - base_dir="${opt_b:-.}" - - if ${opt_h:-false}; then - cmd='help' - elif ${opt_V:-false}; then - cmd='version' - elif [ ${#} -lt 1 ]; then - cmd_help_main >&2 - exit 1 - else - cmd="${1}" - shift 1 - fi - - run_cmd "${cmd}" "${@}" - status=${?} - - return ${status} -} -- cgit v0.9.1