file-res.mkvi / last modification: 2020-01-30 14:16
%D \module
%D   [       file=file-mod, % was supp-fil,
%D        version=20110701, % 1995.10.10,
%D          title=\CONTEXT\ File Macros,
%D       subtitle=Resolvers,
%D         author=Hans Hagen,
%D           date=\currentdate,
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C details.

\unprotect

\registerctxluafile{file-res}{}

%D \macros
%D
%D One cannot be sure if a file exists. When no file can be
%D found, the \type{\input} primitive gives an error message
%D and switches to interactive mode. The macro \type{\readfile}
%D takes care of non||existing files. This macro has two faces.
%D
%D \starttyping
%D \stoptyping
%D
%D Many \TEX\ implementations have laid out some strategy for
%D locating files. This can lead to unexpected results,
%D current directory. Let's give an example of this. In
%D \CONTEXT\ illustrations can be defined in an external file.
%D The resizing macro first looks if an illustration is defined
%D in the local definitions file. When no such file is found,
%D it searches for a global file and when this file is not
%D found either, the illustration itself is scanned for
%D dimensions. One can imagine what happens if an adapted,
%D localy stored illustration, is scaled according to
%D dimensions stored somewhere else.
%D
%D When some \TEX\ implementation starts looking for a file, it
%D normally first looks in the current directory. When no file
%D is found, \TEX\ starts searching on the path where format
%D and|/|or style files are stored. Depending on the implementation
%D this can considerably slow down processing speed.
%D
%D In \CONTEXT, we support a project||wise ordening of files.
%D In such an approach it seems feasible to store common files
%D in a lower directory. When for instance searching for a
%D general layout file, we therefore have to backtrack.
%D
%D
%D We first present an earlier implementation of
%D \type{\readfile}. This command backtracks parent
%D directories, upto a predefined level. Users can change this
%D level (on the commandline using a directive); we default to~3.
%D
%D We use \type{\normalinput} instead of \type{\input}
%D because we want to be able to redefine the original
%D party libraries.

\expandafter\secondoftwoarguments
\else
\fi}

{#true%
\relax
\relax}

%D \macros
%D
%D This implementation honnors the third situation, but we
%D still can get unwanted files loaded and/or can get involved
%D in extensive searching.
%D
%D Due to different needs, we decided to offer four alternative
%D file and do no backtracking, while \type{\readlocfile}
%D backtracks~\number\maxreadlevel\ directories, including the current
%D one.
%D
%D System files can be anywhere and therefore
%D \type{\readsysfile} is not bound to the current directory
%D and obeys the \TEX\ implementation.
%D
%D Of the last two, \type{\readfixfile} searches on the
%D directory specified and backtracks too, while
%D \type{\readsetfile} does only search on the specified path.
%D
%D The most liberal is \type {\readfile}.

%D
%D \starttyping
%D
%D \stoptyping

{\pushcatcodetable
\catcodetable\ctxcatcodes
\popcatcodetable}

{\pushcatcodetable
\catcodetable\xmlcatcodes
\popcatcodetable}

%D \macros
%D   {doiflocfileelse,locfilename}
%D
%D \starttyping