% \iffalse meta-comment
%
% Copyright 1994 the LaTeX3 project and the individual authors.
% All rights reserved. For further copyright information see the file
% legal.txt, and any other copyright indicated in this file.
% 
% This file is part of the LaTeX2e system.
% ----------------------------------------
% 
%  This system is distributed in the hope that it will be useful,
%  but WITHOUT ANY WARRANTY; without even the implied warranty of
%  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
% 
% 
% IMPORTANT NOTICE:
% 
% For error reports in case of UNCHANGED versions see bugs.txt.
% 
% Please do not request updates from us directly.  Distribution is
% done through Mail-Servers and TeX organizations.
% 
% You are not allowed to change this file.
% 
% You are allowed to distribute this file under the condition that
% it is distributed together with all files mentioned in manifest.txt.
% 
% If you receive only some of these files from someone, complain!
% 
% You are NOT ALLOWED to distribute this file alone.  You are NOT
% ALLOWED to take money for the distribution or use of either this
% file or a changed version, except for a nominal charge for copying
% etc.
% \fi
%
% \iffalse
%%% File: ltfiles
%<*driver>
% \fi
\ProvidesFile{ltfiles.dtx}
             [1994/05/21 v1.0h LaTeX Kernel (File Handling)]
% \iffalse
\documentclass{ltxdoc}
\GetFileInfo{ltfiles.dtx}
\title{\filename}
\date{\filedate}
 \author{%
  Johannes Braams\and
  David Carlisle\and
  Alan Jeffrey\and
  Leslie Lamport\and
  Frank Mittelbach\and
  Chris Rowley\and
  Rainer Sch\"opf}

\begin{document}
\maketitle
 \DocInput{\filename}
\end{document}
%</driver>
% \fi
%
% \CheckSum{320}
%
% \changes{v1.0h}{1994/05/21}{Use new error commands}
%
% \section{File Handling}
%
% The following user commands are defined in this part:
%
%  \DescribeMacro{\document} (ie |\begin{document}|)\\          
%      Reads in the .AUX files and |\catcode|'s |@| to 12.
%
%  \DescribeMacro{\nofiles}\\            
%       Suppresses all file output by setting |\@filesw| false.
%
%  \DescribeMacro{\includeonly}\marg{NAME1, ... ,NAMEn}\\
%       Causes only parts NAME1, ... ,NAMEn to be read by
%         their |\include| commands.  Works by setting \@partsw true
%         and setting |\@partlist| to NAME1, ... ,NAMEn.
%
%  \DescribeMacro{\include}\marg{NAME}\\
%        Does an |\input| NAME unless |\partsw| is true and
%         NAME is not in |\@partlist|.  If |\@filesw| is true, then
%         it directs .AUX output to NAME.AUX, including a
%         checkpoint at the end.
%
% \DescribeMacro{\input}\marg{NAME}\\
%        The same as TeX's |\input|, except it allows optional
%         braces around the file name. In \LaTeXe, it also avoids
%         the primiive `missing file' error, if the file can not be
%         found.
%
% \DescribeMacro{\IfFileExists}\marg{NAME}\marg{then}\marg{else}\\
%   If the file exists on the system, execute \emph{then} otherwise
%   execute \emph{else}.
%
% \DescribeMacro{\InputIfFileExists}\marg{NAME}\marg{then}\marg{else}\\
%   If the file exists on the system, execute \emph{then} and input
%   \emph{NAME}  otherwise execute \emph{else}.
%
% \StopEventually{}
%
% \changes{v1.0a}{1994/03/07}{Initial version, split from latex.dtx}
% \changes{v1.0a}{1994/03/07}{Long lines wrapped to 72 columns}
%
% \begin{oldcomments}
%
%    \begin{macrocode}
%<*2ekernel>
\message{files,}
%    \end{macrocode}
%
%  VARIABLES, SWITCHES AND INTERNAL COMMANDS:
%    \@mainaux    : Output file number for main .AUX file.
%    \@partaux    : Output file number for current part's .AUX file.
%    \@auxout     : Either \@mainout or \@partout, depending on 
%                   which .AUX file output goes to.
%    \@input{foo} : If file foo exists, then \input's it,
%                   otherwise types a warning message.
%    @filesw       : Switch -- set false if no .AUX, .TOC, .IDX etc
%                     files are to be written
%    @partsw      : Set true by a \includeonly command.
%    \@partlist   : Set to the argument of the \includeonly command.
%
%    \cp@FOO      : The checkpoint for \include'd file FOO.TEX, written
%                   by \@writeckpt at the end of file FOO.AUX
%
% \document ==
%   BEGIN
%     \endgroup   % cancels \begingroup generated by \begin command
%     \@colht := \@colroom := \vsize := \textheight
%     \columnwidth := \textwidth
%     \@clubpenalty := \clubpenalty        % \@clubpenalty saves value.
%     IF @twocolumn = T
%       THEN \columnwidth := (\columnwidth - \columnsep)/2
%            @firstcolumn := T
%     FI
%     \hsize  := \linewidth := \columnwidth
%     \begingroup
%        \@floatplacement \@dblfloatplacement
%        \@input{\jobname.aux}
%     \endgroup
%     IF \@filesw = T
%       THEN  open file \@mainaux for writing
%             write ``\relax''on file \@mainaux
%     FI
%     \csname process@table\endcsname   % execute \process@table
%                                       % if it is defined (NFSS)
%     \glb@currsize := {} %% Force \baselineskip initialisation. (NFSS)
%     \do{COMMAND} == BEGIN \let COMMAND = \@notprerr END
%     \@preamblecmds
%     \do == \noexpand
%     \@normalsize
%     \everypar{}
%     @noskipsec := F
%     G@refundefined := G F
%   END
%
% \includeonly{FILELIST} ==
%  BEGIN
%   \@partsw   := T
%   \@partlist := FILELIST
%  END
%
% \include{FILE} ==
%  BEGIN
%   \clearpage
%   if \@filesw = T
%     then  \immediate\write\@mainaux{\string\@input{FILE.AUX}}
%   fi
%   if  \@partsw = T
%     then \@tempswa := F
%          \@tempb == FILE
%          for \@tempa := \@partlist
%              do if eval(\@tempa) = eval(\@tempb)
%                   then \@tempswa := T          fi
%              od
%   fi
%
%   if \@tempswa = T
%      then \@auxout := \@partaux
%           if \@filesw = T
%             then  \immediate\openout\@partaux{FILE.AUX}
%                   \immediate\write\@partaux{\relax}
%           fi
%           \@input{FILE.TEX}
%           \clearpage
%           \@writeckpt{FILE}
%           if @filesw then \closeout \@partaux fi
%           \@auxout := \@mainaux
%      else \cp@FILE
%   fi
%  END
%
% \@writeckpt{FILE} ==
%  BEGIN
%    if \@filesw = T
%        \immediate\write on file \@partaux:
%                  \@setckpt{FILE}{                  %% }
%        for \@tempa := \cl@@ckpt
%           do  \immediate\write on file \@partaux:
%                   \global\string\setcounter
%                       {eval(\@tempa)}{eval(\c@eval(\@tempa))}
%           od                                     %% {
%        \immediate\write on file \@partaux:  }
%    fi
%  END
%
% \@setckpt{FILE}{LIST} ==
%  BEGIN
%    G \cp@FILE := LIST
%  END
%
%  INITIALIZATION
%    \@tempswa := T
%
% \end{oldcomments}
%
%
% \begin{oldcomments}
%    \begin{macrocode}
\newif\if@filesw \@fileswtrue
\newif\if@partsw \@partswfalse
\newwrite\@mainaux
\newwrite\@partaux
%    \end{macrocode}
%
%    \begin{macrocode}
\newcount\@clubpenalty
%    \end{macrocode}
%
% FMi & RmS 91/08/26 set @noskipsec switch to true in the preamble
% and to false by \begin{document} to catch lists in the preamble,
% i.e., to produce a ``nodocument'' error when things like
% \maketitle appear before \begin{document}.
%
% \@noskipsectrue %% set below where switch is defined
%
% 91/03/26 FMi: |\process@table| added to support NFSS.
% This will also work with old lfonts if no other style defines
% |\process@table|.
% \end{oldcomments}
% 
%
%  \begin{macro}{\document}
%    
% \changes{v0.9e}{1993/12/09}{Hook added}
%    \begin{macrocode}
\def\document{\endgroup
%    \end{macrocode}
%    If some options on |\documentclass| haven't been used by any
%    package we will now give a warning since this is most certainly a
%    misspelling.
%    \begin{macrocode}
  \ifx\@unusedoptionlist\@empty\else
    \@latex@warning@no@line{Unused global option(s):^^J%
            \@spaces[\@unusedoptionlist]}%
  \fi
  \@colht\textheight  
  \@colroom\textheight \vsize\textheight
  \columnwidth\textwidth 
  \@clubpenalty\clubpenalty
  \if@twocolumn 
    \advance\columnwidth -\columnsep
    \divide\columnwidth\tw@ \hsize\columnwidth \@firstcolumntrue
  \fi
  \hsize\columnwidth \linewidth\hsize
  \begingroup\@floatplacement\@dblfloatplacement
   \makeatletter\let\@writefile\@gobbletwo
   \global\@multiplelabelsfalse
   \@input{\jobname.aux}%
  \endgroup
  \if@filesw 
    \immediate\openout\@mainaux\jobname.aux
    \immediate\write\@mainaux{\relax}%
  \fi
  \process@table
  \let\glb@currsize\@empty  %% Force math initialisation.
%    \end{macrocode}
% \changes{v0.9t}{1994/01/31}
%     {set \cs{@normalsize} or \cs{normalsize} if necessary}
% \changes{v1.0d}{1994/03/28}
%     {(DPC) remove \cs{@normalsize check}}
% \changes{v1.0d}{1994/03/28}
%     {(DPC) Use \cs{normalsize} not \cs{@normalsize}}
% \changes{v1.0g}{1994/05/13}{Added execution of \cmd\every@size}
%    \begin{macrocode}
  \normalsize\the\every@size
  \everypar{}\@noskipsecfalse\G@refundefinedfalse
%    \end{macrocode}
%    Just before disabling the preamble commands we execute the begin
%    document hook which contains any code contributed by
%    |\AtBeginDocument|. Also disable the gathering of the file list,
%    if no |\listfiles| has been issued.
% \changes{v1.0c}{1994/03/16}
%         {(DPC) directly add file list settings}
%    \begin{macrocode}
  \@begindocumenthook
  \let\@begindocumenthook\@undefined
  \ifx\@listfiles\@undefined
    \let\@filelist\relax
    \let\@addtofilelist\@gobble
  \fi
%    \end{macrocode}
%    At the very end we disable all preamble commands. This has to
%    happen after the begin document hooks was executed so that this
%    hook can still use such commands.
%    |\AtBeginDocument|.
% \changes{v0.9o}{1994/01/15}{move `@preamblecmds after document hook}
%    \begin{macrocode}
  \def\do##1{\let ##1\@notprerr}%
  \@preamblecmds
  \let\do\noexpand
}
%    \end{macrocode}
%  \end{macro}
%
%
%    \begin{macrocode}
\def\nofiles{\@fileswfalse \typeout
   {No auxiliary output files.}\typeout{}}
