\def\tofax#1{\def\tofaxnum{#1}}
\def\tofaxnum{}
\def\sendfaxoptions#1{}
\def\pages#1{\def\nopages{#1}}
\def\nopages{0}

\newcounter{n@pages}
\let\@orig@outputpage=\@outputpage
\def\@outputpage{\addtocounter{n@pages}{1}\@orig@outputpage}

% Following for merging in pages, e.g., with dviconcat
\def\pageadjust#1{\addtocounter{page}{#1}\addtocounter{n@pages}{#1}}

\newwrite\@fxi

\let\@orig@@end=\@@end
\def\@@end{%
\immediate\openout\@fxi=\jobname.fxi\relax%
\immediate\write\@fxi{\string\pages{\arabic{n@pages}}}%
\immediate\closeout\@fxi%
\ifnum\value{n@pages}=\nopages\else\typeout{RIG's fax.sty warning: No. of pages may have changed.  Rerun to get right}\fi
\@orig@@end
}

\def\faxhead#1{{\large
To: #1 \\
Fax: \tofaxnum \\
Page 1 of \ifnum\nopages=0?\else\nopages\fi
\bigskip
}}

\@input{\jobname.fxi}
