% --------------------------------------%--------------------------------------
% ---------------------------- Identification part ----------------------------
% --------------------------------------%--------------------------------------

\RequirePackage{rcs}

\RCS$Date: 2002/07/09 23:45:45 $
\RCS$RCSfile: aasrc.sty,v $
\RCS$Revision: 1.1 $
\RCS$State: Exp $
\RCS$Author: aa $

\input{aausercs}


% --------------------------------------%--------------------------------------
% -------------------------------- Start code ---------------------------------
% --------------------------------------%--------------------------------------


% --------------------------------------%--------------------------------------
% -------------------------- Declaration of options ---------------------------
% --------------------------------------%--------------------------------------

% Font options

\DeclareOption{courier}{%
  % Some symbols need special treatment in LaTeX depending on the
  % selected font.
  \def\aabar{\ensuremath{|}}%
  \def\aabs{\ensuremath{\backslash}}%
  \def\aahat{\symbol{'136}}%
  \def\aatilde{\symbol{'176}}%
  \def\aalt{\ensuremath{<}}%
  \def\aagt{\ensuremath{>}}%
  \def\aast{\symbol{'052}}%
  \def\aaus{{\_}}%
  \def\aalbrace{{\{}}%
  \def\aarbrace{{\}}}%
  % Text is default
  \def\aatextfont{%
%     \def\aabarbar##1|{{\aacodefont ##1}\catcode`\|=\active}%
%     \def\aagtgtgt{\@ifnextchar>{\@aagtgt}{\aagt\catcode`\>=\active}}%
    \def\aabar{\ensuremath{|}}%
    \def\aabs{\ensuremath{\backslash}}%
    \def\aalt{\ensuremath{<}}%
    \def\aagt{\ensuremath{>}}%
    \def\aaus{{\_}}%
    \def\aalbrace{{\{}}%
    \def\aarbrace{{\}}}%
    \rmfamily}%
  % Comments in the default text font
  \def\aacomfont{\aatextfont}%
  % Code font in courier (we need to redefine some symbols for this font)
  \def\aacodefont{%
    \def\aabar{\symbol{'174}}%
    \def\aabs{\symbol{'134}}%
    \def\aalt{\symbol{'074}}%
    \def\aagt{\symbol{'076}}%
    \def\aaus{\symbol{'137}}%
    \def\aalbrace{\symbol{'173}}%
    \def\aarbrace{\symbol{'175}}%
    %\fontsize{9}{12}\selectfont%
    \fontfamily{pcr}\selectfont}%
  % Keywords are bold
  \def\aakwfont{\bfseries}%
  % Names are bold and slanted
  \def\aanamefont{\bfseries\slshape}%
  % Strings (quotes) are slanted
  \def\aastringfont{\slshape}%
  % Line numbers are small (tiny)
  \def\aalinenumfont{\rmfamily\tiny}}

\DeclareOption{betong}{%
  % Some symbols need special treatment in LaTeX depending on the
  % selected font.
  \def\aabar{\ensuremath{|}}%
  \def\aabs{\ensuremath{\backslash}}%
  \def\aahat{\symbol{'136}}%
  \def\aatilde{\symbol{'176}}%
  \def\aalt{\ensuremath{<}}%
  \def\aagt{\ensuremath{>}}%
  \def\aast{\symbol{'052}}%
  \def\aaus{{\_}}%
  \def\aalbrace{{\{}}%
  \def\aarbrace{{\}}}%
  % Text is default
  \def\aatextfont{%
%     \def\aabarbar##1|{{\aacodefont ##1}\catcode`\|=\active}%
%     \def\aagtgtgt{\@ifnextchar>{\@aagtgt}{\aagt\catcode`\>=\active}}%
    \rmfamily}%
  % Comments in the default text font
  \def\aacomfont{\aatextfont}%
  % Code font in concrete (we need to redefine some symbols for this font)
  \def\aacodefont{%
    \def\aalbrace{\textrm{\{}}%
    \def\aarbrace{\textrm{\}}}%
    \fontfamily{ccr}\selectfont}%
  % Keywords are sans-serfi
  \def\aakwfont{\fontfamily{cmss}\selectfont}%
  % Names are bold and sans-serif
  \def\aanamefont{\fontfamily{cmss}\selectfont\bfseries}%
  % Strings (quotes) are tt
  \def\aastringfont{%
    \def\aabar{\symbol{'174}}%
    \def\aabs{\symbol{'134}}%
    \def\aalt{\symbol{'074}}%
    \def\aagt{\symbol{'076}}%
    \def\aaus{\symbol{'137}}%
    \def\aalbrace{\symbol{'173}}%
    \def\aarbrace{\symbol{'175}}%
    \ttfamily}%
  % Line numbers are small (tiny)
  \def\aalinenumfont{\rmfamily\tiny}}

\DeclareOption{ssf}{%
  % Some symbols need special treatment in LaTeX depending on the
  % selected font.
  \def\aabar{\ensuremath{|}}%
  \def\aabs{\ensuremath{\backslash}}%
  \def\aahat{\symbol{'136}}%
  \def\aatilde{\symbol{'176}}%
  \def\aalt{\ensuremath{<}}%
  \def\aagt{\ensuremath{>}}%
  \def\aast{\symbol{'052}}%
  \def\aaus{{\_}}%
  \def\aalbrace{{\{}}%
  \def\aarbrace{{\}}}%
  % Text is default
  \def\aatextfont{%
%     \def\aabarbar##1|{{\aacodefont ##1}\catcode`\|=\active}%
%     \def\aagtgtgt{\@ifnextchar>{\@aagtgt}{\aagt\catcode`\>=\active}}%
    \rmfamily}%
  % Comments in the default text font
  \def\aacomfont{\aatextfont}%
  % Code font in sans-serif
  \def\aacodefont{%
%    \def\aalbrace{\textrm{\{}}%
%    \def\aarbrace{\textrm{\}}}%
    \fontfamily{cmss}\selectfont}%
  % Keywords are sans-serfi
  \def\aakwfont{\fontfamily{cmss}\selectfont}%
  % Names are bold and sans-serif
  \def\aanamefont{\fontfamily{cmss}\selectfont}%
  % Strings (quotes) are sans-serif
  \def\aastringfont{\fontfamily{cmss}\selectfont}%
  % Line numbers are small (tiny)
  \def\aalinenumfont{\rmfamily\tiny}}

\DeclareOption{sf}{%
  % Some symbols need special treatment in LaTeX depending on the
  % selected font.
  \def\aabar{\ensuremath{|}}%
  \def\aabs{\ensuremath{\backslash}}%
  \def\aahat{\symbol{'136}}%
  \def\aatilde{\symbol{'176}}%
  \def\aalt{\ensuremath{<}}%
  \def\aagt{\ensuremath{>}}%
  \def\aast{\symbol{'052}}%
  \def\aaus{{\_}}%
  \def\aalbrace{{\{}}%
  \def\aarbrace{{\}}}%
  % Text is default
  \def\aatextfont{%
%     \def\aabarbar##1|{{\aacodefont ##1}\catcode`\|=\active}%
%     \def\aagtgtgt{\@ifnextchar>{\@aagtgt}{\aagt\catcode`\>=\active}}%
    \rmfamily}%
  % Comments in the default text font
  \def\aacomfont{\aatextfont}%
  % Code font in sans-serif
  \def\aacodefont{%
%    \def\aalbrace{\textrm{\{}}%
%    \def\aarbrace{\textrm{\}}}%
    \fontfamily{cmss}\selectfont}%
  % Keywords are sans-serfi
  \def\aakwfont{\fontfamily{cmss}\selectfont\slshape}%
  % Names are bold and sans-serif
  \def\aanamefont{\fontfamily{cmss}\selectfont\bfseries}%
  % Strings (quotes) are tt
  \def\aastringfont{%
    \def\aabar{\symbol{'174}}%
    \def\aabs{\symbol{'134}}%
    \def\aalt{\symbol{'074}}%
    \def\aagt{\symbol{'076}}%
    \def\aaus{\symbol{'137}}%
    \def\aalbrace{\symbol{'173}}%
    \def\aarbrace{\symbol{'175}}%
    \ttfamily}%
  % Line numbers are small (tiny)
  \def\aalinenumfont{\rmfamily\tiny}}

\DeclareOption{tt}{%
  % Some symbols need special treatment in LaTeX depending on the
  % selected font.
  \def\aabar{\symbol{'174}}%
  \def\aabs{\symbol{'134}}%
  \def\aahat{\symbol{'136}}%
  \def\aatilde{\symbol{'176}}%
  \def\aalt{\symbol{'074}}%
  \def\aagt{\symbol{'076}}%
  \def\aast{\symbol{'052}}%
  \def\aaus{\symbol{'137}}%
  \def\aalbrace{\symbol{'173}}%
  \def\aarbrace{\symbol{'175}}%
  % Text is default
  \def\aatextfont{%
%     \def\aabarbar##1|{{\aacodefont ##1}\catcode`\|=\active}%
%     \def\aagtgtgt{\@ifnextchar>{\@aagtgt}{\aagt\catcode`\>=\active}}%
    \ttfamily}%
  % Comments in the default text font
  \def\aacomfont{\aatextfont}%
  % Code font in tt
  \def\aacodefont{\ttfamily}%
  % Keywords are tt
  \def\aakwfont{\aacodefont}%
  % Names are tt
  \def\aanamefont{\aacodefont}%
  % Strings (quotes) are tt
  \def\aastringfont{\ttfamily}%
  % Line numbers are small (tiny)
  \def\aalinenumfont{\rmfamily\tiny}}

% Other options

% Print document strings
\newboolean{nodoc}
\DeclareOption{nodoc}{\setboolean{nodoc}{true}}

% --------------------------------------%--------------------------------------
% --------------------------- Execution of options ----------------------------
% --------------------------------------%--------------------------------------

\ExecuteOptions{courier}
\ProcessOptions


% --------------------------------------%--------------------------------------
% ------------------------------ Package loading ------------------------------
% --------------------------------------%--------------------------------------


% --------------------------------------%--------------------------------------
% --------------------------------- Main code ---------------------------------
% --------------------------------------%--------------------------------------


% %\def\aabarbar#1|{{\aacodefont #1}\catcode`\|=\active}
% \def\aabarbar{\aabar\catcode`\|=\active}
% \catcode`\|=\active
% \def|{\catcode`\|= 12 \aabarbar}

% %\def\aagtgtgt{\@ifnextchar>{\@aagtgt}{\aagt\catcode`\>=\active}}
% \def\@aagtgt>{\@ifnextchar>{\@aagt}{\@@aagtgt}}
% \def\@aagt>#1<<<{%
%     \catcode`\>=\active
%     \quad\mbox{\aacodefont#1}}%
% \def\@@aagtgt{\@ifnextchar[{\@@xaagt}{\@@aagt{@}:}}
% \def\@@xaagt[#1]{\@@aagt{#1}:}
% \def\@@aagt#1:#2<<{%
%     \catcode`\>=\active
%     \@hangfrom{\makebox[2em][r]{\if #1@--\else#1.\fi~}}\ignorespaces#2}%
% \def\aagtgtgt{\aagt\catcode`\>=\active}
% \catcode`\>=\active
% \def>{\catcode`\>= 12 \aagtgtgt}



% The width of a white space
\newlength{\aawslength}
\settowidth{\aawslength}{\aacodefont{0}}
\newlength{\aaparlen}\newlength{\aastlen}

% A box used to remove stuff
\newsavebox{\erasedbox}

% Make the aasrc commads
\def\aamakecom{%
  % Each line is typed inside an aaline
  \def\aaline##1##2{%
    % Make a line inside a box
    \makebox[\linewidth][l]{{\aacodefont ##2}%
      % Insert the line number
      \hfill\makebox[0pt][r]{\raisebox{0.3ex}{{\aalinenumfont ##1}}}}}%
  % A keyword
  \def\aakw##1{{\aakwfont ##1}}%
  % White spaces
  \def\aaws##1{\makebox[##1\aawslength][l]{~}}%
  % Document strings
  \ifthenelse{\boolean{nodoc}}{%
    \def\aadoc##1##2##3{\begin{lrbox}{\erasedbox}}%
    \def\endaadoc##1{\end{lrbox}}%
  }{%
    \def\aadoc##1##2##3{%
      \gdef\aalinenum{##1}%
      \settowidth{\aastlen}{##2}%
      \setlength{\aaparlen}{\linewidth}%
      \addtolength{\aaparlen}{-\aastlen}%
      %\addtolength{\aaparlen}{-2em}%
      {\aacodefont ##2}\begin{minipage}[t]{\aaparlen}\parskip=\medskipamount
        {\aacodefont ##3}\aatextfont}%
    % Ends document strings
    \def\endaadoc##1{{\aacodefont ##1}\end{minipage}%
      \hfill\makebox[0pt][r]{\raisebox{0.3ex}{{\aalinenumfont \aalinenum}}}}}%
  % A quote (string)
  \def\aaqt##1{{\aastringfont ##1}}%
  % A comment
  \def\aacom##1{{\aacomfont ##1}}%
  % A function name
  \def\aafunc##1{{\aanamefont ##1}}%
  % A class
  \def\aacls##1{{\aanamefont ##1}}%
  % A module
  \def\aamod##1{{\aanamefont ##1}}%
  % Other names
  \def\aanm##1{{\aanamefont ##1}}}

% The code is typed inside the aasrc environment
\newenvironment{aasrc}{%
  % No indentation, but save it
  \let\aappin\parindent%
  \parindent=0pt%
  \aamakecom}{%
  \parindent=\aappin
  \vspace*{-\baselineskip}}     % This is a hack!

