1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27\writestatus{loading}{ConTeXt File Macros Helpers}
28
29\registerctxluafile{fileini}{}
30
31\unprotect
32
33
34
35
36
37
38
39
40\ifdefined\scratchread \else \newread \scratchread \fi
41\ifdefined\scratchwrite \else \newwrite\scratchwrite \fi
42
43
44
45\permanent\def\openinputfile #handle#name{\immediate\openin #handle={#name}\relax}
46\permanent\def\openoutputfile #handle#name{\immediate\openout#handle={#name}\relax}
47
48\permanent\def\closeinputfile #handle{\immediate\closein #handle\relax}
49\permanent\def\closeoutputfile#handle{\immediate\closeout#handle\relax}
50
51
52
53
54
55
56\permanent\def\writeln#handle{\write#handle{}}
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72\installsystemnamespace{eolstack}
73
74\newinteger\c_system_files_eol_level
75
76\permanent\protected\def\pushendofline
77 {\advanceby\c_system_files_eol_level\plusone
78 \expandafter\chardef\csname\??eolstack\the\c_system_files_eol_level\endcsname\catcode\endoflineasciicode
79 \catcode\endoflineasciicode\commentcatcode}
80
81\permanent\protected\def\popendofline
82 {\catcode\endoflineasciicode\csname\??eolstack\the\c_system_files_eol_level\endcsname
83 \advanceby\c_system_files_eol_level\minusone}
84
85\permanent\protected\def\restoreendofline
86 {\catcode\endoflineasciicode\endoflinecatcode}
87
88
89
90
91
92
93\newinteger\readingfilelevel
94\newtoks \everystartreadingfile
95\newtoks \everystopreadingfile
96
97\permanent\protected\def\startreadingfile
98 {\global\advanceby\readingfilelevel\plusone
99 \expand\everystartreadingfile
100 \pushcatcodetable
101 \setcatcodetable\ctxcatcodes
102 \pushregime}
103
104\permanent\protected\def\stopreadingfile
105 {\popcatcodetable
106 \popregime
107 \expand\everystopreadingfile
108 \global\advanceby\readingfilelevel\minusone}
109
110
111
112
113
114
115
116
117
118\permanent\def\inputgivenfile#name{\normalinput{#name}}
119
120
121
122
123
124
125
126
127
128
129
130\permanent\protected\def\doifelsefile {\clf_doifelsefileexist}
131\permanent\protected\def\doifelsepath {\clf_doifelsepathexist}
132\permanent\protected\def\doiffile #name{\clf_doifelsefileexist{#name}\firstofoneargument\gobbleoneargument}
133\permanent\protected\def\doifnotfile #name{\clf_doifelsefileexist{#name}\gobbleoneargument\firstofoneargument}
134
135\aliased\let\doiffileelse\doifelsefile
136\aliased\let\doifpathelse\doifelsepath
137
138\aliased\let\doifelsefileexists\doifelsefile
139\aliased\let\doifelsepathexists\doifelsepath
140
141\aliased\let\doiffileexistselse\doifelsefileexists
142\aliased\let\doifpathexistselse\doifelsepathexists
143
144
145
146
147
148
149
150
151\ifdefined\outputfilename \else \def\outputfilename{\jobname} \fi
152
153\permanent\protected\def\doifelseparentfile{\clf_doifelseparentfile}
154
155\aliased\let\doifparentfileelse\doifelseparentfile
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181\newconstant\kindoffile
182\newconstant\splitoffkind
183
184\mutable\def\splitoffroot{.}
185
186\mutable\lettonothing\splitofffull
187\mutable\lettonothing\splitoffpath
188\mutable\lettonothing\splitoffbase
189\mutable\lettonothing\splitoffname
190\mutable\lettonothing\splitofftype
191
192\permanent\protected\def\splitfilename{\clf_splitfilename}
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211\installsystemnamespace{fileonce}
212
213\permanent\protected\def\doonlyonce#whatever
214 {\ifcsname\??fileonce#whatever\endcsname
215 \expandafter\gobbleoneargument
216 \else
217 \aliased\gletcsname\??fileonce#whatever\endcsname\relax
218 \expandafter\firstofoneargument
219 \fi}
220
221\permanent\protected\def\doinputonce#name
222 {\doonlyonce{#name}{\doifelsefile{#name}{\inputgivenfile{#name}}\donothing}}
223
224\permanent\protected\def\doendinputonce#name
225 {\ifcsname\??fileonce#name\endcsname
226 \expandafter\endinput
227 \fi}
228
229\permanent\protected\def\forgetdoingonce#whatever
230 {\global\undefinevalue{\??fileonce#whatever}}
231
232\protect \endinput
233 |