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
|
%D \module
%D [ file=file-job, % copied from main-001, later core-job
%D version=1997.03.31,
%D title=\CONTEXT\ Core Macros,
%D subtitle=Job Handling,
%D author=Hans Hagen,
%D date=\currentdate,
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
%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 File Macros / Job Handling}
\unprotect
\registerctxluafile{file-job}{1.001}
% processing
\unexpanded\def\doifinputfileelse#name%
{\ctxcommand{doifinputfileelse("#name")}}
\unexpanded\def\processfile#name%
{\ctxcommand{processfile("#name")}}
% path control
\unexpanded\def\usepath[#path]%
{\ctxcommand{usepath("#path")}}
\unexpanded\def\usesubpath[#path]%
{\ctxcommand{usesubpath("#path")}}
\def\allinputpaths
{\ctxcommand{allinputpaths()}}
% helper (not really needed nowadays)
\let\locatedfilepath\empty
\unexpanded\def\locatefilepath#name% no [] ?
{\edef\locatedfilepath{\ctxcommand{locatefilepath("#name")}}}
% zip files are tree'd
\unexpanded\def\usezipfile
{\dodoubleempty\syst_files_use_zip_file}
\def\syst_files_use_zip_file[#zipname][#subtree]%
{\ctxcommand{usezipfile("#zipname","#subtree")}}
% exa stuff might become obsolete:
\unexpanded\def\loadexamodes
{\dosingleempty\syst_files_load_exa_modes}
\def\syst_files_load_exa_modes[#name]%
{\ctxcommand{loadexamodes("#name")}}
% runtime files (maybe also do this in lua?)
% \def\doloadsystemfile#1% only mkiv files
% {\readfile{sys:///#1.\mksuffix}{\showmessage\m!system2{#1.\mksuffix}}\donothing}
\unexpanded\def\loadsystemfiles
{\syst_files_load\f!newfilename % new code, to be integrated at some point, plus fixes posted on the list
\syst_files_load\f!locfilename % new code, somewhat experimental, not distributed (outside the dev group)
\syst_files_load\f!expfilename % new code, very experimental, can be engine specific, mostly for me only
\syst_files_load\f!sysfilename} % local settings, but probably not that good an idea to use
\def\syst_files_load#name% only mkiv files
{\readsysfile{#name.\mksuffix}{\showmessage\m!system2{#name.\mksuffix}}\donothing}
% obsolete, but we keep it as reference of what happened
%
% \unexpanded\def\loadoptionfile
% {\readjobfile{\jobname.\f!optionextension}
% {\writestatus\m!system{\jobname.\f!optionextension\space loaded}%
% \ctxcommand{copyfiletolog("\jobname.\f!optionextension")}}%
% {\writestatus\m!system{no \jobname.\f!optionextension}}}
% document structure
\ifdefined\textlevel \else \newcount\textlevel \fi % might go away
\ifdefined\strc_pagenumbers_flush_final_page \else \let\strc_pagenumbers_flush_final_page\relax \fi % ugly
\unexpanded\def\dostarttext
{\glet\dostarttext\relax
\the\everystarttext
\global\everystarttext\emptytoks}
\unexpanded\def\dostoptext
{\glet\dostoptext\relax
\strc_pagenumbers_flush_final_page
\page % hm, bonus
\the\everystoptext
\global\everystoptext\emptytoks
\the\everybye
\global\everybye\emptytoks
\the\everygoodbye
\global\everygoodbye\emptytoks
\doifsometokselse\everynotabene{\writeline\the\everynotabene\writeline}\donothing
\normalend} % tex's \end
\unexpanded\def\starttext {\ctxcommand{starttext()}}
\unexpanded\def\stoptext {\ctxcommand{stoptext()}}
\unexpanded\def\forcequitjob {\ctxcommand{forcequitjob()}}
\unexpanded\def\end {\ctxcommand{forceendjob()}}
\unexpanded\def\autostarttext{\ctxcommand{autostarttext()}}
\unexpanded\def\autostoptext {\ctxcommand{autostoptext()}}
\unexpanded\def\finishjob{\stoptext} % nicer in luatex call commandline
\newtoks\everystartnotext
\newtoks\everystopnotext
\unexpanded\def\startnotext {\the\everystartnotext}
\unexpanded\def\stopnotext {\the\everystopnotext \normalend}
% protect structure
\unexpanded\def\processfilemany#name{\ctxcommand{processfilemany("#name")}}
\unexpanded\def\processfileonce#name{\ctxcommand{processfileonce("#name")}}
\unexpanded\def\processfilenone#name{\ctxcommand{processfilenone("#name")}}
\unexpanded\def\project {\doifnextoptionalelse\useproject \syst_structure_arg_project}
\unexpanded\def\product {\doifnextoptionalelse\useproduct \syst_structure_arg_product}
\unexpanded\def\component {\doifnextoptionalelse\usecomponent \syst_structure_arg_component}
\unexpanded\def\environment{\doifnextoptionalelse\useenvironment\syst_structure_arg_environment}
\def\syst_structure_arg_project #name {\ctxcommand{useproject ("#name")}}
\def\syst_structure_arg_product #name {\ctxcommand{useproduct ("#name")}}
\def\syst_structure_arg_component #name {\ctxcommand{usecomponent ("#name")}}
\def\syst_structure_arg_environment#name {\ctxcommand{useenvironment("#name")}}
\unexpanded\def\startproject {\doifnextoptionalelse\syst_structure_start_opt_project \syst_structure_start_arg_project }
\unexpanded\def\startproduct {\doifnextoptionalelse\syst_structure_start_opt_product \syst_structure_start_arg_product }
\unexpanded\def\startcomponent {\doifnextoptionalelse\syst_structure_start_opt_component \syst_structure_start_arg_component }
\unexpanded\def\startenvironment{\doifnextoptionalelse\syst_structure_start_opt_environment\syst_structure_start_arg_environment}
\def\syst_structure_start_arg_project #name {\ctxcommand{startproject ("#name")}}
\def\syst_structure_start_arg_product #name {\ctxcommand{startproduct ("#name")}}
\def\syst_structure_start_arg_component #name {\ctxcommand{startcomponent ("#name")}}
\def\syst_structure_start_arg_environment#name {\ctxcommand{startenvironment("#name")}}
\unexpanded\def\useproject [#name]{\ctxcommand{useproject ("#name")}}
\unexpanded\def\useproduct [#name]{\ctxcommand{useproduct ("#name")}}
\unexpanded\def\usecomponent [#name]{\ctxcommand{usecomponent ("#name")}}
\unexpanded\def\useenvironment[#name]{\ctxcommand{useenvironment("#name")}}
\unexpanded\def\syst_structure_start_opt_project [#name]{\ctxcommand{startproject ("#name")}}
\unexpanded\def\syst_structure_start_opt_product [#name]{\ctxcommand{startproduct ("#name")}}
\unexpanded\def\syst_structure_start_opt_component [#name]{\ctxcommand{startcomponent ("#name")}}
\unexpanded\def\syst_structure_start_opt_environment[#name]{\ctxcommand{startenvironment("#name")}}
\newconditional\endofinput % hack, needed because \endinput happens one level down in the input when we write from lua
\unexpanded\def\signalendofinput#1% argument just for tracing
{\global\settrue\endofinput}
\unexpanded\def\honorendofinput
{\ifconditional\endofinput
\global\setfalse\endofinput
\endinput
\fi}
\unexpanded\def\stopproject {\ctxcommand{stopproject ()}\honorendofinput}
\unexpanded\def\stopproduct {\ctxcommand{stopproduct ()}\honorendofinput}
\unexpanded\def\stopcomponent {\ctxcommand{stopcomponent ()}\honorendofinput}
\unexpanded\def\stopenvironment {\ctxcommand{stopenvironment()}\honorendofinput}
\def\currentproject {\ctxcommand{currentproject ()}}
\def\currentproduct {\ctxcommand{currentproduct ()}}
\def\currentcomponent {\ctxcommand{currentcomponent ()}}
\def\currentenvironment {\ctxcommand{currentenvironment()}}
\def\processedfile {\ctxcommand{processedfile()}}
\def\processedfiles {\ctxcommand{processedfiles()}}
\unexpanded\def\dostarttextfile #name{\ctxcommand{dostarttextfile(name)}}
\unexpanded\def\dostoptextfile {\ctxcommand{dostoptextfile()}}
\unexpanded\def\loadtexfile [#name]{\ctxcommand{usetexfile("#name")}}
\unexpanded\def\loadluafile [#name]{\ctxcommand{useluafile("#name")}}
\unexpanded\def\loadcldfile [#name]{\ctxcommand{usecldfile("#name")}}
\unexpanded\def\loadanyfile [#name]{\ctxcommand{useanyfile("#name")}}
\unexpanded\def\loadtexfileonce [#name]{\ctxcommand{usetexfile("#name",true)}}
\unexpanded\def\loadluafileonce [#name]{\ctxcommand{useluafile("#name",true)}}
\unexpanded\def\loadcldfileonce [#name]{\ctxcommand{usecldfile("#name",true)}}
\unexpanded\def\loadanyfileonce [#name]{\ctxcommand{useanyfile("#name",true)}}
%D Handy for modules that have a test/demo appended (true added).
\unexpanded\def\continueifinputfile#name{\ctxcommand{doifelsecontinuewithfile("#name",true)}\relax\endinput} % we cannot do \endinput via lua
% \startproject test
% 1: \startmode[*project] project \stopmode \endgraf
% 2: \startmode[*product] product \stopmode \endgraf
% \stopproject
% 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
% \doifcommonelse{\currentproject,\currentproduct,\currentcomponent,\currentenvironment}\loadedlocalenvironments
% {\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}}
% weird place:
\neverypar\emptytoks
%D Wrappers (the signal is a synchronization with lua hack):
\newsystemmode\v!project
\newsystemmode\v!product
\newsystemmode\v!component
\newsystemmode\v!environment
\unexpanded\def\startprojectindeed
{\starttext
\pushsystemmode\v!project
\setsystemmode\v!project}
\unexpanded\def\stopprojectindeed
{\popsystemmode\v!project
\stoptext
\signalendofinput\v!project}
\unexpanded\def\startproductindeed
{\starttext
\pushsystemmode\v!product
\setsystemmode\v!product}
\unexpanded\def\stopproductindeed
{\popsystemmode\v!product
\stoptext
\signalendofinput\v!product}
\unexpanded\def\startcomponentindeed
{\starttext
\pushreferenceprefix\currentcomponent
\pushsystemmode\v!component
\setsystemmode\v!component}
\unexpanded\def\stopcomponentindeed
{\popsystemmode\v!component
\popreferenceprefix
\stoptext
\signalendofinput\v!component}
\unexpanded\def\startenvironmentindeed
{\pushsystemmode\v!environment
\setsystemmode\v!environment}
\unexpanded\def\stopenvironmentindeed
{\popsystemmode\v!environment
\signalendofinput\v!environment}
%D Relatively new (might move as it depends on setups):
\newtoks\everysetupdocument
\unexpanded\def\startdocument % todo: dostarttagged\t!document
{\dosingleargument\syst_structure_document_start}
\unexpanded\def\syst_structure_document_start[#settings]%
{\setvariables[\s!document][#settings]%
\the\everysetupdocument\relax
\starttext
\documentvariable\c!before}
\unexpanded\def\stopdocument % todo: dostoptagged\t!document
{\documentvariable\c!after
\stoptext}
\def\documentvariable#name%
{\getvariable\s!document{#name}}
\unexpanded\def\setupdocument[#settings]%
{\setvariables[\s!document][#settings]%
\the\everysetupdocument\relax}
% metadata:author metadata:title metadata:subject
\setvariables
[document]
[\c!before=\directsetup{\s!document:start},
\c!after=\directsetup{\s!document:stop}]
%S The document: namespace will be used elsewhere too.
\protect \endinput
|