\@onlypreamble\nofiles
%    \end{macrocode}
%
%    \begin{macrocode}
\let\@auxout=\@mainaux
%    \end{macrocode}
%
%    \begin{macrocode}
\def\includeonly#1{\@partswtrue\edef\@partlist{#1}}
%    \end{macrocode}
%
% \begin{macro}{\include}
% \changes{v0.9p}{1994/01/18}
%         {Use \cmd{\@input@} so include files are listed.}
% In the definition of |\include|, |\def\@tempb| changed to
% |\edef\@tempb| to be consistent with the |\edef| in |\includeonly|.
% (Suggested by Rainer Sch\"opf \& Frank Mittelbach.  
% Change made 20 Jul 88.) 
%
% Changed definition of |\include| to allow space at end of file name
% --- otherwise, typing |\include{foo }| would cause \LaTeX\ to
% overwrite |foo.tex|.  Change made 24 May 89, suggested by Rainer
% Sch\"opf  and Frank Mittelbach
%
% Made |\include| check for being used inside an |\include|'d file, as
% this will not work and cause surprising results.
%    \begin{macrocode}
\def\include#1{\relax
  \ifnum\@auxout=\@partaux
    \@latex@error{\string\include\space cannot be nested}\@eha
  \else \@include#1 \fi}
