diff options
Diffstat (limited to 'usr.sbin/bsdconfig/share/common.subr')
-rw-r--r-- | usr.sbin/bsdconfig/share/common.subr | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/usr.sbin/bsdconfig/share/common.subr b/usr.sbin/bsdconfig/share/common.subr index 667a8f6..9d034ea 100644 --- a/usr.sbin/bsdconfig/share/common.subr +++ b/usr.sbin/bsdconfig/share/common.subr @@ -179,6 +179,44 @@ f_include_lang() fi } +# f_include_help [$file] +# +# When given an argument, cache the contents of a language help-file (to later +# be retrieved by executing again without arguments). +# +# Automatically takes $LANG and $LC_ALL into consideration when reading $file +# (suffix ".$LC_ALL" or ".$LANG" will automatically be added prior to loading +# the language help-file). +# +# No error is produced if (a) a language has been requested (by setting either +# $LANG or $LC_ALL in the environment) and (b) the language help-file does not +# exist -- in which case we will fall back to loading $file without-suffix. +# +# If the language help-file does not exist, an error is cached in place of the +# help-file contents. +# +# When called without arguments, the cached value (if any) is produced. Each +# time this function is called, the cache is overwritten with the newly loaded +# contents. +# +f_include_help() +{ + local file="$1" + + if [ "$file" ]; then + local lang="${LANG:-$LC_ALL}" + + f_dprintf "lang=[$lang]" + if [ -f "$file.$lang" ]; then + setvar HELP_$$ "$( cat "$file.$lang" 2>&1 )" + else + setvar HELP_$$ "$( cat "$file" 2>&1 )" + fi + else + eval echo \"\$HELP_$$\" + fi +} + # f_usage $file [ $key1 $value1 ... ] # # Display USAGE file with optional pre-processor macro definitions. The first |