#! /bin/bash -ue
# Last edited on 2025-05-04 22:45:38 by stolfi

# Creates plain text and LaTeX tables specific for a ${lang}, ${book}, and section ${sec}.
# Plain text tables are placed in folder ${gen_dir}, while LaTeX tables
# are placed in ${tex_dir}.

# Assumes that the script {make_lang_book_sec_data_files.sh} 
# has been run for this combination of ${lang}, ${book}, and ${sec},
# and also possibly for the other sections, including the pseudo-section "tot.1".
# Thus it assumes that there are files "{XXX}.tlw", "{XXX}.wfr", and "{XXX}.wdf"
# where {XXX} is "raw", "bad", and "gud".

lang="$1"; shift    # Language ("voyn", "chin", "engl", etc.)
book="$1"; shift    # A book of language  ${lang} ("prs", "cul", "lab", "maj", etc.)
sec="$1"; shift     # A specific section (possibly "tot.1").

if [[ "/${lang}" == "/" ]]; then echo "** lang not specified" 1>&2; exit 1; fi
if [[ "/${book}" == "/" ]]; then echo "** book not specified" 1>&2; exit 1; fi
if [[ "/${sec}" == "/" ]]; then echo "** sec not specified" 1>&2; exit 1; fi

if [[ "/${lang}" != "/voyn" ]]; then echo "** cannot handle language ${lang}" 1>&2; exit 1; fi

# Top folders for output data and output TeX tables of this note:
gen_sec_dir="gen/${lang}/${book}/${sec}"; mkdir -p ${gen_sec_dir}
tex_sec_dir="tex/${lang}/${book}/${sec}"; mkdir -p ${tex_sec_dir}

raw_tlw="${gen_sec_dir}/raw.tlw"
gud_tlw="${gen_sec_dir}/gud.tlw"
bad_tlw="${gen_sec_dir}/bad.tlw"

whole_tlw="${gen_sec_dir}/whole.tlw"
trunc_tlw="${gen_sec_dir}/trunc.tlw"

raw_wfr="${gen_sec_dir}/raw.wfr"
gud_wfr="${gen_sec_dir}/gud.wfr"
bad_wfr="${gen_sec_dir}/bad.wfr"

raw_wdf="${gen_sec_dir}/raw.wdf"
gud_wdf="${gen_sec_dir}/gud.wdf"
bad_wdf="${gen_sec_dir}/bad.wdf"

echo "!!! MUST CREATE THE TEX TABLES !!!" 1>&2