When looking inside the filecontents environment in the file latex.ltx (or the similar version in filecontents.sty), I have found this code that I can not understand:
\edef\E{\@backslashchar end\string{\@currenvir\string}}%
\edef\reserved@b{%
\def\noexpand\reserved@b%
####1\E####2\E####3\relax}%
\reserved@b{%
\ifx\relax##3\relax%
\immediate\write\reserved@c{##1}%
\else%
\edef^^M{\noexpand\end{\@currenvir}}%
\ifx\relax##1\relax%
\else%
\@latex@warning{Writing text `##1' before %
\string\end{\@currenvir}\MessageBreak as last line of #1}%
\immediate\write\reserved@c{##1}%
\fi%
\ifx\relax##2\relax%
\else%
\@latex@warning{%
Ignoring text `##2' after \string\end{\@currenvir}}%
\fi%
\fi%
^^M}%
\catcode`\^^L\active%
\let\L\@undefined%
\def^^L{\expandafter\ifx\csname L\endcsname\relax\fi ^^J^^J}%
\catcode`\^^I\active%
\let\I\@undefined%
\def^^I{\expandafter\ifx\csname I\endcsname\relax\fi\space}%
\catcode`\^^M\active%
\edef^^M##1^^M{%
\noexpand\reserved@b##1\E\E\relax}}%
This environment is provided to write some text in a file. After transforming all catcode to 12 (characters) the text is written in the file with the command \reserved@b. I have a lot of trouble with this coding:
Why there is some recursive coding?
\edef\reserved@b{% \def\noexpand\reserved@b% ####1\E####2\E####3\relax}%What is the role of the parameter delimiter
\Ewhich is\end{filecontents}- Why the end of line (
^^L) is transformed in\end{filecontents}
Any help about the fine tricks used in this code will be greatly appreciated.