diff options
Diffstat (limited to 'Master/texmf-dist/source/latex/l3kernel/l3file.dtx')
-rw-r--r-- | Master/texmf-dist/source/latex/l3kernel/l3file.dtx | 157 |
1 files changed, 154 insertions, 3 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3file.dtx b/Master/texmf-dist/source/latex/l3kernel/l3file.dtx index 2b6c86f8f89..274d5da8ecc 100644 --- a/Master/texmf-dist/source/latex/l3kernel/l3file.dtx +++ b/Master/texmf-dist/source/latex/l3kernel/l3file.dtx @@ -2,7 +2,7 @@ % %% File: l3file.dtx % -% Copyright (C) 1990-2019 The LaTeX3 Project +% Copyright (C) 1990-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 @@ -44,7 +44,7 @@ % }^^A % } % -% \date{Released 2019-11-07} +% \date{Released 2020-01-12} % % \maketitle % @@ -702,6 +702,35 @@ % quote (|"|) characters or is surrounded by a pair of quotes. % \end{function} % +% \begin{function}[rEXP, added = 2019-11-19] +% {\file_hex_dump:n, \file_hex_dump:nnn} +% \begin{syntax} +% \cs{file_hex_dump:n} \Arg{file name} +% \cs{file_hex_dump:nnn} \Arg{file name} \Arg{start index} \Arg{end index} +% \end{syntax} +% Searches for \meta{file name} using the current \TeX{} search +% path and the additional paths controlled by \cs{l_file_search_path_seq}. +% It then expands to leave the hexadecimal dump of the file content in the +% input stream. The file is read as bytes, which means that in +% contrast to most \TeX{} behaviour there will be a difference in result +% depending on the line endings used in text files. The same file will +% produce the same result between different engines: the algorithm used +% is the same in all cases. When the file is not found, the result of +% expansion is empty. The \Arg{start index} and \Arg{end index} values +% work as described for \cs{str_range:nnn}. +% \end{function} +% +% \begin{function}[noTF, added = 2019-11-19] +% {\file_get_hex_dump:nN, \file_get_hex_dump:nnnN} +% \begin{syntax} +% \cs{file_get_hex_dump:nN} \Arg{file name} \meta{tl var} +% \cs{file_get_hex_dump:nnnN} \Arg{file name} \Arg{start index} \Arg{end index} \meta{tl var} +% \end{syntax} +% Sets the \meta{tl var} to the result of applying +% \cs{file_hex_dump:n}/\cs{file_hex_dump:nnn} to the \meta{file}. +% If the file is not found, the \meta{tl var} will be set to \cs{q_no_value}. +% \end{function} +% % \begin{function}[rEXP, added = 2019-09-03]{\file_mdfive_hash:n} % \begin{syntax} % \cs{file_mdfive_hash:n} \Arg{file name} @@ -2858,18 +2887,119 @@ % \end{macro} % \end{macro} % +% \begin{macro}[rEXP]{\file_hex_dump:nnn, \@@_hex_dump_auxi:nnn} +% \begin{macro}[rEXP]{\@@_hex_dump_auxii:nnnn, \@@_hex_dump_auxiii:nnnn} +% \begin{macro}[rEXP]{\@@_hex_dump_auxiiv:nnn} +% \begin{macro}[rEXP]{\file_hex_dump:n, \@@_hex_dump:n} +% These are separate as they need multiple arguments \emph{or} the +% file size. For \LuaTeX{}, the emulation does not need the file +% size so we save a little on expansion. +% \begin{macrocode} +\cs_new:Npn \file_hex_dump:nnn #1#2#3 + { + \exp_args:Neee \@@_hex_dump_auxi:nnn + { \file_full_name:n {#1} } + { \int_eval:n {#2} } + { \int_eval:n {#3} } + } +\cs_new:Npn \@@_hex_dump_auxi:nnn #1#2#3 + { + \bool_lazy_any:nF + { + { \tl_if_blank_p:n {#1} } + { \int_compare_p:nNn {#2} = 0 } + { \int_compare_p:nNn {#3} = 0 } + } + { + \exp_args:Ne \@@_hex_dump_auxii:nnnn + { \@@_details_aux:nn {#1} { size } } + {#1} {#2} {#3} + } + } +\cs_new:Npn \@@_hex_dump_auxii:nnnn #1#2#3#4 + { + \int_compare:nNnTF {#3} > 0 + { \@@_hex_dump_auxiii:nnnn {#3} } + { + \exp_args:Ne \@@_hex_dump_auxiii:nnnn + { \int_eval:n { #1 + #3 } } + } + {#1} {#2} {#4} + } +\cs_new:Npn \@@_hex_dump_auxiii:nnnn #1#2#3#4 + { + \int_compare:nNnTF {#4} > 0 + { \@@_hex_dump_auxiv:nnn {#4} } + { + \exp_args:Ne \@@_hex_dump_auxiv:nnn + { \int_eval:n { #2 + #4 } } + } + {#1} {#3} + } +\cs_new:Npn \@@_hex_dump_auxiv:nnn #1#2#3 + { + \tex_filedump:D + offset ~ \int_eval:n { #2 - 1 } ~ + length ~ \int_eval:n { #1 - #2 + 1 } + {#3} + } +\sys_if_engine_luatex:T + { + \cs_gset:Npn \@@_hex_dump_auxiv:nnn #1#2#3 + { + \lua_now:e + { + l3kernel.filedump + ( + " \lua_escape:e {#3} " , + \int_eval:n { #2 - 1 } , + \int_eval:n { #1 - #2 + 1 } + ) + } + } + } +\cs_new:Npn \file_hex_dump:n #1 + { \exp_args:Ne \@@_hex_dump:n { \file_full_name:n {#1} } } +\cs_new:Npn \@@_hex_dump:n #1 + { + \tl_if_blank:nF {#1} + { \tex_filedump:D length \tex_filesize:D {#1} {#1} } + } +\sys_if_engine_luatex:T + { + \cs_gset:Npn \@@_hex_dump:n #1 + { + \lua_now:e + { l3kernel.filedump ( " \lua_escape:e { #1 } " ) } + } + } +% \end{macrocode} +% \end{macro} +% \end{macro} +% \end{macro} +% \end{macro} +% % \begin{macro}[noTF] -% {\file_get_mdfive_hash:nN, \file_get_size:nN, \file_get_timestamp:nN} +% { +% \file_get_hex_dump:nN, +% \file_get_mdfive_hash:nN +% \file_get_size:nN, +% \file_get_timestamp:nN +% } % \begin{macro}{\@@_get_details:nnN} % Non-expandable wrappers around the above in the case where appropriate % primitive support exists. % \begin{macrocode} +\cs_new_protected:Npn \file_get_hex_dump:nN #1#2 + { \file_get_hex_dump:nNF {#1} #2 { \tl_set:Nn #2 { \q_no_value } } } \cs_new_protected:Npn \file_get_mdfive_hash:nN #1#2 { \file_get_mdfive_hash:nNF {#1} #2 { \tl_set:Nn #2 { \q_no_value } } } \cs_new_protected:Npn \file_get_size:nN #1#2 { \file_get_size:nNF {#1} #2 { \tl_set:Nn #2 { \q_no_value } } } \cs_new_protected:Npn \file_get_timestamp:nN #1#2 { \file_get_timestamp:nNF {#1} #2 { \tl_set:Nn #2 { \q_no_value } } } +\prg_new_protected_conditional:Npnn \file_get_hex_dump:nN #1#2 { T , F , TF } + { \@@_get_details:nnN {#1} { hex_dump } #2 } \prg_new_protected_conditional:Npnn \file_get_mdfive_hash:nN #1#2 { T , F , TF } { \@@_get_details:nnN {#1} { mdfive_hash } #2 } \prg_new_protected_conditional:Npnn \file_get_size:nN #1#2 { T , F , TF } @@ -2901,6 +3031,7 @@ \token_to_str:N \(pdf)file \str_case:nn {#2} { + { hex_dump } { dump } { mdfive_hash } { mdfivesum } { timestamp } { moddate } { size } { size } @@ -2913,6 +3044,26 @@ % \end{macro} % \end{macro} % +% \begin{macro}[noTF]{\file_get_hex_dump:nnnN} +% Custom code due to the additional arguments. +% \begin{macrocode} +\cs_new_protected:Npn \file_get_hex_dump:nnnN #1#2#3#4 + { + \file_get_hex_dump:nnnNF {#1} {#2} {#3} #4 + { \tl_set:Nn #4 { \q_no_value } } + } +\prg_new_protected_conditional:Npnn \file_get_hex_dump:nnnN #1#2#3#4 + { T , F , TF } + { + \tl_set:Nx #4 + { \file_hex_dump:nnn {#1} {#2} {#3} } + \tl_if_empty:NTF #4 + { \prg_return_false: } + { \prg_return_true: } + } +% \end{macrocode} +% \end{macro} +% % \begin{macro}[EXP]{\@@_str_cmp:nn} % \begin{macro}[EXP]{\@@_str_escape:n} % As we are doing a fixed-length \enquote{big} integer comparison, it |