#! /bin/bash -ue
# Last edited on 2026-07-19 13:26:05 by stolfi

cmd="$0"; cmd="${cmd##*/}"

usage="${cmd} {LANG}/{BOOK}"
if [[ $# -ne 1 ]]; then
  echo "usage: ${usage}" 1>&2; exit 1
fi

smp="$1"; shift;          # Sample name, {lang/book}
       
totattr=( `get_sample_section_attrs.sh ${smp}/tot.1` )
echo "  totattr = ( ${totattr[*]} )" 1>&2
langbook="${totattr[1]}"

echo "  creating link dat/${smp}/org to ../../langbank/${langbook}" 1>&2
relink_source_dir.sh dat/${smp} org ../../langbank/${langbook}
srcFile="dat/${smp}/org/main.src"
wdsFile="dat/${smp}/org/main.wds"
if [[ -s ${srcFile} ]]; then 
  echo "  recreating ${wdsFile} from ${srcFile}" 1>&2
  ( cd dat/${smp}/org && ( rm -f main.wds ; make main.wds ) ) 2>&1 | sed -e 's:^:    :g' 1>&2
else
  echo "** ${srcFile} not found" 1>&2; exit 1
fi
if [[ ! ( -s ${wdsFile} ) ]]; then 
  echo "** file ${wdsFile} not created" 1>&2; exit 1
fi
