core-sys.mkiv /size: 13 Kb    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=core-sys, % moved from main-001
3
%D version=1997.03.31,
4
%D title=\CONTEXT\ Core Macros,
5
%D subtitle=System,
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
% we need to mkiv-ize this file !
15 16
\writestatus
{
loading
}{
ConTeXt
Core
Macros
/
System
}
17 18
\registerctxluafile
{
core
-
sys
}{}
19 20
\unprotect
21 22
%D Version checking:
23 24
\unexpanded
\def
\newcontextversion
#
1
%
25
{
\doifelse
{
#
1
}
\contextversion
26
{
\let
\newcontextversion
\gobbleoneargument
}
27
{
\writeline
28
\writestatus
{
Fatal
Error
}{
Your
format
does
not
match
the
base
files
!
}
%
29
\writeline
30
\writestatus
{
Format
Version
}{
\contextversion
\space
\contextmark
}
%
31
\writestatus
{
Files
Version
}{
#
1
}
%
32
\batchmode
33
\normalend
}}
34 35
%D End of lines to the output. \TEX\ will map this onto the platform specific
36
%D line ending. I hate this mess.
37 38
\let
\operatingsystem
\clf_operatingsystem
39 40
%D The jobname is what gets loaded by the cont-yes stub file. This name
41
%D also determines the name of tuc etc files.
42 43
\let
\jobfilefullname
\clf_jobfilefullname
44
\let
\jobfilename
\clf_jobfilename
45
\let
\jobfilesuffix
\clf_jobfilesuffix
46 47
%D However, that one can itself load another file.
48 49
\let
\inputfilebarename
\clf_inputfilebarename
50
\let
\inputfilerealsuffix
\clf_inputfilerealsuffix
51
\let
\inputfilesuffix
\clf_inputfilesuffix
52
\let
\inputfilename
\clf_inputfilename
53 54
%D The output name is only used for some checking.
55 56
\let
\outputfilename
\clf_outputfilename
57 58
\installcorenamespace
{
system
}
59 60
\installdirectcommandhandler
\??system
{
system
}
61 62
\appendtoks
63
% \edef\outputfilename {\directsystemparameter\c!file }%
64
% \edef\inputfilename {\directsystemparameter\c!inputfile }%
65
\to
\everysetupsystem
66 67
\appendtoks
68
\ifcase
\directsystemparameter
\c!n
\relax
69
% % 0 : unknown
70
\or
71
\setsystemmode
\v!first
% 1 : first run
72
\or
73
% % 2 : successive run
74
\or
75
\setsystemmode
\v!first
% 3 : first and only run
76
\or
77
\setsystemmode
\v!last
% 4 : (extra) last run
78
\fi
79
\to
\everysetupsystem
80 81
\newconditional
\prerollrun
% when true it means that we have a forced number of runs
82 83
% Some mechanisms (see x-res-01) use either \jobfilename or
84
% \jobfilename.somesuffix, in which case we need to use the
85
% full name if given or a default (like \jobfilename.xml);
86
% this comes down to replacing the default tex suffix.
87 88
\def
\jobfullname
{
\jobfilename
.
\jobfilesuffix
}
89 90
\unexpanded
\def
\setjobfullname
#
1
% #1 = default if not given
91
{
\doifelsenothing
\jobfilename
92
{
\let
\jobfullname
\empty
}
93
{
\doif
\jobfilesuffix
\c!tex
{
\edef
\jobfullname
{
\jobfilename
.
#
1
}}}}
94 95
%D There are a couple of system states avaiable:
96
%D
97
%D \starttabulate [|T|T|]
98
%D \NC \type{\jobname} \NC \jobname \NC \NR
99
%D \NC \type{\jobfilename} \NC \jobfilename \NC \NR
100
%D \NC \type{\jobfilesuffix} \NC \jobfilesuffix \NC \NR
101
%D \NC \type{\inputfilename} \NC \inputfilename \NC \NR
102
%D \NC \type{\inputfilebarename} \NC \inputfilebarename \NC \NR
103
%D \NC \type{\inputfilesuffix} \NC \inputfilesuffix \NC \NR
104
%D \NC \type{\outputfilename} \NC \outputfilename \NC \NR
105
%D \NC \type{\operatingsystem} \NC \operatingsystem \NC \NR
106
%D \stoptabulate
107 108
\appendtoks
109
\edef
\outputresolution
{
\directsystemparameter
\c!resolution
}
%
110
\to
\everysetupsystem
111 112
%D The system modes set by the setup command can be used in
113
%D situations like:
114
%D
115
%D \starttyping
116
%D \startmode[*first]
117
%D \executesystemcommand{cleanupxml text.xml clean-text.xml}
118
%D \stopmode
119
%D
120
%D \starttext
121
%D \typefile{clean-text.xml}
122
%D \stoptext
123
%D \stoptyping
124 125
\unexpanded
\def
\setuprandomize
[#
1
]
%
126
{
\doifsomething
{
#
1
}
127
{
\begingroup
128
% tex's time is in minutes
129
\scratchcounter
\normaltime
130
\processaction
131
[#
1
]
132
[
\v!small
=>
\divide
\scratchcounter
1
5
,
% 900,
133
\v!medium
=>
\divide
\scratchcounter
3
0
,
% 1800,
134
\v!big
=>
\divide
\scratchcounter
6
0
,
% 3600,
135
\v!normal
=>
\getnewrandomseed
\scratchcounter
,
136
\s!default
=>
\getnewrandomseed
\scratchcounter
,
137
\s!unknown
=>
\scratchcounter
#
1
]
%
138
\expanded
{
\setrandomseed
{
\the
\scratchcounter
}}
%
139
% \writestatus\m!system{randomseed: \the\scratchcounter}%
140
\endgroup
}}
141 142
\setupsystem
143
[
\c!directory
=
,
144
\c!n
=
0
,
% 0:unknown 1: one run 2: first 3: successive 4: final run
145
\c!resolution
=
6
0
0
,
% in dpi, no unit in mkiv
146
% \c!random=, % obsolete here
147
% \c!file=\jobname,
148
% \c!inputfile=\outputfilename,
149
\c!type
=
unix
,
% windows is normally less sensitive to handle
150
\c!bodyfont
=
\normalizedlocalbodyfontsize
]
% of iets anders
151 152
%D Remark: windows programs normally handle \type {cr|lf|crlf} but unix
153
%D is more picky, so we default to the \type {cr}. I never understood why
154
%D \type {crlf} was not used in all systems, since it makes most sense.
155
%D But anyway, in \MKIV\ we avoid most of the complications anyway as we
156
%D deal with much at the \LUA\ end.
157 158
\unexpanded
\def
\start
159
{
\dosingleempty
\syst_start
}
160 161
\def
\syst_start
162
{
\bgroup
163
\iffirstargument
164
\expandafter
\syst_start_yes
165
\else
166
\expandafter
\syst_start_nop
167
\fi
}
168 169
\def
\syst_start_yes
[#
1
]
%
170
{
\edef
\m_syst_start_stop
{
#
1
}
%
171
\ifx
\m_syst_start_stop
\empty
172
\let
\syst_stop_indeed
\donothing
173
\else\ifcsname
\e!start
\m_syst_start_stop
\endcsname
174
\expandafter\let\expandafter
\syst_stop_indeed
\csname
\e!stop
\m_syst_start_stop
\endcsname
175
\csname
\e!start
\m_syst_start_stop
\expandafter\expandafter\expandafter\endcsname
176
\else
177
\let
\syst_stop_indeed
\donothing
178
\fi\fi
}
179 180
\def
\syst_start_nop
[#
1
]
%
181
{
\let
\syst_stop_indeed
\donothing
}
182 183
\unexpanded
\def
\stop
184
{
\syst_stop_indeed
185
\egroup
}
186 187
% \c!before \c!after \c!inbetween \c!commands \c!style \c!color
188 189
\installcorenamespace
{
startstop
}
190 191
\installcommandhandler
\??startstop
{
startstop
}
\??startstop
192 193
\appendtoks
194
\setuevalue
{
\e!start
\currentstartstop
}{
\syst_startstop_start
{
\currentstartstop
}}
%
195
\setuevalue
{
\e!stop
\currentstartstop
}{
\syst_startstop_stop
{
\currentstartstop
}}
%
196
\setuevalue
{
\currentstartstop
}{
\syst_startstop_indeed
{
\currentstartstop
}}
%
197
\to
\everydefinestartstop
198 199
\ifdefined
\dotagconstruct
\else
\let
\dotagconstruct
\relax
\fi
200 201
\unexpanded
\def
\syst_startstop_start
#
1
%
202
{
\namedstartstopparameter
{
#
1
}
\c!before
\relax
203
\bgroup
204
\def
\currentstartstop
{
#
1
}
%
205
% we will keep this for a while:
206
\startstopparameter
\c!commands
\relax
% obsolete
207
% this is the new method:
208
\usesetupsparameter
\startstopparameter
\relax
% only in the display version
209
\dostarttagged
\t!construct
\currentstartstop
210
\usestartstopstyleandcolor
\c!style\c!color
211
\dotagconstruct
}
212 213
\unexpanded
\def
\syst_startstop_stop
#
1
%
214
{
\dostoptagged
215
\egroup
216
\namedstartstopparameter
{
#
1
}
\c!after
\relax
}
217 218
\unexpanded
\def
\syst_startstop_indeed
#
1
%
219
{
\groupedcommand
220
{
\def
\currentstartstop
{
#
1
}
%
221
\startstopparameter
\c!commands
\relax
% better: setups so that will show op soon
222
\dostarttagged
\t!construct
\currentstartstop
223
\usestartstopstyleandcolor
\c!style\c!color
224
\startstopparameter
\c!left
\relax
}
225
{
\def
\currentstartstop
{
#
1
}
% safeguard, not really needed
226
\startstopparameter
\c!right
\relax
227
\dostoptagged
228
\startstopparameter
\c!inbetween
\relax
}}
229 230
% \definestartstop[tracing][\c!style=\tt]
231 232
% \unexpanded\def\ignorestartstop[#1]%
233
% {\unexpanded\expandafter\def\csname\e!start#1\expandafter\endcsname\expandafter
234
% {\expandafter\gobbleuntil\csname\e!stop#1\endcsname}}
235
%
236
% \ignorestartstop[bagger]
237 238
\installcorenamespace
{
highlight
}
239 240
\installcommandhandler
\??highlight
{
highlight
}
\??highlight
% we could do with less
241 242
\setuphighlight
243
[
\c!command
=
\v!yes
]
244 245
\appendtoks
246
\edef
\p_command
{
\highlightparameter
\c!command
}
%
247
\ifx
\p_command
\v!yes
248
\setuevalue
\currenthighlight
{
\typo_highlights_indeed
{
\currenthighlight
}}
%
249
\fi
250
\to
\everydefinehighlight
251 252
\ifdefined
\dotaghighlight
\else
\let
\dotaghighlight
\relax
\fi
253 254
\unexpanded
\def
\typo_highlights_indeed
#
1
% inline style/color switch
255
{
\dontleavehmode\groupedcommand
% otherwise wrong par number in tags
256
{
\def
\currenthighlight
{
#
1
}
%
257
\dostarttagged
\t!highlight
\currenthighlight
258
\usehighlightstyleandcolor
\c!style\c!color
259
\dotaghighlight
}
260
{
\dostoptagged
}}
261 262
\unexpanded
\def
\highlight
[#
1
]
%
263
{
\typo_highlights_indeed
{
#
1
}}
264 265
\unexpanded
\def
\starthighlight
[#
1
]
%
266
{
\begingroup
267
\def
\currenthighlight
{
#
1
}
%
268
\dostarttagged
\t!highlight
\currenthighlight
269
\usehighlightstyleandcolor
\c!style\c!color
270
\dotaghighlight
}
271 272
\unexpanded
\def
\stophighlight
273
{
\dostoptagged
274
\endgroup
}
275 276
\let
\directhighlight
\typo_highlights_indeed
277 278
\unexpanded
\def
\defineexpandable
279
{
\doifelsenextoptional
280
{
\syst_basics_define_yes
\def
}
%
281
{
\syst_basics_define_nop
\def
}}
282 283
\unexpanded
\def
\define
284
{
\doifelsenextoptional
285
{
\syst_basics_define_yes
{
\unexpanded
\def
}}
%
286
{
\syst_basics_define_nop
{
\unexpanded
\def
}}}
287 288
\unexpanded
\def
\syst_basics_define_yes
#
1
[#
2
]#
3
#
4
%
289
{
\ifdefined
#
3
%
290
\showmessage
\m!system
4
{
\string
#
3
}
%
291
\fi
292
\ifcase
0
#
2
\relax
293
#
1
#
3
{
#
4
}
\or
294
#
1
#
3
##
1
{
#
4
}
\or
295
#
1
#
3
##
1
##
2
{
#
4
}
\or
296
#
1
#
3
##
1
##
2
##
3
{
#
4
}
\or
297
#
1
#
3
##
1
##
2
##
3
##
4
{
#
4
}
\or
298
#
1
#
3
##
1
##
2
##
3
##
4
##
5
{
#
4
}
\or
299
#
1
#
3
##
1
##
2
##
3
##
4
##
5
##
6
{
#
4
}
\or
300
#
1
#
3
##
1
##
2
##
3
##
4
##
5
##
6
##
7
{
#
4
}
\or
301
#
1
#
3
##
1
##
2
##
3
##
4
##
5
##
6
##
7
##
8
{
#
4
}
\or
302
#
1
#
3
##
1
##
2
##
3
##
4
##
5
##
6
##
7
##
8
##
9
{
#
4
}
\else
303
#
1
#
3
{
#
4
}
\fi
}
304 305
\unexpanded
\def
\syst_basics_define_nop
#
1
#
2
#
3
%
306
{
\ifdefined
#
2
%
307
\showmessage
\m!system
4
{
\string
#
2
}
%
308
\fi
309
#
1
#
2
{
#
3
}}
310 311
% new:
312
%
313
% \checked\def \whatever#alpha#beta{#alpha + #beta}
314
% \checked\edef\whatever#alpha#beta{#alpha + #beta}
315 316
\unexpanded
\def
\unique
#
1
#
2
%
317
{
\ifdefined
#
2
%
318
\showmessage
\m!system
4
{
\string
#
2
}
%
319
\expandafter
#
1
\expandafter
\gobbleddefinition
320
\else
321
\expandafter
#
1
%
322
\fi
#
2
}
323 324
\unexpanded
\def
\checked
#
1
#
2
%
325
{
\ifdefined
#
2
%
326
\showmessage
\m!system
4
{
\string
#
2
}
%
327
\fi
328
#
1
#
2
}
329 330
% \startluacode
331
% local formatters = string.formatters
332
% local contextsprint, ctxcatcodes, prtcatcodes = context.sprint, tex.ctxcatcodes, tex.prtcatcodes
333
% local match, gmatch, rep = string.match, string.gmatch, string.rep
334
% local empty = {
335
% "single",
336
% "double",
337
% "triple",
338
% "quadruple",
339
% "quintuple",
340
% }
341
% local check = {
342
% "first",
343
% "second",
344
% "third",
345
% "fourth",
346
% "fifth",
347
% }
348
% function commands.define(str)
349
% -- we could store the defaults in lua and call lua instead but why bother
350
% local arg, cmd = match(str,"(.*)\\(.-)$")
351
% local a = { }
352
% for s in gmatch(arg,"%[(.-)%]") do
353
% a[#a+1] = s
354
% end
355
% local n = tonumber(a[#a])
356
% if n then
357
% a[#a] = nil
358
% else
359
% n = 0
360
% end
361
% contextsprint(ctxcatcodes,formatters["\\unexpanded\\def\\%s"](cmd))
362
% if #a > 0 then
363
% contextsprint(prtcatcodes,formatters["{\\do%sempty\\user_defined_%s}"](empty[#a],cmd))
364
% contextsprint(prtcatcodes,formatters["\\def\\user_defined_%s"](cmd))
365
% for i=1,#a do
366
% contextsprint(ctxcatcodes,formatters["[#%s]"](i))
367
% end
368
% contextsprint(ctxcatcodes,"{")
369
% for i=#a,1,-1 do
370
% contextsprint(ctxcatcodes,formatters["\\if%sargument"](check[i]))
371
% contextsprint(prtcatcodes,formatters["\\def\\next{\\user_defined_indeed_%s"](cmd))
372
% for j=1,#a-i do
373
% contextsprint(ctxcatcodes,formatters["[%s]"](a[j]))
374
% end
375
% for j=1,i do
376
% contextsprint(ctxcatcodes,formatters["[#%s]"](j))
377
% end
378
% contextsprint(ctxcatcodes,"}")
379
% if i == 1 then
380
% contextsprint(ctxcatcodes,rep("\\fi",#a))
381
% else
382
% contextsprint(ctxcatcodes,"\\else")
383
% end
384
% end
385
% contextsprint(ctxcatcodes,"\\next}")
386
% contextsprint(prtcatcodes,formatters["\\def\\user_defined_indeed_%s"](cmd))
387
% for i=1,#a do
388
% contextsprint(ctxcatcodes,formatters["[#%s]"](i))
389
% end
390
% end
391
% for i=1,n do
392
% contextsprint(ctxcatcodes,formatters["#%s"](#a+i))
393
% end
394
% end
395
% \stopluacode
396
%
397
% \unexpanded\def\define#1#{\ctxcommand{define([[\detokenize{#1}]])}}
398
%
399
% \starttext
400
% \define[2]\whatevera{#1+#2}
401
% \whatevera{A}{B}
402
% \define[me][too][2]\whateverb{#1+#2+#3+#4}
403
% \whateverb[A]{B}{C}
404
% \whateverb[A][B]{C}{D}
405
% \define[alpha][beta][gamma][delta]\whateverc{#1+#2+#3+#4}
406
% \whateverc[P][Q]
407
% \stoptext
408 409
%D This is a checked variant of \type {\getvalue}.
410 411
\unexpanded
\def
\macroname
#
1
% brrr
412
% {\csname\ifcsname#1\endcsname#1\else\s!empty\fi\endcsname}
413
{
\begincsname
#
1
\endcsname
}
414 415
% %D A weird one that I probably needed once, so it might as well become
416
% %D obsolete.
417
%
418
% \unexpanded\def\usecommands#1%
419
% {\begingroup
420
% \def\docommand##1{\setbox\scratchbox\hbox{\csname\string##1\endcsname##1}}%
421
% \processcommalist[#1]\docommand
422
% \endgroup}
423 424
\unexpanded
\def
\syst_log_indeed
#
1
#
2
#
3
%
425
{
\ctxcommand{
systemlog
(
"
#1
"
,
"
#2
"
,
\!!bs
#3
\!!es
)
}
}
426 427
\let
\systemlog
\syst_log_indeed
428 429
\unexpanded
\def
\systemlogfirst
430
{
\ifcase
\directsystemparameter
\c!n
\relax
431
\expandafter
\syst_log_indeed
432
\or
433
\expandafter
\syst_log_indeed
434
\else
435
\expandafter
\gobblethreearguments
436
\fi
}
437 438
\unexpanded
\def
\systemloglast
439
{
\ifcase
\directsystemparameter
\c!n
\relax
440
\expandafter
\syst_log_indeed
441
\or
442
\expandafter
\gobblethreearguments
443
\or
444
\expandafter
\gobblethreearguments
445
\or
446
\expandafter
\gobblethreearguments
447
\or
448
\expandafter
\syst_log_indeed
449
\fi
}
450 451
\protect
\endinput
452