diff options
author | Gavin Howard <yzena.tech@gmail.com> | 2019-04-09 09:01:15 -0600 |
---|---|---|
committer | Gavin Howard <yzena.tech@gmail.com> | 2019-04-09 09:01:15 -0600 |
commit | aea5bdb808f2bdb32214f08d040bfb59c32a7a2b (patch) | |
tree | acb865e7cb896ed0c5eed7ae4682b1ef660f51de /functions.sh | |
parent | ea73c8c2a7ca545fe860427ebc79a159b860bee2 (diff) | |
download | bc-aea5bdb808f2bdb32214f08d040bfb59c32a7a2b.tar.gz |
Use $NLSPATH to install locales
Diffstat (limited to 'functions.sh')
-rwxr-xr-x | functions.sh | 89 |
1 files changed, 80 insertions, 9 deletions
diff --git a/functions.sh b/functions.sh index ec8a1a48..e7361324 100755 --- a/functions.sh +++ b/functions.sh @@ -29,12 +29,27 @@ readlink() { - local exe="$1" + local f="$1" shift - L=$(ls -dl "$exe") + local arrow="-> " + local d=$(dirname "$f") - printf "${L#*-> }" + local lsout="" + local link="" + + lsout=$(ls -dl "$f") + link=$(printf '%s' "${lsout#*$arrow}") + + while [ -z "${lsout##*$arrow*}" ]; do + cd "$d" + f="$link" + d=$(dirname "$f") + lsout=$(ls -dl "$f") + link=$(printf '%s' "${lsout#*$arrow}") + done + + printf '%s' "${f##*$d/}" } removeext() { @@ -125,15 +140,71 @@ checktest() substring_replace() { - if [ "$#" -ne 3 ]; then - err_exit "Invalid number of args to $0" - fi + local str="$1" + shift + + local needle="$1" + shift - str="$1" - needle="$2" - replacement="$3" + local replacement="$1" + shift result=$(printf '%s' "$str" | sed -e "s!$needle!$replacement!g") printf '%s\n' "$result" } + +gen_nlspath() { + + local nlspath="$1" + shift + + local locale="$1" + shift + + local execname="$1" + shift + + local char="@" + local modifier="${locale#*$char}" + local tmplocale="${locale%%$char*}" + + char="." + local charset="${tmplocale#*$char}" + tmplocale="${tmplocale%%$char*}" + + if [ "$charset" = "$tmplocale" ]; then + charset="" + fi + + char="_" + local territory="${tmplocale#*$char}" + local language="${tmplocale%%$char*}" + + if [ "$territory" = "$tmplocale" ]; then + territory="" + fi + + if [ "$language" = "$tmplocale" ]; then + language="" + fi + + local needles="%%:%L:%N:%l:%t:%c" + + needles=$(printf '%s' "$needles" | tr ':' '\n') + + for i in $needles; do + nlspath=$(substring_replace "$nlspath" "$i" "\n$i\n") + done + + nlspath=$(substring_replace "$nlspath" "%%" "%") + nlspath=$(substring_replace "$nlspath" "%L" "$locale") + nlspath=$(substring_replace "$nlspath" "%N" "$execname") + nlspath=$(substring_replace "$nlspath" "%l" "$language") + nlspath=$(substring_replace "$nlspath" "%t" "$territory") + nlspath=$(substring_replace "$nlspath" "%c" "$charset") + + nlspath=$(printf '%s' "$nlspath" | tr -d '\n') + + printf '%s\n' "$nlspath" +} |