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

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

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

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

19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
27# $FreeBSD: stable/10/usr.sbin/bsdconfig/share/dialog.subr 260678 2014-01-15 07:49:17Z dteske $
27# $FreeBSD: stable/10/usr.sbin/bsdconfig/share/dialog.subr 263980 2014-04-01 00:19:13Z dteske $
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." dialog.subr
34f_include $BSDCFG_SHARE/strings.subr
35f_include $BSDCFG_SHARE/variable.subr

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

464 # Return failure unless at least one var_* argument is passed
465 [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] ||
466 return $FAILURE
467
468 #
469 # Print debug warnings if any given (non-NULL) argument are invalid
470 # NOTE: Don't change the name of $__{var,min,}{height,width,rows}
471 #
28#
29############################################################ INCLUDES
30
31BSDCFG_SHARE="/usr/share/bsdconfig"
32. $BSDCFG_SHARE/common.subr || exit 1
33f_dprintf "%s: loading includes..." dialog.subr
34f_include $BSDCFG_SHARE/strings.subr
35f_include $BSDCFG_SHARE/variable.subr

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

464 # Return failure unless at least one var_* argument is passed
465 [ "$__var_height" -o "$__var_width" -o "$__var_rows" ] ||
466 return $FAILURE
467
468 #
469 # Print debug warnings if any given (non-NULL) argument are invalid
470 # NOTE: Don't change the name of $__{var,min,}{height,width,rows}
471 #
472 local __height __width __rows
472 local __height_menu_constrain __width_menu_constrain
473 local __rows_menu_constrain
473 local __arg __cp __fname=f_dialog_menu_constrain
474 for __arg in height width rows; do
475 debug= f_getvar __var_$__arg __cp
476 [ "$__cp" ] || continue
474 local __arg __cp __fname=f_dialog_menu_constrain
475 for __arg in height width rows; do
476 debug= f_getvar __var_$__arg __cp
477 [ "$__cp" ] || continue
477 if ! debug= f_getvar "$__cp" __$__arg; then
478 if ! debug= f_getvar "$__cp" __${__arg}_menu_constrain; then
478 f_dprintf "%s: var_%s variable \`%s' not set" \
479 $__fname $__arg "$__cp"
480 __retval=$FAILURE
479 f_dprintf "%s: var_%s variable \`%s' not set" \
480 $__fname $__arg "$__cp"
481 __retval=$FAILURE
481 elif ! eval f_isinteger \$__$__arg; then
482 elif ! eval f_isinteger \$__${__arg}_menu_constrain; then
482 f_dprintf "%s: var_%s variable value not a number" \
483 $__fname $__arg
484 __retval=$FAILURE
485 fi
486 done
487 for __arg in height width rows; do
488 debug= f_getvar __min_$__arg __cp
489 [ "$__cp" ] || continue

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

497 # NOTE: Function name appended to prevent __var_{height,width} values
498 # from becoming local (and thus preventing setvar from working).
499 local __max_height_menu_constrain __max_width_menu_constrain
500 f_dialog_max_size \
501 __max_height_menu_constrain __max_width_menu_constrain
502
503 # Adjust height if desired
504 if [ "$__var_height" ]; then
483 f_dprintf "%s: var_%s variable value not a number" \
484 $__fname $__arg
485 __retval=$FAILURE
486 fi
487 done
488 for __arg in height width rows; do
489 debug= f_getvar __min_$__arg __cp
490 [ "$__cp" ] || continue

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

