#!/bin/sh

if [ $# -lt 1 ]
then
	echo "usage: src2latex <.cpp source file>"
	exit
fi

root=`echo $1 | sed "s/\.cpp//" `

if [ $root = $1 ]
then
	echo "usage: src2latex <.cpp source file>"
	exit
fi

echo "\begin{flushleft}" > $root.tex
echo "\begin{minipage}[t]{\textwidth}" >> $root.tex
echo "\hrulefill" >> $root.tex
echo >> $root.tex
echo "\vspace*{-5mm}" >> $root.tex
echo >> $root.tex
echo "\begin{verbatim}" >> $root.tex

expand $1 > /tmp/d
cat /tmp/d >> $root.tex

echo "\end{verbatim}" >> $root.tex
echo >> $root.tex
echo "\vspace*{-7mm}" >> $root.tex
echo >> $root.tex
echo "\hrulefill" >> $root.tex
echo >> $root.tex
echo "\vspace*{-5mm}" >> $root.tex
echo >> $root.tex

echo "\end{minipage}" >> $root.tex
echo "\end{flushleft}" >> $root.tex

rm /tmp/d
