%
%   dwrite.sty                         ver 1.0 92/03/20
%
% following environment is defined
%
%  \begin{Dwrite}    \end{Dwrite}
%
%  following commands are defined%
%
%  \Dopenfile{file-name}
%  \Dclosefile
%  \Dinsertfile
%
\def\Dopenfile#1{%
  \gdef\D@auxfilename{#1}
  \if@filesw \immediate\openout\D@auxfile=\D@auxfilename \fi
  \Dopendtrue}
\def\Dclosefile{%
  \if@filesw \immediate\closeout\D@auxfile\fi
  \Dopendfalse}
\def\Dinsertfile{%
  \ifDopend\Dclosefile\fi
  \input{\D@auxfilename}}
%
\def\D@auxfilename{}
\newif\ifDopend
%
\begingroup \catcode `|=0 \catcode `[= 1
  \catcode`]=2 \catcode `\{=12 \catcode `\}=12  \catcode`\\=12 
|gdef|D@xxwrite[\end{Dwrite}]
|endgroup
\newwrite\D@auxfile
\def\endD@write{\endgroup\endgroup}
%
\def\Dwrite{
\let\D@xwrite\D@xxwrite
\begingroup\D@setupwrite\D@write}
\def\D@setupwrite{
\let\do\@makeother\dospecials
 \catcode`\|=12 \obeylines}
{\obeylines
 \gdef\D@write#1
  {\def\next{#1}\ifx\next\D@xwrite\let\next=\endD@write
   \else\if@filesw \immediate\write\D@auxfile{\next}\fi
   \let\next=\D@write\fi\next}
 \gdef\D@writeX#1
  {\def\next{#1}
   \if@filesw \immediate\write\D@auxfile{\next}\fi
   \ifx\next\D@xwrite\let\next=\endD@write
   \else\let\next=\D@writeX\fi\next}
}
