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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
%D \module
%D [ file=core-job, % copied from main-001,
%D version=1997.03.31,
%D title=\CONTEXT\ Core Macros,
%D subtitle=Job Handling,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA / Hans Hagen \& Ton Otten}]
%C
%C This module is part of the \CONTEXT\ macro||package and is
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
%C details.
%D This module is still to be split and documented.
\writestatus{loading}{ConTeXt Core Macros / Job Handling}
\unprotect
\registerctxluafile{core-job}{1.001}
\let \currentproject \empty
\let \currentproduct \empty
\let \currentenvironment \empty
\let \currentcomponent \empty
\let \loadedfiles \empty
\let \processedfiles \empty
\let \nomorefiles \relax
\let \allinputpaths \empty
\let \locatedfilepath \empty
\newcount\textlevel
\newcount\fileprocesslevel
\setvalue{\c!file::0}{\jobname}
\def\processedfile % is used in styles, don't change !
{\getvalue{\c!file::\number\fileprocesslevel}}
\def\dostarttextfile#1%
{\global\advance\fileprocesslevel\plusone
\setxvalue{\c!file::\number\fileprocesslevel}{#1}%
\doglobal\addtocommalist{#1}\processedfiles}
\def\dostoptextfile
{\global\advance\fileprocesslevel\minusone}
\def\processlocalfile#1#2%
{#1{#2}\donothing{\readfile{#2}\donothing\donothing}}
\def\processfile #1{\ctxcommand{processfile("#1")}}
\def\doifinputfileelse #1{\ctxcommand{doifinputfileelse("#1")}}
\def\locatefilepath #1{\edef\locatedfilepath{\ctxcommand{locatefilepath("#1")}}}
\def\usepath [#1]{\edef\allinputpaths{\ctxcommand{usepath("#1")}}}
\def\usesubpath [#1]{\edef\allinputpaths{\ctxcommand{usesubpath("#1")}}}
\def\usezipfile {\dodoubleempty\dousezipfile}
\def\dousezipfile[#1][#2]{\ctxcommand{usezipfile("#1","#2")}} % [filename] [optional subtree]
\def\loadexamodes {\dosingleempty\doloadexamodes}
\def\doloadexamodes [#1]{\ctxcommand{loadexamodes("#1")}}
\def\registerfileinfo[#1#2]#3% geen \showmessage ?
{\writestatus\m!systems{#1#2 file #3 at line \the\inputlineno}}
\def\doloadsystemfile#1% only mkiv files
{\readsysfile{#1.\mksuffix}{\showmessage\m!systems2{#1.\mksuffix}}\donothing}
\def\loadsystemfiles
{\doloadsystemfile\f!newfilename % new code, to be integrated at some point, plus fixes posted on the list
\doloadsystemfile\f!locfilename % new code, somewhat experimental, not distributed (outside the dev group)
\doloadsystemfile\f!expfilename % new code, very experimental, can be engine specific, mostly for me only
\doloadsystemfile\f!sysfilename} % local settings, but probably not that good an idea to use
%D We don't want multiple jobfiles to interfere.
\def\loadoptionfile % todo : mark document.* tables as storage
{\readjobfile{\jobname.\f!optionextension}
{\showmessage\m!systems2{\jobname.\f!optionextension}%
\ctxcommand{logoptionfile("\jobname.\f!optionextension")}}%
{\writestatus\m!systems {no \jobname.\f!optionextension}}}
% Most natural ...
%
% \def\doateverystarttext
% {\the\everystarttext
% \global\let\doateverystarttext\relax}
%
% ... most practical, since we can load env's in a
% something.run file (nested \starttext's; see for
% instance x-res-08, where we definitely want to
% open the file!).
\def\doateverystarttext
{\the\everystarttext
\global\everystarttext\emptytoks}
\unexpanded\def\starttext
{\doateverystarttext
\ifcase\textlevel
\registerfileinfo[begin]\jobfilename
\fi
\global\advance\textlevel\plusone}
\unexpanded\def\stoptext
{\global\advance\textlevel\minusone
\ifnum\textlevel>\zerocount \else
\flushfinallayoutpage % optional
\page % anyway
\the\everystoptext
%\the\everybye %
%\the\everygoodbye % == \end (new)
%\expandafter\normalend %
\ifcase\textlevel
\registerfileinfo[end]\jobfilename
\fi
\expandafter\finalend
\fi}
\def\forcequitjob#1%
{\writestatus\m!systems{forcing quit: #1}%
\batchmode
\dorecurse\textlevel{\stoptext}
\normalend}
\let\autostoptext\relax
\def\autostarttext
{\ifcase\textlevel
\starttext
\writestatus\m!systems{auto \string\starttext..\string\stoptext}%
\let\autostoptext\stoptext
\fi}
\def\finalend
{\ifnum\textlevel>\zerocount \else
\the\everybye
\the\everygoodbye
\doifsometokselse\everynotabene{\writeline\the\everynotabene\writeline}\donothing
\global\everybye \emptytoks % rather unneeded
\global\everygoodbye\emptytoks % but for sure
\expandafter\normalend
\fi}
\let\end\finalend
\def\emergencyend
{\writestatus\m!systems{invalid \@EA\string\csname\e!start\v!text\endcsname...\@EA\string\csname\e!stop\v!text\endcsname\space structure}%
\stoptext}
\def\currentfile{\inputfilename}
\def\doexecutefileonce#1%
{\beforesplitstring#1\at.\to\currentfile
\doifnotinset\currentfile\loadedfiles
{\addtocommalist\currentfile\loadedfiles
\doexecutefile{#1}}}
\def\doexecutefile#1%
{\registerfileinfo[begin]{#1}%
\dostarttextfile{#1}%
\processfile{#1}%
\dostoptextfile
\registerfileinfo[end]{#1}}
\def\donotexecutefile#1%
{}
\unexpanded\def\project {\doifnextoptionalelse\useproject \redoproject}
\unexpanded\def\environment{\doifnextoptionalelse\useenvironment\redoenvironment}
\unexpanded\def\product {\doifnextoptionalelse\useproduct \redoproduct}
\unexpanded\def\component {\doifnextoptionalelse\usecomponent \redocomponent}
\def\redoproject #1 {\useproject [#1]}
\def\redoenvironment #1 {\useenvironment[#1]}
\def\redoproduct #1 {\useproduct [#1]}
\def\redocomponent #1 {\usecomponent [#1]}
\def\useproject[#1]%
{}
\def\useenvironment[#1]% maybe commalist
{\pushmacro\dostartenvironment % we could use a depth counter
\pushmacro\stopenvironment
\unexpanded\def\dostartenvironment[##1]{}%
\let\stopenvironment\relax
\startreadingfile
\doexecutefileonce{#1}
\stopreadingfile
\popmacro\stopenvironment
\popmacro\dostartenvironment}
\def\useproduct[#1]%
{}
\def\usecomponent[#1]%
{\dostarttextfile{#1}%
\processfile{#1}%
\dostoptextfile}
\newcount\filelevel
\let\currentcomponent \v!text
\let\currentcomponentpath\f!currentpath
\def\donextlevel#1#2#3#4#5#6#7\\% we will move this to lua
{\pushmacro\currentcomponent
\pushmacro\currentcomponentpath
\let\currentcomponent#1%
\setsystemmode\currentcomponent
\splitfilename{#1}%
\ifx\splitoffpath\empty
\let\currentcomponentpath\f!currentpath
\else
\let\currentcomponentpath\splitoffpath
\fi
\beforesplitstring#7\at.\to#2\relax % can become path + base
\ifcase\filelevel\relax
\starttext
\unexpanded\def\useproject [##1]{#3{##1}}%
\unexpanded\def\useenvironment[##1]{#4{##1}}%
\unexpanded\def\useproduct [##1]{#5{##1}}%
\unexpanded\def\usecomponent [##1]{#6{##1}}%
\fi
\advance\filelevel\plusone
\addtocommalist{#1}\loadedfiles}
\def\doprevlevel
{\popmacro\currentcomponentpath
\popmacro\currentcomponent
\setsystemmode\currentcomponent
\ifnum\filelevel=\plusone
\expandafter\stoptext
\else
\advance\filelevel\minusone
\expandafter\endinput
\fi}
\unexpanded\def\startproject {\doifnextoptionalelse\dostartproject \redostartproject}
\unexpanded\def\startenvironment{\doifnextoptionalelse\dostartenvironment\redostartenvironment}
\unexpanded\def\startproduct {\doifnextoptionalelse\dostartproduct \redostartproduct}
\unexpanded\def\startcomponent {\doifnextoptionalelse\dostartcomponent \redostartcomponent}
\def\redostartproject #1 {\dostartproject [#1]}
\def\redostartenvironment #1 {\dostartenvironment[#1]}
\def\redostartproduct #1 {\dostartproduct [#1]}
\def\redostartcomponent #1 {\dostartcomponent [#1]}
\def\dostartproject[#1]%
{\donextlevel\v!project\currentproject
\donotexecutefile\doexecutefileonce
\doexecutefileonce\doexecutefile#1\\}
\def\dostartproduct[#1]%
{\doateverystarttext
\donextlevel\v!product\currentproduct
\doexecutefileonce\doexecutefileonce
\donotexecutefile\doexecutefile#1\\}
\def\dostartcomponent[#1]%
{\doateverystarttext
\donextlevel\v!component\currentcomponent
\doexecutefileonce\doexecutefileonce
\donotexecutefile\doexecutefile#1\\}
\def\dostartenvironment[#1]%
{\donextlevel\v!environment\currentenvironment
\donotexecutefile\doexecutefileonce
\donotexecutefile\donotexecutefile#1\\}
% \startproject test
% 1: \startmode[*project] project \stopmode \endgraf
% 2: \startmode[*product] product \stopmode \endgraf
% \stopproject
\unexpanded\def\stopproject {\doprevlevel}
\unexpanded\def\stopproduct {\doprevlevel}
\unexpanded\def\stopcomponent {\doprevlevel}
\unexpanded\def\stopenvironment{\doprevlevel}
% more or less replaced by modes
\setvalue{\e!start\v!localenvironment}[#1]%
{\let\loadedlocalenvironments\empty
\def\docommand##1%
{\beforesplitstring##1\at.\to\someevironment
\addtocommalist\someevironment\loadedlocalenvironments}%
\processcommalist[#1]\docommand
\expanded{\doifcommonelse{\currentproject,\currentproduct,\currentcomponent,\currentenvironment}{\loadedlocalenvironments}} % \expanded not needed
{\letvalue{\e!stop\v!localenvironment}\relax}
{\grabuntil{\e!stop\v!localenvironment}\gobbleoneargument}}
\setvalue{\v!localenvironment}{\doifnextoptionalelse\uselocalenvironment\redolocalenvironment}
\def\redolocalenvironment#1 {\uselocalenvironment[#1]}
\def\uselocalenvironment[#1]{\doexecutefileonce{#1}}
\neverypar\emptytoks % here ?
% \appendtoks \flushnotes \to \everypar
% \appendtoks \synchronizesidefloats \to \everypar
% \appendtoks \checkindentation \to \everypar
% \appendtoks \showparagraphnumber \to \everypar
% \appendtoks \flushmargincontents \to \everypar
% \appendtoks \flushcommentanchors \to \everypar
% \appendtoks \synchronizenotes \to \everypar
% \appendtoks \flushnotes \to \everydisplay
% \appendtoks \adjustsidefloatdisplaylines \to \everydisplay
\protect \endinput
|