%%
%% This is file `ydocincl.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% ydoc.dtx  (with options: `ydocincl.tex')
%% 
\expandafter\ifx\csname ydocinclversion\endcsname\relax\else
    \endinput
\fi

\chardef\ydocinclversion=1

\newread\inFile
\newread\subFile
\newwrite\outFile
\newif\ifContinue
\newlinechar=`^^J

\def\makeOther#1{\catcode`#1=12\relax}

\let\inLine\relax
\let\lastLine\relax

\def\includefiles#1#2{%
    \begingroup
    \immediate\openin\inFile#1\relax
    \immediate\openout\outFile#2\relax
    \makeOther\@%
    \makeOther\ \makeOther\\\makeOther\$%
    \makeOther\#\makeOther\^\makeOther\^^K%
    \makeOther\_\makeOther\^^A\makeOther\%%
    \makeOther\~\makeOther\{\makeOther\}\makeOther\&%
    \endlinechar-1\relax
    \Continuetrue
    \loop
      \let\lastLine\inLine
      \read\inFile to\inLine
      \ifeof\inFile
        \Continuefalse
      \else
        \expandafter\checkLine\inLine\empty\empty\empty\endLine
      \fi
      \ifContinue
    \repeat
    \immediate\closein\inFile
    \immediate\closeout\outFile
    \endgroup
    \end
}

\def\copyline{%
    \immediate\write\outFile{\inLine}%
}

\chardef\percentcharnum=`\%

\begingroup
\makeOther\%\makeOther\@\relax
\gdef\SubFileOptionString{%<@}\relax
\gdef\CommentChar{%}\relax
\catcode`\|=0
\makeOther\ \makeOther\\|relax
|gdef|IfFalseString{% \iffalse}|relax
|gdef|FiString{% \fi}|relax
|endgroup

\def\checkLine#1#2#3#4\endLine{%
    \def\firstthree{#1#2#3}%
    \ifx\firstthree\SubFileOptionString
        \readSubFile#4\endLine
    \else
        \copyline
    \fi
}

\def\readSubFile#1>#2\endLine{%
    \immediate\openin\subFile=#1\relax
    \ifeof\subFile
        % File not found
    \else
        \message{^^JIncluding subfile '#1'^^J}%
        \immediate\write\outFile{\CommentChar<*#1>}%
        \ifx\lastLine\IfFalseString
            \immediate\write\outFile{\FiString}%
        \fi
        \copySubFile
        \ifx\lastLine\IfFalseString
            \immediate\write\outFile{\IfFalseString}%
        \fi
        \immediate\write\outFile{\CommentChar</#1>}%
    \fi
    \immediate\closein\subFile
}

\def\copySubFile{%
    \read\subFile to\subLine
    \ifeof\subFile\else
        \immediate\write\outFile{\subLine}%
        \expandafter\copySubFile
    \fi
}
\endinput
%%
%% End of file `ydocincl.tex'.
