Deleted Added
full compact
common.subr (260678) common.subr (263980)
1if [ ! "$_COMMON_SUBR" ]; then _COMMON_SUBR=1
2#
3# Copyright (c) 2012 Ron McDowell
1if [ ! "$_COMMON_SUBR" ]; then _COMMON_SUBR=1
2#
3# Copyright (c) 2012 Ron McDowell
4# Copyright (c) 2012-2013 Devin Teske
4# Copyright (c) 2012-2014 Devin Teske
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright

--- 7 unchanged lines hidden (view full) ---

20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
5# All rights reserved.
6#
7# Redistribution and use in source and binary forms, with or without
8# modification, are permitted provided that the following conditions
9# are met:
10# 1. Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# 2. Redistributions in binary form must reproduce the above copyright

--- 7 unchanged lines hidden (view full) ---

20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26# SUCH DAMAGE.
27#
28# $FreeBSD: stable/10/usr.sbin/bsdconfig/share/common.subr 260678 2014-01-15 07:49:17Z dteske $
28# $FreeBSD: stable/10/usr.sbin/bsdconfig/share/common.subr 263980 2014-04-01 00:19:13Z dteske $
29#
30############################################################ CONFIGURATION
31
32#
33# Default file descriptors to link to stdout/stderr for passthru allowing
34# redirection within a sub-shell to bypass directly to the terminal.
35#
36: ${TERMINAL_STDOUT_PASSTHRU:=3}}

--- 111 unchanged lines hidden (view full) ---

148# Initialize debugging. Truncates $debugFile to zero bytes if set.
149#
150f_debug_init()
151{
152 #
153 # Process stored command-line arguments
154 #
155 set -- $ARGV
29#
30############################################################ CONFIGURATION
31
32#
33# Default file descriptors to link to stdout/stderr for passthru allowing
34# redirection within a sub-shell to bypass directly to the terminal.
35#
36: ${TERMINAL_STDOUT_PASSTHRU:=3}}

--- 111 unchanged lines hidden (view full) ---

148# Initialize debugging. Truncates $debugFile to zero bytes if set.
149#
150f_debug_init()
151{
152 #
153 # Process stored command-line arguments
154 #
155 set -- $ARGV
156 local OPTIND
156 local OPTIND flag
157 f_dprintf "f_debug_init: ARGV=[%s] GETOPTS_STDARGS=[%s]" \
158 "$ARGV" "$GETOPTS_STDARGS"
159 while getopts "$GETOPTS_STDARGS$GETOPTS_EXTRA$GETOPTS_ALLFLAGS" flag \
160 > /dev/null; do
161 case "$flag" in
162 d) debug=1 ;;
163 D) debugFile="$OPTARG" ;;
164 esac

--- 100 unchanged lines hidden (view full) ---

265# If $var_to_set is missing or NULL, the value of $var_to_get is printed to
266# standard output for capturing in a sub-shell (which is less-recommended
267# because of performance degredation; for example, when called in a loop).
268#
269f_getvar()
270{
271 local __var_to_get="$1" __var_to_set="$2"
272 [ "$__var_to_set" ] || local value
157 f_dprintf "f_debug_init: ARGV=[%s] GETOPTS_STDARGS=[%s]" \
158 "$ARGV" "$GETOPTS_STDARGS"
159 while getopts "$GETOPTS_STDARGS$GETOPTS_EXTRA$GETOPTS_ALLFLAGS" flag \
160 > /dev/null; do
161 case "$flag" in
162 d) debug=1 ;;
163 D) debugFile="$OPTARG" ;;
164 esac

--- 100 unchanged lines hidden (view full) ---

