file-job.mkvi /size: 12 Kb    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=file-job, % copied from main-001, later core-job
3
%D version=1997.03.31,
4
%D title=\CONTEXT\ Core Macros,
5
%D subtitle=Job Handling,
6
%D author=Hans Hagen,
7
%D date=\currentdate,
8
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9
%C
10
%C This module is part of the \CONTEXT\ macro||package and is
11
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12
%C details.
13 14
%D This module is still to be split and documented.
15 16
\writestatus
{
loading
}{
ConTeXt
File
Macros
/
Job
Handling
}
17 18
\unprotect
19 20
\registerctxluafile
{
file
-
job
}{}
21 22
% processing
23 24
\unexpanded
\def
\doifelseinputfile
#
name
%
25
{
\clf_doifelseinputfile
{
#
name
}}
26 27
\let
\doifinputfileelse\doifelseinputfile
28 29
\unexpanded
\def
\processfile
#
name
%
30
{
\clf_processfile
{
#
name
}}
31 32
% path control
33 34
%D In the following example the lookup order is \type {.}, {/foo}, \type
35
%D {foo/bar} as one can always explicitly prefix a wanted file.
36
%D
37
%D \starttyping
38
%D \pushpath[foo]
39
%D \pushpath[foo/bar]
40
%D \input test
41
%D \poppath
42
%D \poppath
43
%D \stoptyping
44 45
\unexpanded
\def
\usepath
[#
path
]
%
46
{
\clf_usepath
{
#
path
}}
47 48
\unexpanded
\def
\usesubpath
[#
path
]
%
49
{
\clf_usesubpath
{
#
path
}}
50 51
\unexpanded
\def
\pushpath
[#
path
]
%
52
{
\clf_pushpath
{
#
path
}}
53 54
\unexpanded
\def
\poppath
55
{
\clf_poppath
}
56 57
\unexpanded
\def
\resetpath
% not the pushed paths
58
{
\clf_resetpath
}
59 60
\def
\allinputpaths
61
{
\clf_allinputpaths
}
62 63
% helper (not really needed nowadays)
64 65
\let
\locatedfilepath
\empty
66 67
\unexpanded
\def
\locatefilepath
#
name
% no [] ?
68
{
\edef
\locatedfilepath
{
\clf_locatefilepath
{
#
name
}}}
69 70
% % maybe:
71
%
72
% % \dirlist{c:/data/temporary/foo}{images/bar.jpg}
73
% % \dirfile{c:/data/temporary/foo}{images/bar.jpg}
74
%
75
% \def\dirlist#1#2{dirlist://#1/**/#2}
76
% \def\dirfile#1#2{dirlist://#1/**/#2?option=fileonly}
77 78
% zip files are tree'd
79 80
\unexpanded
\def
\usezipfile
81
{
\dodoubleempty
\syst_files_use_zip_file
}
82 83
\def
\syst_files_use_zip_file
[#
zipname
][#
subtree
]
%
84
{
\clf_usezipfile
{
#
zipname
}{
#
subtree
}}
85 86
% exa stuff might become obsolete:
87 88
\unexpanded
\def
\loadexamodes
89
{
\dosingleempty
\syst_files_load_exa_modes
}
90 91
\def
\syst_files_load_exa_modes
[#
name
]
%
92
{
\clf_loadexamodes
{
#
name
}}
93 94
% runtime files (maybe also do this in lua?)
95 96
% \def\doloadsystemfile#1% only mkiv files
97
% {\readfile{sys:///#1.\mksuffix}{\showmessage\m!system2{#1.\mksuffix}}\donothing}
98 99
\unexpanded
\def
\syst_files_load
100
{
\syst_files_load_indeed
\f!newfilename
% new code, to be integrated at some point, plus fixes posted on the list
101
\syst_files_load_indeed
\f!locfilename
% new code, somewhat experimental, not distributed (outside the dev group)
102
\syst_files_load_indeed
\f!expfilename
% new code, very experimental, can be engine specific, mostly for me only
103
\syst_files_load_indeed
\f!sysfilename
% local settings, but probably not that good an idea to use
104
%\syst_files_load_indeed\f!fntfilename % maybe some day, can load goodies and patches
105
}
106 107
\def
\syst_files_load_indeed
#
name
% from now on we assume a suffix to be part of the name
108
{
\readsysfile
{
#
name
}{
\showmessage
\m!system
2
{
#
name
}}
\donothing
}
109 110
% document structure
111 112
\ifdefined
\textlevel
\else
\newcount
\textlevel
\fi
% might go away
113
\ifdefined
\strc_pagenumbers_flush_final_page
\else
\let
\strc_pagenumbers_flush_final_page
\relax
\fi
% ugly
114 115
\unexpanded
\def
\dostarttext
116
{
\glet
\dostarttext
\relax
117
\the
\everystarttext
118
\global
\everystarttext\emptytoks
}
119 120
\unexpanded
\def
\dostoptext
121
{
\glet
\dostoptext
\relax
122
\strc_pagenumbers_flush_final_page
123
\page
% hm, bonus
124
\the
\everystoptext
125
\global
\everystoptext\emptytoks
126
\the
\everybye
127
\global
\everybye
\emptytoks
128
\the
\everygoodbye
129
\global
\everygoodbye
\emptytoks
130
\doifelsesometoks
\everynotabene
{
\writeline
\the
\everynotabene
\writeline
}
\donothing
131
\normalend
}
% tex's \end
132 133
\unexpanded
\def
\starttext
{
\clf_starttext
}
134
\unexpanded
\def
\stoptext
{
\clf_stoptext
}
135
\unexpanded
\def
\forcequitjob
{
\clf_forcequitjob
}
136
\unexpanded
\def\end
{
\clf_forceendjob
}
137
\unexpanded
\def
\autostarttext
{
\clf_autostarttext
}
138
\unexpanded
\def
\autostoptext
{
\clf_autostoptext
}
139 140
\unexpanded
\def
\finishjob
{
\stoptext
}
% nicer in luatex call commandline
141 142
\newtoks
\everystartnotext
143
\newtoks
\everystopnotext
144 145
\unexpanded
\def
\startnotext
{
\the
\everystartnotext
}
146
\unexpanded
\def
\stopnotext
{
\the
\everystopnotext
\normalend
}
147 148
% protect structure
149 150
\unexpanded
\def
\processfilemany
#
name
{
\clf_processfilemany
{
#
name
}}
151
\unexpanded
\def
\processfileonce
#
name
{
\clf_processfileonce
{
#
name
}}
152
\unexpanded
\def
\processfilenone
#
name
{
\clf_processfilenone
{
#
name
}}
153 154
\unexpanded
\def
\project
{
\doifelsenextoptionalcs
\useproject
\syst_structure_arg_project
}
155
\unexpanded
\def
\product
{
\doifelsenextoptionalcs
\useproduct
\syst_structure_arg_product
}
156
\unexpanded
\def
\component
{
\doifelsenextoptionalcs
\usecomponent
\syst_structure_arg_component
}
157
\unexpanded
\def
\environment
{
\doifelsenextoptionalcs
\useenvironment
\syst_structure_arg_environment
}
158 159
\def
\syst_structure_arg_project
#
name
{
\clf_useproject
{
#
name
}}
160
\def
\syst_structure_arg_product
#
name
{
\clf_useproduct
{
#
name
}}
161
\def
\syst_structure_arg_component
#
name
{
\clf_usecomponent
{
#
name
}}
162
\def
\syst_structure_arg_environment
#
name
{
\clf_useenvironment
{
#
name
}}
163 164
\unexpanded
\def
\startproject
{
\doifelsenextoptionalcs
\syst_structure_start_opt_project
\syst_structure_start_arg_project
}
165
\unexpanded
\def
\startproduct
{
\doifelsenextoptionalcs
\syst_structure_start_opt_product
\syst_structure_start_arg_product
}
166
\unexpanded
\def
\startcomponent
{
\doifelsenextoptionalcs
\syst_structure_start_opt_component
\syst_structure_start_arg_component
}
167
\unexpanded
\def
\startenvironment
{
\doifelsenextoptionalcs
\syst_structure_start_opt_environment
\syst_structure_start_arg_environment
}
168 169
\def
\syst_structure_start_arg_project
#
name
{
\clf_startproject
{
#
name
}}
170
\def
\syst_structure_start_arg_product
#
name
{
\clf_startproduct
{
#
name
}}
171
\def
\syst_structure_start_arg_component
#
name
{
\clf_startcomponent
{
#
name
}}
172
\def
\syst_structure_start_arg_environment
#
name
{
\clf_startenvironment
{
#
name
}}
173 174
\unexpanded
\def
\useproject
[#
name
]
{
\clf_useproject
{
#
name
}}
175
\unexpanded
\def
\useproduct
[#
name
]
{
\clf_useproduct
{
#
name
}}
176
\unexpanded
\def
\usecomponent
[#
name
]
{
\clf_usecomponent
{
#
name
}}
177
\unexpanded
\def
\useenvironment
[#
name
]
{
\clf_useenvironment
{
#
name
}}
178 179
\unexpanded
\def
\syst_structure_start_opt_project
[#
name
]
{
\clf_startproject
{
#
name
}}
180
\unexpanded
\def
\syst_structure_start_opt_product
[#
name
]
{
\clf_startproduct
{
#
name
}}
181
\unexpanded
\def
\syst_structure_start_opt_component
[#
name
]
{
\clf_startcomponent
{
#
name
}}
182
\unexpanded
\def
\syst_structure_start_opt_environment
[#
name
]
{
\clf_startenvironment
{
#
name
}}
183 184
\newconditional
\endofinput
% hack, needed because \endinput happens one level down in the input when we write from lua
185 186
\unexpanded
\def
\signalendofinput
#
1
% argument just for tracing
187
{
\global
\settrue
\endofinput
}
188 189
\unexpanded
\def
\honorendofinput
190
{
\ifconditional
\endofinput
191
\global
\setfalse
\endofinput
192
\endinput
193
\fi
}
194 195
\unexpanded
\def
\stopproject
{
\clf_stopproject
\honorendofinput
}
196
\unexpanded
\def
\stopproduct
{
\clf_stopproduct
\honorendofinput
}
197
\unexpanded
\def
\stopcomponent
{
\clf_stopcomponent
\honorendofinput
}
198
\unexpanded
\def
\stopenvironment
{
\clf_stopenvironment
\honorendofinput
}
199 200
\let
\currentproject
\clf_currentproject
201
\let
\currentproduct
\clf_currentproduct
202
\let
\currentcomponent
\clf_currentcomponent
203
\let
\currentenvironment
\clf_currentenvironment
204
\let
\processedfile
\clf_processedfile
205
\let
\processedfiles
\clf_processedfiles
206 207
\unexpanded
\def
\dostarttextfile
#
name
{
\clf_dostarttextfile
{
name
}}
208
\unexpanded
\def
\dostoptextfile
{
\clf_dostoptextfile
}
209 210
\unexpanded
\def
\loadtexfile
[#
name
]
{
\clf_usetexfile
{
#
name
}}
211
\unexpanded
\def
\loadluafile
[#
name
]
{
\clf_useluafile
{
#
name
}}
212
\unexpanded
\def
\loadcldfile
[#
name
]
{
\clf_usecldfile
{
#
name
}}
213
\unexpanded
\def
\loadanyfile
[#
name
]
{
\clf_useanyfile
{
#
name
}}
214 215
\unexpanded
\def
\loadtexfileonce
[#
name
]
{
\clf_usetexfileonce
{
#
name
}}
216
\unexpanded
\def
\loadluafileonce
[#
name
]
{
\clf_useluafileonce
{
#
name
}}
217
\unexpanded
\def
\loadcldfileonce
[#
name
]
{
\clf_usecldfileonce
{
#
name
}}
218
\unexpanded
\def
\loadanyfileonce
[#
name
]
{
\clf_useanyfileonce
{
#
name
}}
219 220
%D Handy for modules that have a test/demo appended (true added).
221 222
\unexpanded
\def
\continueifinputfile
#
name
%
223
{
\clf_doifelsecontinuewithfile
{
#
name
}
\relax\endinput
}
% we cannot do \endinput via lua
224 225
% \startproject test
226
% 1: \startmode[*project] project \stopmode \endgraf
227
% 2: \startmode[*product] product \stopmode \endgraf
228
% \stopproject
229 230
% replaced by modes:
231
%
232
% \setvalue{\e!start\v!localenvironment}[#1]%
233
% {\let\loadedlocalenvironments\empty
234
% \def\docommand##1%
235
% {\beforesplitstring##1\at.\to\someevironment
236
% \addtocommalist\someevironment\loadedlocalenvironments}%
237
% \processcommalist[#1]\docommand
238
% \doifcommonelse{\currentproject,\currentproduct,\currentcomponent,\currentenvironment}\loadedlocalenvironments
239
% {\letvalue{\e!stop\v!localenvironment}\relax}
240
% {\grabuntil{\e!stop\v!localenvironment}\gobbleoneargument}}
241
%
242
% \setvalue{\v!localenvironment}{\doifnextoptionalcselse\uselocalenvironment\redolocalenvironment}
243
%
244
% \def\redolocalenvironment#1 {\uselocalenvironment[#1]}
245
% \def\uselocalenvironment[#1]{\doexecutefileonce{#1}}
246 247
% weird place:
248 249
\neverypar
\emptytoks
250 251
%D Wrappers (the signal is a synchronization with lua hack):
252 253
\newsystemmode
\v!project
254
\newsystemmode
\v!product
255
\newsystemmode
\v!component
256
\newsystemmode
\v!environment
257 258
\unexpanded
\def
\startprojectindeed
259
{
%starttext
260
\pushsystemmode
\v!project
261
\setsystemmode
\v!project
}
262 263
\unexpanded
\def
\stopprojectindeed
264
{
\popsystemmode
\v!project
265
%stoptext
266
\signalendofinput
\v!project
}
267 268
\unexpanded
\def
\startproductindeed
269
{
\starttext
270
\pushsystemmode
\v!product
271
\setsystemmode
\v!product
}
272 273
\unexpanded
\def
\stopproductindeed
274
{
\popsystemmode
\v!product
275
\stoptext
276
\signalendofinput
\v!product
}
277 278
\unexpanded
\def
\startcomponentindeed
279
{
\starttext
280
\pushreferenceprefix
\currentcomponent
281
\pushsystemmode
\v!component
282
\setsystemmode
\v!component
}
283 284
\unexpanded
\def
\stopcomponentindeed
285
{
\popsystemmode
\v!component
286
\popreferenceprefix
287
\stoptext
288
\signalendofinput
\v!component
}
289 290
\unexpanded
\def
\startenvironmentindeed
291
{
\pushsystemmode
\v!environment
292
\setsystemmode
\v!environment
}
293 294
\unexpanded
\def
\stopenvironmentindeed
295
{
\popsystemmode
\v!environment
296
\signalendofinput
\v!environment
}
297 298
%D Relatively new (might move as it depends on setups):
299 300
%newtoks\everysetupdocument
301 302
\unexpanded
\def
\startdocument
% todo: dostarttagged\t!document
303
{
\dosingleargument
\syst_structure_document_start
}
304 305
\unexpanded
\def
\syst_structure_document_start
[#
settings
]
%
306
{
\setvariables
[
\s!document
][#
settings
]
%
307
\the
\everysetupdocument
\relax
308
\starttext
309
\documentvariable
\c!before
}
310 311
\unexpanded
\def
\stopdocument
% todo: dostoptagged\t!document
312
{
\documentvariable
\c!after
313
\stoptext
}
314 315
\unexpanded
\def
\doifelsedocumentvariable
#
name
{
\doifelsesomething
{
\documentvariable
{
#
name
}}}
316
\unexpanded
\def
\doifdocumentvariable
#
name
{
\doifsomething
{
\documentvariable
{
#
name
}}}
317
\unexpanded
\def
\doifnotdocumentvariable
#
name
{
\doifnot
{
\documentvariable
{
#
name
}}}
318 319
\let
\doifdocumentvariableelse\doifelsedocumentvariable
320 321
\def
\documentvariable
#
name
%
322
{
\getvariable
\s!document
{
#
name
}}
323 324
\unexpanded
\def
\unexpandeddocumentvariable
#
name
%
325
{
\getvariable
\s!document
{
#
name
}}
326 327
\unexpanded
\def
\setupdocument
[#
settings
]
%
328
{
\setvariables
[
\s!document
][#
settings
]
%
329
\the
\everysetupdocument
\relax
}
330 331
\unexpanded
\def
\presetdocument
[#
settings
]
%
332
{
\checkvariables
[
\s!document
][#
settings
]
}
333 334
% We silently ignore missing documents. Beware: there are no begin/end setups
335
% invoked as we expect the loaded document to be wrapped in \startdocument ...
336
% \stopdocument. This is just a convenient variant of input.
337
%
338
% \unexpanded\def\document
339
% {\dosingleempty\syst_document}
340
%
341
% \def\syst_document[#1]#2%
342
% \startdocument[#1]
343
% \readfile{#2}{}{}}
344 345
% metadata:author metadata:title metadata:subject
346 347
\setvariables
348
[
document
]
349
[
\c!before
=
\directsetup
{
\s!document
:
start
}
,
350
\c!after
=
\directsetup
{
\s!document
:
stop
}
]
351 352
%S The document: namespace will be used elsewhere too.
353 354
% Bonus:
355 356
% \installcorenamespace{samplefile}
357
%
358
% \unexpanded\def\samplefile#1%
359
% {\ifcsname\??samplefile#1\endcsname \else
360
% \setxvalue{\??samplefile#1}{\cldloadfile{#1}}%
361
% \fi
362
% \lastnamedcs}
363 364
\unexpanded
\def
\samplefile
#
1
%
365
{
\clf_samplefile
{
#
1
}}
366 367
\protect
\endinput
368