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
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
|
% \iffalse meta-comment
%
%% File: l3sys.dtx
%
% Copyright (C) 2015-2020 The LaTeX3 Project
%
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
% license or (at your option) any later version. The latest version
% of this license is in the file
%
% https://www.latex-project.org/lppl.txt
%
% This file is part of the "l3kernel bundle" (The Work in LPPL)
% and all files in that bundle must be distributed together.
%
% -----------------------------------------------------------------------
%
% The development version of the bundle can be found at
%
% https://github.com/latex3/latex3
%
% for those people who are interested.
%
%<*driver>
\documentclass[full,kernel]{l3doc}
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \title{^^A
% The \pkg{l3sys} package: System/runtime functions^^A
% }
%
% \author{^^A
% The \LaTeX3 Project\thanks
% {^^A
% E-mail:
% \href{mailto:latex-team@latex-project.org}
% {latex-team@latex-project.org}^^A
% }^^A
% }
%
% \date{Released 2020-02-08}
%
% \maketitle
%
% \begin{documentation}
%
% \section{The name of the job}
%
% \begin{variable}[added = 2015-09-19, updated = 2019-10-27]{\c_sys_jobname_str}
% Constant that gets the \enquote{job name} assigned when \TeX{} starts.
% \begin{texnote}
% This copies the contents of the primitive \tn{jobname}. For technical
% reasons, the string here is not of the same internal form as other,
% but may be manipulated using normal string functions.
% \end{texnote}
% \end{variable}
%
% \section{Date and time}
%
% \begin{variable}[added = 2015-09-22]
% {
% \c_sys_minute_int,
% \c_sys_hour_int,
% \c_sys_day_int,
% \c_sys_month_int,
% \c_sys_year_int,
% }
% The date and time at which the current job was started: these are
% all reported as integers.
% \begin{texnote}
% Whilst the underlying primitives can be altered by the user, this
% interface to the time and date is intended to be the \enquote{real}
% values.
% \end{texnote}
% \end{variable}
%
% \section{Engine}
%
% \begin{function}[added = 2015-09-07, EXP, pTF]
% {
% \sys_if_engine_luatex:,
% \sys_if_engine_pdftex:,
% \sys_if_engine_ptex: ,
% \sys_if_engine_uptex: ,
% \sys_if_engine_xetex:
% }
% \begin{syntax}
% \cs{sys_if_engine_pdftex:TF} \Arg{true code} \Arg{false code}
% \end{syntax}
% Conditionals which allow engine-specific code to be used. The names
% follow naturally from those of the engine binaries: note that the
% |(u)ptex| tests are for \epTeX{} and \eupTeX{} as \pkg{expl3} requires
% the \eTeX{} extensions. Each conditional is true for
% \emph{exactly one} supported engine. In particular,
% |\sys_if_engine_ptex_p:| is true for \epTeX{} but false for \eupTeX{}.
% \end{function}
%
% \begin{variable}[added = 2015-09-19]{\c_sys_engine_str}
% The current engine given as a lower case string: one of
% |luatex|, |pdftex|, |ptex|, |uptex| or |xetex|.
% \end{variable}
%
% \section{Output format}
%
% \begin{function}[added = 2015-09-19, EXP, pTF]
% {
% \sys_if_output_dvi:,
% \sys_if_output_pdf:
% }
% \begin{syntax}
% \cs{sys_if_output_dvi:TF} \Arg{true code} \Arg{false code}
% \end{syntax}
% Conditionals which give the current output mode the \TeX{} run is
% operating in. This is always one of two outcomes, DVI mode or
% PDF mode. The two sets of conditionals are thus complementary and
% are both provided to allow the programmer to emphasise the most
% appropriate case.
% \end{function}
%
% \begin{variable}[added = 2015-09-19]{\c_sys_output_str}
% The current output mode given as a lower case string: one of
% |dvi| or |pdf|.
% \end{variable}
%
% \section{Platform}
%
% \begin{function}[added = 2018-07-27, EXP, pTF]
% {
% \sys_if_platform_unix:,
% \sys_if_platform_windows:
% }
% \begin{syntax}
% \cs{sys_if_platform_unix:TF} \Arg{true code} \Arg{false code}
% \end{syntax}
% Conditionals which allow platform-specific code to be used. The names
% follow the \Lua{} |os.type()| function, \emph{i.e.}~all Unix-like systems
% are |unix| (including Linux and MacOS).
% \end{function}
%
% \begin{variable}[added = 2018-07-27]{\c_sys_platform_str}
% The current platform given as a lower case string: one of
% |unix|, |windows| or |unknown|.
% \end{variable}
%
% \section{Random numbers}
%
% \begin{function}[added = 2017-05-27, EXP]{\sys_rand_seed:}
% \begin{syntax}
% \cs{sys_rand_seed:}
% \end{syntax}
% Expands to the current value of the engine's random seed, a
% non-negative integer. In engines without random number support this
% expands to $0$.
% \end{function}
%
% \begin{function}[added = 2017-05-27]{\sys_gset_rand_seed:n}
% \begin{syntax}
% \cs{sys_gset_rand_seed:n} \Arg{intexpr}
% \end{syntax}
% Globally sets the seed for the engine's pseudo-random number
% generator to the \meta{integer expression}. This random seed
% affects all \cs[no-index]{\ldots{}_rand} functions (such as
% \cs{int_rand:nn} or \cs{clist_rand_item:n}) as well as other
% packages relying on the engine's random number generator. In
% engines without random number support this produces an error.
% \begin{texnote}
% While a $32$-bit (signed) integer can be given as a seed, only the
% absolute value is used and any number beyond $2^{28}$ is divided
% by an appropriate power of~$2$. We recommend using an integer in
% $[0,2^{28}-1]$.
% \end{texnote}
% \end{function}
%
% \section{Access to the shell}
%
% \begin{function}[noTF, added = 2019-09-20]
% {\sys_get_shell:nnN}
% \begin{syntax}
% \cs{sys_get_shell:nnN} \Arg{shell~command} \Arg{setup} \meta{tl~var}
% \cs{sys_get_shell:nnNTF} \Arg{shell~command} \Arg{setup} \meta{tl~var} \Arg{true code} \Arg{false code}
% \end{syntax}
% Defines \meta{tl} to the text returned by the \meta{shell command}.
% The \meta{shell command} is converted to a string using
% \cs{tl_to_str:n}. Category codes may need to be set appropriately
% via the \meta{setup} argument, which is run just before running the
% \meta{shell command} (in a group).
% If shell escape is disabled, the \meta{tl~var} will be set to
% \cs{q_no_value} in the non-branching version.
% Note that quote characters (|"|) \emph{cannot} be used inside the
% \meta{shell command}. The \cs{sys_get_shell:nnNTF} conditional
% returns \texttt{true} if the shell is available and no quote is
% detected, and \texttt{false} otherwise.
% \end{function}
%
% \begin{variable}[added = 2017-05-27]{\c_sys_shell_escape_int}
% This variable exposes the internal triple of the shell escape
% status. The possible values are
% \begin{description}
% \item[0] Shell escape is disabled
% \item[1] Unrestricted shell escape is enabled
% \item[2] Restricted shell escape is enabled
% \end{description}
% \end{variable}
%
% \begin{function}[added = 2017-05-27, EXP, pTF]{\sys_if_shell:}
% \begin{syntax}
% \cs{sys_if_shell_p:}
% \cs{sys_if_shell:TF} \Arg{true code} \Arg{false code}
% \end{syntax}
% Performs a check for whether shell escape is enabled. This
% returns true if either of restricted or unrestricted shell escape
% is enabled.
% \end{function}
%
% \begin{function}[added = 2017-05-27, EXP, pTF]{\sys_if_shell_unrestricted:}
% \begin{syntax}
% \cs{sys_if_shell_unrestricted_p:}
% \cs{sys_if_shell_unrestricted:TF} \Arg{true code} \Arg{false code}
% \end{syntax}
% Performs a check for whether \emph{unrestricted} shell escape is
% enabled.
% \end{function}
%
% \begin{function}[added = 2017-05-27, EXP, pTF]{\sys_if_shell_restricted:}
% \begin{syntax}
% \cs{sys_if_shell_restricted_p:}
% \cs{sys_if_shell_restricted:TF} \Arg{true code} \Arg{false code}
% \end{syntax}
% Performs a check for whether \emph{restricted} shell escape is
% enabled. This returns false if unrestricted shell escape is
% enabled. Unrestricted shell escape is not considered a superset
% of restricted shell escape in this case. To find whether any
% shell escape is enabled use \cs{sys_if_shell:}.
% \end{function}
%
% \begin{function}[added = 2017-05-27]{\sys_shell_now:n, \sys_shell_now:x}
% \begin{syntax}
% \cs{sys_shell_now:n} \Arg{tokens}
% \end{syntax}
% Execute \meta{tokens} through shell escape immediately.
% \end{function}
%
% \begin{function}[added = 2017-05-27]{\sys_shell_shipout:n, \sys_shell_shipout:x}
% \begin{syntax}
% \cs{sys_shell_shipout:n} \Arg{tokens}
% \end{syntax}
% Execute \meta{tokens} through shell escape at shipout.
% \end{function}
%
% \subsection{Loading configuration data}
%
% \begin{function}[added = 2019-09-12]{\sys_load_backend:n}
% \begin{syntax}
% \cs{sys_load_backend:n} \Arg{backend}
% \end{syntax}
% Loads the additional configuration file needed for backend support.
% If the \meta{backend} is empty, the standard backend for the engine in
% use will be loaded. This command may only be used once.
% \end{function}
%
% \begin{variable}{\c_sys_backend_str}
% Set to the name of the backend in use by \cs{sys_load_backend:n} when
% issued.
% \end{variable}
%
% \begin{function}[added = 2019-09-12]{\sys_load_debug:, \sys_load_deprecation:}
% \begin{syntax}
% \cs{sys_load_debug:}
% \cs{sys_load_deprecation:}
% \end{syntax}
% Load the additional configuration files for debugging support and rolling
% back deprecations, respectively.
% \end{function}
%
% \subsection{Final settins}
%
% \begin{function}[added = 2019-10-06]{\sys_finalise:}
% \begin{syntax}
% \cs{sys_finalise:}
% \end{syntax}
% Finalises all system-dependent functionality: required before loading
% a backend.
% \end{function}
%
% \end{documentation}
%
% \begin{implementation}
%
% \section{\pkg{l3sys} implementation}
%
% \begin{macrocode}
%<@@=sys>
% \end{macrocode}
%
% \subsection{Kernel code}
%
% \begin{macrocode}
%<*initex|package>
% \end{macrocode}
%
% \subsubsection{Detecting the engine}
%
% \begin{macro}{\@@_const:nn}
% Set the |T|, |F|, |TF|, |p| forms of |#1| to be constants equal to
% the result of evaluating the boolean expression~|#2|.
% \begin{macrocode}
\cs_new_protected:Npn \@@_const:nn #1#2
{
\bool_if:nTF {#2}
{
\cs_new_eq:cN { #1 :T } \use:n
\cs_new_eq:cN { #1 :F } \use_none:n
\cs_new_eq:cN { #1 :TF } \use_i:nn
\cs_new_eq:cN { #1 _p: } \c_true_bool
}
{
\cs_new_eq:cN { #1 :T } \use_none:n
\cs_new_eq:cN { #1 :F } \use:n
\cs_new_eq:cN { #1 :TF } \use_ii:nn
\cs_new_eq:cN { #1 _p: } \c_false_bool
}
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}[pTF, EXP]
% {
% \sys_if_engine_luatex:,
% \sys_if_engine_pdftex:,
% \sys_if_engine_ptex:,
% \sys_if_engine_uptex:,
% \sys_if_engine_xetex:
% }
% \begin{variable}{\c_sys_engine_str}
% Set up the engine tests on the basis exactly one test should be true.
% Mainly a case of looking for the appropriate marker primitive.
% \begin{macrocode}
\str_const:Nx \c_sys_engine_str
{
\cs_if_exist:NT \tex_luatexversion:D { luatex }
\cs_if_exist:NT \tex_pdftexversion:D { pdftex }
\cs_if_exist:NT \tex_kanjiskip:D
{
\cs_if_exist:NTF \tex_enablecjktoken:D
{ uptex }
{ ptex }
}
\cs_if_exist:NT \tex_XeTeXversion:D { xetex }
}
\tl_map_inline:nn { { luatex } { pdftex } { ptex } { uptex } { xetex } }
{
\@@_const:nn { sys_if_engine_ #1 }
{ \str_if_eq_p:Vn \c_sys_engine_str {#1} }
}
% \end{macrocode}
% \end{variable}
% \end{macro}
%
% \subsubsection{Randomness}
%
% This candidate function is placed there because
% \cs{sys_if_rand_exist:TF} is used in \pkg{l3fp-rand}.
%
% \begin{macro}[EXP, pTF]{\sys_if_rand_exist:}
% Currently, randomness exists under \pdfTeX{}, \LuaTeX{}, \pTeX{} and \upTeX{}.
% \begin{macrocode}
\@@_const:nn { sys_if_rand_exist }
{ \cs_if_exist_p:N \tex_uniformdeviate:D }
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Platform}
%
% \begin{macro}[pTF]{\sys_if_platform_unix:, \sys_if_platform_windows:}
% \begin{variable}{\c_sys_platform_str}
% Setting these up requires the file module (file lookup), so is actually
% implemented there.
% \end{variable}
% \end{macro}
%
% \subsubsection{Configurations}
%
% \begin{macro}{\sys_load_backend:n}
% \begin{macro}{\@@_load_backend_check:N}
% \begin{variable}{\c_sys_backend_str}
% Loading the backend code is pretty simply: check that the backend is valid,
% then load it up.
% \begin{macrocode}
\cs_new_protected:Npn \sys_load_backend:n #1
{
\sys_finalise:
\str_if_exist:NTF \c_sys_backend_str
{
\str_if_eq:VnF \c_sys_backend_str {#1}
{ \__kernel_msg_error:nn { sys } { backend-set } }
}
{
\tl_if_blank:nF {#1}
{ \tl_set:Nn \g_@@_backend_tl {#1} }
\@@_load_backend_check:N \g_@@_backend_tl
\str_const:Nx \c_sys_backend_str { \g_@@_backend_tl }
\__kernel_sys_configuration_load:n
{ l3backend- \c_sys_backend_str }
}
}
\cs_new_protected:Npn \@@_load_backend_check:N #1
{
\sys_if_engine_xetex:TF
{
\str_if_eq:VnF #1 { xdvipdfmx }
{
\__kernel_msg_error:nnxx { sys } { wrong-backend }
#1 { xdvipdfmx }
\tl_gset:Nn #1 { xdvipdfmx }
}
}
{
\sys_if_output_pdf:TF
{
\str_if_eq:VnF #1 { pdfmode }
{
\__kernel_msg_error:nnxx { sys } { wrong-backend }
#1 { pdfmode }
\tl_gset:Nn #1 { pdfmode }
}
}
{
\str_case:VnF #1
{
{ dvipdfmx } { }
{ dvips } { }
{ dvisvgm } { }
}
{
\__kernel_msg_error:nnxx { sys } { wrong-backend }
#1 { dvips }
\tl_gset:Nn #1 { dvips }
}
}
}
}
% \end{macrocode}
% \end{variable}
% \end{macro}
% \end{macro}
%
% \begin{variable}{\g_@@_debug_bool, \g_@@_deprecation_bool}
% \begin{macrocode}
\bool_new:N \g_@@_debug_bool
\bool_new:N \g_@@_deprecation_bool
% \end{macrocode}
% \end{variable}
%
% \begin{macro}{\sys_load_debug:, \sys_load_deprecation:}
% Simple.
% \begin{macrocode}
\cs_new_protected:Npn \sys_load_debug:
{
\bool_if:NF \g_@@_debug_bool
{ \__kernel_sys_configuration_load:n { l3debug } }
\bool_gset_true:N \g_@@_debug_bool
}
\cs_new_protected:Npn \sys_load_deprecation:
{
\bool_if:NF \g_@@_deprecation_bool
{ \__kernel_sys_configuration_load:n { l3deprecation } }
\bool_gset_true:N \g_@@_deprecation_bool
}
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Access to the shell}
%
% \begin{variable}{\l_@@_internal_tl}
% \begin{macrocode}
\tl_new:N \l_@@_internal_tl
% \end{macrocode}
% \end{variable}
%
% \begin{variable}{\c_@@_marker_tl}
% The same idea as the marker for rescanning token lists.
% \begin{macrocode}
\tl_const:Nx \c_@@_marker_tl { : \token_to_str:N : }
% \end{macrocode}
% \end{variable}
%
% \begin{macro}[TF]{\sys_get_shell:nnN}
% \begin{macro}{\sys_get_shell:nnN,\@@_get:nnN,\@@_get_do:Nw}
% Setting using a shell is at this level just a slightly specialised file
% operation, with an additional check for quotes, as these are not supported.
% \begin{macrocode}
\cs_new_protected:Npn \sys_get_shell:nnN #1#2#3
{
\sys_get_shell:nnNF {#1} {#2} #3
{ \tl_set:Nn #3 { \q_no_value } }
}
\prg_new_protected_conditional:Npnn \sys_get_shell:nnN #1#2#3 { T , F , TF }
{
\sys_if_shell:TF
{ \exp_args:No \@@_get:nnN { \tl_to_str:n {#1} } {#2} #3 }
{ \prg_return_false: }
}
\cs_new_protected:Npn \@@_get:nnN #1#2#3
{
\tl_if_in:nnTF {#1} { " }
{
\__kernel_msg_error:nnx
{ kernel } { quote-in-shell } {#1}
\prg_return_false:
}
{
\group_begin:
\if_false: { \fi:
\int_set_eq:NN \tex_tracingnesting:D \c_zero_int
\exp_args:No \tex_everyeof:D { \c_@@_marker_tl }
#2 \scan_stop:
\exp_after:wN \@@_get_do:Nw
\exp_after:wN #3
\exp_after:wN \prg_do_nothing:
\tex_input:D | "#1" \scan_stop:
\if_false: } \fi:
\prg_return_true:
}
}
\exp_args:Nno \use:nn
{ \cs_new_protected:Npn \@@_get_do:Nw #1#2 }
{ \c_@@_marker_tl }
{
\group_end:
\tl_set:No #1 {#2}
}
% \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{variable}{\c_@@_shell_stream_int}
% This is not needed for \LuaTeX{}: shell escape there isn't done using
% a \TeX{} interface.
% \begin{macrocode}
\sys_if_engine_luatex:F
{ \int_const:Nn \c_@@_shell_stream_int { 18 } }
% \end{macrocode}
% \end{variable}
%
% \begin{macro}{\sys_shell_now:n}
% Execute commands through shell escape immediately.
% \begin{macrocode}
\sys_if_engine_luatex:TF
{
\cs_new_protected:Npn \sys_shell_now:n #1
{
\lua_now:e
{ l3kernel.shellescape(" \lua_escape:e { \tl_to_str:n {#1} } ") }
}
}
{
\cs_new_protected:Npn \sys_shell_now:n #1
{ \iow_now:Nn \c_@@_shell_stream_int {#1} }
}
\cs_generate_variant:Nn \sys_shell_now:n { x }
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\sys_shell_shipout:n}
% Execute commands through shell escape at shipout.
% \begin{macrocode}
\sys_if_engine_luatex:TF
{
\cs_new_protected:Npn \sys_shell_shipout:n #1
{
\lua_shipout_e:n
{ l3kernel.shellescape(" \lua_escape:e { \tl_to_str:n {#1} } ") }
}
}
{
\cs_new_protected:Npn \sys_shell_shipout:n #1
{ \iow_shipout:Nn \c_@@_shell_stream_int {#1} }
}
\cs_generate_variant:Nn \sys_shell_shipout:n { x }
% \end{macrocode}
% \end{macro}
%
% \subsection{Dynamic (every job) code}
%
% \begin{macro}{\sys_everyjob:}
% \begin{macro}{\@@_everyjob:n}
% \begin{variable}{\g_@@_everyjob_tl}
% \begin{macrocode}
\cs_new_protected:Npn \sys_everyjob:
{
\tl_use:N \g_@@_everyjob_tl
\tl_gclear:N \g_@@_everyjob_tl
}
\cs_new_protected:Npn \@@_everyjob:n #1
{ \tl_gput_right:Nn \g_@@_everyjob_tl {#1} }
\tl_new:N \g_@@_everyjob_tl
% \end{macrocode}
% \end{variable}
% \end{macro}
% \end{macro}
%
% \subsubsection{The name of the job}
%
% \begin{variable}{\c_sys_jobname_str}
% Inherited from the \LaTeX3 name for the primitive. This \emph{has} to be
% the primitive as it's set in \tn{everyjob}. If the user does
% \begin{verbatim}
% pdflatex \input some-file-name
% \end{verbatim}
% then \tn{everyjob} is inserted \emph{before} \tn{jobname} is changed form
% |texput|, and thus we would have the wrong result.
% \begin{macrocode}
\@@_everyjob:n
{ \cs_new_eq:NN \c_sys_jobname_str \tex_jobname:D }
% \end{macrocode}
% \end{variable}
%
% \subsubsection{Time and date}
%
% \begin{variable}
% {
% \c_sys_minute_int,
% \c_sys_hour_int,
% \c_sys_day_int,
% \c_sys_month_int,
% \c_sys_year_int,
% }
% Copies of the information provided by \TeX{}. There is a lot of defensive
% code in package mode: someone may have moved the primitives, and they can
% only be recovered if we have \tn{primitive} and it is working correctly.
% For Ini\TeX{} of course that is all redundant but does no harm.
% \begin{macrocode}
\@@_everyjob:n
{
\group_begin:
\cs_set:Npn \@@_tmp:w #1
{
\str_if_eq:eeTF { \cs_meaning:N #1 } { \token_to_str:N #1 }
{ #1 }
{
\cs_if_exist:NTF \tex_primitive:D
{
\bool_lazy_and:nnTF
{ \sys_if_engine_xetex_p: }
{
\int_compare_p:nNn
{ \exp_after:wN \use_none:n \tex_XeTeXrevision:D }
< { 99999 }
}
{ 0 }
{ \tex_primitive:D #1 }
}
{ 0 }
}
}
\int_const:Nn \c_sys_minute_int
{ \int_mod:nn { \@@_tmp:w \time } { 60 } }
\int_const:Nn \c_sys_hour_int
{ \int_div_truncate:nn { \@@_tmp:w \time } { 60 } }
\int_const:Nn \c_sys_day_int { \@@_tmp:w \day }
\int_const:Nn \c_sys_month_int { \@@_tmp:w \month }
\int_const:Nn \c_sys_year_int { \@@_tmp:w \year }
\group_end:
}
% \end{macrocode}
% \end{variable}
%
% \subsubsection{Random numbers}
%
% \begin{macro}[EXP]{\sys_rand_seed:}
% Unpack the primitive. When random numbers are not available, we
% return zero after an error (and incidentally make sure the number of
% expansions needed is the same as with random numbers available).
% \begin{macrocode}
\@@_everyjob:n
{
\sys_if_rand_exist:TF
{ \cs_new:Npn \sys_rand_seed: { \tex_the:D \tex_randomseed:D } }
{
\cs_new:Npn \sys_rand_seed:
{
\int_value:w
\__kernel_msg_expandable_error:nnn { kernel } { fp-no-random }
{ \sys_rand_seed: }
\c_zero_int
}
}
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\sys_gset_rand_seed:n}
% The primitive always assigns the seed globally.
% \begin{macrocode}
\@@_everyjob:n
{
\sys_if_rand_exist:TF
{
\cs_new_protected:Npn \sys_gset_rand_seed:n #1
{ \tex_setrandomseed:D \int_eval:n {#1} \exp_stop_f: }
}
{
\cs_new_protected:Npn \sys_gset_rand_seed:n #1
{
\__kernel_msg_error:nnn { kernel } { fp-no-random }
{ \sys_gset_rand_seed:n {#1} }
}
}
}
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Access to the shell}
%
% \begin{variable}{\c_sys_shell_escape_int}
% Expose the engine's shell escape status to the user.
% \begin{macrocode}
\@@_everyjob:n
{
\int_const:Nn \c_sys_shell_escape_int
{
\sys_if_engine_luatex:TF
{
\tex_directlua:D
{ tex.sprint(status.shell_escape~or~os.execute()) }
}
{ \tex_shellescape:D }
}
}
% \end{macrocode}
% \end{variable}
%
% \begin{macro}[EXP, pTF]{\sys_if_shell:, \sys_if_shell_unrestricted:, \sys_if_shell_restricted:}
% Performs a check for whether shell escape is enabled. The first set
% of functions returns true if either of restricted or unrestricted
% shell escape is enabled, while the other two sets of functions
% return true in only one of these two cases.
% \begin{macrocode}
\@@_everyjob:n
{
\@@_const:nn { sys_if_shell }
{ \int_compare_p:nNn \c_sys_shell_escape_int > 0 }
\@@_const:nn { sys_if_shell_unrestricted }
{ \int_compare_p:nNn \c_sys_shell_escape_int = 1 }
\@@_const:nn { sys_if_shell_restricted }
{ \int_compare_p:nNn \c_sys_shell_escape_int = 2 }
}
% \end{macrocode}
% \end{macro}
%
% \subsubsection{Held over from \pkg{l3file}}
%
% \begin{variable}{\g_file_curr_name_str}
% See comments about \cs{c_sys_jobname_str}: here, as soon as there is
% file input/output, things get \enquote{tided up}.
% \begin{macrocode}
\@@_everyjob:n
{ \cs_gset_eq:NN \g_file_curr_name_str \tex_jobname:D }
% \end{macrocode}
% \end{variable}
%
% \subsection{Last-minute code}
%
% \begin{macro}{\sys_finalise:}
% \begin{macro}{\@@_finalise:n}
% \begin{variable}{\g_@@_finalise_tl}
% A simple hook to finalise the system-dependent layer. This is forced by
% the backend loader, which is forced by the main loader, so we do not need
% to include that here.
% \begin{macrocode}
\cs_new_protected:Npn \sys_finalise:
{
\sys_everyjob:
\tl_use:N \g_@@_finalise_tl
\tl_gclear:N \g_@@_finalise_tl
}
\cs_new_protected:Npn \@@_finalise:n #1
{ \tl_gput_right:Nn \g_@@_finalise_tl {#1} }
\tl_new:N \g_@@_finalise_tl
% \end{macrocode}
% \end{variable}
% \end{macro}
% \end{macro}
%
% \subsubsection{Detecting the output}
%
% \begin{macro}[pTF, EXP]
% {
% \sys_if_output_dvi:,
% \sys_if_output_pdf:
% }
% \begin{variable}{\c_sys_output_str}
% This is a simple enough concept: the two views here are complementary.
% \begin{macrocode}
\@@_finalise:n
{
\str_const:Nx \c_sys_output_str
{
\int_compare:nNnTF
{ \cs_if_exist_use:NF \tex_pdfoutput:D { 0 } } > { 0 }
{ pdf }
{ dvi }
}
\@@_const:nn { sys_if_output_dvi }
{ \str_if_eq_p:Vn \c_sys_output_str { dvi } }
\@@_const:nn { sys_if_output_pdf }
{ \str_if_eq_p:Vn \c_sys_output_str { pdf } }
}
% \end{macrocode}
% \end{variable}
% \end{macro}
%
% \subsubsection{Configurations}
%
% \begin{variable}{\g_@@_backend_tl}
% As the backend has to be checked and possibly adjusted, the approach here
% is to create a variable and use that in a one-shot to set a constant.
% \begin{macrocode}
\tl_new:N \g_@@_backend_tl
\@@_finalise:n
{
\tl_gset:Nx \g_@@_backend_tl
{
\sys_if_engine_xetex:TF
{ xdvipdfmx }
{
\sys_if_output_pdf:TF
{ pdfmode }
{ dvips }
}
}
}
% \end{macrocode}
% If there is a class option set, and recognised, we pick it up: these
% will over-ride anything set automatically but will themselves be
% over-written if there is a package option.
% \begin{macrocode}
\@@_finalise:n
{
\cs_if_exist:NT \@classoptionslist
{
\cs_if_eq:NNF \@classoptionslist \scan_stop:
{
\clist_map_inline:Nn \@classoptionslist
{
\str_case:nnT {#1}
{
{ dvipdfmx }
{ \tl_gset:Nn \g_@@_backend_tl { dvipdfmx } }
{ dvips }
{ \tl_gset:Nn \g_@@_backend_tl { dvips } }
{ dvisvgm }
{ \tl_gset:Nn \g_@@_backend_tl { dvisvgm } }
{ pdftex }
{ \tl_gset:Nn \g_@@_backend_tl { pdfmode } }
{ xetex }
{ \tl_gset:Nn \g_@@_backend_tl { xdvipdfmx } }
}
{ \clist_remove_all:Nn \@unusedoptionlist {#1} }
}
}
}
}
% \end{macrocode}
% \end{variable}
%
% \begin{macrocode}
%</initex|package>
% \end{macrocode}
%
%\end{implementation}
%
%\PrintIndex
|