265# If $var_to_set is missing or NULL, the value of $var_to_get is printed to
266# standard output for capturing in a sub-shell (which is less-recommended
267# because of performance degredation; for example, when called in a loop).
268#
269f_getvar()
270{
271 local __var_to_get="$1" __var_to_set="$2"
272 [ "$__var_to_set" ] || local value
273 eval ${__var_to_set:-value}=\"\${$__var_to_get}\"
274 eval [ \"\${$__var_to_get+set}\" ]
275 local __retval=$?
273 eval [ \"\${$__var_to_get+set}\" ]
274 local __retval=$?
275 eval ${__var_to_set:-value}=\"\${$__var_to_get}\"
276 eval f_dprintf '"f_getvar: var=[%s] value=[%s] r=%u"' \
277 \"\$__var_to_get\" \"\$${__var_to_set:-value}\" \$__retval
278 [ "$__var_to_set" ] || { [ "$value" ] && echo "$value"; }
279 return $__retval
280}
281
282# f_isset $var
283#

--- 79 unchanged lines hidden (view full) ---

363 else
364 dialog --msgbox "$msg" 0 0
365 fi
366}
367
368# f_show_err $format [$arguments ...]
369#
370# Display a message in a dialog box with ``Error'' i18n title (overridden by
276 eval f_dprintf '"f_getvar: var=[%s] value=[%s] r=%u"' \
277 \"\$__var_to_get\" \"\$${__var_to_set:-value}\" \$__retval
278 [ "$__var_to_set" ] || { [ "$value" ] && echo "$value"; }
279 return $__retval
280}
281
282# f_isset $var
283#

--- 79 unchanged lines hidden (view full) ---

363 else
364 dialog --msgbox "$msg" 0 0
365 fi
366}
367
368# f_show_err $format [$arguments ...]
369#
370# Display a message in a dialog box with ``Error'' i18n title (overridden by
371# setting msg_error) using printf(1) syntax. If running non-interactively,
372# the process will terminate (using [above] f_die()).
371# setting msg_error) using printf(1) syntax.
373#
374f_show_err()
375{
372#
373f_show_err()
374{
376 [ "$nonInteractive" ] && f_die
377
378 local msg
379 msg=$( printf "$@" )
380
381 : ${msg:=${msg_an_unknown_error_occurred:-An unknown error occurred}}
382
383 if [ "$_DIALOG_SUBR" ]; then
384 f_dialog_title "${msg_error:-Error}"
385 f_dialog_msgbox "$msg"

--- 132 unchanged lines hidden (view full) ---

518#
519# If additional arguments appear after $file, substitutions are made while
520# printing the contents of the USAGE file. The pre-processor macro syntax is in
521# the style of autoconf(1), for example:
522#
523# f_usage $file "FOO" "BAR"
524#
525# Will cause instances of "@FOO@" appearing in $file to be replaced with the
375 local msg
376 msg=$( printf "$@" )
377
378 : ${msg:=${msg_an_unknown_error_occurred:-An unknown error occurred}}
379
380 if [ "$_DIALOG_SUBR" ]; then
381 f_dialog_title "${msg_error:-Error}"
382 f_dialog_msgbox "$msg"

--- 132 unchanged lines hidden (view full) ---

515#
516# If additional arguments appear after $file, substitutions are made while
517# printing the contents of the USAGE file. The pre-processor macro syntax is in
518# the style of autoconf(1), for example:
519#
520# f_usage $file "FOO" "BAR"
521#
522# Will cause instances of "@FOO@" appearing in $file to be replaced with the
526# text "BAR" before bering printed to the screen.
523# text "BAR" before being printed to the screen.
527#
528# This function is a two-parter. Below is the awk(1) portion of the function,
529# afterward is the sh(1) function which utilizes the below awk script.
530#
531f_usage_awk='
532BEGIN { found = 0 }
533{
534 if ( !found && $0 ~ /^[[:space:]]*($|#)/ ) next

--- 476 unchanged lines hidden ---
524#
525# This function is a two-parter. Below is the awk(1) portion of the function,
526# afterward is the sh(1) function which utilizes the below awk script.
527#
528f_usage_awk='
529BEGIN { found = 0 }
530{
531 if ( !found && $0 ~ /^[[:space:]]*($|#)/ ) next

--- 476 unchanged lines hidden ---