common.subr (241899) | common.subr (242107) |
---|---|
1if [ ! "$_COMMON_SUBR" ]; then _COMMON_SUBR=1 2# 3# Copyright (c) 2012 Ron McDowell 4# Copyright (c) 2012 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 --- 11 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# | 1if [ ! "$_COMMON_SUBR" ]; then _COMMON_SUBR=1 2# 3# Copyright (c) 2012 Ron McDowell 4# Copyright (c) 2012 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 --- 11 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: head/usr.sbin/bsdconfig/share/common.subr 241899 2012-10-22 18:01:38Z dteske $ | 28# $FreeBSD: head/usr.sbin/bsdconfig/share/common.subr 242107 2012-10-26 00:31:25Z dteske $ |
29# 30############################################################ GLOBALS 31 32# 33# Program name 34# 35pgm="${0##*/}" 36 --- 98 unchanged lines hidden (view full) --- 135 # 136 if f_have f_dialog_msgbox; then 137 f_dialog_msgbox "$msg" 138 else 139 dialog --msgbox "$msg" 0 0 140 fi 141} 142 | 29# 30############################################################ GLOBALS 31 32# 33# Program name 34# 35pgm="${0##*/}" 36 --- 98 unchanged lines hidden (view full) --- 135 # 136 if f_have f_dialog_msgbox; then 137 f_dialog_msgbox "$msg" 138 else 139 dialog --msgbox "$msg" 0 0 140 fi 141} 142 |
143# f_show_help $file 144# 145# Display a language help-file. Automatically takes $LANG and $LC_ALL into 146# consideration when displaying $file (suffix ".$LC_ALL" or ".$LANG" will 147# automatically be added prior to loading the language help-file). 148# 149# If a language has been requested by setting either $LANG or $LC_ALL in the 150# environment and the language-specific help-file does not exist we will fall 151# back to $file without-suffix. 152# 153# If the language help-file does not exist, an error is displayed instead. 154# 155f_show_help() 156{ 157 local file="$1" 158 local lang="${LANG:-$LC_ALL}" 159 160 [ -f "$file.$lang" ] && file="$file.$lang" 161 162 # 163 # Use f_dialog_textbox from dialog.subr if possible, otherwise fall 164 # back to dialog(1) (without options, making it obvious when using 165 # un-aided system dialog). 166 # 167 if f_have f_dialog_textbox; then 168 f_dialog_textbox "$file" 169 else 170 dialog --msgbox "$( cat "$file" 2>&1 )" 0 0 171 fi 172} 173 |
|
143# f_include $file 144# 145# Include a shell subroutine file. 146# 147# If the subroutine file exists but returns error status during loading, exit 148# is called and execution is prematurely terminated with the same error status. 149# 150f_include() --- 23 unchanged lines hidden (view full) --- 174 f_dprintf "lang=[$lang]" 175 if [ -f "$file.$lang" ]; then 176 . "$file.$lang" || exit $? 177 else 178 . "$file" || exit $? 179 fi 180} 181 | 174# f_include $file 175# 176# Include a shell subroutine file. 177# 178# If the subroutine file exists but returns error status during loading, exit 179# is called and execution is prematurely terminated with the same error status. 180# 181f_include() --- 23 unchanged lines hidden (view full) --- 205 f_dprintf "lang=[$lang]" 206 if [ -f "$file.$lang" ]; then 207 . "$file.$lang" || exit $? 208 else 209 . "$file" || exit $? 210 fi 211} 212 |
182# f_include_help NAME [$file] 183# 184# When given both arguments, cache the contents of a language help-file to 185# later be retrieved by executing again with only the first argument. 186# 187# Automatically takes $LANG and $LC_ALL into consideration when reading $file 188# (suffix ".$LC_ALL" or ".$LANG" will automatically be added prior to loading 189# the language help-file). 190# 191# If a language has been requested by setting either $LANG or $LC_ALL in the 192# environment and the language-specific help-file does not exist we will fall 193# back to $file without-suffix. 194# 195# If the language help-file does not exist, an error is cached in place of the 196# help-file contents. 197# 198f_include_help() 199{ 200 local name="$1" file="$2" 201 202 if [ "$file" ]; then 203 local lang="${LANG:-$LC_ALL}" 204 205 f_dprintf "name=[$name] lang=[$lang]" 206 if [ -f "$file.$lang" ]; then 207 setvar HELP_${name}_$$ "$( cat "$file.$lang" 2>&1 )" 208 else 209 setvar HELP_${name}_$$ "$( cat "$file" 2>&1 )" 210 fi 211 else 212 eval echo \"\$HELP_${name}_$$\" 213 fi 214} 215 | |
216# f_usage $file [ $key1 $value1 ... ] 217# 218# Display USAGE file with optional pre-processor macro definitions. The first 219# argument is the template file containing the usage text to be displayed. If 220# $LANG or $LC_ALL (in order of preference, respectively) is set, ".encoding" 221# will automatically be appended as a suffix to the provided $file pathname. 222# 223# When processing $file, output begins at the first line containing that is --- 110 unchanged lines hidden --- | 213# f_usage $file [ $key1 $value1 ... ] 214# 215# Display USAGE file with optional pre-processor macro definitions. The first 216# argument is the template file containing the usage text to be displayed. If 217# $LANG or $LC_ALL (in order of preference, respectively) is set, ".encoding" 218# will automatically be appended as a suffix to the provided $file pathname. 219# 220# When processing $file, output begins at the first line containing that is --- 110 unchanged lines hidden --- |