You are on page 1of 1

#!

/bin/bash
# (c) Pep Diz - licensed as GPLv2

sintaxis() {
echo "$0 bas|basm|asm|c [varname]"
echo
echo "read a udg file from stdin and writes it to stdout in selected format"
echo "that means file is 21 lines with 8 bytes each csv separated"
echo "basically extract any csv values and wrap them in right language syntax"
exit
}

bas-array() {
echo "dim $V(20,7) as ubyte => { _"
sed -r -e '$s/.* (([0-9]+,)+[0-9]+)/{\1} _/;$!s/.* (([0-9]+,)+[0-9]+)/{\1} , _/'
# sed -e 's/^[0-9][0-9]* DATA \(..*\)$/{ \1 } , _/'
echo "}"
}

c-array() {
echo "unsigned char $V[21][8] = { _"
sed -r -e '$s/.* (([0-9]+,)+[0-9]+)/{\1}\n};/;$!s/.* (([0-9]+,)+[0-9]+)/{\1} ,/'
# sed -e 's/^[0-9][0-9]* DATA \(..*\)$/\{\1\} , _/'
# echo "}"
}

asm-bytes() {
echo "$V:"
# sed -e 's/^[0-9][0-9]* DATA \(..*\)$/db \1/'
sed -r -e 's/.* (([0-9]+,)+[0-9]+)/db \1/'
}

basm-bytes() {
echo "$V:"
echo "ASM"
sed -r -e '$s/.* (([0-9]+,)+[0-9]+)/db \1\nEND ASM/;$!s/.* (([0-9]+,)+[0-
9]+)/db \1/'
# sed -e 's/^[0-9][0-9]* DATA \(..*\)$/db \1/'
}

V=${3:-udgSet}

case $1 in
bas) dos2unix | bas-array ;;
basm) dos2unix | basm-bytes ;;
c) dos2unix | c-array ;;
asm) dos2unix | asm-bytes ;;
*) sintaxis ;;
esac

You might also like