#! /bin/sh

     ###################################### 
     ##### Model Transformation Tools #####
     ######################################

# Bourne shell script: makedoc
# Encapsulates a tex file in a document.

# P.J.Gawthrop August 1996
# Copyright (c) P.J.Gawthrop, 1996.

###############################################################
## Version control history
###############################################################
## $Id$
## $Log$
## Revision 1.1  1997/05/17 13:55:42  peterg
## Initial revision
##
# Revision 1.2  1997/04/23  10:06:51  peterg
# Put output in the correct file!
#
# Revision 1.1  1997/04/23  10:03:41  peterg
# Initial revision
#
###############################################################

date=`date`
switches=$1
system=$2
representation=$3
lang=$4
args=$5
documenttype=$6
ps=$7

if [ "$documenttype" = "book" ]; then
  document=book
else
  document=article
fi

if [ "$documenttype" = "book" ]||[ "$documenttype" = "article" ]; then
    title="\title{Report on $system}"
else
    title="\title{System $system, representation $representation}"
fi

filename=$2_$3.doc
texname=$2_$3.tex
indexname=$2_$3.ind

# Inform user
echo "Creating $filename"
# Make arguments acceptable to LateX
Args=`echo $args | sed 's/_/\\\_/g'`

cat<<EOF  > $filename 
\nonstopmode
\documentclass[12pt,a4paper]{$document}
    $title
    \author{Generated by MTT using :\\\\
     (mtt $switches $system $representation $lang $Args)}
    \date{$date}
EOF

if [ "$documenttype" = "book" ]; then
  cat <<EOF   >> $filename 
  \makeindex
EOF
fi

cp -v $MTTPATH/trans/*.sty .
cat  >> $filename <<EOF
\usepackage{mtt_$ps}
EOF

cat <<EOF  >> $filename 
\begin{document}
  \maketitle
EOF

if [ "$documenttype" = "book" ]||[ "$documenttype" = "article" ]; then
  cat $MTTPATH/trans/contents.tex >> $filename
fi

cat <<EOF  >> $filename 
%Fancy headings
  \pagestyle{fancy}
  \renewcommand{\sectionmark}[1]{\markboth{#1}{}}
  \lhead{Report \textbf{$system}}
  \rhead{Representation \textbf{$representation}}
  \rfoot{Page \thepage.}\cfoot{}
  \lfoot{\emph{$date}}

  \input{$texname}
EOF

if [ "$documenttype" = "book" ]; then
  cat <<EOF   >> $filename 
  \input{$indexname}
EOF
fi

cat<<EOF  >> $filename 
\end{document}
EOF












