% Macros for the Snafu letter document type.
% Copyright (C) 1993, 1994 Gary Houston
% This program may be copied and modified under the terms of the 
% GNU General Public License version 2.

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{sletter}[1994/08/26 gf Snafu letter class]

% The "leftalign" option aligns the letter components on the left of the
% page, instead of the American-style default.
\newif\if@left
\@leftfalse
\DeclareOption{leftalign}{\@lefttrue}

\DeclareOption*{%
  \PassOptionsToClass{\CurrentOption}{letter}%
}
\ProcessOptions

\LoadClass{letter}

\RequirePackage{gftext}
\RequirePackage{gfdisplay}
\RequirePackage{gfhead}
\RequirePackage{gffig}
\RequirePackage{gfstructure}
\RequirePackage{gflink}

% Don't normally number sections in a letter.
\setcounter{secnumdepth}{0}

\regularspacing

% Postscripts.
\renewcommand{\ps}[2]
 {%
  \count0=#1%
  \par
  \ifnum\count0=1\vspace{2\parskip}\fi
  \textbf{%
    \loop
    \ifnum\count0>0
      \advance\count0 by -1
    p%
    \repeat
    s. 
  }#2%
}

\newcommand{\enclosure}{\par\textbf{Enclosure}}

\newcommand{\contact}[2]
{%
  \def\contacta{#1}%
  \def\contactb{phone}%
  \def\found{0}%
  \ifx\contacta\contactb Tel: \def\found{1}\fi
  \def\contactb{fax}%
  \ifx\contacta\contactb Fax: \def\found{1}\fi
  \def\contactb{email}%
  \ifx\contacta\contactb Email: \def\found{1}\fi
  \ifnum\found=0 #1: \fi
#2}

\let\@subject\@empty
\newcommand{\subject}[1]{\renewcommand\@subject{#1}}

% Redefine the default \opening, to allow a subject line and docnum.
\renewcommand{\opening}[1]
{%
  \global\@topnum\z@ % Stop figures appearing at top of page.
  \ifx\@empty\fromaddress
    \thispagestyle{empty}%
    {\if@left\else\raggedleft
       \begin{tabular}{l}\ignorespaces
     \fi
     \@date
     \ifx\@empty\@docnum
     \else
       \\ref: \@docnum
     \fi
     \if@left\else
       \end{tabular}%
     \fi
     \par
    }%
  \else
    \thispagestyle{empty}%
     {\if@left\else
       \raggedleft
       \begin{tabular}{l}\ignorespaces
      \fi
      \fromaddress \\*[2\parskip]%
      \@date 
      \ifx\@empty\@docnum
      \else
	\\ref: \@docnum
      \fi
      \if@left\else
        \end{tabular}%
      \fi
      \par
     }%
  \fi
  \vspace{2\parskip}%
  {\raggedright \toname \\ \toaddress \par}%
  \vspace{2\parskip}%
  \ifx\@empty\@subject\else
    {\bf\@subject}\par\vspace{2\parskip}\fi
  #1\par\nobreak
}

\let\@cc\@empty
\renewcommand{\cc}[1]{\renewcommand{\@cc}{#1}}

\renewcommand{\closing}[1]
 {\par\nobreak\vspace{\parskip}%
  \stopbreaks
  \noindent
  \hspace*{\longindentation}%
  \parbox{\indentedwidth}%
  {\raggedright
    \ignorespaces
    #1
  }
 }

\newcommand{\signed}[1]
 {\stopbreaks
  \noindent
  \par\vspace{6\medskipamount}%
  \hspace*{\longindentation}%
  \parbox{\indentedwidth}%
  {\raggedright
    \ignorespaces
    #1
  }
 }

\@fileswtrue

% Redefine the closing to use cc:
\renewenvironment{letter}[1]
  {\newpage
    \if@twoside \ifodd\c@page
                \else\thispagestyle{empty} \hbox{}\newpage\fi
    \fi
    \c@page\@ne
    \interlinepenalty=200 % smaller than the TeXbook value
    \@processto{\leavevmode\ignorespaces #1}}
 {\ifx\@empty\@cc\relax
  \else{%
    \par\noindent
    \setbox0=\hbox{\bf cc: }%
    \dimen0=\hsize\advance\dimen0 by -\wd0
    \box0\vtop{\noindent\hsize=\the\dimen0
      \ignorespaces\strut\@cc\strut
    }%
  }%
  \fi
  \stopletter\@@par\pagebreak\@@par
}

% Add definitions for the figure environment (missing from letter.sty).
\newcommand{\figurename}{Figure}
\newcommand{\@makecaption}[2]
  {%
   \vskip 10\p@
   \setbox\@tempboxa\hbox{#1: #2}%
   \ifdim \wd\@tempboxa >\hsize
       #1: #2\par
     \else
       \hbox to\hsize{\hfil\box\@tempboxa\hfil}%
   \fi}

\newcounter{figure}

\newcommand{\fps@figure}{tbp}
\newcommand{\ftype@figure}{1}
\newcommand{\ext@figure}{lof}
\newcommand{\fnum@figure}{\figurename~\thefigure}
\newenvironment{figure}
 {\@float{figure}}
 {\end@float}
\@namedef{figure*}{\@dblfloat{figure}}
\@namedef{endfigure*}{\end@dblfloat}

% Prevent indentation of the closing.
\if@left
  \longindentation = 0pt
\fi
