#! /bin/sh

# Jonathan Frech, 2021-09-04; see blog.jfrech.com/248
# hotfix 2021-12-21: fixed URI


TMP='/tmp/jfrech.com/jblog-248'
BC='2021-09-04_jonathan-frech_brainfuck-compiler-project'
TMPSTDIN="$TMP/$BC/macro-assembler-sources/stdin.ma"

[ -z "$1" ] \
    && printf 'usage: %s <source.ma>\n' "$0" \
    && printf '       %s - << \x27SRC\x27\n' "$0" \
    && printf '       ...\n' \
    && printf '       SRC\n' \
    && printf '       %s --install-vim-syntax-highlighting\n' "$0" && exit 1

mkdir -p "$TMP" && cd "$TMP"

[ ! -f "$BC.tar" ] && rm -rf "$BC" "$BC.tar" \
    && curl -fsSL https://blog.jfrech.com/248/"$BC.tar" -o "$BC.tar" \
    && tar -xf "$BC.tar" \
    && cd "$BC"

[ "$1" = '--install-vim-syntax-highlighting' ] && make -C vim-syntax && exit 0

SRC="$1"
[ "$1" = '-' ] && SRC="$TMPSTDIN" && dd of="$SRC"
"$TMP/$BC/runbc" "$SRC"
