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

lang="$1"; shift
book="$1"; shift

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

echo "######################################################################" 1>&2
echo "### lang = ${lang} book = ${book} " 1>&2

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_book_dir="gen/${lang}/${book}"; mkdir -p ${gen_book_dir} 
tex_book_dir="tex/${lang}/${book}"; mkdir -p ${tex_book_dir}

./make_lang_book_specific_evt_file.sh ${lang} ${book}

./make_lang_book_list_of_sections.sh ${lang} ${book}

occ_sec_list="${gen_book_dir}/sections-occ.tags"
echo "getting the list of sections occurring in ${lang}/${book} from ${occ_sec_list} ..." 1>&2
occ_secs=( `cat ${occ_sec_list}` )

use_sec_list="${gen_book_dir}/sections-use.tags"
echo "getting the list of sections ${lang}/${book} to analyze from ${use_sec_list} ..." 1>&2
use_secs=( `cat ${use_sec_list}` )

echo "making data files of ${lang}/${book} for each occurring section ..."
for sec in ${occ_secs[@]} tot.1; do \
  ./make_lang_book_sec_data_files.sh ${lang} ${book} ${sec}
done

./make_lang_book_tables.sh ${lang} ${book}

for sec in ${use_secs[@]}; do
  ./make_lang_book_sec_tables.sh ${lang} ${book} ${sec}
done

echo "### end of book = ${book}" 1>&2
echo "######################################################################" 1>&2

