summaryrefslogtreecommitdiff
path: root/tex/context/base/supp-fil.tex
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2004-06-10 00:00:00 +0200
committerHans Hagen <pragma@wxs.nl>2004-06-10 00:00:00 +0200
commit51d573f4c0e8d3b8499bff7a3c6fba3dcd71d725 (patch)
treea902c3c67fe2272ee9e2325d6a6f28f0fd15d9d8 /tex/context/base/supp-fil.tex
parentab3f887feadf929129087cd2cbc3783064507565 (diff)
downloadcontext-51d573f4c0e8d3b8499bff7a3c6fba3dcd71d725.tar.gz
stable 2004.06.10
Diffstat (limited to 'tex/context/base/supp-fil.tex')
-rw-r--r--tex/context/base/supp-fil.tex168
1 files changed, 66 insertions, 102 deletions
diff --git a/tex/context/base/supp-fil.tex b/tex/context/base/supp-fil.tex
index c2da977dd..9d54663af 100644
--- a/tex/context/base/supp-fil.tex
+++ b/tex/context/base/supp-fil.tex
@@ -15,12 +15,12 @@
%D is a separate module for file support. In \CONTEXT\ files
%D are used for several purposes:
%D
-%D \startopsomming[opelkaar]
-%D \som general textual input
-%D \som logging status information
-%D \som saving registers, lists and references
-%D \som buffering defered textual input
-%D \stopopsomming
+%D \startitemize[packed]
+%D \item general textual input
+%D \item logging status information
+%D \item saving registers, lists and references
+%D \item buffering defered textual input
+%D \stopitemize
%D
%D When dealing with files we can load them as a whole, using
%D the \type{\input} primitive or load them on a line||by||line
@@ -55,11 +55,11 @@
%D line ending character the \CATCODE\ comment. This is
%D accomplished by
%D
-%D \starttypen
+%D \starttyping
%D \pushendofline
%D ... reading ...
%D \popendofline
-%D \stoptypen
+%D \stoptyping
%D
%D Just to be sure, we save the current meaning of \type{^^M}
%D in \type{\poppedendofline}.
@@ -118,9 +118,9 @@
%D The next macro offers a framework for processing files on a
%D line by line basis.
%D
-%D \starttypen
+%D \starttyping
%D \doprocessfile \identifier {name} \action
-%D \stoptypen
+%D \stoptyping
%D
%D The first argument can for instance be \type{\scratchread}.
%D The action must do something with \type{\fileline}, which
@@ -136,11 +136,11 @@
{\immediate\openin#1=#2\relax
\ifeof#1%
\fileprocessedfalse
- \immediate\closein#1\relax
+ \immediate\closein#1%
\else
\fileprocessedtrue
\gdef\dofinishfile
- {\immediate\closein#1\relax
+ {\immediate\closein#1%
\global\let\doprocessline\relax}%
\gdef\doprocessline
{\ifeof#1%
@@ -159,9 +159,9 @@
%D Use \type{\pathplusfile} to compose a full file name, like
%D in:
%D
-%D \starttypen
+%D \starttyping
%D \pathplusfile{path}{file}
-%D \stoptypen
+%D \stoptyping
%D
%D By default, this expands into {\tt \pathplusfile{path}{file}}.
@@ -183,14 +183,17 @@
\catcode`\/=\@@active
\catcode`\:=\@@active
\catcode`\~=\@@active
+\catcode`\_=\@@active
\gdef\sanitizefilename#1\to#2%
{\bgroup
\edef/{\string/}%
\edef:{\string:}%
\edef~{\string~}%
+ \edef_{\string_}%
\expanded{\xdef\noexpand\sanitizedfilename{#1}}%
\egroup
+ % maybe \convertcommand\sanitizedfilename\to#2%
\let#2\sanitizedfilename}
\egroup
@@ -207,18 +210,30 @@
{\chardef\kindoffile\zerocount}}}
%D \macros
-%D {readfile,ReadFile,maxreadlevel,
-%D normalinput}
+%D {input, normalinput}
+%D
+%D Sometimes we run into troubles when \type {\input} wants to get
+%D expanded, e.g. in a \type {\write} (which happens in the metafun
+%D manual when we permit long MP lines). So, instead of fixing that,
+%D we go for a redefinition of \type {\input}. Of course it's better
+%D to use \type {\readfile} or \type {\processfile}.
+
+\ifx\normalinput\undefined \let\normalinput\input \fi
+
+\unexpanded\def\input{\normalinput}
+
+%D \macros
+%D {readfile,ReadFile,maxreadlevel}
%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 \starttypen
+%D \starttyping
%D \ReadFile {filename}
%D \readfile {filename} {before loading} {not found}
-%D \stoptypen
+%D \stoptyping
%D
%D Many \TEX\ implementations have laid out some strategy for
%D locating files. This can lead to unexpected results,
@@ -252,9 +267,9 @@
%D directories, upto a predefined level. Users can change this
%D level, but we default to~3.
%D
-%D \starttypen
+%D \starttyping
%D \def\maxreadlevel {3}
-%D \stoptypen
+%D \stoptyping
%D
%D This is a pseudo \COUNTER.
%D
@@ -268,8 +283,6 @@
\let \everyreadfile \everybeforereadfile
-\ifx\normalinput\undefined \let\normalinput\input \fi
-
\newif\iftracefiles
\def\maxreadlevel{3}
@@ -330,26 +343,6 @@
\fi
\next}
-% \def\redoreadfile#1#2#3%
-% {\immediate\openin\scratchread=#1\relax
-% \ifeof\scratchread
-% \iftracefiles\writestatus\m!systems{cannot locate #1}\fi
-% \immediate\closein\scratchread
-% \decrement\readlevel\relax
-% \ifnum\readlevel>\zerocount
-% \edef\readfilename{\pathplusfile{\f!parentpath}{\readfilename}}%
-% \def\next{\redoreadfile\readfilename{#2}{#3}}%
-% \else
-% \def\next{#3}%
-% \fi
-% \else
-% \immediate\closein\scratchread
-% \edef\readfilename{#1}%
-% \iftracefiles\writestatus\m!systems{#1 located}\fi
-% \def\next{#2\dodoreadfile}%
-% \fi
-% \next}
-
\def\redoreadfile#1#2#3%
{\doiffileexistselse{#1}%
{\edef\readfilename{#1}%
@@ -365,11 +358,6 @@
\fi}%
\next}
-% \def\dodoreadfile % we provide hooks, for instance for \enableXML
-% {\the\everybeforereadfile
-% \normalinput\readfilename\relax
-% \the\everyafterreadfile}
-
\def\dodoreadfile % we provide hooks, for instance for \enableXML
{\ifconditional\trackfilenames
\setxvalue{fn..\trackedfilename}{\readfilename}%
@@ -378,12 +366,11 @@
\normalinput\readfilename\relax
\the\everyafterreadfile}
-\def\readfile% #1%
+\unexpanded\def\readfile% #1%
{\let\readlevel\maxreadlevel
- %\doreadfile} % {#1}
\doreadfile\empty} % {#1}
-\def\ReadFile#1%
+\unexpanded\def\ReadFile#1%
{\readfile{#1}\donothing\donothing}
%D \macros
@@ -400,63 +387,53 @@
%D backtracks~\readlevel\ directories, including the current
%D one.
-\def\readjobfile#1% current path, no backtracking
+\unexpanded\def\readjobfile % #1% current path, no backtracking
{\newcounter\readlevel
- %\doreadfile{\pathplusfile{\f!currentpath}{#1}}}
- \doreadfile\f!currentpath{#1}}
+ \doreadfile\f!currentpath} % {#1}}
-\def\readlocfile#1% current path, backtracking
+\unexpanded\def\readlocfile % #1% current path, backtracking
{\let\readlevel\maxreadlevel
- %\doreadfile{\pathplusfile{\f!currentpath}{#1}}}
- \doreadfile\f!currentpath{#1}}
+ \doreadfile\f!currentpath} % {#1}}
%D System files can be anywhere and therefore
%D \type{\readsysfile} is not bound to the current directory
%D and obeys the \TEX\ implementation.
-% \def\readsysfile#1% current path, obeys tex search
-% {\let\readlevel\maxreadlevel
-% %\doreadfile{#1}}
-% \doreadfile\empty{#1}}
-
-\def\readsysfile#1% current path, obeys tex search
+\unexpanded\def\readsysfile % #1% current path, obeys tex search
{\newcounter\readlevel
- %\doreadfile{#1}}
- \doreadfile\empty{#1}}
+ \doreadfile\empty} % {#1}}
%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.
-\def\readfixfile#1#2% specified path, backtracking
+\unexpanded\def\readfixfile % #1#2% specified path, backtracking
{\let\readlevel\maxreadlevel
- %\doreadfile{\pathplusfile{#1}{#2}}}
- \doreadfile{#1}{#2}}
+ \doreadfile} % {#1}{#2}}
-\def\readsetfile#1#2% specified path, no backtracking
+\unexpanded\def\readsetfile % #1#2% specified path, no backtracking
{\newcounter\readlevel
- %\doreadfile{\pathplusfile{#1}{#2}}}
- \doreadfile{#1}{#2}}
+ \doreadfile} % {#1}{#2}}
%D After having defined this commands, we reconsidered the
%D previously defined \type{\readfile}. This time we more or
%D less impose the search order.
-\def\readfile#1#2#3%
+\unexpanded\def\readfile#1#2#3%
{\readlocfile{#1}{#2}
{\readjobfile{#1}{#2}
{\readsysfile{#1}{#2}{#3}}}}
%D So now we've got ourselves five file loading commands:
%D
-%D \starttypen
+%D \starttyping
%D \readfile {filename} {before loading} {not found}
%D
%D \readjobfile {filename} {before loading} {not found}
%D \readlocfile {filename} {before loading} {not found}
%D \readfixfile {filename} {before loading} {not found}
%D \readsysfile {directory} {filename} {before loading} {not found}
-%D \stoptypen
+%D \stoptyping
%D \macros
%D {readjobfile,readlocfile,readsysfile,readfixfile}
@@ -472,10 +449,10 @@
\ifcase\kindoffile
\increment\readlevel
\immediate\openin#1=\readfilename\relax
- \ifeof#1\relax
- \ifnum\readlevel>\maxreadlevel\relax
+ \ifeof#1% \relax
+ \ifnum\readlevel>\maxreadlevel % \relax
\else
- \immediate\closein#1\relax
+ \immediate\closein#1% \relax
\doopenin{#1}{\pathplusfile\f!parentpath{#2}}%
\fi
\fi
@@ -485,9 +462,9 @@
{\newcounter\readlevel
\doopenin{#1}{\pathplusfile\f!currentpath{#2}}}
-\def\opensysin#1#2%
+\def\opensysin % #1#2%
{\let\readlevel\maxreadlevel
- \doopenin{#1}{#2}}
+ \doopenin} % {#1}{#2}}
\def\openlocin#1#2%
{\let\readlevel\maxreadlevel
@@ -504,26 +481,16 @@
%D loading is done. This one obeys the standard \TEX\
%D implementation method.
%D
-%D \starttypen
+%D \starttyping
%D \doiffileelse {filename} {before loading} {not found}
-%D \stoptypen
+%D \stoptyping
%D
%D We use \type{\next} here, because we want to close the
%D file first. We also provide the alternatives:
%D
-%D \starttypen
+%D \starttyping
%D \doiflocfileelse {filename} {before loading} {not found}
-%D \stoptypen
-
-% \def\doiffileelse#1#2#3%
-% {\immediate\openin\scratchread=#1\relax
-% \ifeof\scratchread
-% \def\next{#3}%
-% \else
-% \def\next{#2}%
-% \fi
-% \immediate\closein\scratchread
-% \next}
+%D \stoptyping
\def\doiffileelse#1%
{\doifelsenothing{#1}
@@ -537,9 +504,6 @@
\expandafter\firstoftwoarguments
\fi}}
-% \def\doiflocfileelse#1%
-% {\doiffileelse{\pathplusfile\f!currentpath{#1}}}
-
\def\doiflocfileelse#1%
{\makelocreadfilename{#1}%
\doiffileelse\readfilename}
@@ -560,19 +524,19 @@
%D capacity is limited. One can prevent multiple execution and
%D loading by using one of both:
%D
-%D \starttypen
+%D \starttyping
%D \doonlyonce{actions}
%D \doinputonce{filename}
%D \doendinputonce{filename}
-%D \stoptypen
+%D \stoptyping
%D
%D This command obeys the standard method for locating files.
\long\def\doonlyonce#1#2%
- {\doifundefined{@@@#1@@@}{\setgvalue{@@@#1@@@}{}#2}}
+ {\doifundefined{@@@#1@@@}{\letgvalue{@@@#1@@@}\empty#2}}
\def\doinputonce#1%
- {\doonlyonce{#1}{\doiffileelse{#1}{\normalinput #1\relax}{}}}
+ {\doonlyonce{#1}{\doiffileelse{#1}{\normalinput#1\relax}\donothing}}
\def\doendinputonce#1%
{\doifdefined{@@@#1@@@}\endinput}
@@ -588,9 +552,9 @@
%D to characters with \CATCODE~12, while the characters in
%D \type{filename} have \CATCODE~11. So we can better use:
%D
-%D \starttypen
+%D \starttyping
%D \doifparentfileelse{filename}{yes}{no}
-%D \stoptypen
+%D \stoptyping
%D
%D Since \TEXEXEC\ (and thereby \CONTEXT) supports renaming of
%D the outputfile, we also need to check on that alternative
@@ -703,5 +667,5 @@
%% \catcode`"=\@@other
%% \catcode`<=\@@other
%% \catcode`>=\@@other}
-
+
\protect \endinput