% MANPAGE DOCUMENT STYLE -- Created 25 May 1990
% manpage.sty

% Rong Chen (rchen@cs.uiuc.edu)
% Department of Computer Science
% University of Illinois at Urbana-Champaign
% Urbana, IL 61801

% Copyright (c) 1990 by Rong Chen 
% Permission to copy all or part of this work is granted, provided
% that the copies are not made or distributed for resale, and that
% the copyright notice and this notice are retained.
% 
% THIS WORK IS PROVIDED ON AN "AS IS" BASIS.  THE AUTHOR PROVIDES NO
% WARRANTY WHATSOEVER, EITHER EXPRESS OR IMPLIED, REGARDING THE WORK,
% INCLUDING WARRANTIES WITH RESPECT TO ITS MERCHANTABILITY OR FITNESS
% FOR ANY PARTICULAR PURPOSE.

% This style option is designed to work with the report document style
% of LaTeX version 2.09.  Use \documentstyle[11pt,manpage]{report}
% 
% The commands that are created in the style file are:
%
% \begin{manpage}{Title}{Module}{Version} % see an example, all will be clear
% \end{manpage}                           % end of manpage environment
% \function#1  (e.g., \function{void demo(int dummy)})  % with \medskip added
% \function*#1 (e.g., \function*{void demo(int dummy)}) % no extra spacing
% \subtitle#1  (e.g., \subtitle{ANTHOR})  % fit into the same line if possible
% \subtitle*#1 (e.g., \subtitle{AUTHOR})  % always break a newline
% "#1"         (e.g., "dummy_variable")   % argument is in italic&unbreakable
% \separator   % draw a line of linewith long to seperate suntitle from text
%
% The following characters (control-sequents) are defined (or redefined):
%
% \* --- the same as $\ast$
% \< --- the same as $\langle$
% \> --- the same as $\rangle$
% <  --- the same as $<$
% >  --- the same as $>$
% _  --- the same as \_
% +  --- the same as $+$
% |  --- the same as $\mid$
% ^  --- hat character that is defined as $\wedge$ being raised 0.6ex

% If you make any improvements, I'd like to hear about them.

%\headheight 24pt          % See LaTeX book for definitions
%\headsep 12pt
%\textwidth 6.25in
%\textheight 8.0in
%\topmargin 0in
%\marginparwidth 0pt
%\oddsidemargin 0pt
%\evensidemargin 0pt
%\marginparsep 0pt
\parindent 0pt

\newdimen\argindent \argindent 3em  % indentation for function arguments

\newdimen\arg@dim         % temp variables that you don't want to know
\newdimen\line@siz
\newbox\arg@box

\catcode`\"=\active
\def\arg@quote#1"{\hbox{\it #1\/}} \def\tt@quote{{\tt \char`\"}}
\let"=\tt@quote

\def\separator{\rule{\linewidth}{0.5pt}}

\def\function{\@ifstar{\@func@star}{\@func@norm}}
\def\@func@star#1{\expandafter\@function#1 \\ }
\def\@func@norm#1{\expandafter\@function#1 \medskip\\ }

\def\@function#1(#2)#3 {%
  \begingroup%
  \setbox\arg@box=\hbox{\bf #1}\global\arg@dim\wd\arg@box%
  \setbox\arg@box=\hbox{\rm $)$;}%
  \global\line@siz\linewidth\global\advance\line@siz-\wd\arg@box%
  \pagebreak[3]%
  \expandafter\print@name#1 \@@
  \def\@comma{}\ignorespaces%
  \@for\@tempa:=#2\do{\ignorespaces%
    \setbox\arg@box=\hbox{\@comma}\global\advance\arg@dim\wd\arg@box%
    \unskip\@comma\def\@comma{\nobreak%%%%%,
		\penalty-\@m}\ignorespaces%
    \expandafter\print@arg\@tempa\@@\ignorespaces%
  }{\nobreak#3}%
  \endgroup%
}

\def\print@arg#1#2 #3\@@{%
  \setbox\arg@box=\hbox{#1#2\expandafter\print@dummy#3=\@@}%
  \global\advance\arg@dim\wd\arg@box%
  \ifdim\arg@dim>\line@siz%
    \global\arg@dim\argindent\global\advance\arg@dim\wd\arg@box%
    \hfill\penalty-\@m\hbox{}\kern\argindent\fi%
  \box\arg@box%
}

\def\Function{\@ifstar{\@Func@star}{\@Func@norm}}
\def\@Func@star#1{\expandafter\@Function#1 \\ }
\def\@Func@norm#1{\expandafter\@Function#1 \medskip\\ }

