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\def\openinputfile #handle#name{\immediate\openin #handle={#name}\relax}
46\def\openoutputfile #handle#name{\immediate\openout#handle={#name}\relax}
47
48\def\closeinputfile #handle{\immediate\closein #handle\relax}
49\def\closeoutputfile#handle{\immediate\closeout#handle\relax}
50
51
52
53
54
55
56\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\newcount\c_system_files_eol_level
75
76\unexpanded\def\pushendofline
77 {\advance\c_system_files_eol_level\plusone
78 \expandafter\chardef\csname\??eolstack\number\c_system_files_eol_level\endcsname\catcode\endoflineasciicode
79 \catcode\endoflineasciicode\commentcatcode}
80
81\unexpanded\def\popendofline
82 {\catcode\endoflineasciicode\csname\??eolstack\number\c_system_files_eol_level\endcsname
83 \advance\c_system_files_eol_level\minusone}
84
85\unexpanded\def\restoreendofline
86 {\catcode\endoflineasciicode\endoflinecatcode}
87
88
89
90
91
92
93\newcount\readingfilelevel
94\newtoks \everystartreadingfile
95\newtoks \everystopreadingfile
96
97\unexpanded\def\startreadingfile
98 {\global\advance\readingfilelevel\plusone
99 \the\everystartreadingfile
100 \pushcatcodetable
101 \setcatcodetable\ctxcatcodes
102 \clf_pushregime}
103
104\unexpanded\def\stopreadingfile
105 {\popcatcodetable
106 \clf_popregime
107 \the\everystopreadingfile
108 \global\advance\readingfilelevel\minusone}
109
110
111
112
113
114
115
116
117
118
119
120\def\inputgivenfile#name{\normalinput{#name}}
121
122
123
124
125
126
127
128
129
130
131
132\unexpanded\def\doifelsefile {\clf_doifelsefileexist}
133\unexpanded\def\doifelsepath {\clf_doifelsepathexist}
134\unexpanded\def\doiffile #name{\clf_doifelsefileexist{#name}\firstofoneargument\gobbleoneargument}
135\unexpanded\def\doifnotfile #name{\clf_doifelsefileexist{#name}\gobbleoneargument\firstofoneargument}
136
137\let\doiffileelse\doifelsefile
138\let\doifpathelse\doifelsepath
139
140\let\doifelsefileexists\doifelsefile
141\let\doifelsepathexists\doifelsepath
142
143\let\doiffileexistselse\doifelsefileexists
144\let\doifpathexistselse\doifelsepathexists
145
146
147
148
149
150
151
152
153\ifdefined\outputfilename \else \def\outputfilename{\jobname} \fi
154
155\unexpanded\def\doifelseparentfile{\clf_doifelseparentfile}
156
157\let\doifparentfileelse\doifelseparentfile
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183\newconstant\kindoffile
184
185\def\splitoffroot{.} \newconstant\splitoffkind
186
187\let\splitofffull\empty
188\let\splitoffpath\empty
189\let\splitoffbase\empty
190\let\splitoffname\empty
191\let\splitofftype\empty
192
193\unexpanded\def\splitfilename{\clf_splitfilename}
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212\installsystemnamespace {fileonce}
213
214\unexpanded\def\doonlyonce#whatever
215 {\ifcsname\??fileonce#whatever\endcsname
216 \expandafter\gobbleoneargument
217 \else
218 \letgvalue{\??fileonce#whatever}\relax
219 \expandafter\firstofoneargument
220 \fi}
221
222\unexpanded\def\doinputonce#name
223 {\doonlyonce{#name}{\doifelsefile{#name}{\inputgivenfile{#name}}\donothing}}
224
225\unexpanded\def\doendinputonce#name
226 {\ifcsname\??fileonce#name\endcsname
227 \expandafter\endinput
228 \fi}
229
230\unexpanded\def\forgetdoingonce#whatever
231 {\global\undefinevalue{\??fileonce#whatever}}
232
233\protect \endinput
234 |