# Description:
#   This script is designed to take a text glossary type of file and
#   make the entries in it alphabetical
# See Also:
#   There are a set of scripts which transform to HTML:
#   diary2html.sh, linkdoc2html.sh, plaintext2pdf.sh, plaintext2html-simple.sh
#   plaintext2html.sh
# Author:
#   m.j.bishop


 
 if [ "$1" = "" ]
 then
   echo "usage: $0  textFileName "
   cat $0 | sed -n "/^[ ]*#/p" 
   exit 1;
 fi

 sFile="$1"
 
 cat $1 | csplit -fxxxx - "/^[ ]*\*/" "{*}" > /dev/null

 for i in xxxx*
 do
   sNewFileName=$(grep "^[ ]*\*" $i | \
    sed "s/^[ ]*\*/GLOSS-/g" | \
    tr ' */' '-')
   #echo "FILE-NAME=$i NEW-FILE-NAME=$sNewFileName"
   
   if [ "$sNewFileName" != "" ]
   then
     cp $i $sNewFileName    
   else
     cp $i header.temp
   fi
 done;
  
  
  
 cat GLOSS-* > temp.txt
 rm -f GLOSS-*
 rm -f xxxx*
 cat header.temp
 rm -f header.temp
 cat temp.txt