[latex3-commits] [git/LaTeX3-latex3-latex3] master: Add expandable file-info functions (de88a2408)
Joseph Wright
joseph.wright at morningstar2.co.uk
Tue Sep 3 19:28:33 CEST 2019
Repository : https://github.com/latex3/latex3
On branch : master
Link : https://github.com/latex3/latex3/commit/de88a2408b8083479e698a81a78a9a3dc93cb3cd
>---------------------------------------------------------------
commit de88a2408b8083479e698a81a78a9a3dc93cb3cd
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Tue Sep 3 18:28:33 2019 +0100
Add expandable file-info functions
>---------------------------------------------------------------
de88a2408b8083479e698a81a78a9a3dc93cb3cd
l3kernel/CHANGELOG.md | 3 +-
l3kernel/l3file.dtx | 188 +++++++++++++++++++-------------
l3kernel/testfiles/m3expl001.luatex.tlg | 5 +
l3kernel/testfiles/m3expl001.ptex.tlg | 6 +
l3kernel/testfiles/m3expl001.tlg | 6 +
l3kernel/testfiles/m3expl001.uptex.tlg | 6 +
l3kernel/testfiles/m3expl001.xetex.tlg | 6 +
l3kernel/testfiles/m3expl003.luatex.tlg | 5 +
l3kernel/testfiles/m3expl003.ptex.tlg | 6 +
l3kernel/testfiles/m3expl003.tlg | 6 +
l3kernel/testfiles/m3expl003.uptex.tlg | 6 +
l3kernel/testfiles/m3expl003.xetex.tlg | 6 +
12 files changed, 173 insertions(+), 76 deletions(-)
diff --git a/l3kernel/CHANGELOG.md b/l3kernel/CHANGELOG.md
index 3f98293ac..7f1738752 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -9,7 +9,8 @@ this project uses date-based 'snapshot' version identifiers.
### Added
-- `\file_full_name:n`
+- `\file_full_name:n`, \file_mdfive_hash:n`, `\file_size:n`,
+ `\file_timestamp:n`
- `\seq_map_tokens:Nn`, `\tl_map_tokens:nn`, \tl_map_tokens:Nn`
### Changed
diff --git a/l3kernel/l3file.dtx b/l3kernel/l3file.dtx
index ea10e5fe7..6342e89d4 100644
--- a/l3kernel/l3file.dtx
+++ b/l3kernel/l3file.dtx
@@ -663,21 +663,39 @@
% quote (|"|) characters or is surrounded by a pair of quotes.
% \end{function}
%
-% \begin{function}[noTF, added = 2017-07-11, updated = 2019-02-16]
-% {\file_get_mdfive_hash:nN}
+% \begin{function}[rEXP, added = 2019-09-03]{\file_mdfive_hash:n}
% \begin{syntax}
-% \cs{file_get_mdfive_hash:nN} \Arg{file name} \meta{tl var}
+% \cs{file_mdfive_hash:nN} \Arg{file name}
% \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}.
-% If found, sets the \meta{tl var} to the MD5 sum generated from the
-% content of the file. The file is read as bytes, which means that in
+% It then expands to leave the MD5 sum generated from the contents of
+% the file 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.
-% Where the file is not found, the \meta{tl var} will set to
-% \cs{q_no_value}.
+% is the same in all cases. When the file is not found, the result of
+% expansion is empty.
+% \end{function}
+%
+% \begin{function}[noTF, added = 2017-07-11, updated = 2019-02-16]
+% {\file_get_mdfive_hash:nN}
+% \begin{syntax}
+% \cs{file_get_mdfive_hash:nN} \Arg{file name} \meta{tl var}
+% \end{syntax}
+% Sets the \meta{tl var} to the result of applying
+% \cs{file_mdfive_hash:n} 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_size:n}
+% \begin{syntax}
+% \cs{file_size:n} \Arg{file name}
+% \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 size of the file in bytes in the input stream.
+% When the file is not found, the result of expansion is empty.
% \end{function}
%
% \begin{function}[noTF, added = 2017-07-09, updated = 2019-02-16]
@@ -685,10 +703,24 @@
% \begin{syntax}
% \cs{file_get_size:nN} \Arg{file name} \meta{tl var}
% \end{syntax}
+% Sets the \meta{tl var} to the result of applying
+% \cs{file_size:n} to the \meta{file}. If the file is not found,
+% the \meta{tl var} will be set to \cs{q_no_value}.
+% This is not available in older versions of \XeTeX{}.
+% \end{function}
+%
+% \begin{function}[rEXP, added = 2019-09-03]{\file_timestamp:n}
+% \begin{syntax}
+% \cs{file_timestamp:n} \Arg{file name}
+% \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}.
-% If found, sets the \meta{tl var} to the size of the file in bytes.
-% Where the file is not found, the \meta{tl var} will set to \cs{q_no_value}.
+% It then expands to leave the modification timestamp of
+% the file in the input stream. The timestamp is of the form
+% |D:|\meta{year}\meta{month}\meta{day}\meta{hour}^^A
+% \meta{minute}\meta{second}\meta{offset}, where the latter may be |Z|
+% (UTC) or \meta{plus-minus}\meta{hours}|'|\meta{minutes}|'|.
+% When the file is not found, the result of expansion is empty.
% This is not available in older versions of \XeTeX{}.
% \end{function}
%
@@ -697,14 +729,9 @@
% \begin{syntax}
% \cs{file_get_timestamp:nN} \Arg{file name} \meta{tl var}
% \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}.
-% If found, sets the \meta{tl var} to the modification timestamp of
-% the file in the form |D:|\meta{year}\meta{month}\meta{day}\meta{hour}^^A
-% \meta{minute}\meta{second}\meta{offset}, where the latter may be |Z|
-% (UTC) or \meta{plus-minus}\meta{hours}|'|\meta{minutes}|'|.
-% Where the file is not found, the \meta{tl var} will be set to
-% \cs{q_no_value}.
+% Sets the \meta{tl var} to the result of applying
+% \cs{file_timestamp:n} to the \meta{file}. If the file is not found,
+% the \meta{tl var} will be set to \cs{q_no_value}.
% This is not available in older versions of \XeTeX{}.
% \end{function}
%
@@ -2688,16 +2715,53 @@
% \end{macro}
% \end{macro}
%
+% \begin{macro}[rEXP]{\file_mdfive_hash:n, \file_size:n, \file_timestamp:n}
+% \begin{macro}[rEXP]{\@@_details:nn, \@@_details_aux:nn}
+% \begin{macro}[rEXP]{\@@_mdfive_hash:n}
+% Getting file details by expansion is relatively easy if a bit repetitive.
+% As the MD5 function has a slightly different syntax from the other commands,
+% there is a little cleaning up to do.
+% \begin{macrocode}
+\cs_new:Npn \file_mdfive_hash:n #1
+ { \@@_details:nn {#1} { mdfivesum } }
+\cs_new:Npn \file_size:n #1
+ { \@@_details:nn {#1} { size } }
+\cs_new:Npn \file_timestamp:n #1
+ { \@@_details:nn {#1} { moddate } }
+\cs_new:Npn \@@_details:nn #1#2
+ {
+ \exp_args:Ne \@@_details_aux:nn
+ { \file_full_name:n {#1} } {#2}
+ }
+\cs_new:Npn \@@_details_aux:nn #1#2
+ {
+ \tl_if_blank:nF {#1}
+ { \use:c { tex_file #2 :D } {#1} }
+ }
+\sys_if_engine_luatex:TF
+ {
+ \cs_gset:Npn \@@_details_aux:nn #1#2
+ {
+ \lua_now:e
+ { l3kernel.file#2 ( " \lua_escape:e { #1 } " ) }
+ }
+ }
+ {
+ \cs_gset:Npn \file_mdfive_hash:n #1
+ { \exp_args:Ne \@@_mdfive_hash:n { \file_full_name:n {#1} } }
+ \cs_new:Npn \@@_mdfive_hash:n #1
+ { \tex_mdfivesum:D file {#1} }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+% \end{macro}
+%
% \begin{macro}
% {\file_get_mdfive_hash:nN, \file_get_size:nN, \file_get_timestamp:nN}
% \begin{macro}{\@@_get_details:nnN}
-% These are all wrappers around the \pdfTeX{} primitives doing the same
-% jobs: as we want consistent file paths to be found, they are all set up
-% using \cs{file_get_full_name:nN} and so are non-expandable \texttt{get}
-% functions. Much of the code is repetitive but we need to branch for
-% \LuaTeX{} (emulation in Lua), for the slightly different syntax
-% needed for \tn{tex_mdfivesum:D} and for the fact that primitive
-% coverage varies in other engines.
+% Non-expandable wrappers around the above in the case where appropriate
+% primitive support exists.
% \begin{macrocode}
\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 } } }
@@ -2706,68 +2770,42 @@
\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_mdfive_hash:nN #1#2 { T , F , TF }
- { \@@_get_details:nnN {#1} { mdfivesum } {#2} }
+ { \@@_get_details:nnN {#1} { mdfive_hash } #2 }
\prg_new_protected_conditional:Npnn \file_get_size:nN #1#2 { T , F , TF }
- { \@@_get_details:nnN {#1} { size } {#2} }
+ { \@@_get_details:nnN {#1} { size } #2 }
\prg_new_protected_conditional:Npnn \file_get_timestamp:nN #1#2 { T , F , TF }
- { \@@_get_details:nnN {#1} { moddate } {#2} }
+ { \@@_get_details:nnN {#1} { timestamp } #2 }
\cs_new_protected:Npn \@@_get_details:nnN #1#2#3
{
- \file_get_full_name:nNTF {#1} \l_@@_full_name_tl
- {
- \tl_set:Nx #3
- {
- \use:c { tex_file #2 :D } \exp_after:wN
- { \l_@@_full_name_tl }
- }
- \prg_return_true:
- }
+ \tl_set:Nx #3
+ { \use:c { file_ #2 :n } {#1} }
+ \tl_if_emtpy:NTF #3
{ \prg_return_false: }
+ { \prg_return_true: }
}
-\sys_if_engine_luatex:TF
+% \end{macrocode}
+% Where the primitive is not available, issue an error: this is a little
+% more conservative than absolutely needed, but does work.
+% \begin{macrocode}
+\bool_lazy_or:nnF
+ { \cs_if_exist_p:N \tex_filesize:D }
+ { \sys_if_engine_luatex_p: }
{
\cs_set_protected:Npn \@@_get_details:nnN #1#2#3
- {
- \file_get_full_name:nNTF {#1} \l_@@_full_name_tl
- {
- \tl_set:Nx #3
- {
- \lua_now:e
- {
- l3kernel.file#2
- ( " \lua_escape:e { \l_@@_full_name_tl } " )
- }
- }
- \prg_return_true:
- }
- { \prg_return_false: }
- }
- }
- {
- \prg_set_protected_conditional:Npnn \file_get_mdfive_hash:nN #1#2
- { T , F , TF }
- {
- \file_get_full_name:nNTF {#1} \l_@@_full_name_tl
+ {
+ \tl_clear:N #3
+ \__kernel_msg_error:nnx
+ { kernel } { primitive-not-available }
{
- \tl_set:Nx #2
+ \token_to_str:N \(pdf)file
+ \str_case:nn {#2}
{
- \tex_mdfivesum:D file \exp_after:wN
- { \l_@@_full_name_tl }
+ { mdfive_hash } { mdfivesum }
+ { timestamp } { moddate }
+ { size } { size }
}
- \prg_return_true:
- }
- { \prg_return_false: }
- }
- \cs_if_exist:NF \tex_filesize:D
- {
- \cs_set_protected:Npn \@@_get_details:nnN #1#2#3
- {
- \tl_clear:N #3
- \__kernel_msg_error:nnx
- { kernel } { primitive-not-available }
- { \token_to_str:N \(pdf)file #2 }
- \prg_return_false:
}
+ \prg_return_false:
}
}
% \end{macrocode}
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index 004ac9313..c49d0e3c5 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -2937,6 +2937,11 @@ Defining \file_get_full_name:VNT on line ...
Defining \file_get_full_name:VNF on line ...
Defining \file_get_full_name:VNTF on line ...
Defining \__file_get_full_name_search:nN on line ...
+Defining \file_mdfive_hash:n on line ...
+Defining \file_size:n on line ...
+Defining \file_timestamp:n on line ...
+Defining \__file_details:nn on line ...
+Defining \__file_details_aux:nn on line ...
Defining \file_get_mdfive_hash:nN on line ...
Defining \file_get_size:nN on line ...
Defining \file_get_timestamp:nN on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index 4b9fac75a..2a3524ac5 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -3191,6 +3191,12 @@ Defining \file_get_full_name:VNT on line ...
Defining \file_get_full_name:VNF on line ...
Defining \file_get_full_name:VNTF on line ...
Defining \__file_get_full_name_search:nN on line ...
+Defining \file_mdfive_hash:n on line ...
+Defining \file_size:n on line ...
+Defining \file_timestamp:n on line ...
+Defining \__file_details:nn on line ...
+Defining \__file_details_aux:nn on line ...
+Defining \__file_mdfive_hash:n on line ...
Defining \file_get_mdfive_hash:nN on line ...
Defining \file_get_size:nN on line ...
Defining \file_get_timestamp:nN on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index f29aed8e5..66d10164e 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -3191,6 +3191,12 @@ Defining \file_get_full_name:VNT on line ...
Defining \file_get_full_name:VNF on line ...
Defining \file_get_full_name:VNTF on line ...
Defining \__file_get_full_name_search:nN on line ...
+Defining \file_mdfive_hash:n on line ...
+Defining \file_size:n on line ...
+Defining \file_timestamp:n on line ...
+Defining \__file_details:nn on line ...
+Defining \__file_details_aux:nn on line ...
+Defining \__file_mdfive_hash:n on line ...
Defining \file_get_mdfive_hash:nN on line ...
Defining \file_get_size:nN on line ...
Defining \file_get_timestamp:nN on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index ffaae8d37..65d325f1e 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -3191,6 +3191,12 @@ Defining \file_get_full_name:VNT on line ...
Defining \file_get_full_name:VNF on line ...
Defining \file_get_full_name:VNTF on line ...
Defining \__file_get_full_name_search:nN on line ...
+Defining \file_mdfive_hash:n on line ...
+Defining \file_size:n on line ...
+Defining \file_timestamp:n on line ...
+Defining \__file_details:nn on line ...
+Defining \__file_details_aux:nn on line ...
+Defining \__file_mdfive_hash:n on line ...
Defining \file_get_mdfive_hash:nN on line ...
Defining \file_get_size:nN on line ...
Defining \file_get_timestamp:nN on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index 1f2407158..3afc65b21 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -2935,6 +2935,12 @@ Defining \file_get_full_name:VNT on line ...
Defining \file_get_full_name:VNF on line ...
Defining \file_get_full_name:VNTF on line ...
Defining \__file_get_full_name_search:nN on line ...
+Defining \file_mdfive_hash:n on line ...
+Defining \file_size:n on line ...
+Defining \file_timestamp:n on line ...
+Defining \__file_details:nn on line ...
+Defining \__file_details_aux:nn on line ...
+Defining \__file_mdfive_hash:n on line ...
Defining \file_get_mdfive_hash:nN on line ...
Defining \file_get_size:nN on line ...
Defining \file_get_timestamp:nN on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 004ac9313..c49d0e3c5 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -2937,6 +2937,11 @@ Defining \file_get_full_name:VNT on line ...
Defining \file_get_full_name:VNF on line ...
Defining \file_get_full_name:VNTF on line ...
Defining \__file_get_full_name_search:nN on line ...
+Defining \file_mdfive_hash:n on line ...
+Defining \file_size:n on line ...
+Defining \file_timestamp:n on line ...
+Defining \__file_details:nn on line ...
+Defining \__file_details_aux:nn on line ...
Defining \file_get_mdfive_hash:nN on line ...
Defining \file_get_size:nN on line ...
Defining \file_get_timestamp:nN on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index 4b9fac75a..2a3524ac5 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -3191,6 +3191,12 @@ Defining \file_get_full_name:VNT on line ...
Defining \file_get_full_name:VNF on line ...
Defining \file_get_full_name:VNTF on line ...
Defining \__file_get_full_name_search:nN on line ...
+Defining \file_mdfive_hash:n on line ...
+Defining \file_size:n on line ...
+Defining \file_timestamp:n on line ...
+Defining \__file_details:nn on line ...
+Defining \__file_details_aux:nn on line ...
+Defining \__file_mdfive_hash:n on line ...
Defining \file_get_mdfive_hash:nN on line ...
Defining \file_get_size:nN on line ...
Defining \file_get_timestamp:nN on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index f29aed8e5..66d10164e 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -3191,6 +3191,12 @@ Defining \file_get_full_name:VNT on line ...
Defining \file_get_full_name:VNF on line ...
Defining \file_get_full_name:VNTF on line ...
Defining \__file_get_full_name_search:nN on line ...
+Defining \file_mdfive_hash:n on line ...
+Defining \file_size:n on line ...
+Defining \file_timestamp:n on line ...
+Defining \__file_details:nn on line ...
+Defining \__file_details_aux:nn on line ...
+Defining \__file_mdfive_hash:n on line ...
Defining \file_get_mdfive_hash:nN on line ...
Defining \file_get_size:nN on line ...
Defining \file_get_timestamp:nN on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index ffaae8d37..65d325f1e 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -3191,6 +3191,12 @@ Defining \file_get_full_name:VNT on line ...
Defining \file_get_full_name:VNF on line ...
Defining \file_get_full_name:VNTF on line ...
Defining \__file_get_full_name_search:nN on line ...
+Defining \file_mdfive_hash:n on line ...
+Defining \file_size:n on line ...
+Defining \file_timestamp:n on line ...
+Defining \__file_details:nn on line ...
+Defining \__file_details_aux:nn on line ...
+Defining \__file_mdfive_hash:n on line ...
Defining \file_get_mdfive_hash:nN on line ...
Defining \file_get_size:nN on line ...
Defining \file_get_timestamp:nN on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index 1f2407158..3afc65b21 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -2935,6 +2935,12 @@ Defining \file_get_full_name:VNT on line ...
Defining \file_get_full_name:VNF on line ...
Defining \file_get_full_name:VNTF on line ...
Defining \__file_get_full_name_search:nN on line ...
+Defining \file_mdfive_hash:n on line ...
+Defining \file_size:n on line ...
+Defining \file_timestamp:n on line ...
+Defining \__file_details:nn on line ...
+Defining \__file_details_aux:nn on line ...
+Defining \__file_mdfive_hash:n on line ...
Defining \file_get_mdfive_hash:nN on line ...
Defining \file_get_size:nN on line ...
Defining \file_get_timestamp:nN on line ...
More information about the latex3-commits
mailing list