[latex3-commits] [git/LaTeX3-latex3-latex3] master: Add \sys_shell_get_ls:nN (2143f4d)

Joseph Wright joseph.wright at morningstar2.co.uk
Fri Jul 27 13:10:45 CEST 2018


Repository : https://github.com/latex3/latex3
On branch  : master
Link       : https://github.com/latex3/latex3/commit/2143f4d8afd142d81cbb59486003ccf19624dcca

>---------------------------------------------------------------

commit 2143f4d8afd142d81cbb59486003ccf19624dcca
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date:   Fri Jul 27 12:09:57 2018 +0100

    Add \sys_shell_get_ls:nN


>---------------------------------------------------------------

2143f4d8afd142d81cbb59486003ccf19624dcca
 l3kernel/l3candidates.dtx               |   42 +++++++++++++++++++++++++++++++
 l3kernel/testfiles/m3expl001.luatex.tlg |    1 +
 l3kernel/testfiles/m3expl001.ptex.tlg   |    1 +
 l3kernel/testfiles/m3expl001.tlg        |    1 +
 l3kernel/testfiles/m3expl001.uptex.tlg  |    1 +
 l3kernel/testfiles/m3expl001.xetex.tlg  |    1 +
 l3kernel/testfiles/m3expl003.luatex.tlg |    1 +
 l3kernel/testfiles/m3expl003.ptex.tlg   |    1 +
 l3kernel/testfiles/m3expl003.tlg        |    1 +
 l3kernel/testfiles/m3expl003.uptex.tlg  |    1 +
 l3kernel/testfiles/m3expl003.xetex.tlg  |    1 +
 11 files changed, 52 insertions(+)

diff --git a/l3kernel/l3candidates.dtx b/l3kernel/l3candidates.dtx
index b4d8082..33a9ee8 100644
--- a/l3kernel/l3candidates.dtx
+++ b/l3kernel/l3candidates.dtx
@@ -1023,6 +1023,16 @@
 %   enabled, no action is taken.
 % \end{function}
 %
+% \begin{function}[added = 2018-07-28]{\sys_shell_split_ls:nN}
+%   \begin{syntax}
+%     \cs{sys_shell_split_ls:N} \Arg{glob} \meta{seq}
+%   \end{syntax}
+%   Sets the \meta{seq var} to contain one entry per directory listing
+%   (equivalent to |ls -1| or |dir /b|) as specified by the \meta{glob}: the
+%   entries are strings. If unrestricted shell is not enabled, no action is
+%   taken.
+% \end{function}
+%
 % \section{Additions to \pkg{l3tl}}
 %
 % \begin{function}[EXP,pTF]{\tl_if_single_token:n}
