% -*- Mode: LaTeX -*-
%
%  PROGRAM environment.  Lines are produced in tt font as they appear in the file.
%      Spacing and alignment should be the same.  This differs from the verbatim
%      environment by NOT disabling special characters, thus font changes are
%      possible.
%  DOUBLEPROGRAM environment.  Produces two column output.  The two-column split
%      must be declared manually by using the \second command to indicate the
%      start of the second column.  The columns cannot be broken across a page.
%      This may require some more manual formatting on the part of the user.
%
% \def\allowblanklines{\def\par{\leavevmode\endgraf} \catcode`\`=\active}
%

\def\programsize{\normalsize}
\def\programindent{0pt}

\def\pszgraf{\def\pszgraf{\unskip\mbox{}\\\mbox{}\unskip}\obeylines}

{\catcode`\^^M=\active %
  \gdef\obeylines{\catcode`\^^M=\active \let^^M=\pszgraf}%
  \global\let^^M=\pszgraf}

\newenvironment{program}%
{\begin{list}{}{\parskip=0pt\leftmargin=\programindent\topsep=-\baselineskip\programsize\tt%
\catcode`\~=11%
\def\_{\leavevmode\vbox{\hbox to .5em{\hfill\rule[-1.5pt]{.38em}{1pt}\hfill}}}%
\obeylines\obeyspaces}\item{}}%
{\end{list}}

{\obeyspaces\global\let =\ } % Needed to stop leading spaces from being discarded!
\newlength\colsize
\newlength\spacesize  %% Is this really necessary now??

\newenvironment{doubleprogram}[1]{\begin{program}\settowidth{\spacesize}{ }%
\colsize\columnwidth\relax\advance\colsize -\columnsep\relax\divide\colsize 2\relax%
\kern -\spacesize\programsize\tt#1\begin{minipage}[t]{\colsize}\def\first{}%
\def\second{\end{minipage}\hspace{\columnsep}\begin{minipage}[t]{\colsize}}}%
{\end{minipage}\end{program}\\}
