#!/bin/sh
#  
# fmts	K. J. Turner	11/05/02
# 
# This filter takes plain, formatted SDL text and turns it into
# something that can be printed sensibly by LaTeX. Input is from
# "stdin" and output is to "stdout". The flag "-n" causes lines to be
# numbered at the right. The environment variable FMT may be set to this value
# for the same effect.
# 
# The script uses the "lex" program "sdltex" to embolden SDL
# keywords, to deal with LaTeX special characters, and to handle
# indentation and layout using spaces and tabs. A LaTeX tabbing
# environment "sdl" is assumed; the "comment" environment is also
# needed. The "sdl" environment should have a form such as:
# 
# \newenvironment{sdl}
#   {
#     \begin{tabbing}
#       \hspace{4em}\=\hspace{4em}\=\hspace{4em}\=\hspace{4em}\=
#       \hspace{4em}\=\hspace{4em}\=\hspace{4em}\=\hspace{4em}\=
#       \hspace{4em}\=\hspace{4em}\=\hspace{4em}\=\hspace{4em}\=
#       \hspace{4em}\=\\
#   }%
#   {
#     \end{tabbing}
#   }
# 
# The script may be called directly from an editor as a filter. However
# if this is done, note that there may be a limit on how much text
# may be filtered at one time. It may therefore be necessary to filter
# a large amount of text in several goes.

prog="`basename $0`"
tmpname=/tmp/$prog$$

if [ "$FMT" != "" ]
  then flags="$FMT"
  else flags=""
fi

while [ $# -gt 0 ]
  do
    case $1 in
      -n) flags=$1;;
      -*) echo "$prog: unknown flag $1";;
      *)  echo "$prog: unknown parameter $1";;
    esac
    shift
  done

echo "\\\\begin{comment}"
tee $tmpname
echo "\\end{comment}"

echo

echo "\\\\begin{sdl}"
sdltex $flags < $tmpname
echo "\\end{sdl}"

rm $tmpname