@@ -3244,6 +3254,38 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\sys_shell_split_ls:nN}
+%   Getting a one-per-line listing is easy enough. We need to set
+%   \cs{ExplSyntaxOff} as that deals with the end-of-line character. After that,
+%   just a case of tidying up. The listing always ends in |^^M| so there is an
+%   extra entry to trim.
+%    \begin{macrocode}
+\cs_new_protected:Npx \sys_shell_split_ls:nN #1#2
+  {
+    \sys_if_shell_unrestricted:T
+      {
+        \exp_not:N \tl_set_from_shell:Nnn \exp_not:N \l_@@_tmp_tl
+          {
+            \ExplSyntaxOff
+            \char_set_catcode_other:N \exp_not:N \\
+            \char_set_catcode_other:N \exp_not:N \#
+            \char_set_catcode_other:N \exp_not:N \~
+            \char_set_catcode_other:N \exp_not:N \%
+            \char_set_catcode_other:n { 13 }
+          }
+          {
+            \sys_if_platform_unix:T { ls~-1~ #1 }
+            \sys_if_platform_windows:T { dir~/b~ #1 }
+          }
+        \str_set:NV \exp_not:N \l_@@_tmp_tl \exp_not:N \l_@@_tmp_tl
+        \seq_set_split:NnV #2 { \char_generate:nn { `\^^M } { 12 } }
+          \exp_not:N \l_@@_tmp_tl
+        \seq_pop_right:NN #2 \exp_not:N \l_@@_tmp_tl
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+%
 % \subsection{Additions to \pkg{l3tl}}
 %
 %    \begin{macrocode}
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index de50427..d5cae7a 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -5874,6 +5874,7 @@ Defining \sys_shell_rm:n on line ...
 Defining \sys_shell_rmdir:n on line ...
 Defining \l__sys_tmp_tl on line ...
 Defining \sys_shell_get_pwd:N on line ...
+Defining \sys_shell_split_ls:nN on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index 8af90c1..82108c8 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -5908,6 +5908,7 @@ Defining \sys_shell_rm:n on line ...
 Defining \sys_shell_rmdir:n on line ...
 Defining \l__sys_tmp_tl on line ...
 Defining \sys_shell_get_pwd:N on line ...
+Defining \sys_shell_split_ls:nN on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index c8dedf3..2d3ae54 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -5908,6 +5908,7 @@ Defining \sys_shell_rm:n on line ...
 Defining \sys_shell_rmdir:n on line ...
 Defining \l__sys_tmp_tl on line ...
 Defining \sys_shell_get_pwd:N on line ...
+Defining \sys_shell_split_ls:nN on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index 4a08ddb..5d5e139 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -5905,6 +5905,7 @@ Defining \sys_shell_rm:n on line ...
 Defining \sys_shell_rmdir:n on line ...
 Defining \l__sys_tmp_tl on line ...
 Defining \sys_shell_get_pwd:N on line ...
+Defining \sys_shell_split_ls:nN on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index 2e8f77b..6772d70 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -5878,6 +5878,7 @@ Defining \sys_shell_rm:n on line ...
 Defining \sys_shell_rmdir:n on line ...
 Defining \l__sys_tmp_tl on line ...
 Defining \sys_shell_get_pwd:N on line ...
+Defining \sys_shell_split_ls:nN on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index de50427..d5cae7a 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -5874,6 +5874,7 @@ Defining \sys_shell_rm:n on line ...
 Defining \sys_shell_rmdir:n on line ...
 Defining \l__sys_tmp_tl on line ...
 Defining \sys_shell_get_pwd:N on line ...
+Defining \sys_shell_split_ls:nN on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index 8af90c1..82108c8 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -5908,6 +5908,7 @@ Defining \sys_shell_rm:n on line ...
 Defining \sys_shell_rmdir:n on line ...
 Defining \l__sys_tmp_tl on line ...
 Defining \sys_shell_get_pwd:N on line ...
+Defining \sys_shell_split_ls:nN on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index c8dedf3..2d3ae54 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -5908,6 +5908,7 @@ Defining \sys_shell_rm:n on line ...
 Defining \sys_shell_rmdir:n on line ...
 Defining \l__sys_tmp_tl on line ...
 Defining \sys_shell_get_pwd:N on line ...
+Defining \sys_shell_split_ls:nN on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index 4a08ddb..5d5e139 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -5905,6 +5905,7 @@ Defining \sys_shell_rm:n on line ...
 Defining \sys_shell_rmdir:n on line ...
 Defining \l__sys_tmp_tl on line ...
 Defining \sys_shell_get_pwd:N on line ...
+Defining \sys_shell_split_ls:nN on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index 2e8f77b..6772d70 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -5878,6 +5878,7 @@ Defining \sys_shell_rm:n on line ...
 Defining \sys_shell_rmdir:n on line ...
 Defining \l__sys_tmp_tl on line ...
 Defining \sys_shell_get_pwd:N on line ...
+Defining \sys_shell_split_ls:nN on line ...
 Defining \tl_if_single_token_p:n on line ...
 Defining \tl_if_single_token:nT on line ...
 Defining \tl_if_single_token:nF on line ...





More information about the latex3-commits mailing list