summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/generic/ydoc/ydocincl.tex
blob: 1a1f0b5c00f545e2921b5828e66017acea2dcb63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
%%
%% 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'.