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.
This commit is contained in:
Devin Teske 2013-05-14 03:21:13 +00:00
parent e946bdbe31
commit c3755aa30c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=250633
43 changed files with 72 additions and 46 deletions

View File

@ -239,7 +239,7 @@ fi
# Process command-line arguments
#
scripts_loaded=0
while getopts dD:f:hSX flag; do
while getopts f:h$GETOPTS_STDARGS flag; do
case "$flag" in
f) [ $scripts_loaded -eq 0 ] && f_include $BSDCFG_SHARE/script.subr
f_script_load "$OPTARG"

View File

@ -95,7 +95,7 @@ dialog_menu_main()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -119,7 +119,7 @@ dialog_menu_main()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -217,7 +217,7 @@ dialog_menu_main()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -99,7 +99,7 @@ dialog_menu_main()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -118,7 +118,7 @@ dialog_menu_main()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -103,7 +103,7 @@ dialog_menu_main()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -163,7 +163,7 @@ ttys_set_type()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -56,7 +56,7 @@ X11TERM_OPTS=
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -56,7 +56,7 @@ X11TERM_OPTS=
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -56,7 +56,7 @@ MOUSED_PIDFILE=/var/run/moused.pid
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -56,7 +56,7 @@ MOUSED_PIDFILE=/var/run/moused.pid
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -56,7 +56,7 @@ MOUSED_PIDFILE=/var/run/moused.pid
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -94,7 +94,7 @@ dialog_menu_main()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -103,7 +103,7 @@ dialog_menu_main()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -111,7 +111,7 @@ dialog_menu_main()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -49,7 +49,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -54,7 +54,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line options
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -52,7 +52,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -52,7 +52,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -91,7 +91,7 @@ dialog_menu_main()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -55,7 +55,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -55,7 +55,7 @@ USER_ROOT=root
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -108,7 +108,7 @@ dialog_menu_main()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -133,7 +133,7 @@ dialog_menu_main()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -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)

View File

@ -1530,25 +1530,37 @@ 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

View File

@ -319,7 +319,7 @@ dialog_input_value()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -97,7 +97,7 @@ dialog_menu_main()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -201,7 +201,7 @@ dialog_menu_main()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -301,7 +301,7 @@ dialog_menu_confirm_delete()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -49,7 +49,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -161,7 +161,7 @@ dialog_menu_main()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -92,7 +92,7 @@ dialog_menu_main()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -117,7 +117,7 @@ dialog_menu_main()
#
# Process command-line arguments
#
while getopts C:dD:ehnrsSvX flag; do
while getopts C:ehnrsv$GETOPTS_STDARGS flag; do
case "$flag" in
C) CHROOTENV="$OPTARG";;
e) TZ_OR_FAIL=1;;

View File

@ -67,7 +67,7 @@ ETC_TTYS=/etc/ttys
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -47,7 +47,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -50,7 +50,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -50,7 +50,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -47,7 +47,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -50,7 +50,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -50,7 +50,7 @@ ipgm=$( f_index_menusel_keyword $BSDCFG_LIBE/$APP_DIR/INDEX "$pgm" )
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac

View File

@ -111,7 +111,7 @@ dialog_menu_main()
#
# Process command-line arguments
#
while getopts dD:hSX flag; do
while getopts h$GETOPTS_STDARGS flag; do
case "$flag" in
h|\?) f_usage $BSDCFG_LIBE/$APP_DIR/USAGE "PROGRAM_NAME" "$pgm";;
esac