#! /bin/bash
# Last edited on 2023-05-10 11:25:37 by stolfi

cmd="$0"; cmd="${cmd##*/}"
usage="${cmd} LANG/BUK/STAG"

# Extracts from sample-sections.tbl the attributes of 
# the given sample and section, outputs as five blank-separated fields

if [[ $# -ne 1 ]]; then
  echo "usage: ${usage}"; exit 1
fi

smpsec="$1"; shift;

tbl="sample-sections.tbl"

cat ${tbl} \
  | gawk -v smpsec="${smpsec}" \
     ' /^ *([#]|$)/ { next; } \
       ($1 == smpsec) { print; } \
     ' \
  > .tmp$$
attr=( `cat .tmp$$` )
/bin/rm -f .tmp$$
if [[ ${#attr[@]} -eq 0 ]]; then
  echo "${smpsec} not found in ${tbl}" 1>&2;
  exit 1
fi
if [[ ${#attr[@]} -ne 5 ]]; then
  echo "format error in ${tbl}" 1>&2; 
  echo "[${attr[@]}]";
  exit 1
fi
if [[ "/${attr[0]}" != "/${smpsec}" ]]; then
  echo "sample/section mismatch  = \"${attr[0]}\"";
  exit 1
fi
echo "${attr[@]}"