\def\@include#1 {\clearpage
\if@filesw \immediate\write\@mainaux{\string\@input{#1.aux}}\fi
\@tempswatrue\if@partsw \@tempswafalse\edef\@tempb{#1}\@for
\@tempa:=\@partlist\do{\ifx\@tempa\@tempb\@tempswatrue\fi}\fi
\if@tempswa \let\@auxout\@partaux \if@filesw
\immediate\openout\@partaux #1.aux
\immediate\write\@partaux{\relax}\fi\@input@{#1.tex}\clearpage
\@writeckpt{#1}\if@filesw \immediate\closeout\@partaux \fi
\else\@nameuse{cp@#1}\fi\let\@auxout\@mainaux}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\@writeckpt#1{\if@filesw
\immediate\write\@partaux{\string\@setckpt{#1}\@charlb}%
{\let\@elt\@wckptelt \cl@@ckpt}\immediate\write\@partaux{\@charrb}\fi}
%    \end{macrocode}
%
%    \begin{macrocode}
\def\@wckptelt#1{\immediate\write\@partaux
{\string\setcounter{#1}{\the\@nameuse{c@#1}}}}
%    \end{macrocode}
%
% RmS 93/08/31: introduced |\@setckpt|
%    \begin{macrocode}
\def\@setckpt#1{\global\@namedef{cp@#1}}
%    \end{macrocode}
%
% The following defines |\@charlb| and |\@charrb| to be |{| and |}|,
% respectively with |\catcode| 11.
%    \begin{macrocode}
{\catcode`[=1 \catcode`]=2
\catcode`{=11 \catcode`}=11
\gdef\@charlb[{]
\gdef\@charrb[}]
]% }brace matching
%    \end{macrocode}
% \end{macro}
%
%
% \section{Safe Input Macros}
%
% \begin{macro}{\IfFileExists}
% \changes{v0.9b}{1993/12/04}{Macro added}
% \changes{v0.9p}{1994/01/18}{New Definition}
%
%    \begin{macrocode}
\def\IfFileExists#1#2#3{%
  \openin\@inputcheck#1 %
  \ifeof\@inputcheck
    \ifx\input@path\@undefined
      \def\@tempa{#3}%
    \else     
      \def\@tempa{\@iffileonpath{#1}{#2}{#3}}%
    \fi
  \else
    \closein\@inputcheck
    \edef\@filef@und{#1 }%
    \def\@tempa{#2}%
  \fi
  \@tempa}
%    \end{macrocode}
%
% \begin{macro}{\@iffileonpath}
% If the file is not found by |\openin|, and |\input@path| is defined, 
% look in all the directories specified in |\input@path|.
% \changes{v0.9p}{1994/01/18}{Macro added}
% \changes{v1.0f}{1994/05/02}
%     {\cs{@break@loop} renamed to \cs{@break@tfor}}
%    \begin{macrocode}
\def\@iffileonpath#1#2#3{%
  \def\@tempa{#3}%
  \expandafter\@tfor\expandafter\@tempb\expandafter
             :\expandafter=\input@path\do{%
    \openin\@inputcheck\@tempb#1 %
    \ifeof\@inputcheck\else
      \edef\@filef@und{\@tempb#1 }%
      \def\@tempa{#2}%
      \closein\@inputcheck
      \@break@tfor
    \fi}%
  \@tempa}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%
% \begin{macro}{\InputIfFileExists}
% \changes{v0.9b}
%         {1993/12/04}{Macro added}
% \changes{v0.9p}
%         {1994/01/18}{New Definition}
% \changes{v0.3b}{1994/03/13}
%         {Use new cmd \cmd{\@addtofilelist}}
% Now define |\InputIfFileExists| to input |#1| if it seems to exist.
% Immediately prior to the input, |#2| is executed.
% If the file |#1| does not exist, execute `|#3|'. 
%    \begin{macrocode}
\def\InputIfFileExists#1#2{%
  \IfFileExists{#1}%
    {#2\@addtofilelist{#1}\@@input \@filef@und}}
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}{\input}
%    Input a file: if argument is given in braces use save input
%    macros, otherwise use \TeX's primitive |\input| command (which is
%    called |\@@input| in \LaTeX).
% \changes{v0.9b}{1993/12/04}{Macro reimplemented}
%    \begin{macrocode}
\def\input{\@ifnextchar\bgroup\@iinput\@@input}
%    \end{macrocode}
%  \end{macro}
%
% \begin{macro}{\@iinput}
%    Define |\@iinput| (i.e., |\input|) in terms of
%    |\InputIfIfileExists|.
% \changes{v0.9b}{1993/12/04}{Macro reimplemented}
%    \begin{macrocode}
\def\@iinput#1{%
  \InputIfFileExists{#1}{}%
  {\filename@parse{#1}%
   \edef\@tempa{\noexpand\@missingfileerror
     {\filename@area\filename@base}%
     {\ifx\filename@ext\relax tex\else\filename@ext\fi}}%
   \@tempa}}
%    \end{macrocode}
%  \end{macro}
%
% \begin{macro}{\@input}
% \changes{v0.9b}{1993/12/04}{Macro reimplemented}
% \changes{v0.9p}{1994/01/18}%
%         {do not use a different definition for \cmd{\input@path}}
%    Define |\@input| in terms of |\IfIfileExists|.
%    So this is a `safe input' command, but the files input are not
%    listed by |\listfiles|.
%
%    We don't want |.aux|, |.toc| files etc be listed by |\listfiles|.
%    However, something like |.bbl| probably should be listed and thus
%    should be implemented not by |\@input| inside |latex.tex|.
% \task{???}{change uses of `@input}
%    \begin{macrocode}
\def\@input#1{%
  \IfFileExists{#1}{\@@input\@filef@und}{\typeout{No file #1.}}}
%    \end{macrocode}
%  \end{macro}
%
% \begin{macro}{\@input@}
% \changes{v0.9p}{1994/01/18}{Macro added}
% \task{???}{share code with `@input ?}
% Version of |\@input| that does add the file to |\@filelist|.
%    \begin{macrocode}
\def\@input@#1{\InputIfFileExists{#1}{}{\typeout{No file #1.}}}
%    \end{macrocode}
%  \end{macro}
%
%
% \begin{macro}{\@obsoletefile}
%    For compatibility with \LaTeX~2.09 document styles, we distribute
%    files called |article.sty|, |book.sty|, |report.sty|,
%    |slides.sty| and |letter.sty|.  These use the command
%    |\@obsoletefile|, which produces a warning message.
%    \changes{v0.9m}{1993/12/20}{Added this command, removed
%                               @oldfilewarning}
% \changes{v1.0f}{1994/05/02}{Make \cs{@onlypreamble}}
%    \begin{macrocode}
\def\@obsoletefile#1#2{%
   \@latex@warning@no@line{inputting `#1' instead of obsolete `#2'}}
\@onlypreamble\@obsoletefile
%</2ekernel>
%    \end{macrocode}
% \end{macro}
%
% \Finale
%