\def\@Function#1!#2!#3 {%
  \begingroup%
  \setbox\arg@box=\hbox{\bf #1}\global\arg@dim\wd\arg@box%
  \setbox\arg@box=\hbox{\rm $)$;}%
  \global\line@siz\linewidth\global\advance\line@siz-\wd\arg@box%
  \pagebreak[3]%
  \expandafter\print@name#1 \@@
  \setbox2=\hbox{\ }
  \def\@comma{}\ignorespaces%
  \@for\@tempa:=#2\do{\ignorespaces%
    \setbox\arg@box=\hbox{\@comma}\global\advance\arg@dim\wd\arg@box%
    \unskip\@comma\def\@comma{\nobreak\hskip-\wd2,%%%%%,
		\penalty-\@m}\ignorespaces%
    \expandafter\print@arg\@tempa\@@\ignorespaces%
  }{\nobreak#3}%
  \endgroup%
}

\def\print@name#1#2 #3\@@{
  \unskip\edef\tmp@name{#3}\ignorespaces
  \ifx\tmp@name\@empty{\bf #1#2 }\else{\rm #1#2\bf #3}\fi
}

\def\print@dummy#1=#2\@@{
  {\it #1\/}\ifx #2\@nil\else{\rm $=$}\expandafter\strip@eq#2\fi
}

\def\strip@eq#1={{\rm #1}}

\def\subtitle{\@ifstar{\@subtit@star}{\@subtit@norm}}

\def\@subtit@star#1{
  \item[\hbox{\large\bf\begin{tabular}[t]{l}#1\end{tabular}}\hfill]
  \hfil\par
  \expandafter{\let\par=\space\ignorespaces\let\par=\endgraf}
}

\def\@subtit@norm#1{
  \setbox\arg@box=\hbox{\large\bf\begin{tabular}[t]{l}#1\end{tabular}}
  \ifdim \wd\arg@box > \labelwidth \item[\copy\arg@box\hfill]\hfil\par
  \else \dp\arg@box=0pt \item[\copy\arg@box\hfill] \fi
  \expandafter{\let\par=\space\ignorespaces\let\par=\endgraf}
}

\newenvironment{manpage}[3]{\@beginManpage#1\@@#2\@@#3\@@}{\@endManpage}

\def\@beginManpage#1\@@#2\@@#3\@@{
  \clearpage
  \gdef\@header{{#2}{#1}{#2}}
  \gdef\@footer{{#3}{\thepage}{\today}}
  \begin{list}{}{
    \setlength\labelwidth{1.2in}
    \setlength\leftmargin{\labelwidth}
    \addtolength\leftmargin{\labelsep}
    \topsep  5pt plus 2pt minus 2pt
    \itemsep 5pt plus 2pt minus 2pt
    \parsep 10pt plus 2pt minus 2pt
  }
  \raggedbottom
  \let"=\arg@quote
}

\def\@endManpage{
  \end{list} \clearpage \flushbottom
}

\def\@first#1#2#3{#1}
\def\@second#1#2#3{#2}
\def\@third#1#2#3{#3}

\def\ps@headings{
  \def\@oddhead{\parbox{\textwidth}{
    {\rm\ \ \expandafter\@first\@header\hfill
      \expandafter\@second\@header\hfill
      \expandafter\@third\@header\ \ } \\[.1cm]
    \hbox{}\rule[12pt]{\textwidth}{1pt}
  }}
  \def\@evenhead{\parbox{\textwidth}{
    {\rm\ \ \expandafter\@third\@header\hfill
      \expandafter\@second\@header\hfill
      \expandafter\@first\@header\ \ } \\[.1cm]
    \hbox{}\rule[12pt]{\textwidth}{1pt}
  }}
  \def\@oddfoot{\parbox{\textwidth}{
    \hbox{}\rule{\textwidth}{1pt} \\[.1cm]
    {\sl\ \ \expandafter\@first\@footer\hfill
      \rm\expandafter\@second\@footer\hfill
      \sl\expandafter\@third\@footer\ }
  }}
  \def\@evenfoot{\parbox{\textwidth}{
    \hbox{}\rule{\textwidth}{1pt} \\[.1cm]
    {\sl\ \ \expandafter\@third\@footer\hfill
      \rm\expandafter\@second\@footer\hfill
      \sl\expandafter\@first\@footer\ }
  }}
}

\pagestyle{headings}

\catcode`\<=\active \def\mit@less{$\char`\<$} \let<=\mit@less
\catcode`\>=\active \def\mit@more{$\char`\>$} \let>=\mit@more
\def\<{$\langle$} \def\>{$\rangle$} \def\*{$\ast$}


%\catcode`\_=\active \def_{\kern.06em \vbox{\hrule width.3em}}
%\catcode`\_=\active \global\let_=\_
%\catcode`\^=\active \def^{\raise.06ex \hbox{\small $\wedge$}}
\catcode`\+=\active \def+{$\char`\+$}
%\catcode`\|=\active \def|{$\mid$}


