common.subr (241701) | common.subr (241899) |
---|---|
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 241701 2012-10-18 18:43:54Z dteske $ | 28# $FreeBSD: head/usr.sbin/bsdconfig/share/common.subr 241899 2012-10-22 18:01:38Z dteske $ |
29# 30############################################################ GLOBALS 31 32# 33# Program name 34# 35pgm="${0##*/}" 36 --- 137 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 | 29# 30############################################################ GLOBALS 31 32# 33# Program name 34# 35pgm="${0##*/}" 36 --- 137 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 |
182# f_include_help [$file] | 182# f_include_help NAME [$file] |
183# | 183# |
184# When given an argument, cache the contents of a language help-file (to later 185# be retrieved by executing again without arguments). | 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# | 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# No error is produced if (a) a language has been requested (by setting either 192# $LANG or $LC_ALL in the environment) and (b) the language help-file does not 193# exist -- in which case we will fall back to loading $file without-suffix. | 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# | 194# 195# If the language help-file does not exist, an error is cached in place of the 196# help-file contents. 197# |
198# When called without arguments, the cached value (if any) is produced. Each 199# time this function is called, the cache is overwritten with the newly loaded 200# contents. 201# | |
202f_include_help() 203{ | 198f_include_help() 199{ |
204 local file="$1" | 200 local name="$1" file="$2" |
205 206 if [ "$file" ]; then 207 local lang="${LANG:-$LC_ALL}" 208 | 201 202 if [ "$file" ]; then 203 local lang="${LANG:-$LC_ALL}" 204 |
209 f_dprintf "lang=[$lang]" | 205 f_dprintf "name=[$name] lang=[$lang]" |
210 if [ -f "$file.$lang" ]; then | 206 if [ -f "$file.$lang" ]; then |
211 setvar HELP_$$ "$( cat "$file.$lang" 2>&1 )" | 207 setvar HELP_${name}_$$ "$( cat "$file.$lang" 2>&1 )" |
212 else | 208 else |
213 setvar HELP_$$ "$( cat "$file" 2>&1 )" | 209 setvar HELP_${name}_$$ "$( cat "$file" 2>&1 )" |
214 fi 215 else | 210 fi 211 else |
216 eval echo \"\$HELP_$$\" | 212 eval echo \"\$HELP_${name}_$$\" |
217 fi 218} 219 220# f_usage $file [ $key1 $value1 ... ] 221# 222# Display USAGE file with optional pre-processor macro definitions. The first 223# argument is the template file containing the usage text to be displayed. If 224# $LANG or $LC_ALL (in order of preference, respectively) is set, ".encoding" --- 113 unchanged lines hidden --- | 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" --- 113 unchanged lines hidden --- |