%% [merge-nobody.sty]
%%
%% version to generate labels (without letter bodies) by bert@mit.edu
%%
%% based on:
%%
%%	  MERGE -- A Form Letter Option to the LaTeX Letter Style
%%				by
%% {Graeme McKinstry \\ Computing Services Centre \\ University of Otago \\
%% P O Box 56 \\ Dunedin, New Zealand \\ graeme%otago.ac.nz@relay.cs.net}
%%
%%
%%
%% Merge-NoBody is a substyle [option] under the Latex style 'Letter'
%% which generates mailing labels from a separate file containing addresses
%% and opening lines.  (Opening lines are used in original 'Merge' option,
%% but not in Merge-NoBody.)
%%
%% Detailed instructions for preparation of labels appear at the end
%% of this file.
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\typeout{Letter Sub-Style 'Merge-NoBody'.}
%% Original 'Merge' style by Graeme McKinstry

%% The basic algorithm is:
%%      1. Open the address file.
%%      2. Read the addresses file getting the address and opening line.
%%      3. Repeat step 2 until there are no more addresses.


\newbox\@store
\long\def\@contents{}  % store the contents
\long\def\@endcontents{}    % of the letter

\def\@sendaddress{test}
\def\@openingtext{test}

\newread\@addrfile                           % allocate an input stream

\def\@openfile{\openin\@addrfile=\@mergefile % open the address file
\ifeof\@addrfile                             % i.e., didn't open successfully
  \loop \immediate\write16{Could not open address file \@mergefile}
     \closein\@addrfile % close the input stream \read16 to
     \@mergefile % get another file name \openin\@addrfile=\@mergefile
     % open up input stream \ifeof\@addrfile \repeat % repeat until
     successfully opened
\fi}

% The merge environment (used as the \begin{merge}. The argument (#1) is
% the name of the file containing the addresses (a default of .tex extension)
% This file is opened (\@openfile), read (\@readfile), and then the box
% containing the contents of the standard letter is started (\@contents).

\def\labels#1{\def\@mergefile{#1 }\@openfile
                 \@readfile}
% Read address file getting the address and opening line.

\def\@getopeningline{\global\read\@addrfile
                            to\@openingtext}  % get the opening line

\def\@readfile{\global\read\@addrfile to\@sendaddress   % get the address
 \ifeof\@addrfile\else
  \@getopeningline
  \@processto{\@sendaddress}
  \if@filesw\begingroup\let\\=\relax\def\protect##1{\string##1\space}
    \immediate\write\@auxout{\string\mlabel{\returnaddress}{\toname
      \\\toaddress}}
  \endgroup\fi
  \ifeof\@addrfile
    \message{End of file}
    \let\next=\relax
  \else
    \let\next=\@readfile          % loop round yet again
  \fi\next
 \fi}

\makelabels
\endinput

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% A letter, say LABELS.TEX, would be set up as follows:

%% \documentstyle[merge-nobody]{letter}
%%
%% \begin{document}
%% \labels{myaddresses}	% MYADDRESSES.TEX contains addresses+openings
%% \end{document}

%% The address file, MYADDRESSES.TEX, would contain:

%% {Computing Services Centre, \\	% first address
%%  University of Otago, \\
%%  Dunedin, \\
%%  New Zealand}
%% {Dear Graeme,}		% \opening for first address
%% {Charles S. Roberson\\	% next address
%%  Dept. of Computer Science\\
%%  College of William and Mary\\
%%  Williamsburg, VA  23185}
%% {Dear Chip,}			% next \opening
%% ....				% etc.

%% NOTES:
%%   Braces are matched, except that if the input is only one line then it
%%     is not necessary to contain it within braces.
%%   It is important to leave NO BLANK LINES at the end of the address file.
%%   Be sure to supply the "\\" for breaking the addresses. -csr
