#!/bin/sh
# Actually do the argument parsing here
targetroot=$PWD
pplist=ppl
dialog=directory
data=file
while [ $# -gt 0 ]; do
        case "$1" in
        *=*)    key=`expr "$1" : '\(.*\)=.*'`
                val=`expr "$1" : '.*=\(.*\)'`
                eval "$key"=\'"$val"\'
                unset key val
                shift ;;
        *)      break;;
        esac
done

# end option parser

if [ "${tmproot:+isset}" != isset ] 
then
  tmproot=$targetroot
fi

case $dialog in
directory)
( cd ${sourceroot:?} ;
for n in [a-z][0-9][0-9][0-9][a-z] # fuer vm1#
  do
    mkdir $tmproot/$n
    mkdir $targetroot/$n
    ( cd $n ;
       for sf in $n[0-9][0-9][0-9].*  # fuer vm1#
      do
        phondat2nist phonfile=$sourceroot/$n/$sf \
             nistfile=$tmproot/$n/`echo $sf | sed 's/\..*$/.nist/'`
        echo $tmproot/$n/`echo $sf | sed 's/\..*$/.nist/'` $targetroot/$n/`echo $sf | sed 's/\..*$/.htk/'` \
           >> $targetroot/$pplist
      done )
   done ) ;;
*)
( cd ${sourceroot:?} ;
    mkdir $tmproot/$dialog
    mkdir $targetroot/$dialog
    ( cd $dialog ;
         phondat2nist phonfile=$sourceroot/$dialog/$data \
             nistfile=$tmproot/$dialog/`echo $data | sed 's/\..*$/.nist/'`
        echo $tmproot/$dialog/`echo $data | sed 's/\..*$/.nist/'` $targetroot/$dialog/`echo $data | sed 's/\..*$/.htk/'` \
           >> $targetroot/$pplist));;
esac

/export/home/HTK_V2.1/bin.sun4_solaris/HCopy \
  -C /home/kip/projekte/HTK/DEF/preproconfig \
  -S $targetroot/$pplist

rm $targetroot/*/*.nist
rm  $targetroot/$pplist
