Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 113 lines (98 sloc) 2.68 KB
#!/bin/sh
#
# 2015-10-30
#
# This file was written by Robert Quattlebaum <darco@deepdarc.com>.
#
# This work is provided as-is. Unless otherwise provided in writing,
# Robert Quattlebaum makes no representations or warranties of any
# kind concerning this work, express, implied, statutory or otherwise,
# including without limitation warranties of title, merchantability,
# fitness for a particular purpose, non infringement, or the absence
# of latent or other defects, accuracy, or the present or absence of
# errors, whether or not discoverable, all to the greatest extent
# permissible under applicable law.
#
# To the extent possible under law, Robert Quattlebaum has waived all
# copyright and related or neighboring rights to this work. This work
# is published from the United States.
#
# I, Robert Quattlebaum, dedicate any and all copyright interest in
# this work to the public domain. I make this dedication for the
# benefit of the public at large and to the detriment of my heirs and
# successors. I intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to
# this code under copyright law. In jurisdictions where this is not
# possible, I hereby release this code under the Creative Commons
# Zero (CC0) license.
#
# * <http://creativecommons.org/publicdomain/zero/1.0/>
#
echon() {
# echo -n "$@"
printf %s "$*"
}
SCRIPT_PATH="`dirname $0`"
CALLSIGN="${1-$(xargs)}"
if [ -x "${SCRIPT_PATH}/callsign-escape" ]
then CALLSIGN="$(${SCRIPT_PATH}/callsign-escape "${CALLSIGN}")"
fi
char_to_hamindex () {
case ${1} in
a|A) echo "1" ;;
b|B) echo "2" ;;
c|C) echo "3" ;;
d|D) echo "4" ;;
e|E) echo "5" ;;
f|F) echo "6" ;;
g|G) echo "7" ;;
h|H) echo "8" ;;
i|I) echo "9" ;;
j|J) echo "10" ;;
k|K) echo "11" ;;
l|L) echo "12" ;;
m|M) echo "13" ;;
n|N) echo "14" ;;
o|O) echo "15" ;;
p|P) echo "16" ;;
q|Q) echo "17" ;;
r|R) echo "18" ;;
s|S) echo "19" ;;
t|T) echo "20" ;;
u|U) echo "21" ;;
v|V) echo "22" ;;
w|W) echo "23" ;;
x|X) echo "24" ;;
y|Y) echo "25" ;;
z|Z) echo "26" ;;
0) echo "27" ;;
1) echo "28" ;;
2) echo "29" ;;
3) echo "30" ;;
4) echo "31" ;;
5) echo "32" ;;
6) echo "33" ;;
7) echo "34" ;;
8) echo "35" ;;
9) echo "36" ;;
/) echo "37" ;;
-) echo "38" ;;
\\) echo "39" ;;
^) echo "39" ;;
*) echo "0" ;;
esac
}
triplet_to_chunk () {
local a=$(char_to_hamindex "${1:0:1}")
local b=$(char_to_hamindex "${1:1:1}")
local c=$(char_to_hamindex "${1:2:1}")
printf '%04X' $((a*1600 + b*40 + c))
}
echon "$(triplet_to_chunk $CALLSIGN)"
CALLSIGN="${CALLSIGN:3}"
while [ ${#CALLSIGN} != 0 ]
do
echon ":$(triplet_to_chunk $CALLSIGN)"
CALLSIGN="${CALLSIGN:3}"
done
echo