diff options
author | dteske <dteske@FreeBSD.org> | 2013-05-14 03:21:13 +0000 |
---|---|---|
committer | dteske <dteske@FreeBSD.org> | 2013-05-14 03:21:13 +0000 |
commit | 7c4460149dcf39ce45a63a428447da0574a29ddf (patch) | |
tree | 3e3774586a73d5c2921a5c3209867c7f40baf2a1 /usr.sbin/bsdconfig/share | |
parent | cc1a3599913049d157572c1dac7420d275fa208a (diff) | |
download | FreeBSD-src-7c4460149dcf39ce45a63a428447da0574a29ddf.zip FreeBSD-src-7c4460149dcf39ce45a63a428447da0574a29ddf.tar.gz |
Centralize standard getopts arguments, both for convenience and to correct
a bug in which certain combinations of arguments produced unexpected results
such as `-dX' (now properly produces debugging and X11), `-XS' (now properly
produces X11 in secure mode), `-df-' (enables debugging when reading a
script from standard-input, etc. Multi-word variations such as `-d -X',
`-X -S', `-d -f-', `-d -f -', etc. also work as expected. Also tested were
variations in argument order, which are now working as expected.
Diffstat (limited to 'usr.sbin/bsdconfig/share')
-rw-r--r-- | usr.sbin/bsdconfig/share/common.subr | 16 | ||||
-rw-r--r-- | usr.sbin/bsdconfig/share/dialog.subr | 20 |
2 files changed, 31 insertions, 5 deletions
diff --git a/usr.sbin/bsdconfig/share/common.subr b/usr.sbin/bsdconfig/share/common.subr index d92592c..88594b5 100644 --- a/usr.sbin/bsdconfig/share/common.subr +++ b/usr.sbin/bsdconfig/share/common.subr @@ -67,6 +67,16 @@ export UNAME_R="$(uname -r)" # Release Level (i.e. X.Y-RELEASE) # : ${DEBUG_SELF_INITIALIZE=1} +# +# Define standard optstring arguments that should be supported by all programs +# using this include (unless DEBUG_SELF_INITIALIZE is set to NULL to prevent +# f_debug_init() from autamatically processing "$@" for the below arguments): +# +# d Sets $debug to 1 +# D: Sets $debugFile to $OPTARG +# +GETOPTS_STDARGS="dD:" + ############################################################ FUNCTIONS # f_dprintf $fmt [ $opts ... ] @@ -102,7 +112,9 @@ f_debug_init() # set -- $ARGV local OPTIND - while getopts dD: flag > /dev/null; do + f_dprintf "f_debug_init: ARGV=[%s] GETOPTS_STDARGS=[%s]" \ + "$ARGV" "$GETOPTS_STDARGS" + while getopts "$GETOPTS_STDARGS" flag > /dev/null; do case "$flag" in d) debug=1;; D) debugFile="$OPTARG";; @@ -110,6 +122,8 @@ f_debug_init() esac done shift $(( $OPTIND - 1 )) + f_dprintf "f_debug_init: debug=[%s] debugFile=[%s]" \ + "$debug" "$debugFile" # # Automagically enable debugging if debugFile is set (and non-NULL) diff --git a/usr.sbin/bsdconfig/share/dialog.subr b/usr.sbin/bsdconfig/share/dialog.subr index 0f3187d..294dbf0 100644 --- a/usr.sbin/bsdconfig/share/dialog.subr +++ b/usr.sbin/bsdconfig/share/dialog.subr @@ -1531,24 +1531,36 @@ f_dialog_init() eval exec $DIALOG_TERMINAL_PASSTHRU_FD\>\&1 # + # Add `-S' and `-X' to the list of standard arguments supported by all + # + case "$GETOPTS_STDARGS" in + *SX*) : good ;; # already present + *) GETOPTS_STDARGS="${GETOPTS_STDARGS}SX" + esac + + # # Process stored command-line arguments # - SECURE=$( set -- "$ARGV" - while getopts S flag > /dev/null; do + f_dprintf "f_dialog_init: ARGV=[%s] GETOPTS_STDARGS=[%s]" \ + "$ARGV" "$GETOPTS_STDARGS" + SECURE=$( set -- $ARGV + while getopts "$GETOPTS_STDARGS" flag > /dev/null; do case "$flag" in S) echo 1;; \?) continue;; esac done ) - USE_XDIALOG=$( set -- "$ARGV" - while getopts SX flag > /dev/null; do + USE_XDIALOG=$( set -- $ARGV + while getopts $GETOPTS_STDARGS flag > /dev/null; do case "$flag" in S|X) echo 1;; \?) continue;; esac done ) + f_dprintf "f_dialog_init: SECURE=[%s] USE_XDIALOG=[%s]" \ + "$SECURE" "$USE_XDIALOG" # # Process `-X' command-line option |