basedec.sh: Add the `-s' option

This commit is contained in:
styan 2020-06-10 08:31:12 +00:00
parent 7c17ad79bd
commit 96a9bed118
1 changed files with 7 additions and 4 deletions

View File

@ -1,6 +1,6 @@
#!/bin/sh
usage() {
printf 'usage: %s [-t type] [file ...]\n' "${0##*/}" >&2
printf 'usage: %s [-s] [-t type] [file ...]\n' "${0##*/}" >&2
exit 64
}
case "$(printf %s "${0##*/}" | tr A-Z a-z)" in
@ -17,7 +17,8 @@ b32=ABCDEFGHIJKLMNOPQRSTUVWXYZ234567
b32hex=0123456789ABCDEFGHIJKLMNOPQRSTUV
b64=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
b64safe=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_
while getopts t: opt; do
strict=0
while getopts t:s opt; do
case "$opt" in
t) case "$(printf %s "$OPTARG" | tr A-Z a-z)" in
16) type=16;;
@ -29,6 +30,7 @@ while getopts t: opt; do
*) usage;;
esac
;;
s) strict=1;;
*) usage;;
esac
done
@ -52,7 +54,7 @@ case "$type" in
*) usage;; # Unreachable
esac
cat -- "$@" | awk -vbits="$bits" -valphabet="$alphabet" \
-vinsensitive="$insensitive" '
-vinsensitive="$insensitive" -vstrict="$strict" '
function leftshift(a, b) {
return a * 2 ** b
}
@ -81,6 +83,7 @@ cat -- "$@" | awk -vbits="$bits" -valphabet="$alphabet" \
t = mask(t, b)
count++
}
}
} else if (strict && $i != "=")
exit 65
}
}'