498 # NOTE: Function name appended to prevent __var_{height,width} values
499 # from becoming local (and thus preventing setvar from working).
500 local __max_height_menu_constrain __max_width_menu_constrain
501 f_dialog_max_size \
502 __max_height_menu_constrain __max_width_menu_constrain
503
504 # Adjust height if desired
505 if [ "$__var_height" ]; then
505 if [ $__height -lt ${__min_height:-0} ]; then
506 if [ $__height_menu_constrain -lt ${__min_height:-0} ]; then
506 setvar "$__var_height" $__min_height
507 setvar "$__var_height" $__min_height
507 elif [ $__height -gt $__max_height_menu_constrain ]; then
508 elif [ $__height_menu_constrain -gt \
509 $__max_height_menu_constrain ]
510 then
508 setvar "$__var_height" $__max_height_menu_constrain
509 fi
510 fi
511
512 # Adjust width if desired
513 if [ "$__var_width" ]; then
514 if [ "$USE_XDIALOG" ]; then
515 : ${__min_width:=${XDIALOG_MIN_WIDTH:-35}}
516 else
517 : ${__min_width:=${DIALOG_MIN_WIDTH:-24}}
518 fi
511 setvar "$__var_height" $__max_height_menu_constrain
512 fi
513 fi
514
515 # Adjust width if desired
516 if [ "$__var_width" ]; then
517 if [ "$USE_XDIALOG" ]; then
518 : ${__min_width:=${XDIALOG_MIN_WIDTH:-35}}
519 else
520 : ${__min_width:=${DIALOG_MIN_WIDTH:-24}}
521 fi
519 if [ $__width -lt $__min_width ]; then
522 if [ $__width_menu_constrain -lt $__min_width ]; then
520 setvar "$__var_width" $__min_width
523 setvar "$__var_width" $__min_width
521 elif [ $__width -gt $__max_width_menu_constrain ]; then
524 elif [ $__width_menu_constrain -gt \
525 $__max_width_menu_constrain ]
526 then
522 setvar "$__var_width" $__max_width_menu_constrain
523 fi
524 fi
525
526 # Adjust rows if desired
527 if [ "$__var_rows" ]; then
528 if [ "$USE_XDIALOG" ]; then
529 : ${__min_rows:=1}
530 else
531 : ${__min_rows:=0}
532 fi
533
527 setvar "$__var_width" $__max_width_menu_constrain
528 fi
529 fi
530
531 # Adjust rows if desired
532 if [ "$__var_rows" ]; then
533 if [ "$USE_XDIALOG" ]; then
534 : ${__min_rows:=1}
535 else
536 : ${__min_rows:=0}
537 fi
538
534 local __max_rows=$(( $__max_height_menu_constrain - 7 ))
539 local __max_rows_menu_constrain=$((
540 $__max_height_menu_constrain - 7
541 ))
535 # If prompt_len is zero (no prompt), bump the max-rows by 1
536 # Default assumption is (if no argument) that there's no prompt
542 # If prompt_len is zero (no prompt), bump the max-rows by 1
543 # Default assumption is (if no argument) that there's no prompt
537 [ ${__prompt_len:-0} -gt 0 ] ||
538 __max_rows=$(( $__max_rows + 1 ))
544 [ ${__prompt_len:-0} -gt 0 ] || __max_rows_menu_constrain=$((
545 $__max_rows_menu_constrain + 1
546 ))
539
547
540 if [ $__rows -lt $__min_rows ]; then
548 if [ $__rows_menu_constrain -lt $__min_rows ]; then
541 setvar "$__var_rows" $__min_rows
549 setvar "$__var_rows" $__min_rows
542 elif [ $__rows -gt $__max_rows ]; then
543 setvar "$__var_rows" $__max_rows
550 elif [ $__rows_menu_constrain -gt $__max_rows_menu_constrain ]
551 then
552 setvar "$__var_rows" $__max_rows_menu_constrain
544 fi
545 fi
546
547 if [ "$debug" ]; then
548 # Print final constrained values to debugging
549 [ "$__var_height" ] && f_quietly f_getvar "$__var_height"
550 [ "$__var_width" ] && f_quietly f_getvar "$__var_width"
551 [ "$__var_rows" ] && f_quietly f_getvar "$__var_rows"

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

1095 "${__var_width:+__width_rlist_size}" \
1096 "$__title" "$__btitle" "$__prompt" "$__hline"
1097
1098 #
1099 # Always process the menu-item arguments to get the longest tag-length,
1100 # longest item-length (both used to bump the width), and the number of
1101 # rows (used to bump the height).
1102 #
553 fi
554 fi
555
556 if [ "$debug" ]; then
557 # Print final constrained values to debugging
558 [ "$__var_height" ] && f_quietly f_getvar "$__var_height"
559 [ "$__var_width" ] && f_quietly f_getvar "$__var_width"
560 [ "$__var_rows" ] && f_quietly f_getvar "$__var_rows"

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

