From ad045829cfb08a8fd140c738bd689c89a859a37f Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 21 Mar 2012 19:43:39 -0400 Subject: gcc-config: make arg parsing less forgiving with multi-actions Currently, if someone specifies more than one action flag, we just ignore all but the first. This isn't exactly clear, so just error out if we see too many flags. Signed-off-by: Mike Frysinger --- gcc-config | 37 ++++++++++++------------------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/gcc-config b/gcc-config index 754df49..e360b8e 100755 --- a/gcc-config +++ b/gcc-config @@ -568,8 +568,11 @@ chop_gcc_ver_spec() { echo ${splitTED/ /-} # ver-spec } -NEED_ACTION="yes" -DOIT="switch_profile" +set_doit() { + [[ -n ${DOIT} ]] && die_eerror "too many actions selected!" + DOIT=$1 +} +DOIT="" FORCE="no" CC_COMP= @@ -591,16 +594,10 @@ for x in "$@" ; do FORCE="yes" ;; -c|--get-current-profile) - if [[ ${NEED_ACTION} == "yes" ]] ; then - NEED_ACTION="no" - DOIT="get_current_profile" - fi + set_doit get_current_profile ;; -l|--list-profiles) - if [[ ${NEED_ACTION} == "yes" ]] ; then - NEED_ACTION="no" - DOIT="list_profiles" - fi + set_doit list_profiles ;; -S|--split-profile) if [[ ( $1 != "-S" && $1 != "--split-profile" ) || $# -eq 1 ]] ; then @@ -613,22 +610,13 @@ for x in "$@" ; do exit 0 ;; -E|--print-environ) - if [[ ${NEED_ACTION} == "yes" ]] ; then - NEED_ACTION="no" - DOIT="print_environ" - fi + set_doit print_environ ;; -B|--get-bin-path) - if [[ ${NEED_ACTION} == "yes" ]] ; then - NEED_ACTION="no" - DOIT="get_bin_path" - fi + set_doit get_bin_path ;; -L|--get-lib-path) - if [[ ${NEED_ACTION} == "yes" ]] ; then - NEED_ACTION="no" - DOIT="get_lib_path" - fi + set_doit get_lib_path ;; -x|--debug) set -x @@ -687,9 +675,8 @@ for x in "$@" ; do esac done -if [[ ${DOIT} == "switch_profile" ]] && [[ -z ${CC_COMP} ]] ; then - usage 1 -fi +[[ -z ${DOIT}${CC_COMP} ]] && usage 1 +: ${DOIT:="switch_profile"} get_chost [[ ${DOIT} == "get_current_profile" ]] \ -- cgit v1.2.3-65-gdbad