#! /bin/bash -ue
# Last edited on 2026-07-24 00:06:23 by stolfi

lang="$1"; shift

echo "# ...................................................................." 1>&2
echo "### $0 ${lang}" 1>&2

# Top folders for input files, output data, and output TeX tables of this note:
inp_dir="inp"; if [[ ! ( -d ${inp_dir} ) ]]; then 
  echo "** directory ${inp_dir} missing" 1>&2; exit 1
fi
gen_dir="gen"; mkdir -p ${gen_dir}
tex_dir="tex"; mkdir -p ${tex_dir}

echo "making all derived files and tables for language ${lang} ..." 1>&2

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

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

# Creates all the data files and tables for all the  books and sections 
# of language ${lang}.

if [[ "${lang}" == "voyn" ]]; then 
  # Use the per section-and-type transcription 
  # files in Notes/074/st_files:
  books=( prs lab ini mid fin )
else
  echo "** cannot handle language '${lang}'" 1>&2 ; exit 1
fi

echo "processing books for language ${lang} (${books[@]}) ..." 1>&2
for book in ${books[@]}; do 
  ./make_lang_book_data_and_tables.sh ${lang} ${book}
done

echo "counting and listing bad tokens and lexemes in ${lang} per book ..." 1>&2
bad_counts="${gen_lang_dir}/bad_counts.txt"
./count_bad_token_lexemes_per_book_and_type.sh ${lang} ${books[@]} > ${bad_counts}

echo "# exiting $0" 1>&2
echo "# ...................................................................." 1>&2