1104 "${__var_width:+__width_rlist_size}" \
1105 "$__title" "$__btitle" "$__prompt" "$__hline"
1106
1107 #
1108 # Always process the menu-item arguments to get the longest tag-length,
1109 # longest item-length (both used to bump the width), and the number of
1110 # rows (used to bump the height).
1111 #
1103 local __longest_tag=0 __longest_item=0 __rows=0
1112 local __longest_tag=0 __longest_item=0 __rows_rlist_size=0
1104 while [ $# -ge 3 ]; do
1105 local __tag="$1" __item="$2"
1106 shift 3 # tag/item/status
1107 [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag}
1108 [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item}
1113 while [ $# -ge 3 ]; do
1114 local __tag="$1" __item="$2"
1115 shift 3 # tag/item/status
1116 [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag}
1117 [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item}
1109 __rows=$(( $__rows + 1 ))
1118 __rows_rlist_size=$(( $__rows_rlist_size + 1 ))
1110 done
1111
1112 # Adjust rows early (for up-coming height calculation)
1113 if [ "$__var_height" -o "$__var_rows" ]; then
1114 # Add a row for visual aid if using Xdialog(1)
1119 done
1120
1121 # Adjust rows early (for up-coming height calculation)
1122 if [ "$__var_height" -o "$__var_rows" ]; then
1123 # Add a row for visual aid if using Xdialog(1)
1115 [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 ))
1124 [ "$USE_XDIALOG" ] &&
1125 __rows_rlist_size=$(( $__rows_rlist_size + 1 ))
1116 fi
1117
1118 # Adjust height if desired
1119 if [ "$__var_height" ]; then
1120 # Add rows to height
1121 if [ "$USE_XDIALOG" ]; then
1122 __height_rlist_size=$((
1126 fi
1127
1128 # Adjust height if desired
1129 if [ "$__var_height" ]; then
1130 # Add rows to height
1131 if [ "$USE_XDIALOG" ]; then
1132 __height_rlist_size=$((
1123 $__height_rlist_size + $__rows + 7 ))
1133 $__height_rlist_size + $__rows_rlist_size + 7
1134 ))
1124 else
1125 __height_rlist_size=$((
1135 else
1136 __height_rlist_size=$((
1126 $__height_rlist_size + $__rows + 4 ))
1137 $__height_rlist_size + $__rows_rlist_size + 4
1138 ))
1127 fi
1128 setvar "$__var_height" $__height_rlist_size
1129 fi
1130
1131 # Adjust width if desired
1132 if [ "$__var_width" ]; then
1133 # Sum total between longest tag-length, longest item-length,
1134 # and radio-button width should be used to bump menu width
1135 local __n=$(( $__longest_tag + $__longest_item + 13 ))
1136 [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6%
1137 [ $__n -gt $__width_rlist_size ] && __width_rlist_size=$__n
1138
1139 setvar "$__var_width" $__width_rlist_size
1140 fi
1141
1142 # Store adjusted rows if desired
1139 fi
1140 setvar "$__var_height" $__height_rlist_size
1141 fi
1142
1143 # Adjust width if desired
1144 if [ "$__var_width" ]; then
1145 # Sum total between longest tag-length, longest item-length,
1146 # and radio-button width should be used to bump menu width
1147 local __n=$(( $__longest_tag + $__longest_item + 13 ))
1148 [ "$USE_XDIALOG" ] && __n=$(( $__n + $__n / 6 )) # plus 16.6%
1149 [ $__n -gt $__width_rlist_size ] && __width_rlist_size=$__n
1150
1151 setvar "$__var_width" $__width_rlist_size
1152 fi
1153
1154 # Store adjusted rows if desired
1143 [ "$__var_rows" ] && setvar "$__var_rows" $__rows
1155 [ "$__var_rows" ] && setvar "$__var_rows" $__rows_rlist_size
1144
1145 # Constrain height, width, and rows to sensible minimum/maximum values
1146 # Return success if no-constrain, else return status from constrain
1147 [ ! "$__constrain" ] || f_dialog_menu_constrain \
1148 "$__var_height" "$__var_width" "$__var_rows" "$__prompt"
1149}
1150
1151# f_dialog_checklist_size [-n] $var_height $var_width $var_rows \

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

1215
1216 #
1217 # Always process the menu-item arguments to get the longest tag-length,
1218 # longest item-length, longest help-length (help-length only considered
1219 # if using Xdialog(1), as it places the help string in the widget) --
1220 # all used to bump the width -- and the number of rows (used to bump
1221 # the height).
1222 #
1156
1157 # Constrain height, width, and rows to sensible minimum/maximum values
1158 # Return success if no-constrain, else return status from constrain
1159 [ ! "$__constrain" ] || f_dialog_menu_constrain \
1160 "$__var_height" "$__var_width" "$__var_rows" "$__prompt"
1161}
1162
1163# f_dialog_checklist_size [-n] $var_height $var_width $var_rows \

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

