[latex3-commits] [git/LaTeX3-latex3-latex3] master: Modify \file_hex_dump:nnn to use start/end index (0cb694326)
Joseph Wright
joseph.wright at morningstar2.co.uk
Wed Nov 20 15:29:53 CET 2019
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/0cb694326152c30ec080689101a64017a21f9ff5
>---------------------------------------------------------------
commit 0cb694326152c30ec080689101a64017a21f9ff5
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Wed Nov 20 14:29:53 2019 +0000
Modify \file_hex_dump:nnn to use start/end index
This matches e.g. \str_range:nnn.
>---------------------------------------------------------------
0cb694326152c30ec080689101a64017a21f9ff5
l3kernel/l3expan.dtx | 4 +-
l3kernel/l3file.dtx | 76 ++++++++++++++++++++++++++++------
l3kernel/testfiles/m3file001.lvt | 7 +++-
l3kernel/testfiles/m3file001.ptex.tlg | 1 +
l3kernel/testfiles/m3file001.tlg | 1 +
l3kernel/testfiles/m3file001.uptex.tlg | 1 +
l3kernel/testfiles/m3file001.xetex.tlg | 1 +
7 files changed, 77 insertions(+), 14 deletions(-)
diff --git a/l3kernel/l3expan.dtx b/l3kernel/l3expan.dtx
index 7f3ea57e6..562fb79d2 100644
--- a/l3kernel/l3expan.dtx
+++ b/l3kernel/l3expan.dtx
@@ -536,6 +536,7 @@
% \exp_args:Nooo,
% \exp_args:Noof,
% \exp_args:Nffo,
+% \exp_args:Neee
% }
% \begin{syntax}
% \cs{exp_args:NNoo} \meta{token_1} \meta{token_2} \Arg{token_3} \Arg{tokens}
@@ -2841,7 +2842,7 @@
% \exp_args:NNno, \exp_args:NNnV, \exp_args:NNoo, \exp_args:NNVV,
% \exp_args:Ncno, \exp_args:NcnV, \exp_args:Ncoo, \exp_args:NcVV,
% \exp_args:Nnnc, \exp_args:Nnno, \exp_args:Nnnf, \exp_args:Nnff,
-% \exp_args:Nooo, \exp_args:Noof, \exp_args:Nffo,
+% \exp_args:Nooo, \exp_args:Noof, \exp_args:Nffo, \exp_args:Neee
% }
% \begin{macro}
% {
@@ -2866,6 +2867,7 @@
\@@_tmp:w { ooo }
\@@_tmp:w { oof }
\@@_tmp:w { ffo }
+\@@_tmp:w { eee }
\@@_tmp:w { NNx }
\@@_tmp:w { Nnx }
\@@_tmp:w { Nox }
diff --git a/l3kernel/l3file.dtx b/l3kernel/l3file.dtx
index 222465d49..ec23c407c 100644
--- a/l3kernel/l3file.dtx
+++ b/l3kernel/l3file.dtx
@@ -706,7 +706,7 @@
% {\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{offset} \Arg{length}
+% \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}.
@@ -716,15 +716,15 @@
% 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 \meta{offset} from the start of the file
-% and \meta{length} are given in bytes.
+% 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{offset} \Arg{length} \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}.
@@ -2887,25 +2887,75 @@
% \end{macro}
% \end{macro}
%
-% \begin{macro}{\file_hex_dump:nnn, \@@_hex_dump:nnn}
-% \begin{macro}{\file_hex_dump:n, \@@_hex_dump:n}
+% \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:Ne \@@_hex_dump:nnn { \file_full_name:n {#1} } {#2} {#3} }
-\cs_new:Npn \@@_hex_dump:nnn #1#2#3
{
- \tl_if_blank:nF {#1}
- { \tex_filedump:D offset ~ #2 ~ length #3 {#1} }
+ \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:nnn #1#2#3
+ \cs_gset:Npn \@@_hex_dump_auxiv:nnn #1#2#3
{
\lua_now:e
- { l3kernel.filedump ( " \lua_escape:e { #1 } " , #2 , #3 ) }
+ {
+ 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
@@ -2926,6 +2976,8 @@
% \end{macrocode}
% \end{macro}
% \end{macro}
+% \end{macro}
+% \end{macro}
%
% \begin{macro}[noTF]
% {
diff --git a/l3kernel/testfiles/m3file001.lvt b/l3kernel/testfiles/m3file001.lvt
index 2f76ce026..937ec19ef 100644
--- a/l3kernel/testfiles/m3file001.lvt
+++ b/l3kernel/testfiles/m3file001.lvt
@@ -172,10 +172,15 @@
{ \ERROR }
}
\str_if_eq:eeTF
- { \file_hex_dump:nnn { filetest.txt } { 0 } { 10 } }
+ { \file_hex_dump:nnn { filetest.txt } { 1 } { 10 } }
{ 5C4578706C53796E7461 }
\TRUE
\ERROR
+ \str_if_eq:eeTF
+ { \file_hex_dump:nnn { filetest.txt } { -2 } { -1 } }
+ { 784F }
+ \TRUE
+ \ERROR
\file_get_mdfive_hash:nN { NotAFile.txt } \l_tmpa_tl
\tl_show:N \l_tmpa_tl
\file_get_size:nN { NotAFile.txt } \l_tmpa_tl
diff --git a/l3kernel/testfiles/m3file001.ptex.tlg b/l3kernel/testfiles/m3file001.ptex.tlg
index 5b8b08837..2af7cb35d 100644
--- a/l3kernel/testfiles/m3file001.ptex.tlg
+++ b/l3kernel/testfiles/m3file001.ptex.tlg
@@ -207,6 +207,7 @@ TEST 10: Getting file information
============================================================
TRUE
TRUE
+TRUE
> \l_tmpa_tl=\q_no_value .
<recently read> }
l. ... }
diff --git a/l3kernel/testfiles/m3file001.tlg b/l3kernel/testfiles/m3file001.tlg
index 8cf0907c5..a3146abcf 100644
--- a/l3kernel/testfiles/m3file001.tlg
+++ b/l3kernel/testfiles/m3file001.tlg
@@ -207,6 +207,7 @@ TEST 10: Getting file information
============================================================
TRUE
TRUE
+TRUE
> \l_tmpa_tl=\q_no_value .
<recently read> }
l. ... }
diff --git a/l3kernel/testfiles/m3file001.uptex.tlg b/l3kernel/testfiles/m3file001.uptex.tlg
index 5b8b08837..2af7cb35d 100644
--- a/l3kernel/testfiles/m3file001.uptex.tlg
+++ b/l3kernel/testfiles/m3file001.uptex.tlg
@@ -207,6 +207,7 @@ TEST 10: Getting file information
============================================================
TRUE
TRUE
+TRUE
> \l_tmpa_tl=\q_no_value .
<recently read> }
l. ... }
diff --git a/l3kernel/testfiles/m3file001.xetex.tlg b/l3kernel/testfiles/m3file001.xetex.tlg
index 10b613b31..fa303524b 100644
--- a/l3kernel/testfiles/m3file001.xetex.tlg
+++ b/l3kernel/testfiles/m3file001.xetex.tlg
@@ -207,6 +207,7 @@ TEST 10: Getting file information
============================================================
TRUE
TRUE
+TRUE
> \l_tmpa_tl=\q_no_value .
<recently read> }
l. ... }
More information about the latex3-commits
mailing list