#!/bin/bash
set -eu
input=$1
template=$2
output=$3
firstname ()
{
local -r fullname=$1
local name=${fullname%% *}
echo ${name,}
}
generate-parameters ()
{
read fullname
local -r firstname=$(firstname "${fullname}")
cat <(.+)
$,\1,'
}
generate-main ()
{
read fullname
read instrument
read emph1
read emph2
local -r name=$(firstname "${fullname}")
cat <
${fullname}
${instrument}
EOF
while read line
do
# Ignore empty lines.
if [[ ${line} =~ ^[[:space:]]*$ ]]
then
continue
fi
# Pasting from GDoc yields trailing spaces; remove those.
if ! [[ ${line} =~ ([^?]+\?)\ (.+[^ ])\ * ]]
then
>&2 echo "Invalid line: ${line}"
continue
fi
cat <
$(pandoc-inline <<< "${BASH_REMATCH[1]}")
$(pandoc-inline <<< ${BASH_REMATCH[2]})
EOF
done
imgdir=$(realpath --relative-to $(dirname "${template}") images)
cat <
EOF
}
./build.sh <(generate-main < "${input}") \
<(generate-parameters < "${input}") \
"${template}" \
"${output}"