From 81bd2e3065c0c9d53722b0521a214d7cd29658b5 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Fri, 6 Oct 2017 13:33:08 -0400 Subject: [PATCH] Make mpw_mkpw symlinkable. --- platform-independent/scripts/bashlib | 38 ++++++++++++++++++++++++--- platform-independent/scripts/mpw_mkpw | 6 ++--- 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/platform-independent/scripts/bashlib b/platform-independent/scripts/bashlib index 4e9c3ec7..99844f44 100755 --- a/platform-independent/scripts/bashlib +++ b/platform-independent/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/platform-independent/scripts/mpw_mkpw b/platform-independent/scripts/mpw_mkpw index 5993bd1f..52771d7a 100755 --- a/platform-independent/scripts/mpw_mkpw +++ b/platform-independent/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