1227
1228 #
1229 # Always process the menu-item arguments to get the longest tag-length,
1230 # longest item-length, longest help-length (help-length only considered
1231 # if using Xdialog(1), as it places the help string in the widget) --
1232 # all used to bump the width -- and the number of rows (used to bump
1233 # the height).
1234 #
1223 local __longest_tag=0 __longest_item=0 __longest_help=0 __rows=0
1235 local __longest_tag=0 __longest_item=0 __longest_help=0
1236 local __rows_rlist_with_help_size=0
1224 while [ $# -ge 4 ]; do
1225 local __tag="$1" __item="$2" __status="$3" __help="$4"
1226 shift 4 # tag/item/status/help
1227 [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag}
1228 [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item}
1229 [ ${#__help} -gt $__longest_help ] && __longest_help=${#__help}
1237 while [ $# -ge 4 ]; do
1238 local __tag="$1" __item="$2" __status="$3" __help="$4"
1239 shift 4 # tag/item/status/help
1240 [ ${#__tag} -gt $__longest_tag ] && __longest_tag=${#__tag}
1241 [ ${#__item} -gt $__longest_item ] && __longest_item=${#__item}
1242 [ ${#__help} -gt $__longest_help ] && __longest_help=${#__help}
1230 __rows=$(( $__rows + 1 ))
1243 __rows_rlist_with_help_size=$((
1244 $__rows_rlist_with_help_size + 1
1245 ))
1231 done
1232
1233 # Adjust rows early (for up-coming height calculation)
1234 if [ "$__var_height" -o "$__var_rows" ]; then
1235 # Add a row for visual aid if using Xdialog(1)
1246 done
1247
1248 # Adjust rows early (for up-coming height calculation)
1249 if [ "$__var_height" -o "$__var_rows" ]; then
1250 # Add a row for visual aid if using Xdialog(1)
1236 [ "$USE_XDIALOG" ] && __rows=$(( $__rows + 1 ))
1251 [ "$USE_XDIALOG" ] &&
1252 __rows_rlist_with_help_size=$((
1253 $__rows_rlist_with_help_size + 1
1254 ))
1237 fi
1238
1239 # Adjust height if desired
1240 if [ "$__var_height" ]; then
1241 # Add rows to height
1242 if [ "$USE_XDIALOG" ]; then
1243 __height_rlist_with_help_size=$((
1255 fi
1256
1257 # Adjust height if desired
1258 if [ "$__var_height" ]; then
1259 # Add rows to height
1260 if [ "$USE_XDIALOG" ]; then
1261 __height_rlist_with_help_size=$((
1244 $__height_rlist_with_help_size + $__rows + 7 ))
1262 $__height_rlist_with_help_size +
1263 $__rows_rlist_with_help_size + 7
1264 ))
1245 else
1246 __height_rlist_with_help_size=$((
1265 else
1266 __height_rlist_with_help_size=$((
1247 $__height_rlist_with_help_size + $__rows + 4 ))
1267 $__height_rlist_with_help_size +
1268 $__rows_rlist_with_help_size + 4
1269 ))
1248 fi
1249 setvar "$__var_height" $__height
1250 fi
1251
1252 # Adjust width if desired
1253 if [ "$__var_width" ]; then
1254 # Sum total between longest tag-length, longest item-length,
1255 # and radio-button width should be used to bump menu width

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

1265 [ $__n -gt $__width_rlist_with_help_size ] &&
1266 __width_rlist_with_help_size=$__n
1267 fi
1268
1269 setvar "$__var_width" $__width_rlist_with_help_size
1270 fi
1271
1272 # Store adjusted rows if desired
1270 fi
1271 setvar "$__var_height" $__height
1272 fi
1273
1274 # Adjust width if desired
1275 if [ "$__var_width" ]; then
1276 # Sum total between longest tag-length, longest item-length,
1277 # and radio-button width should be used to bump menu width

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

1287 [ $__n -gt $__width_rlist_with_help_size ] &&
1288 __width_rlist_with_help_size=$__n
1289 fi
1290
1291 setvar "$__var_width" $__width_rlist_with_help_size
1292 fi
1293
1294 # Store adjusted rows if desired
1273 [ "$__var_rows" ] && setvar "$__var_rows" $__rows
1295 [ "$__var_rows" ] && setvar "$__var_rows" $__rows_rlist_with_help_size
1274
1275 # Constrain height, width, and rows to sensible minimum/maximum values
1276 # Return success if no-constrain, else return status from constrain
1277 [ ! "$__constrain" ] || f_dialog_menu_constrain \
1278 "$__var_height" "$__var_width" "$__var_rows" "$__prompt"
1279}
1280
1281# f_dialog_checklist_with_help_size [-n] $var_height $var_width $var_rows \

--- 939 unchanged lines hidden ---
1296
1297 # Constrain height, width, and rows to sensible minimum/maximum values
1298 # Return success if no-constrain, else return status from constrain
1299 [ ! "$__constrain" ] || f_dialog_menu_constrain \
1300 "$__var_height" "$__var_width" "$__var_rows" "$__prompt"
1301}
1302
1303# f_dialog_checklist_with_help_size [-n] $var_height $var_width $var_rows \

--- 939 unchanged lines hidden ---