mirror of
git://git.savannah.gnu.org/libtool.git
synced 2025-02-11 15:00:08 +08:00
libtool: optimizing options-parser hooks
Its not necessary to (re)func_quote_for_eval in each function in the hook hierarchy. Usually it is enough if the leaf function does func_quote_for_eval and its caller just re-uses the <CALLEE>_return variable. This is follow up for the previous commit. * gl/build-aux/options-parser (func_run_hooks): Propagate $EXIT_SUCCESS return code down to caller if *any* hook succeeded. Never re-quote the result -- either the arguments are left untouched, or the options have already been properly quoted by succeeding hooks. (func_parse_options): Quote '$@' and return $EXIT_SUCCESS only if we changed something. (func_validate_options): Likewise. (func_options_prep): Likewise. (func_options_finish): New hook-caller for 'func_options' hooks. (func_options): Propagate return value down to top-level caller, but pay attention we have always set $func_options_result. * build-aux/ltmain.in (libtool_options_prep): Quote '$@' and return $EXIT_SUCCESS only if we changed something. (libtool_parse_options): Likewise. * bootstrap: Sync gl/build-aux/with option-parser.
This commit is contained in:
parent
32f0df9835
commit
16dbc070d3
171
bootstrap
171
bootstrap
@ -1583,7 +1583,7 @@ func_lt_ver ()
|
||||
#! /bin/sh
|
||||
|
||||
# Set a version string for this script.
|
||||
scriptversion=2014-01-07.03; # UTC
|
||||
scriptversion=2015-10-07.11; # UTC
|
||||
|
||||
# A portable, pluggable option parser for Bourne shell.
|
||||
# Written by Gary V. Vaughan, 2010
|
||||
@ -1743,6 +1743,8 @@ func_run_hooks ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
_G_rc_run_hooks=false
|
||||
|
||||
case " $hookable_fns " in
|
||||
*" $1 "*) ;;
|
||||
*) func_fatal_error "'$1' does not support hook funcions.n" ;;
|
||||
@ -1751,16 +1753,16 @@ func_run_hooks ()
|
||||
eval _G_hook_fns=\$$1_hooks; shift
|
||||
|
||||
for _G_hook in $_G_hook_fns; do
|
||||
eval $_G_hook '"$@"'
|
||||
|
||||
# store returned options list back into positional
|
||||
# parameters for next 'cmd' execution.
|
||||
eval _G_hook_result=\$${_G_hook}_result
|
||||
eval set dummy "$_G_hook_result"; shift
|
||||
if eval $_G_hook '"$@"'; then
|
||||
# store returned options list back into positional
|
||||
# parameters for next 'cmd' execution.
|
||||
eval _G_hook_result=\$${_G_hook}_result
|
||||
eval set dummy "$_G_hook_result"; shift
|
||||
_G_rc_run_hooks=:
|
||||
fi
|
||||
done
|
||||
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
func_run_hooks_result=$func_quote_for_eval_result
|
||||
$_G_rc_run_hooks && func_run_hooks_result=$_G_hook_result
|
||||
}
|
||||
|
||||
|
||||
@ -1770,10 +1772,16 @@ func_run_hooks ()
|
||||
## --------------- ##
|
||||
|
||||
# In order to add your own option parsing hooks, you must accept the
|
||||
# full positional parameter list in your hook function, remove any
|
||||
# options that you action, and then pass back the remaining unprocessed
|
||||
# full positional parameter list in your hook function, you may remove/edit
|
||||
# any options that you action, and then pass back the remaining unprocessed
|
||||
# options in '<hooked_function_name>_result', escaped suitably for
|
||||
# 'eval'. Like this:
|
||||
# 'eval'. In this case you also must return $EXIT_SUCCESS to let the
|
||||
# hook's caller know that it should pay attention to
|
||||
# '<hooked_function_name>_result'. Returning $EXIT_FAILURE signalizes that
|
||||
# arguments are left untouched by the hook and therefore caller will ignore the
|
||||
# result variable.
|
||||
#
|
||||
# Like this:
|
||||
#
|
||||
# my_options_prep ()
|
||||
# {
|
||||
@ -1783,9 +1791,11 @@ func_run_hooks ()
|
||||
# usage_message=$usage_message'
|
||||
# -s, --silent don'\''t print informational messages
|
||||
# '
|
||||
#
|
||||
# func_quote_for_eval ${1+"$@"}
|
||||
# my_options_prep_result=$func_quote_for_eval_result
|
||||
# # No change in '$@' (ignored completely by this hook). There is
|
||||
# # no need to do the equivalent (but slower) action:
|
||||
# # func_quote_for_eval ${1+"$@"}
|
||||
# # my_options_prep_result=$func_quote_for_eval_result
|
||||
# false
|
||||
# }
|
||||
# func_add_hook func_options_prep my_options_prep
|
||||
#
|
||||
@ -1794,25 +1804,37 @@ func_run_hooks ()
|
||||
# {
|
||||
# $debug_cmd
|
||||
#
|
||||
# args_changed=false
|
||||
#
|
||||
# # Note that for efficiency, we parse as many options as we can
|
||||
# # recognise in a loop before passing the remainder back to the
|
||||
# # caller on the first unrecognised argument we encounter.
|
||||
# while test $# -gt 0; do
|
||||
# opt=$1; shift
|
||||
# case $opt in
|
||||
# --silent|-s) opt_silent=: ;;
|
||||
# --silent|-s) opt_silent=:
|
||||
# args_changed=:
|
||||
# ;;
|
||||
# # Separate non-argument short options:
|
||||
# -s*) func_split_short_opt "$_G_opt"
|
||||
# set dummy "$func_split_short_opt_name" \
|
||||
# "-$func_split_short_opt_arg" ${1+"$@"}
|
||||
# shift
|
||||
# args_changed=:
|
||||
# ;;
|
||||
# *) set dummy "$_G_opt" "$*"; shift; break ;;
|
||||
# *) # Make sure the first unrecognised option "$_G_opt"
|
||||
# # is added back to "$@", we could need that later
|
||||
# # if $args_changed is true.
|
||||
# set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
|
||||
# esac
|
||||
# done
|
||||
#
|
||||
# func_quote_for_eval ${1+"$@"}
|
||||
# my_silent_option_result=$func_quote_for_eval_result
|
||||
# if $args_changed; then
|
||||
# func_quote_for_eval ${1+"$@"}
|
||||
# my_silent_option_result=$func_quote_for_eval_result
|
||||
# fi
|
||||
#
|
||||
# $args_changed
|
||||
# }
|
||||
# func_add_hook func_parse_options my_silent_option
|
||||
#
|
||||
@ -1824,16 +1846,32 @@ func_run_hooks ()
|
||||
# $opt_silent && $opt_verbose && func_fatal_help "\
|
||||
# '--silent' and '--verbose' options are mutually exclusive."
|
||||
#
|
||||
# func_quote_for_eval ${1+"$@"}
|
||||
# my_option_validation_result=$func_quote_for_eval_result
|
||||
# false
|
||||
# }
|
||||
# func_add_hook func_validate_options my_option_validation
|
||||
#
|
||||
# You'll alse need to manually amend $usage_message to reflect the extra
|
||||
# You'll also need to manually amend $usage_message to reflect the extra
|
||||
# options you parse. It's preferable to append if you can, so that
|
||||
# multiple option parsing hooks can be added safely.
|
||||
|
||||
|
||||
# func_options_finish [ARG]...
|
||||
# ----------------------------
|
||||
# Finishing the option parse loop (call 'func_options' hooks ATM).
|
||||
func_options_finish ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
_G_func_options_finish_exit=false
|
||||
if func_run_hooks func_options ${1+"$@"}; then
|
||||
func_options_finish_result=$func_run_hooks_result
|
||||
_G_func_options_finish_exit=:
|
||||
fi
|
||||
|
||||
$_G_func_options_finish_exit
|
||||
}
|
||||
|
||||
|
||||
# func_options [ARG]...
|
||||
# ---------------------
|
||||
# All the functions called inside func_options are hookable. See the
|
||||
@ -1843,17 +1881,28 @@ func_options ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
func_options_prep ${1+"$@"}
|
||||
eval func_parse_options \
|
||||
${func_options_prep_result+"$func_options_prep_result"}
|
||||
eval func_validate_options \
|
||||
${func_parse_options_result+"$func_parse_options_result"}
|
||||
_G_rc_options=false
|
||||
|
||||
eval func_run_hooks func_options \
|
||||
${func_validate_options_result+"$func_validate_options_result"}
|
||||
for my_func in options_prep parse_options validate_options options_finish
|
||||
do
|
||||
if eval func_$my_func '${1+"$@"}'; then
|
||||
eval _G_res_var='$'"func_${my_func}_result"
|
||||
eval set dummy "$_G_res_var" ; shift
|
||||
_G_rc_options=:
|
||||
fi
|
||||
done
|
||||
|
||||
# save modified positional parameters for caller
|
||||
func_options_result=$func_run_hooks_result
|
||||
# Save modified positional parameters for caller. As a top-level
|
||||
# options-parser function we always need to set the 'func_options_result'
|
||||
# variable (regardless the $_G_rc_options value).
|
||||
if $_G_rc_options; then
|
||||
func_options_result=$_G_res_var
|
||||
else
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
func_options_result=$func_quote_for_eval_result
|
||||
fi
|
||||
|
||||
$_G_rc_options
|
||||
}
|
||||
|
||||
|
||||
@ -1862,9 +1911,9 @@ func_options ()
|
||||
# All initialisations required before starting the option parse loop.
|
||||
# Note that when calling hook functions, we pass through the list of
|
||||
# positional parameters. If a hook function modifies that list, and
|
||||
# needs to propogate that back to rest of this script, then the complete
|
||||
# needs to propagate that back to rest of this script, then the complete
|
||||
# modified list must be put in 'func_run_hooks_result' before
|
||||
# returning.
|
||||
# returning $EXIT_SUCCESS (otherwise $EXIT_FAILURE is returned).
|
||||
func_hookable func_options_prep
|
||||
func_options_prep ()
|
||||
{
|
||||
@ -1874,10 +1923,14 @@ func_options_prep ()
|
||||
opt_verbose=false
|
||||
opt_warning_types=
|
||||
|
||||
func_run_hooks func_options_prep ${1+"$@"}
|
||||
_G_rc_options_prep=false
|
||||
if func_run_hooks func_options_prep ${1+"$@"}; then
|
||||
_G_rc_options_prep=:
|
||||
# save modified positional parameters for caller
|
||||
func_options_prep_result=$func_run_hooks_result
|
||||
fi
|
||||
|
||||
# save modified positional parameters for caller
|
||||
func_options_prep_result=$func_run_hooks_result
|
||||
$_G_rc_options_prep
|
||||
}
|
||||
|
||||
|
||||
@ -1891,18 +1944,20 @@ func_parse_options ()
|
||||
|
||||
func_parse_options_result=
|
||||
|
||||
_G_rc_parse_options=false
|
||||
# this just eases exit handling
|
||||
while test $# -gt 0; do
|
||||
# Defer to hook functions for initial option parsing, so they
|
||||
# get priority in the event of reusing an option name.
|
||||
func_run_hooks func_parse_options ${1+"$@"}
|
||||
|
||||
# Adjust func_parse_options positional parameters to match
|
||||
eval set dummy "$func_run_hooks_result"; shift
|
||||
if func_run_hooks func_parse_options ${1+"$@"}; then
|
||||
eval set dummy "$func_run_hooks_result"; shift
|
||||
_G_rc_parse_options=:
|
||||
fi
|
||||
|
||||
# Break out of the loop if we already parsed every option.
|
||||
test $# -gt 0 || break
|
||||
|
||||
_G_match_parse_options=:
|
||||
_G_opt=$1
|
||||
shift
|
||||
case $_G_opt in
|
||||
@ -1917,7 +1972,10 @@ func_parse_options ()
|
||||
;;
|
||||
|
||||
--warnings|--warning|-W)
|
||||
test $# = 0 && func_missing_arg $_G_opt && break
|
||||
if test $# = 0 && func_missing_arg $_G_opt; then
|
||||
_G_rc_parse_options=:
|
||||
break
|
||||
fi
|
||||
case " $warning_categories $1" in
|
||||
*" $1 "*)
|
||||
# trailing space prevents matching last $1 above
|
||||
@ -1970,15 +2028,25 @@ func_parse_options ()
|
||||
shift
|
||||
;;
|
||||
|
||||
--) break ;;
|
||||
--) _G_rc_parse_options=: ; break ;;
|
||||
-*) func_fatal_help "unrecognised option: '$_G_opt'" ;;
|
||||
*) set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
|
||||
*) set dummy "$_G_opt" ${1+"$@"}; shift
|
||||
_G_match_parse_options=false
|
||||
break
|
||||
;;
|
||||
esac
|
||||
|
||||
$_G_match_parse_options && _G_rc_parse_options=:
|
||||
done
|
||||
|
||||
# save modified positional parameters for caller
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
func_parse_options_result=$func_quote_for_eval_result
|
||||
|
||||
if $_G_rc_parse_options; then
|
||||
# save modified positional parameters for caller
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
func_parse_options_result=$func_quote_for_eval_result
|
||||
fi
|
||||
|
||||
$_G_rc_parse_options
|
||||
}
|
||||
|
||||
|
||||
@ -1991,16 +2059,21 @@ func_validate_options ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
_G_rc_validate_options=false
|
||||
|
||||
# Display all warnings if -W was not given.
|
||||
test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
|
||||
|
||||
func_run_hooks func_validate_options ${1+"$@"}
|
||||
if func_run_hooks func_validate_options ${1+"$@"}; then
|
||||
# save modified positional parameters for caller
|
||||
func_validate_options_result=$func_run_hooks_result
|
||||
_G_rc_validate_options=:
|
||||
fi
|
||||
|
||||
# Bail if the options were screwed!
|
||||
$exit_cmd $EXIT_FAILURE
|
||||
|
||||
# save modified positional parameters for caller
|
||||
func_validate_options_result=$func_run_hooks_result
|
||||
$_G_rc_validate_options
|
||||
}
|
||||
|
||||
|
||||
|
@ -358,6 +358,8 @@ libtool_options_prep ()
|
||||
nonopt=
|
||||
preserve_args=
|
||||
|
||||
_G_rc_lt_options_prep=:
|
||||
|
||||
# Shorthand for --mode=foo, only valid as the first argument
|
||||
case $1 in
|
||||
clean|clea|cle|cl)
|
||||
@ -381,11 +383,18 @@ libtool_options_prep ()
|
||||
uninstall|uninstal|uninsta|uninst|unins|unin|uni|un|u)
|
||||
shift; set dummy --mode uninstall ${1+"$@"}; shift
|
||||
;;
|
||||
*)
|
||||
_G_rc_lt_options_prep=false
|
||||
;;
|
||||
esac
|
||||
|
||||
# Pass back the list of options.
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
libtool_options_prep_result=$func_quote_for_eval_result
|
||||
if $_G_rc_lt_options_prep; then
|
||||
# Pass back the list of options.
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
libtool_options_prep_result=$func_quote_for_eval_result
|
||||
fi
|
||||
|
||||
$_G_rc_lt_options_prep
|
||||
}
|
||||
func_add_hook func_options_prep libtool_options_prep
|
||||
|
||||
@ -397,9 +406,12 @@ libtool_parse_options ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
_G_rc_lt_parse_options=false
|
||||
|
||||
# Perform our own loop to consume as many options as possible in
|
||||
# each iteration.
|
||||
while test $# -gt 0; do
|
||||
_G_match_lt_parse_options=:
|
||||
_G_opt=$1
|
||||
shift
|
||||
case $_G_opt in
|
||||
@ -474,15 +486,22 @@ libtool_parse_options ()
|
||||
func_append preserve_args " $_G_opt"
|
||||
;;
|
||||
|
||||
# An option not handled by this hook function:
|
||||
*) set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
|
||||
# An option not handled by this hook function:
|
||||
*) set dummy "$_G_opt" ${1+"$@"} ; shift
|
||||
_G_match_lt_parse_options=false
|
||||
break
|
||||
;;
|
||||
esac
|
||||
$_G_match_lt_parse_options && _G_rc_lt_parse_options=:
|
||||
done
|
||||
|
||||
if $_G_rc_lt_parse_options; then
|
||||
# save modified positional parameters for caller
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
libtool_parse_options_result=$func_quote_for_eval_result
|
||||
fi
|
||||
|
||||
# save modified positional parameters for caller
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
libtool_parse_options_result=$func_quote_for_eval_result
|
||||
$_G_rc_lt_parse_options
|
||||
}
|
||||
func_add_hook func_parse_options libtool_parse_options
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#! /bin/sh
|
||||
|
||||
# Set a version string for this script.
|
||||
scriptversion=2014-01-07.03; # UTC
|
||||
scriptversion=2015-10-07.11; # UTC
|
||||
|
||||
# A portable, pluggable option parser for Bourne shell.
|
||||
# Written by Gary V. Vaughan, 2010
|
||||
@ -161,6 +161,8 @@ func_run_hooks ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
_G_rc_run_hooks=false
|
||||
|
||||
case " $hookable_fns " in
|
||||
*" $1 "*) ;;
|
||||
*) func_fatal_error "'$1' does not support hook funcions.n" ;;
|
||||
@ -169,16 +171,16 @@ func_run_hooks ()
|
||||
eval _G_hook_fns=\$$1_hooks; shift
|
||||
|
||||
for _G_hook in $_G_hook_fns; do
|
||||
eval $_G_hook '"$@"'
|
||||
|
||||
# store returned options list back into positional
|
||||
# parameters for next 'cmd' execution.
|
||||
eval _G_hook_result=\$${_G_hook}_result
|
||||
eval set dummy "$_G_hook_result"; shift
|
||||
if eval $_G_hook '"$@"'; then
|
||||
# store returned options list back into positional
|
||||
# parameters for next 'cmd' execution.
|
||||
eval _G_hook_result=\$${_G_hook}_result
|
||||
eval set dummy "$_G_hook_result"; shift
|
||||
_G_rc_run_hooks=:
|
||||
fi
|
||||
done
|
||||
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
func_run_hooks_result=$func_quote_for_eval_result
|
||||
$_G_rc_run_hooks && func_run_hooks_result=$_G_hook_result
|
||||
}
|
||||
|
||||
|
||||
@ -188,10 +190,16 @@ func_run_hooks ()
|
||||
## --------------- ##
|
||||
|
||||
# In order to add your own option parsing hooks, you must accept the
|
||||
# full positional parameter list in your hook function, remove any
|
||||
# options that you action, and then pass back the remaining unprocessed
|
||||
# full positional parameter list in your hook function, you may remove/edit
|
||||
# any options that you action, and then pass back the remaining unprocessed
|
||||
# options in '<hooked_function_name>_result', escaped suitably for
|
||||
# 'eval'. Like this:
|
||||
# 'eval'. In this case you also must return $EXIT_SUCCESS to let the
|
||||
# hook's caller know that it should pay attention to
|
||||
# '<hooked_function_name>_result'. Returning $EXIT_FAILURE signalizes that
|
||||
# arguments are left untouched by the hook and therefore caller will ignore the
|
||||
# result variable.
|
||||
#
|
||||
# Like this:
|
||||
#
|
||||
# my_options_prep ()
|
||||
# {
|
||||
@ -201,9 +209,11 @@ func_run_hooks ()
|
||||
# usage_message=$usage_message'
|
||||
# -s, --silent don'\''t print informational messages
|
||||
# '
|
||||
#
|
||||
# func_quote_for_eval ${1+"$@"}
|
||||
# my_options_prep_result=$func_quote_for_eval_result
|
||||
# # No change in '$@' (ignored completely by this hook). There is
|
||||
# # no need to do the equivalent (but slower) action:
|
||||
# # func_quote_for_eval ${1+"$@"}
|
||||
# # my_options_prep_result=$func_quote_for_eval_result
|
||||
# false
|
||||
# }
|
||||
# func_add_hook func_options_prep my_options_prep
|
||||
#
|
||||
@ -212,25 +222,37 @@ func_run_hooks ()
|
||||
# {
|
||||
# $debug_cmd
|
||||
#
|
||||
# args_changed=false
|
||||
#
|
||||
# # Note that for efficiency, we parse as many options as we can
|
||||
# # recognise in a loop before passing the remainder back to the
|
||||
# # caller on the first unrecognised argument we encounter.
|
||||
# while test $# -gt 0; do
|
||||
# opt=$1; shift
|
||||
# case $opt in
|
||||
# --silent|-s) opt_silent=: ;;
|
||||
# --silent|-s) opt_silent=:
|
||||
# args_changed=:
|
||||
# ;;
|
||||
# # Separate non-argument short options:
|
||||
# -s*) func_split_short_opt "$_G_opt"
|
||||
# set dummy "$func_split_short_opt_name" \
|
||||
# "-$func_split_short_opt_arg" ${1+"$@"}
|
||||
# shift
|
||||
# args_changed=:
|
||||
# ;;
|
||||
# *) set dummy "$_G_opt" "$*"; shift; break ;;
|
||||
# *) # Make sure the first unrecognised option "$_G_opt"
|
||||
# # is added back to "$@", we could need that later
|
||||
# # if $args_changed is true.
|
||||
# set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
|
||||
# esac
|
||||
# done
|
||||
#
|
||||
# func_quote_for_eval ${1+"$@"}
|
||||
# my_silent_option_result=$func_quote_for_eval_result
|
||||
# if $args_changed; then
|
||||
# func_quote_for_eval ${1+"$@"}
|
||||
# my_silent_option_result=$func_quote_for_eval_result
|
||||
# fi
|
||||
#
|
||||
# $args_changed
|
||||
# }
|
||||
# func_add_hook func_parse_options my_silent_option
|
||||
#
|
||||
@ -242,16 +264,32 @@ func_run_hooks ()
|
||||
# $opt_silent && $opt_verbose && func_fatal_help "\
|
||||
# '--silent' and '--verbose' options are mutually exclusive."
|
||||
#
|
||||
# func_quote_for_eval ${1+"$@"}
|
||||
# my_option_validation_result=$func_quote_for_eval_result
|
||||
# false
|
||||
# }
|
||||
# func_add_hook func_validate_options my_option_validation
|
||||
#
|
||||
# You'll alse need to manually amend $usage_message to reflect the extra
|
||||
# You'll also need to manually amend $usage_message to reflect the extra
|
||||
# options you parse. It's preferable to append if you can, so that
|
||||
# multiple option parsing hooks can be added safely.
|
||||
|
||||
|
||||
# func_options_finish [ARG]...
|
||||
# ----------------------------
|
||||
# Finishing the option parse loop (call 'func_options' hooks ATM).
|
||||
func_options_finish ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
_G_func_options_finish_exit=false
|
||||
if func_run_hooks func_options ${1+"$@"}; then
|
||||
func_options_finish_result=$func_run_hooks_result
|
||||
_G_func_options_finish_exit=:
|
||||
fi
|
||||
|
||||
$_G_func_options_finish_exit
|
||||
}
|
||||
|
||||
|
||||
# func_options [ARG]...
|
||||
# ---------------------
|
||||
# All the functions called inside func_options are hookable. See the
|
||||
@ -261,17 +299,28 @@ func_options ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
func_options_prep ${1+"$@"}
|
||||
eval func_parse_options \
|
||||
${func_options_prep_result+"$func_options_prep_result"}
|
||||
eval func_validate_options \
|
||||
${func_parse_options_result+"$func_parse_options_result"}
|
||||
_G_rc_options=false
|
||||
|
||||
eval func_run_hooks func_options \
|
||||
${func_validate_options_result+"$func_validate_options_result"}
|
||||
for my_func in options_prep parse_options validate_options options_finish
|
||||
do
|
||||
if eval func_$my_func '${1+"$@"}'; then
|
||||
eval _G_res_var='$'"func_${my_func}_result"
|
||||
eval set dummy "$_G_res_var" ; shift
|
||||
_G_rc_options=:
|
||||
fi
|
||||
done
|
||||
|
||||
# save modified positional parameters for caller
|
||||
func_options_result=$func_run_hooks_result
|
||||
# Save modified positional parameters for caller. As a top-level
|
||||
# options-parser function we always need to set the 'func_options_result'
|
||||
# variable (regardless the $_G_rc_options value).
|
||||
if $_G_rc_options; then
|
||||
func_options_result=$_G_res_var
|
||||
else
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
func_options_result=$func_quote_for_eval_result
|
||||
fi
|
||||
|
||||
$_G_rc_options
|
||||
}
|
||||
|
||||
|
||||
@ -280,9 +329,9 @@ func_options ()
|
||||
# All initialisations required before starting the option parse loop.
|
||||
# Note that when calling hook functions, we pass through the list of
|
||||
# positional parameters. If a hook function modifies that list, and
|
||||
# needs to propogate that back to rest of this script, then the complete
|
||||
# needs to propagate that back to rest of this script, then the complete
|
||||
# modified list must be put in 'func_run_hooks_result' before
|
||||
# returning.
|
||||
# returning $EXIT_SUCCESS (otherwise $EXIT_FAILURE is returned).
|
||||
func_hookable func_options_prep
|
||||
func_options_prep ()
|
||||
{
|
||||
@ -292,10 +341,14 @@ func_options_prep ()
|
||||
opt_verbose=false
|
||||
opt_warning_types=
|
||||
|
||||
func_run_hooks func_options_prep ${1+"$@"}
|
||||
_G_rc_options_prep=false
|
||||
if func_run_hooks func_options_prep ${1+"$@"}; then
|
||||
_G_rc_options_prep=:
|
||||
# save modified positional parameters for caller
|
||||
func_options_prep_result=$func_run_hooks_result
|
||||
fi
|
||||
|
||||
# save modified positional parameters for caller
|
||||
func_options_prep_result=$func_run_hooks_result
|
||||
$_G_rc_options_prep
|
||||
}
|
||||
|
||||
|
||||
@ -309,18 +362,20 @@ func_parse_options ()
|
||||
|
||||
func_parse_options_result=
|
||||
|
||||
_G_rc_parse_options=false
|
||||
# this just eases exit handling
|
||||
while test $# -gt 0; do
|
||||
# Defer to hook functions for initial option parsing, so they
|
||||
# get priority in the event of reusing an option name.
|
||||
func_run_hooks func_parse_options ${1+"$@"}
|
||||
|
||||
# Adjust func_parse_options positional parameters to match
|
||||
eval set dummy "$func_run_hooks_result"; shift
|
||||
if func_run_hooks func_parse_options ${1+"$@"}; then
|
||||
eval set dummy "$func_run_hooks_result"; shift
|
||||
_G_rc_parse_options=:
|
||||
fi
|
||||
|
||||
# Break out of the loop if we already parsed every option.
|
||||
test $# -gt 0 || break
|
||||
|
||||
_G_match_parse_options=:
|
||||
_G_opt=$1
|
||||
shift
|
||||
case $_G_opt in
|
||||
@ -335,7 +390,10 @@ func_parse_options ()
|
||||
;;
|
||||
|
||||
--warnings|--warning|-W)
|
||||
test $# = 0 && func_missing_arg $_G_opt && break
|
||||
if test $# = 0 && func_missing_arg $_G_opt; then
|
||||
_G_rc_parse_options=:
|
||||
break
|
||||
fi
|
||||
case " $warning_categories $1" in
|
||||
*" $1 "*)
|
||||
# trailing space prevents matching last $1 above
|
||||
@ -388,15 +446,25 @@ func_parse_options ()
|
||||
shift
|
||||
;;
|
||||
|
||||
--) break ;;
|
||||
--) _G_rc_parse_options=: ; break ;;
|
||||
-*) func_fatal_help "unrecognised option: '$_G_opt'" ;;
|
||||
*) set dummy "$_G_opt" ${1+"$@"}; shift; break ;;
|
||||
*) set dummy "$_G_opt" ${1+"$@"}; shift
|
||||
_G_match_parse_options=false
|
||||
break
|
||||
;;
|
||||
esac
|
||||
|
||||
$_G_match_parse_options && _G_rc_parse_options=:
|
||||
done
|
||||
|
||||
# save modified positional parameters for caller
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
func_parse_options_result=$func_quote_for_eval_result
|
||||
|
||||
if $_G_rc_parse_options; then
|
||||
# save modified positional parameters for caller
|
||||
func_quote_for_eval ${1+"$@"}
|
||||
func_parse_options_result=$func_quote_for_eval_result
|
||||
fi
|
||||
|
||||
$_G_rc_parse_options
|
||||
}
|
||||
|
||||
|
||||
@ -409,16 +477,21 @@ func_validate_options ()
|
||||
{
|
||||
$debug_cmd
|
||||
|
||||
_G_rc_validate_options=false
|
||||
|
||||
# Display all warnings if -W was not given.
|
||||
test -n "$opt_warning_types" || opt_warning_types=" $warning_categories"
|
||||
|
||||
func_run_hooks func_validate_options ${1+"$@"}
|
||||
if func_run_hooks func_validate_options ${1+"$@"}; then
|
||||
# save modified positional parameters for caller
|
||||
func_validate_options_result=$func_run_hooks_result
|
||||
_G_rc_validate_options=:
|
||||
fi
|
||||
|
||||
# Bail if the options were screwed!
|
||||
$exit_cmd $EXIT_FAILURE
|
||||
|
||||
# save modified positional parameters for caller
|
||||
func_validate_options_result=$func_run_hooks_result
|
||||
$_G_rc_validate_options
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user