% This macro source file is from the four volume series
% "TeX in Practice" by Stephan von Bechtolsheim, published
% 1993 by Springer-Verlag, New York.
% Copyright 1993 Stephan von Bechtolsheim.
% No warranty or liability is assumed.
% This macro may be copied freely if no fees other than
% media cost or shipping charges are charged and as long
% as this copyright and the following source code itself
% is not changed. Please see the series for further information.
%
% Version: 1.0
% Date: May 1, 1993
%
%
% This source code is documented in 30.7.5, p. III-555.
% Original source in file "pp1.TEX", starting line 1123.
\wlog{L: "pm-4.tip" ["pp1.TEX," l. 1123, p. III-555]}%
% This file DOES NOT belong to format "texip."
\InputD{robust.tip}
\InputD{input-at.tip}
\InputD{mspaces.tip}
\catcode`\@ = 11
\let\@ex = \expandafter
\def\WriteToAuxSpecial #1#2#3#4#5{%
   {%
       \@MakeRobustMacros
       \edef\@WriteTemp{%
           \string\@ForSpecialFile{#1}{#2}{#3}%
       }%
       \@ex\@ex\@ex\@p@write\@ex{\@WriteTemp}%
       \edef\@WriteTemp{\EightSpaces{#4}}%
       \@ex\@ex\@ex\@p@write\@ex{\@WriteTemp}%
       \@p@write{\EightSpaces{#5}}%
   }%
}
\def\TableOfContents #1{%
   \@TableOrListOfSomething{\TocFileNameExtension}{#1}%
}
\def\ListOfFigures #1{%
   \@TableOrListOfSomething{\LofFileNameExtension}{#1}%
}
\def\ListOfTables #1{%
   \@TableOrListOfSomething{\LotFileNameExtension}{#1}%
}
\def\@TableOrListOfSomething #1#2{%
   \wlog{\string\@TableOrListOfSomething (#1: "#2")}%
   \def\@SomethingFileList{}%
   \if\EmptyStringConditional{#2}%
       \wlog{\EightSpaces (whole document)}%
       \edef\@SpecialFileBaseName{\jobname}%
       \i@write\@TmpFileStream{%
           \string\@BuildSpecialFile
               {#1}%
               {\@SpecialFileBaseName.#1}%
       }%
       {%
           \def\\##1{%
               \i@write\@TmpFileStream
               {\string\InputC{##1.\AuxFileNameExtension}}}%
           \@AllPartsOfDocumentList
       }%
   \else
       \wlog{\EightSpaces (some parts only)}%
       \edef\@SpecialFileBaseName{\CurrentPartName}%
       \i@write\@TmpFileStream{%
           \noexpand\@BuildSpecialFile
           {#1}%
           {\@SpecialFileBaseName.#1}%
       }
       \ConvertArgsToListAndAppend{\@SomethingFileList}{#2}%
       {%
           \def\\##1{%
               \i@write\@TmpFileStream
               {\string\InputC{##1.\AuxFileNameExtension}}%
               \if\MemberOfListConditional
                   {\@AllPartsOfDocumentList}{##1}%
               \else
                   \wlog{\string\@TableOrListOfSomething:
                       WARNING: part "##1" does NOT
                       belong to this document!}%
               \fi
           }%
           \@SomethingFileList
       }%
   \fi
   \i@write\@TmpFileStream{\string\@EndBuildSpecialFile}%
   \InputCWithAt{\@SpecialFileBaseName.#1}%
}
\def\@BuildNewSpecialFiles{%
   \wlog{\string\@BuildNewSpecialFiles: started.}%
   \InputAt{\jobname.\TmpFileNameExtension}%
   \wlog{\string\@BuildNewSpecialFiles: done.}%
}
\def\@BuildSpecialFile #1#2{%
   \begingroup
   \@MakeRobustMacros
   \wlog{\string\@BuildSpecialFile: working on "#2".}%
   \@IgnoreAuxStuff
   \let\@ForSpecialFile = \@ForSpecialFileSave
   \def\@ForSpecialFileExtension{#1}%
   \OpenGenericOStream{#2}%
}
\def\@ForSpecialFileSave #1#2#3#4#5{%
   \if\StringsEqualConditional{#1}{\@ForSpecialFileExtension}%
       \i@write\GenericOStream{%
           \string\EntryInto#1%
           {#2}{#3}%
       }%
       \i@write\GenericOStream{%
           \EightSpaces{#4}%
       }%
       \i@write\GenericOStream{%
           \EightSpaces{#5}%
       }%
   \fi
}%
\def\@EndBuildSpecialFile{%
   \CloseGenericOStream
   \wlog{\string\@EndBuildSpecialFile: closed file}%
   \endgroup
}
\catcode`\@ = 12