summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2017-04-16 22:19:40 +0000
committerKarl Berry <karl@freefriends.org>2017-04-16 22:19:40 +0000
commitcacc7d77918eb955a4bc5bed894e8ea1445a6ba4 (patch)
tree54307a98b0d3dafd1998f2135dcfe9237f38f9af /Master/texmf-dist/tex
parentb1e4ebb4febbc920047445c1f1416bb2f6a563f7 (diff)
morewrites (14apr17)
git-svn-id: svn://tug.org/texlive/trunk@43862 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r--Master/texmf-dist/tex/latex/morewrites/morewrites.sty612
-rw-r--r--Master/texmf-dist/tex/latex/morewrites/primargs.sty242
2 files changed, 610 insertions, 244 deletions
diff --git a/Master/texmf-dist/tex/latex/morewrites/morewrites.sty b/Master/texmf-dist/tex/latex/morewrites/morewrites.sty
index 37b4f4838b6..5f87462496a 100644
--- a/Master/texmf-dist/tex/latex/morewrites/morewrites.sty
+++ b/Master/texmf-dist/tex/latex/morewrites/morewrites.sty
@@ -9,7 +9,7 @@
%% Communicate any suggestions for changing this package
%% to Bruno Le Floch (blflatex@gmail.com).
%%
-%% File: morewrites.dtx Copyright (C) 2011-2013 Bruno Le Floch
+%% File: morewrites.dtx Copyright (C) 2011-2017 Bruno Le Floch
%%
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
@@ -19,225 +19,401 @@
%% http://www.latex-project.org/lppl.txt
%%
%% -----------------------------------------------------------------------
-\RequirePackage {expl3} [2012/08/14]
-\RequirePackage {primargs} [2013/01/08]
+\RequirePackage {expl3} [2017/03/18]
+\RequirePackage {primargs} [2017/04/10]
\ProvidesExplPackage
- {morewrites} {2013/01/08} {0.2e} {Always room for a new write}
-\cs_generate_variant:Nn \prop_gpop:NnNT { NV }
+ {morewrites} {2017/04/10} {} {Always room for a new write}
+\sys_if_engine_luatex:T
+ {
+ \cs_new_protected:Npn \morewritessetup #1 { }
+ \msg_new:nnn { morewrites } { luatex }
+ { The~morewrites~package~is~unnecessary~in~LuaTeX. }
+ \msg_warning:nn { morewrites } { luatex }
+ \tex_endinput:D
+ }%
\cs_new_eq:NN \__morewrites_tex_immediate:w \tex_immediate:D
\cs_new_eq:NN \__morewrites_tex_openout:w \tex_openout:D
\cs_new_eq:NN \__morewrites_tex_write:w \tex_write:D
\cs_new_eq:NN \__morewrites_tex_closeout:w \tex_closeout:D
-\cs_new_eq:NN \__morewrites_tex_shipout:w \tex_shipout:D
-\int_new:N \g__morewrites_late_write_int
-\prop_new:N \g__morewrites_iow_prop
+\cs_new_eq:NN \__morewrites_tex_openin:w \tex_openin:D
+\cs_new_eq:NN \__morewrites_tex_read:w \tex_read:D
+\cs_new_eq:NN \__morewrites_tex_readline:w \etex_readline:D
+\cs_new_eq:NN \__morewrites_tex_closein:w \tex_closein:D
+\exp_args:NNf \cs_new_protected:Npn \__morewrites_tex_newread:N
+ { \exp_args:NNc \exp_after:wN \exp_stop_f: { newread } }
+\exp_args:NNf \cs_new_protected:Npn \__morewrites_tex_newwrite:N
+ { \exp_args:NNc \exp_after:wN \exp_stop_f: { newwrite } }
+\cs_generate_variant:Nn \prop_gpop:NnNT { NV }
+\cs_generate_variant:Nn \prop_gput:Nnn { NVx }
+\cs_generate_variant:Nn \tl_gput_right:Nn { Nv }
+\tl_new:N \l__morewrites_internal_tl
+\cs_new_eq:NN \__morewrites_tmp:w ?
+\int_new:N \g__morewrites_later_int
+\seq_new:N \g__morewrites_read_seq
+\seq_new:N \g__morewrites_write_seq
+\prop_new:N \g__morewrites_read_prop
+\prop_new:N \g__morewrites_write_prop
+\prop_new:N \g__morewrites_write_file_prop
+\tl_new:N \l__morewrites_code_tl
+\int_new:N \l__morewrites_user_int
+\tl_new:N \l__morewrites_tstr_tl
+\cs_new_eq:NN \l__morewrites_tstr_token ?
+\cs_new_eq:NN \s__morewrites \scan_stop:
\newwrite \g__morewrites_iow
\newread \g__morewrites_ior
\tl_new:N \g__morewrites_tmp_file_tl
-\tl_gset:Nn \g__morewrites_tmp_file_tl { \jobname.mw }
-\clist_new:N \g__morewrites_reserved_iow_clist
-\int_step_inline:nnnn {0} {1} { \g__morewrites_iow - 1 }
- { \clist_gput_right:Nn \g__morewrites_reserved_iow_clist {#1} }
-\clist_gput_right:Nn \g__morewrites_reserved_iow_clist {18}
-\int_new:N \g__morewrites_stream_int
-\cs_new_eq:NN \s__morewrites \scan_stop:
-\tl_new:N \l__morewrites_internal_tl
-\cs_new_protected:Npn \__morewrites_equals_file_name:N #1
+\bool_new:N \g__morewrites_tmp_file_bool
+\bool_gset_false:N \g__morewrites_tmp_file_bool
+\int_new:N \g__morewrites_group_level_int
+\box_new:N \g__morewrites_shipout_box
+\cs_new_protected:Npn \__morewrites_set_file:n #1
+ {
+ \bool_gset_false:N \g__morewrites_tmp_file_bool
+ \tl_gset:Nn \g__morewrites_tmp_file_tl {#1}
+ }
+\cs_new_protected:Npn \__morewrites_empty_file:n #1
+ {
+ \__morewrites_tex_immediate:w \__morewrites_tex_openout:w
+ \g__morewrites_iow = #1 \scan_stop:
+ \__morewrites_tex_immediate:w \__morewrites_tex_closeout:w
+ \g__morewrites_iow
+ }
+\prg_new_conditional:Npnn \__morewrites_if_file_trivial:n #1 { TF }
{
\group_begin:
+ \tex_openin:D \g__morewrites_ior = #1 \scan_stop:
+ \if_eof:w \g__morewrites_ior
+ \cs_gset_eq:NN \__morewrites_tmp:w \prg_return_true:
+ \else:
+ \int_set:Nn \tex_endlinechar:D { -1 }
+ \etex_readline:D \g__morewrites_ior to \l__morewrites_internal_tl
+ \if_eof:w \g__morewrites_ior
+ \cs_gset_eq:NN \__morewrites_tmp:w \prg_return_true:
+ \else:
+ \cs_gset_eq:NN \__morewrites_tmp:w \prg_return_false:
+ \fi:
+ \fi:
+ \tex_closein:D \g__morewrites_ior
+ \group_end:
+ \__morewrites_tmp:w
+ }
+\cs_new_protected:Npn \__morewrites_chk_file:
+ {
+ \__morewrites_if_file_trivial:nTF { \g__morewrites_tmp_file_tl }
+ { \bool_gset_true:N \g__morewrites_tmp_file_bool }
+ {
+ \msg_warning:nnxx { morewrites } { file-exists }
+ { \g__morewrites_tmp_file_tl }
+ { \g__morewrites_tmp_file_tl .mw }
+ \tl_gput_right:Nn \g__morewrites_tmp_file_tl { .mw }
+ \__morewrites_chk_file:
+ }
+ }
+\msg_new:nnnn { morewrites } { file-exists }
+ { File~'#1'~exists,~using~'#2'~instead. }
+ {
+ The~file~`#1'~exists~and~was~not~created~by~this~version~of~the~
+ `morewrites'~package.~Please~move~or~delete~that~file,~or~provide~
+ another~file~name~by~adding
+ \\ \\
+ \iow_indent:n { \iow_char:N\\morewritessetup~{~file~=~other-name~} }
+ \\ \\
+ to~your~source~file.~In~the~meantime,~the~file~`#2'~will~be~used.
+ }
+\cs_new_protected:Npn \__morewrites_equals_file:N #1
+ {
+ \group_begin:
+ \tex_aftergroup:D \primargs_get_file_name:N
\tex_aftergroup:D #1
- \primargs_remove_equals:N \__morewrites_parse_file_name:
+ \primargs_remove_equals:N \group_end:
}
-\cs_new_protected_nopar:Npn \__morewrites_parse_file_name:
- { \primargs_get_file_name:N \group_end: }
-\cs_new_protected_nopar:Npn \__morewrites_immediate:w
- { \primargs_read_x_token:N \__morewrites_immediate_ii: }
-\cs_new_protected_nopar:Npn \__morewrites_immediate_ii:
+\cs_new_protected:Npn \__morewrites_get_user:n #1
{
- \token_if_eq_meaning:NNTF \g_primargs_token \s__morewrites
- { \__morewrites_immediate_iii:N }
- { \__morewrites_tex_immediate:w }
+ \tl_set:Nn \l__morewrites_code_tl {#1}
+ \tex_afterassignment:D \l__morewrites_code_tl
+ \l__morewrites_user_int =
}
-\cs_new_protected:Npn \__morewrites_immediate_iii:N #1
+\cs_new_protected:Npn \__morewrites_user_to_tstr:NTF #1
{
- \tl_if_eq:nnTF { #1 } { \s__morewrites }
- { \__morewrites_immediate_iv:NN }
- { #1 }
+ \tl_set:NV \l__morewrites_tstr_tl \l__morewrites_user_int
+ \int_compare:nNnTF { \l__morewrites_user_int } < { 19 }
+ { \use_i:nn }
+ { \prop_get:NVNTF #1 \l__morewrites_user_int \l__morewrites_tstr_tl }
}
-\cs_new_protected:Npn \__morewrites_immediate_iv:NN #1 #2
+\int_new:N \l__morewrites_collect_next_int
+\cs_new_protected:Npn \__morewrites_collect:x #1
{
- \exp_args:Nc #1
+ \tl_set:Nx \l__morewrites_internal_tl {#1}
+ \__morewrites_collect_aux:cf { l__morewrites_0_tl } { 1 }
+ }
+\cs_new_protected:Npn \__morewrites_collect_aux:Nn #1#2
+ {
+ \int_compare:nNnT {#2} > \l__morewrites_collect_next_int
+ {
+ \tl_clear_new:N #1
+ \int_set:Nn \l__morewrites_collect_next_int {#2}
+ }
+ \tl_if_empty:NTF #1
+ { \tl_set_eq:NN #1 \l__morewrites_internal_tl }
{
- \exp_after:wN \__morewrites_immediate_v:w
- \token_to_str:N #2
+ \tl_put_left:No \l__morewrites_internal_tl {#1}
+ \tl_clear:N #1
+ \__morewrites_collect_aux:cf { l__morewrites_#2_tl }
+ { \int_eval:n { #2 + 1 } }
}
}
-\use:x
+\cs_generate_variant:Nn \__morewrites_collect_aux:Nn { cf }
+\cs_new_protected:Npn \__morewrites_collect_gput_right:N #1
{
- \cs_new:Npn \exp_not:N \__morewrites_immediate_v:w
- ##1 \tl_to_str:n { __morewrites } { __morewrites_immediate }
+ \int_compare:nNnF \l__morewrites_collect_next_int = 0
+ {
+ \int_decr:N \l__morewrites_collect_next_int
+ \tl_gput_right:Nv #1
+ {
+ l__morewrites_
+ \int_use:N \l__morewrites_collect_next_int
+ _tl
+ }
+ \__morewrites_collect_gput_right:N #1
+ }
+ }
+\cs_generate_variant:Nn \__morewrites_collect_gput_right:N { c }
+\cs_new:Npn \__morewrites_user_tl_name:n #1
+ { g__morewrites_iow_ \int_eval:n {#1} _tl }
+\cs_new_protected:Npn \__morewrites_openin:w
+ {
+ \__morewrites_get_user:n
+ {
+ \__morewrites_user_to_tstr:NTF \g__morewrites_read_prop { }
+ {
+ \seq_pop:NNF \g__morewrites_read_seq \l__morewrites_tstr_tl
+ {
+ \__morewrites_tex_newread:N \l__morewrites_tstr_token
+ \tl_set:NV \l__morewrites_tstr_tl \l__morewrites_tstr_token
+ }
+ \prop_gput:NVV \g__morewrites_read_prop \l__morewrites_user_int \l__morewrites_tstr_tl
+ }
+ \__morewrites_tex_openin:w \l__morewrites_tstr_tl \exp_stop_f:
+ }
}
-\cs_new_protected:Npn \__morewrites_immediate_closeout_test:n #1
+\cs_new_protected:Npn \__morewrites_read:w
{
- \int_gset:Nn \g__morewrites_stream_int {#1}
- \clist_if_in:NnTF \g__morewrites_reserved_iow_clist {#1}
- { \__morewrites_tex_immediate:w \__morewrites_tex_closeout:w \g__morewrites_stream_int }
- { \__morewrites_immediate_closeout_aux: }
+ \__morewrites_get_user:n
+ {
+ \__morewrites_user_to_tstr:NTF \g__morewrites_read_prop { } { }
+ \__morewrites_tex_read:w \l__morewrites_tstr_tl \exp_stop_f:
+ }
}
-\cs_new_protected_nopar:Npn \__morewrites_immediate_closeout_aux:
+\cs_new_protected:Npn \__morewrites_readline:w
{
- \prop_gpop:NVNT \g__morewrites_iow_prop \g__morewrites_stream_int \l__morewrites_internal_tl
+ \__morewrites_get_user:n
{
- \__morewrites_immediate_write_and_close:nn
- { \g__morewrites_stream_int } { \l__morewrites_internal_tl }
+ \__morewrites_user_to_tstr:NTF \g__morewrites_read_prop { } { }
+ \__morewrites_tex_readline:w \l__morewrites_tstr_tl \exp_stop_f:
}
}
-\cs_new_protected:Npn \__morewrites_immediate_write_and_close:nn #1#2
+\cs_new_protected:Npn \__morewrites_closein:w
{
- \__morewrites_tex_immediate:w \__morewrites_tex_openout:w
- \g__morewrites_iow #2 \scan_stop:
+ \__morewrites_get_user:n
+ {
+ \__morewrites_user_to_tstr:NTF \g__morewrites_read_prop { } { }
+ \int_compare:nNnF { \l__morewrites_tstr_tl } = { \l__morewrites_user_int }
+ {
+ \prop_gremove:NV \g__morewrites_read_prop \l__morewrites_user_int
+ \seq_gput_left:NV \g__morewrites_read_seq \l__morewrites_tstr_tl
+ }
+ \__morewrites_tex_closein:w \l__morewrites_tstr_tl \exp_stop_f:
+ }
+ }
+\cs_new_protected:Npn \__morewrites_immediate:w
+ { \primargs_read_x_token:N \__morewrites_immediate_auxii: }
+\cs_new_protected:Npn \__morewrites_immediate_auxii:
+ {
+ \token_if_eq_meaning:NNTF \g_primargs_token \s__morewrites
+ { \__morewrites_immediate_auxiii:N }
+ { \__morewrites_tex_immediate:w }
+ }
+\cs_new_protected:Npn \__morewrites_immediate_auxiii:N #1
+ { \str_if_eq:nnTF { #1 } { \s__morewrites } { \use_iii:nnn } { #1 } }
+\cs_new_protected:Npn \__morewrites_closeout:w
+ {
+ \s__morewrites
+ \use_i:nn
+ { \__morewrites_get_user:n { \__morewrites_closeout_later: } }
+ { \__morewrites_get_user:n { \__morewrites_closeout_now: } }
+ }
+\cs_new_protected:Npn \__morewrites_closeout_now:
+ {
+ \__morewrites_user_to_tstr:NTF \g__morewrites_write_prop
+ {
+ \__morewrites_tex_immediate:w \__morewrites_tex_closeout:w \l__morewrites_tstr_tl \exp_stop_f:
+ \int_compare:nNnF { \l__morewrites_tstr_tl } = { \l__morewrites_user_int }
+ {
+ \prop_gremove:NV \g__morewrites_write_prop \l__morewrites_user_int
+ \seq_gput_left:NV \g__morewrites_write_seq \l__morewrites_tstr_tl
+ }
+ }
+ {
+ \prop_gpop:NVNT \g__morewrites_write_file_prop \l__morewrites_user_int \l__morewrites_internal_tl
+ { \__morewrites_closeout_now:nn { \l__morewrites_user_int } { \l__morewrites_internal_tl } }
+ }
+ }
+\cs_new_protected:Npn \__morewrites_closeout_now:nn #1#2
+ {
+ \__morewrites_tex_immediate:w \__morewrites_tex_openout:w \g__morewrites_iow = #2 \scan_stop:
\group_begin:
- \int_set_eq:NN \tex_newlinechar:D \c_minus_one
- \tl_use:c { g__morewrites_iow_ \int_eval:n {#1} _tl }
- \tl_gclear:c { g__morewrites_iow_ \int_eval:n {#1} _tl }
+ \int_set:Nn \tex_newlinechar:D { -1 }
+ \tl_use:c { \__morewrites_user_tl_name:n {#1} }
+ \tl_gclear:c { \__morewrites_user_tl_name:n {#1} }
\group_end:
\__morewrites_tex_immediate:w \__morewrites_tex_closeout:w \g__morewrites_iow
}
-\cs_new_protected:Npn \__morewrites_immediate_openout_test:n #1
+\cs_new_protected:Npn \__morewrites_openout:w
{
- \int_gset:Nn \g__morewrites_stream_int {#1}
- \clist_if_in:NnTF \g__morewrites_reserved_iow_clist {#1}
- { \__morewrites_tex_immediate:w \__morewrites_tex_openout:w \g__morewrites_stream_int }
- { \__morewrites_equals_file_name:N \__morewrites_immediate_openout_aux:n }
+ \s__morewrites
+ \use_i:nn
+ { \__morewrites_get_user:n { \__morewrites_openout_later:w } }
+ { \__morewrites_get_user:n { \__morewrites_equals_file:N \__morewrites_openout_now:n } }
}
-\cs_new_protected:Npn \__morewrites_immediate_openout_aux:n #1
+\cs_new_protected:Npn \__morewrites_openout_now:n #1
{
- \__morewrites_immediate_closeout_aux:
- \prop_gput:NVn \g__morewrites_iow_prop \g__morewrites_stream_int {#1}
- \tl_gclear_new:c { g__morewrites_iow_ \int_use:N \g__morewrites_stream_int _tl }
+ \__morewrites_closeout_now:
+ \seq_pop:NNTF \g__morewrites_write_seq \l__morewrites_tstr_tl
+ {
+ \prop_gput:NVV \g__morewrites_write_prop \l__morewrites_user_int \l__morewrites_tstr_tl
+ \__morewrites_tex_immediate:w \__morewrites_tex_openout:w \l__morewrites_tstr_tl \exp_stop_f:
+ = \tl_to_str:n {#1} \scan_stop:
+ }
+ {
+ \__morewrites_empty_file:n {#1}
+ \prop_gput:NVx \g__morewrites_write_file_prop \l__morewrites_user_int
+ { \tl_to_str:n {#1} }
+ \tl_gclear_new:c { \__morewrites_user_tl_name:n { \l__morewrites_user_int } }
+ }
}
-\cs_new_protected:Npn \__morewrites_immediate_write_test:n #1
+\cs_new_protected:Npn \__morewrites_write:w
{
- \int_gset:Nn \g__morewrites_stream_int {#1}
- \clist_if_in:NnTF \g__morewrites_reserved_iow_clist {#1}
- { \__morewrites_tex_immediate:w \__morewrites_tex_write:w \g__morewrites_stream_int }
- { \primargs_get_general_text:N \__morewrites_immediate_write_aux:n }
+ \s__morewrites
+ \use_i:nn
+ { \__morewrites_get_user:n { \__morewrites_write_later:w } }
+ { \__morewrites_get_user:n { \__morewrites_write_now:w } }
}
-\cs_new_protected_nopar:Npn \__morewrites_immediate_write_aux:n
+\cs_new_protected:Npn \__morewrites_write_now:w
{
- \prop_get:NVNTF \g__morewrites_iow_prop \g__morewrites_stream_int \l__morewrites_internal_tl
- { \__morewrites_immediate_write_open:n }
- { \__morewrites_immediate_write_closed:n }
+ \__morewrites_user_to_tstr:NTF \g__morewrites_write_prop
+ { \__morewrites_tex_immediate:w \__morewrites_tex_write:w \l__morewrites_tstr_tl \exp_stop_f: }
+ { \primargs_get_general_text:N \__morewrites_write_now:n }
}
-\cs_new_protected:Npn \__morewrites_immediate_write_closed:n #1
+\cs_new_protected:Npn \__morewrites_write_now:n
{
- \__morewrites_tex_immediate:w \__morewrites_tex_write:w
- \if_int_compare:w \g__morewrites_stream_int < \c_zero
- -1
- \else:
- 16
- \fi:
- {#1}
+ \prop_get:NVNTF \g__morewrites_write_file_prop \l__morewrites_user_int \l__morewrites_internal_tl
+ { \__morewrites_write_now_open:n }
+ { \__morewrites_tex_immediate:w \__morewrites_tex_write:w 16 }
}
-\cs_new_protected:Npn \__morewrites_immediate_write_open:n #1
+\cs_new_protected:Npn \__morewrites_write_now_open:n #1
{
- \__morewrites_tex_immediate:w \__morewrites_tex_openout:w \g__morewrites_iow
- \g__morewrites_tmp_file_tl \scan_stop:
- \__morewrites_tex_immediate:w \__morewrites_tex_write:w \g__morewrites_iow {#1}
- \__morewrites_tex_immediate:w \__morewrites_tex_closeout:w \g__morewrites_iow
+ \bool_if:NF \g__morewrites_tmp_file_bool { \__morewrites_chk_file: }
+ \__morewrites_tex_immediate:w \__morewrites_tex_openout:w
+ \g__morewrites_iow = \g__morewrites_tmp_file_tl \scan_stop:
+ \__morewrites_tex_immediate:w \__morewrites_tex_write:w
+ \g__morewrites_iow {#1}
+ \__morewrites_tex_immediate:w \__morewrites_tex_closeout:w
+ \g__morewrites_iow
\group_begin:
- \int_set_eq:NN \tex_endlinechar:D \c_minus_one
- \tex_openin:D \g__morewrites_ior \g__morewrites_tmp_file_tl \scan_stop:
- \__morewrites_immediate_write_readlines_loop:
+ \int_set:Nn \tex_endlinechar:D { -1 }
+ \tex_openin:D \g__morewrites_ior = \g__morewrites_tmp_file_tl \scan_stop:
+ \__morewrites_write_now_loop:
\tex_closein:D \g__morewrites_ior
+ \__morewrites_collect_gput_right:c
+ { \__morewrites_user_tl_name:n { \l__morewrites_user_int } }
\group_end:
+ \__morewrites_empty_file:n { \g__morewrites_tmp_file_tl }
}
-\cs_new_protected_nopar:Npn \__morewrites_immediate_write_readlines_loop:
+\cs_new_protected:Npn \__morewrites_write_now_loop:
{
\etex_readline:D \g__morewrites_ior to \l__morewrites_internal_tl
\ior_if_eof:NF \g__morewrites_ior
{
- \tl_gput_right:cx
- { g__morewrites_iow_ \int_use:N \g__morewrites_stream_int _tl }
+ \__morewrites_collect:x
{
- \__morewrites_tex_immediate:w \__morewrites_tex_write:w \g__morewrites_iow
- { \l__morewrites_internal_tl }
+ \__morewrites_tex_immediate:w \__morewrites_tex_write:w
+ \g__morewrites_iow { \l__morewrites_internal_tl }
}
- \__morewrites_immediate_write_readlines_loop:
+ \__morewrites_write_now_loop:
}
}
-\cs_new_protected:Npn \__morewrites_late:n #1
+\cs_new_protected:Npn \__morewrites_later:n #1
{
- \int_gincr:N \g__morewrites_late_write_int
+ \int_gincr:N \g__morewrites_later_int
\tl_const:cx
{
- c__morewrites_late_write_
- \int_use:N \g__morewrites_late_write_int
+ c__morewrites_later_
+ \int_use:N \g__morewrites_later_int
_tl
}
{
- \int_gset:Nn \exp_not:N \g__morewrites_stream_int
- { \exp_not:V \g__morewrites_stream_int }
+ \int_set:Nn \exp_not:N \l__morewrites_user_int
+ { \exp_not:V \l__morewrites_user_int }
\exp_not:n {#1}
}
\exp_args:NNx \__morewrites_tex_write:w \g__morewrites_iow
- { `( \int_use:N \g__morewrites_late_write_int ) }
+ { `( \int_use:N \g__morewrites_later_int ) }
}
-\cs_new_protected_nopar:Npn \__morewrites_openout:w
- { \s__morewrites \primargs_get_number:N \__morewrites_openout_test:n }
-\cs_new_protected:Npn \__morewrites_openout_test:n #1
+\cs_new_protected:Npn \__morewrites_later_do:n #1
+ { \tl_use:c { c__morewrites_later_ \int_eval:n {#1} _tl } }
+\cs_new_protected:Npn \__morewrites_closeout_later:
{
- \int_gset:Nn \g__morewrites_stream_int {#1}
- \clist_if_in:NnTF \g__morewrites_reserved_iow_clist {#1}
- { \__morewrites_tex_openout:w \g__morewrites_stream_int }
- { \__morewrites_equals_file_name:N \__morewrites_openout_aux:n }
+ \int_compare:nNnTF \l__morewrites_user_int < { 19 }
+ { \__morewrites_tex_closeout:w \l__morewrites_user_int }
+ { \__morewrites_later:n { \__morewrites_closeout_now: } }
}
-\cs_new_protected:Npn \__morewrites_openout_aux:n #1
- { \__morewrites_late:n { \__morewrites_immediate_openout_aux:n {#1} } }
-\cs_new_protected_nopar:Npn \__morewrites_write:w
- { \s__morewrites \primargs_get_number:N \__morewrites_write_test:n }
-\cs_new_protected:Npn \__morewrites_write_test:n #1
+\cs_new_protected:Npn \__morewrites_openout_later:w
{
- \int_gset:Nn \g__morewrites_stream_int {#1}
- \clist_if_in:NnTF \g__morewrites_reserved_iow_clist {#1}
- { \__morewrites_tex_write:w \g__morewrites_stream_int }
- { \primargs_get_general_text:N \__morewrites_write_aux:n }
+ \int_compare:nNnTF \l__morewrites_user_int < { 19 }
+ { \__morewrites_tex_openout:w \l__morewrites_user_int }
+ { \__morewrites_equals_file:N \__morewrites_openout_later:n }
}
-\cs_new_protected:Npn \__morewrites_write_aux:n #1
- { \__morewrites_late:n { \__morewrites_immediate_write_aux:n {#1} } }
-\cs_new_protected_nopar:Npn \__morewrites_closeout:w
- { \s__morewrites \primargs_get_number:N \__morewrites_closeout_test:n }
-\cs_new_protected:Npn \__morewrites_closeout_test:n #1
+\cs_new_protected:Npn \__morewrites_openout_later:n #1
+ { \__morewrites_later:n { \__morewrites_openout_now:n {#1} } }
+\cs_new_protected:Npn \__morewrites_write_later:w
{
- \int_gset:Nn \g__morewrites_stream_int {#1}
- \clist_if_in:NnTF \g__morewrites_reserved_iow_clist {#1}
- { \__morewrites_tex_closeout:w \g__morewrites_stream_int }
- { \__morewrites_closeout_aux: }
+ \int_compare:nNnTF \l__morewrites_user_int < { 19 }
+ { \__morewrites_tex_write:w \l__morewrites_user_int }
+ { \primargs_get_general_text:N \__morewrites_write_later:n }
}
-\cs_new_protected_nopar:Npn \__morewrites_closeout_aux:
- { \__morewrites_late:n { \__morewrites_immediate_closeout_aux: } }
-\cs_new_protected_nopar:Npn \__morewrites_before_shipout:
+\cs_new_protected:Npn \__morewrites_write_later:n #1
+ { \__morewrites_later:n { \__morewrites_write_later_aux:n {#1} } }
+\cs_new_protected:Npn \__morewrites_write_later_aux:n
{
- \__morewrites_tex_immediate:w \__morewrites_tex_openout:w \g__morewrites_iow
- \g__morewrites_tmp_file_tl \scan_stop:
+ \__morewrites_user_to_tstr:NTF \g__morewrites_write_prop
+ { \__morewrites_tex_immediate:w \__morewrites_tex_write:w \l__morewrites_tstr_tl \exp_stop_f: }
+ { \__morewrites_write_now:n }
}
-\cs_new_protected_nopar:Npn \__morewrites_after_shipout:
+\cs_new_protected:Npn \__morewrites_before_shipout:
{
- \__morewrites_tex_immediate:w \__morewrites_tex_closeout:w \g__morewrites_iow
+ \bool_if:NF \g__morewrites_tmp_file_bool { \__morewrites_chk_file: }
+ \__morewrites_tex_immediate:w \__morewrites_tex_openout:w
+ \g__morewrites_iow = \g__morewrites_tmp_file_tl \scan_stop:
+ }
+\cs_new_protected:Npn \__morewrites_after_shipout:
+ {
+ \__morewrites_tex_immediate:w \__morewrites_tex_closeout:w
+ \g__morewrites_iow
\group_begin:
\int_set_eq:NN \tex_endlinechar:D \tex_newlinechar:D
\char_set_catcode_other:n { \tex_endlinechar:D }
\tl_map_inline:nn { `(0123456789) }
{ \char_set_catcode_other:n {`##1} }
\etex_everyeof:D { `() \exp_not:N }
- \tl_gset:Nx \g__morewrites_internal_tl
+ \tl_set:Nx \l__morewrites_internal_tl
{
\exp_after:wN \__morewrites_after_shipout_loop:ww
\tex_input:D \g__morewrites_tmp_file_tl \c_space_tl
}
+ \__morewrites_empty_file:n { \g__morewrites_tmp_file_tl }
+ \exp_args:NNo
\group_end:
- \tl_map_inline:Nn \g__morewrites_internal_tl
- { \tl_use:c { c__morewrites_late_write_ ##1 _tl } }
+ \tl_map_function:nN { \l__morewrites_internal_tl } \__morewrites_later_do:n
}
\cs_new:Npn \__morewrites_after_shipout_loop:ww #1 `( #2 )
{
@@ -247,81 +423,93 @@
\__morewrites_after_shipout_loop:ww
}
}
-\IfFileExists{atbegshi.sty}
+\cs_new_protected:Npn \__morewrites_shipout:w
{
- \RequirePackage{atbegshi}
- \tl_replace_once:Nnn \AtBegShi@Output
- { \AtBegShi@OrgShipout \box \AtBeginShipoutBox }
- {
- \__morewrites_before_shipout:
- \AtBegShi@OrgShipout \box \AtBeginShipoutBox
- \__morewrites_after_shipout:
- }
- \tl_replace_once:Nnn \AtBegShi@Output
- { \AtBeginShipoutOriginalShipout \box \AtBeginShipoutBox }
- {
- \__morewrites_before_shipout:
- \AtBeginShipoutOriginalShipout \box \AtBeginShipoutBox
- \__morewrites_after_shipout:
- }
+ \int_gset_eq:NN \g__morewrites_group_level_int \etex_currentgrouplevel:D
+ \tex_afterassignment:D \__morewrites_shipout_i:
+ \tex_global:D \tex_setbox:D \g__morewrites_shipout_box
}
+\cs_new_protected:Npn \__morewrites_shipout_i:
{
- \int_new:N \g__morewrites_group_level_int
- \box_new:N \g__morewrites_shipout_box
- \cs_new_protected_nopar:Npn \__morewrites_shipout:w
- {
- \int_gset_eq:NN \g__morewrites_group_level_int \etex_currentgrouplevel:D
- \tex_afterassignment:D \__morewrites_shipout_i:
- \tex_global:D \tex_setbox:D \g__morewrites_shipout_box
- }
- \cs_new_protected_nopar:Npn \__morewrites_shipout_i:
- {
- \int_compare:nNnTF { \g__morewrites_group_level_int }
- = { \etex_currentgrouplevel:D }
- { \__morewrites_shipout_ii: }
- { \tex_aftergroup:D \__morewrites_shipout_ii: }
- }
- \cs_new_protected_nopar:Npn \__morewrites_shipout_ii:
- {
- \__morewrites_before_shipout:
- \__morewrites_tex_shipout:w \tex_box:D \g__morewrites_shipout_box
- \__morewrites_after_shipout:
- }
- \AtBeginDocument { \cs_gset_eq:NN \shipout \__morewrites_shipout:w }
+ \int_compare:nNnTF { \g__morewrites_group_level_int }
+ = { \etex_currentgrouplevel:D }
+ { \__morewrites_shipout_ii: }
+ { \tex_aftergroup:D \__morewrites_shipout_ii: }
}
-\int_new:N \g__morewrites_at_end_int
-\int_gset:Nn \g__morewrites_at_end_int { 10 }
-\cs_new_protected_nopar:Npn \__morewrites_close_all:
+\cs_new_protected:Npn \__morewrites_shipout_ii:
{
- \prop_map_function:NN \g__morewrites_iow_prop
- \__morewrites_immediate_write_and_close:nn
- \prop_gclear:N \g__morewrites_iow_prop
+ \__morewrites_before_shipout:
+ \__morewrites_tex_shipout:w \tex_box:D \g__morewrites_shipout_box
+ \__morewrites_after_shipout:
}
-\cs_set:Npn \__morewrites_tmp:w #1
+\cs_gset_protected:Npn \__morewrites_tmp:w #1
{
- \cs_new_protected:Npn \__morewrites_close_all_at_end:w ##1 #1
+ \cs_if_exist:NF \__morewrites_tex_shipout:w
+ { \cs_new_eq:NN \__morewrites_tex_shipout:w #1 }
+ \cs_gset_eq:NN #1 \__morewrites_shipout:w
+ }
+\tl_map_inline:nn
+ {
+ \xyrealshipout@
+ \org@shipout
+ \PDFSYNCship@ut@ld
+ \CROP@shipout
+ \@soORI
+ \tex_shipout:D
+ \zwpl@Hship
+ \o@shipout@TP
+ \LL@shipout
+ \Shipout
+ \GXTorg@shipout
+ \AtBegShi@OrgShipout
+ \AtBeginShipoutOriginalShipout
+ \shipout
+ }
+ {
+ \str_if_eq_x:nnT
+ { \cs_meaning:N #1 }
+ { \token_to_str:N \shipout }
+ { \__morewrites_tmp:w #1 }
+ }
+\cs_if_exist:NF \__morewrites_tex_shipout:w
+ {
+ \cs_new_eq:NN \__morewrites_tex_shipout:w \shipout
+ \cs_gset_eq:NN \shipout \__morewrites_shipout:w
+ }
+\cs_new_protected:Npn \__morewrites_close_all:
+ {
+ \prop_map_function:NN \g__morewrites_write_prop
+ \__morewrites_closeout_now:nn
+ \prop_gclear:N \g__morewrites_write_prop
+ }
+\cs_new_protected:Npn \__morewrites_close_all_at_end:nw #1#2 \@@end
+ {
+ \int_compare:nNnTF {#1} > \c_zero
+ { #2 \__morewrites_close_all_at_end:nw { #1 - 1 } }
+ { \__morewrites_close_all: #2 }
+ \@@end
+ }
+\AtEndDocument { \__morewrites_close_all_at_end:nw { 5 } }
+\int_new:N \g__morewrites_alloc_read_int
+\int_set:Nn \g__morewrites_alloc_read_int { 18 }
+\int_new:N \g__morewrites_alloc_write_int
+\int_set:Nn \g__morewrites_alloc_write_int { 18 }
+\cs_new_protected:Npn \__morewrites_newread:N #1
+ {
+ \int_gincr:N \g__morewrites_alloc_read_int
+ \int_set_eq:NN \allocationnumber \g__morewrites_alloc_read_int
+ \cs_undefine:N #1
+ \int_const:Nn #1 { \allocationnumber }
+ \wlog
{
- \int_gdecr:N \g__morewrites_at_end_int
- \int_compare:nNnTF \g__morewrites_at_end_int > \c_zero
- {
- \tl_if_empty:nTF {##1}
- { ##1 \__morewrites_close_all: }
- { ##1 \__morewrites_close_all_at_end:w }
- }
- { \__morewrites_close_all: ##1 }
- #1
+ \token_to_str:N #1
+ = \token_to_str:N \read \int_use:N \allocationnumber
}
}
-\exp_args:Nc \__morewrites_tmp:w { @ @ end }
-\AtEndDocument { \__morewrites_close_all_at_end:w }
-\tex_countdef:D \g__morewrites_alloc_int 17 \scan_stop:
-\cs_new:Npn \__morewrites_newwrite:N #1
+\cs_new_protected:Npn \__morewrites_newwrite:N #1
{
- \int_gincr:N \g__morewrites_alloc_int
- \if_int_compare:w \g__morewrites_alloc_int = \c_sixteen
- \int_gset:Nn \g__morewrites_alloc_int { 20 }
- \fi:
- \int_set_eq:NN \allocationnumber \g__morewrites_alloc_int
+ \int_gincr:N \g__morewrites_alloc_write_int
+ \int_set_eq:NN \allocationnumber \g__morewrites_alloc_write_int
\cs_undefine:N #1
\int_const:Nn #1 { \allocationnumber }
\wlog
@@ -330,6 +518,34 @@
= \token_to_str:N \write \int_use:N \allocationnumber
}
}
+\cs_new_protected:Npn \__morewrites_allocate:n #1
+ {
+ \prg_replicate:nn
+ {
+ \int_max:nn { 0 }
+ {
+ (#1) - \seq_count:N \g__morewrites_write_seq
+ - \prop_count:N \g__morewrites_write_prop
+ }
+ }
+ {
+ \__morewrites_tex_newwrite:N \l__morewrites_tstr_token
+ \seq_put_right:NV \g__morewrites_write_seq \l__morewrites_tstr_token
+ }
+ }
+\cs_new_protected:Npn \morewritessetup #1
+ { \keys_set:nn { __morewrites } {#1} }
+\keys_define:nn { __morewrites }
+ {
+ allocate .code:n = \__morewrites_allocate:n {#1} ,
+ file .code:n = \__morewrites_set_file:n {#1} ,
+ file .initial:n = \c_sys_jobname_str .mw
+ }
+\cs_gset_eq:NN \openin \__morewrites_openin:w
+\cs_gset_eq:NN \read \__morewrites_read:w
+\cs_gset_eq:NN \readline \__morewrites_readline:w
+\cs_gset_eq:NN \closein \__morewrites_closein:w
+\cs_gset_eq:NN \newread \__morewrites_newread:N
\cs_gset_eq:NN \immediate \__morewrites_immediate:w
\cs_gset_eq:NN \openout \__morewrites_openout:w
\cs_gset_eq:NN \write \__morewrites_write:w
diff --git a/Master/texmf-dist/tex/latex/morewrites/primargs.sty b/Master/texmf-dist/tex/latex/morewrites/primargs.sty
index e4b0d10abc3..908e61f948d 100644
--- a/Master/texmf-dist/tex/latex/morewrites/primargs.sty
+++ b/Master/texmf-dist/tex/latex/morewrites/primargs.sty
@@ -9,7 +9,7 @@
%% Communicate any suggestions for changing this package
%% to Bruno Le Floch (blflatex@gmail.com).
%%
-%% File: primargs.dtx Copyright (C) 2012-2013 Bruno Le Floch
+%% File: primargs.dtx Copyright (C) 2012-2017 Bruno Le Floch
%%
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
@@ -19,49 +19,58 @@
%% http://www.latex-project.org/lppl.txt
%%
%% -----------------------------------------------------------------------
-\RequirePackage {expl3} [2012/08/14]
+\RequirePackage {expl3} [2017/03/18]
\ProvidesExplPackage
- {primargs} {2013/01/08} {0.2e} {Parsing arguments of primitives}
-\cs_new_protected_nopar:Npn \g__primargs_code_tl { }
-\cs_new_protected_nopar:Npn \__primargs_no_afterassignment:
- { \tex_afterassignment:D \tex_relax:D }
-\cs_new_protected_nopar:Npn \__primargs_no_localdefs:
+ {primargs} {2017/04/10} {} {Parsing arguments of primitives}
+\tl_new:N \g__primargs_code_tl
+\tl_new:N \g__primargs_file_name_tl
+\tl_new:N \g__primargs_file_name_level_tl
+\cs_new_protected:Npn \__primargs_safe:
{
- \__primargs_no_afterassignment:
- \int_compare:nNnF \tex_globaldefs:D > \c_zero
- { \tex_globaldefs:D = \c_zero }
+ \tex_afterassignment:D \tex_relax:D
+ \if_int_compare:w 0 > \tex_globaldefs:D
+ \int_zero:N \tex_globaldefs:D
+ \fi:
}
-\cs_new_protected_nopar:Npn \primargs_read_x_token:N
+\cs_new_protected:Npn \primargs_read_x_token:N
{
\group_begin:
- \__primargs_no_localdefs:
+ \__primargs_safe:
\__primargs_read_x_token:N
}
-\cs_new_protected_nopar:Npn \__primargs_read_x_token:N
+\cs_new_protected:Npn \__primargs_read_x_token:N
{
- \tex_afterassignment:D \__primargs_read_x_token_ii:N
+ \tex_afterassignment:D \__primargs_read_x_token_aux:N
\tex_global:D \tex_futurelet:D \g_primargs_token
}
-\cs_new_protected_nopar:Npn \__primargs_read_x_token_ii:N
+\cs_new_protected:Npn \__primargs_read_x_token_std:N
{
\exp_after:wN
\if_meaning:w \exp_not:N \g_primargs_token \g_primargs_token
- \group_end:
- \exp_after:wN \use_none:nnn
+ \group_end: \use_i:nnnn
\fi:
\exp_after:wN \__primargs_read_x_token:N \exp_after:wN
}
-\cs_new_protected_nopar:Npn \primargs_read_token:N
+\cs_new_eq:NN \__primargs_read_x_token_aux:N
+ \__primargs_read_x_token_std:N
+\cs_new_protected:Npn \__primargs_read_x_token_file:N
+ {
+ \if_meaning:w \tex_input:D \g_primargs_token
+ \use_i_ii:nnn \group_end:
+ \fi:
+ \__primargs_read_x_token_std:N
+ }
+\cs_new_protected:Npn \primargs_read_token:N
{
\group_begin:
- \__primargs_no_localdefs:
+ \__primargs_safe:
\tex_afterassignment:D \group_end:
\tex_global:D \tex_futurelet:D \g_primargs_token
}
\cs_new_protected:Npn \primargs_remove_token:N #1
{
\group_begin:
- \__primargs_no_localdefs:
+ \__primargs_safe:
\tex_aftergroup:D #1
\tex_afterassignment:D \group_end:
\tex_global:D \tex_let:D \g_primargs_token = ~
@@ -69,13 +78,13 @@
\cs_new_protected:Npn \primargs_remove_one_optional_space:N #1
{
\group_begin:
- \__primargs_no_localdefs:
+ \__primargs_safe:
\tex_aftergroup:D #1
\primargs_read_x_token:N \__primargs_remove_one_optional_space:
}
-\exp_args:NNo \cs_new_protected_nopar:Npn \__primargs_remove_one_optional_space:
+\cs_new_protected:Npn \__primargs_remove_one_optional_space:
{
- \use:n { \if_catcode:w } ~ \exp_not:N \g_primargs_token
+ \if_catcode:w \c_space_token \exp_not:N \g_primargs_token
\exp_after:wN \primargs_remove_token:N
\fi:
\group_end:
@@ -83,15 +92,15 @@
\cs_new_protected:Npn \primargs_remove_optional_spaces:N #1
{
\group_begin:
- \__primargs_no_localdefs:
+ \__primargs_safe:
\tex_aftergroup:D #1
\__primargs_remove_optional_spaces:
}
-\cs_new_protected_nopar:Npn \__primargs_remove_optional_spaces:
- { \primargs_read_x_token:N \__primargs_remove_optional_spaces_ii: }
-\exp_args:NNo \cs_new_protected_nopar:Npn \__primargs_remove_optional_spaces_ii:
+\cs_new_protected:Npn \__primargs_remove_optional_spaces:
+ { \primargs_read_x_token:N \__primargs_remove_optional_spaces_aux: }
+\cs_new_protected:Npn \__primargs_remove_optional_spaces_aux:
{
- \use:n { \if_catcode:w } ~ \exp_not:N \g_primargs_token
+ \if_catcode:w \c_space_token \exp_not:N \g_primargs_token
\exp_after:wN \primargs_remove_token:N
\exp_after:wN \__primargs_remove_optional_spaces:
\else:
@@ -104,19 +113,45 @@
\tex_aftergroup:D #1
\primargs_remove_optional_spaces:N \__primargs_remove_equals:
}
-\cs_new_protected_nopar:Npn \__primargs_remove_equals:
+\cs_new_protected:Npn \__primargs_remove_equals:
{
\if_meaning:w = \g_primargs_token
- \exp_after:wN \__primargs_remove_equals_ii:NN
+ \exp_after:wN \__primargs_remove_equals_aux:NN
\fi:
\group_end:
}
-\cs_new_protected:Npn \__primargs_remove_equals_ii:NN #1#2
+\cs_new_protected:Npn \__primargs_remove_equals_aux:NN #1#2
{ \tl_if_eq:nnTF { #2 } { = } { #1 } { #1 #2 } }
+\cs_new_protected:Npn \primargs_remove_filler:N #1
+ {
+ \group_begin:
+ \__primargs_safe:
+ \tex_aftergroup:D #1
+ \__primargs_remove_filler:
+ }
+\cs_new_protected:Npn \__primargs_remove_filler:
+ { \primargs_read_x_token:N \__primargs_remove_filler_aux: }
+\cs_new_protected:Npn \__primargs_remove_filler_aux:
+ {
+ \if_catcode:w \c_space_token \exp_not:N \g_primargs_token
+ \else:
+ \if_meaning:w \tex_relax:D \g_primargs_token
+ \else:
+ \exp_after:wN
+ \if_meaning:w \exp_not:N \prg_do_nothing: \g_primargs_token
+ \else:
+ \__primargs_remove_filler_end:NNNNN
+ \fi:
+ \fi:
+ \fi:
+ \primargs_remove_token:N \__primargs_remove_filler:
+ }
+\cs_new_protected:Npn \__primargs_remove_filler_end:NNNNN #1#2#3#4#5
+ { #1 #2 #3 \group_end: }
\cs_new_protected:Npn \__primargs_get_rhs:NnN #1#2#3
{
\group_begin:
- \__primargs_no_localdefs:
+ \__primargs_safe:
\tex_aftergroup:D #3
\tl_gset:Nn \g__primargs_code_tl
{
@@ -130,58 +165,103 @@
#1 =
}
\cs_generate_variant:Nn \__primargs_get_rhs:NnN { No }
-\cs_new_protected_nopar:Npn \primargs_get_number:N
+\cs_new_protected:Npn \primargs_get_number:N
{
\__primargs_get_rhs:NoN \tex_deadcycles:D
{ \tex_the:D \tex_deadcycles:D }
}
-\cs_new_protected_nopar:Npn \primargs_get_dimen:N
+\cs_new_protected:Npn \primargs_get_dimen:N
{
\__primargs_get_rhs:NoN \tex_hoffset:D
{ \tex_the:D \tex_hoffset:D }
}
-\cs_new_protected_nopar:Npn \primargs_get_glue:N
+\cs_new_protected:Npn \primargs_get_glue:N
{
\__primargs_get_rhs:NoN \tex_topskip:D
{ \tex_the:D \tex_topskip:D }
}
-\cs_new_protected_nopar:Npn \primargs_get_mudimen:N
+\cs_new_protected:Npn \primargs_get_mudimen:N
{
\msg_warning:nn { primargs } { get-mudimen }
\primargs_get_muglue:N
}
\msg_new:nnn { primargs } { get-mudimen }
{ The~\iow_char:N\\primargs_get_mudimen:N~function~is~buggy. }
-\cs_new_protected_nopar:Npn \primargs_get_muglue:N
+\cs_new_protected:Npn \primargs_get_muglue:N
{
\__primargs_get_rhs:NoN \tex_thinmuskip:D
{ \tex_the:D \tex_thinmuskip:D }
}
-\cs_new_protected_nopar:Npn \primargs_get_general_text:N
- { \__primargs_get_rhs:NoN \tex_errhelp:D { { } } }
-\tl_new:N \g__primargs_file_name_tl
+\cs_new_protected:Npn \primargs_get_general_text:N #1
+ {
+ \group_begin:
+ \__primargs_safe:
+ \tex_aftergroup:D #1
+ \tex_aftergroup:D { \if_false: } \fi:
+ \primargs_remove_filler:N \__primargs_get_general_text:
+ }
+\cs_new_protected:Npn \__primargs_get_general_text:
+ {
+ \if_catcode:w \c_group_begin_token \g_primargs_token
+ \exp_after:wN \primargs_remove_token:N
+ \else:
+ \group_begin:
+ \tex_aftergroup:D \__primargs_get_general_text_error:n
+ \if_catcode:w \c_group_end_token \g_primargs_token
+ \tex_aftergroup:D {
+ \tex_aftergroup:D }
+ \fi:
+ \fi:
+ \group_end:
+ }
+\cs_new_protected:Npn \__primargs_get_general_text_error:n #1
+ {
+ \exp_after:wN \group_end:
+ \etex_unexpanded:D \if_int_compare:w `{ = \c_zero \fi: #1 }
+ }
\cs_new_protected:Npn \primargs_get_file_name:N #1
{
\group_begin:
- \__primargs_no_localdefs:
+ \__primargs_safe:
+ \cs_gset_eq:NN \__primargs_read_x_token_aux:N
+ \__primargs_read_x_token_file:N
\tex_aftergroup:D #1
\tl_gclear:N \g__primargs_file_name_tl
+ \tl_gset:Nn \g__primargs_file_name_level_tl { 0 }
\primargs_remove_optional_spaces:N \__primargs_get_file_name_test:
}
-\cs_new_protected_nopar:Npn \__primargs_get_file_name_test:
+\cs_new_protected:Npn \__primargs_get_file_name_test:
{
\token_if_cs:NTF \g_primargs_token
{ \__primargs_get_file_name_end: }
{
\token_if_eq_charcode:NNTF \c_space_token \g_primargs_token
- { \primargs_remove_token:N \__primargs_get_file_name_end: }
+ { \primargs_remove_token:N \__primargs_get_file_name_space: }
{ \primargs_remove_token:N \__primargs_get_file_name_char: }
}
}
-\cs_new_protected_nopar:Npn \__primargs_get_file_name_end:
- { \exp_args:No \group_end: \g__primargs_file_name_tl }
-\cs_new_protected_nopar:Npn \__primargs_get_file_name_char:
+\cs_new_protected:Npn \__primargs_get_file_name_end:
+ {
+ \cs_gset_eq:NN \__primargs_read_x_token_aux:N
+ \__primargs_read_x_token_std:N
+ \exp_args:No \group_end: \g__primargs_file_name_tl
+ }
+\cs_new_protected:Npn \__primargs_get_file_name_space:
+ {
+ \int_if_odd:nTF { \g__primargs_file_name_level_tl }
+ {
+ \tl_gput_right:Nn \g__primargs_file_name_tl { ~ }
+ \primargs_read_x_token:N \__primargs_get_file_name_test:
+ }
+ { \__primargs_get_file_name_end: }
+ }
+\cs_new_protected:Npn \__primargs_get_file_name_char:
{
+ \token_if_eq_charcode:NNT " \g_primargs_token
+ {
+ \tl_set:Nx \g__primargs_file_name_level_tl
+ { \int_eval:n { 1 - \g__primargs_file_name_level_tl } }
+ }
\tl_gput_right:Nx \g__primargs_file_name_tl
{
\exp_after:wN \__primargs_get_file_name_char_ii:w
@@ -193,6 +273,76 @@
\cs_new:Npn \__primargs_get_file_name_char_ii:w #1 ~ #2 ~ #3 \q_stop
{ \__primargs_get_file_name_char_iii:w #3 ~ #3 ~ \q_stop }
\cs_new:Npn \__primargs_get_file_name_char_iii:w #1 ~ #2 ~ #3 \q_stop {#2}
+\sys_if_engine_luatex:TF
+ {
+ \cs_new_protected:Npn \primargs_get_input_file_name:N #1
+ {
+ \group_begin:
+ \__primargs_safe:
+ \tex_aftergroup:D #1
+ \tl_gclear:N \g__primargs_file_name_tl
+ \tl_gset:Nn \g__primargs_file_name_level_tl { 1 }
+ \primargs_remove_filler:N \__primargs_get_input_file_name_first:
+ }
+ \cs_new_protected:Npn \__primargs_get_input_file_name_first:
+ {
+ \token_if_eq_catcode:NNTF \g_primargs_token \c_group_begin_token
+ { \primargs_remove_token:N \__primargs_get_input_file_name_loop: }
+ { \primargs_get_file_name:N \group_end: }
+ }
+ \cs_new_protected:Npn \__primargs_get_input_file_name_loop:
+ { \primargs_read_x_token:N \__primargs_get_input_file_name_test: }
+ \cs_new_protected:Npn \__primargs_get_input_file_name_test:
+ {
+ \token_if_eq_catcode:NNTF \g_primargs_token \c_group_begin_token
+ {
+ \tl_gset:Nx \g__primargs_file_name_level_tl
+ { \int_eval:n { \g__primargs_file_name_level_tl + 1 } }
+ \primargs_remove_token:N \__primargs_get_input_file_name_brace:
+ }
+ {
+ \token_if_eq_catcode:NNTF \g_primargs_token \c_group_end_token
+ {
+ \tl_gset:Nx \g__primargs_file_name_level_tl
+ { \int_eval:n { \g__primargs_file_name_level_tl - 1 } }
+ \int_compare:nNnTF { \g__primargs_file_name_level_tl } > 0
+ { \primargs_remove_token:N \__primargs_get_input_file_name_brace: }
+ { \primargs_remove_token:N \__primargs_get_file_name_end: }
+ }
+ {
+ \token_if_eq_meaning:NNTF \g_primargs_token \c_space_token
+ {
+ \tl_gput_right:Nn \g__primargs_file_name_tl { ~ }
+ \primargs_remove_token:N \__primargs_get_input_file_name_loop:
+ }
+ { \exp_after:wN \__primargs_get_input_file_name_aux:N \exp_not:N }
+ }
+ }
+ }
+ \cs_new_protected:Npn \__primargs_get_input_file_name_brace:
+ {
+ \tl_gput_right:Nx \g__primargs_file_name_tl
+ {
+ \exp_after:wN \__primargs_get_file_name_char_ii:w
+ \token_to_meaning:N \g_primargs_token
+ \q_stop
+ }
+ \__primargs_get_input_file_name_loop:
+ }
+ \cs_new_protected:Npn \__primargs_get_input_file_name_aux:N #1
+ {
+ \exp_after:wN \str_if_eq_x:nnT
+ \exp_after:wN { \token_to_str:N #1 } { \token_to_str:N \par }
+ { \use_none:nnn }
+ \tex_xdef:D \g__primargs_file_name_tl
+ {
+ \g__primargs_file_name_tl
+ \exp_after:wN \tl_to_str:n \exp_after:wN { \exp_not:N #1 }
+ }
+ \__primargs_get_input_file_name_loop:
+ }
+ }
+ { \cs_new_eq:NN \primargs_get_input_file_name:N \primargs_get_file_name:N }
%%
%%
%% End of file `primargs.sty'.