diff --git a/scripts/bashlib b/scripts/bashlib index 4e9c3ec..99844f4 100755 --- a/scripts/bashlib +++ b/scripts/bashlib @@ -261,7 +261,10 @@ chr() { # Outputs the decimal ASCII value of the given character. # ord() { - printf '%d' "'$1" + local str=$1 s + for (( s=0; s < ${#str}; ++s )); do + printf '%d' "'${str:s:1}" + done } # _____________________________________________________________________ @@ -274,7 +277,10 @@ ord() { # Outputs the hexadecimal ASCII value of the given character. # hex() { - printf '%x' "'$1" + local str=$1 s + for (( s=0; s < ${#str}; ++s )); do + printf '%02X' "'${str:s:1}" + done } # _____________________________________________________________________ @@ -287,7 +293,10 @@ hex() { # Outputs the character that has the given hexadecimal ASCII value. # unhex() { - printf "\\x$1" + local hex=$1 h + for (( h=0; h < ${#hex}; h+=2 )); do + printf "\\x${hex:h:2}" + done } # _____________________________________________________________________ @@ -1422,6 +1431,29 @@ shorten() { +# ______________________________________________________________________ +# |__ CdSource ________________________________________________________________| +# +# cdsource [file] +# +# Change the current directory into the directory where the file is located, resolving symlinks. +# +cdsource() { + local source=${1:-${BASH_SOURCE[1]}} + + while [[ $source ]]; do + [[ $source = */* ]] && cd "${source%/*}" + + if [[ -L ${source##*/} ]]; then + source=$(readlink "${source##*/}") + else + source= + fi + done +} # _____________________________________________________________________ + + + # ______________________________________________________________________ # |__ Up ________________________________________________________________| # diff --git a/scripts/mpw_mkpw b/scripts/mpw_mkpw index 5993bd1..52771d7 100755 --- a/scripts/mpw_mkpw +++ b/scripts/mpw_mkpw @@ -1,4 +1,6 @@ #!/usr/bin/env bash +source bashlib +cdsource getword() { local cat=$1 pop_limit=$2 words=() @@ -19,9 +21,7 @@ declare -A categoryByCharacter=( ['v']=verb ) templates=( - nvan - anvr - anavan + ran # ~32.0 bit ) permutations=1