% a simple environment for code listings
%
% \begin{code}{<indent>}
% ...
% \end{code}

\begingroup
    \catcode `|=0 \catcode `[= 1 \catcode`]=2
    \catcode `\{=12 \catcode `\}=12 \catcode`\\=12
    |gdef|@xcode#1\end{code}[#1|end[code]]
|endgroup

\def\@code{
    \@verbatim\frenchspacing\@vobeyspaces
    \@xcode
}
\let\endcode=\endtrivlist

\newenvironment{code}[1]{
    \precode
    \vspace{\codetopsep}
    \advance\@totalleftmargin#1
    \@code
}{
    \vspace{\codebottomsep}
    \postcode
}

\newlength{\codetopsep} \setlength{\codetopsep}{0.2in}
\newlength{\codebottomsep} \setlength{\codebottomsep}{\codetopsep}

\newcommand{\precode}{
    \small
    \hrule
}

\newcommand{\postcode}{
    \hrule
    \vspace{1ex}
}
