diff options
Diffstat (limited to 'macros/latex/contrib/l3experimental/l3sys-shell.dtx')
-rw-r--r-- | macros/latex/contrib/l3experimental/l3sys-shell.dtx | 55 |
1 files changed, 46 insertions, 9 deletions
diff --git a/macros/latex/contrib/l3experimental/l3sys-shell.dtx b/macros/latex/contrib/l3experimental/l3sys-shell.dtx index ad1733ab77..186a03d87a 100644 --- a/macros/latex/contrib/l3experimental/l3sys-shell.dtx +++ b/macros/latex/contrib/l3experimental/l3sys-shell.dtx @@ -46,7 +46,7 @@ % }^^A % } % -% \date{Released 2024-01-04} +% \date{Released 2024-02-20} % % \maketitle % @@ -126,14 +126,15 @@ % enabled, no action is taken. % \end{function} % -% \begin{function}[added = 2018-07-28]{\sys_shell_split_ls:nN} +% \begin{function}[added = 2018-07-28, updated = 2024-02-20] +% {\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. +% (equivalent to |ls -1| or |dir /b /s| with relative paths) as specified by +% the \meta{glob}: the entries are strings. If unrestricted shell is not +% enabled, no action is taken. % \end{function} % % \end{documentation} @@ -151,7 +152,7 @@ % \end{macrocode} % % \begin{macrocode} -\ProvidesExplPackage{l3sys-shell}{2024-01-04}{} +\ProvidesExplPackage{l3sys-shell}{2024-02-20}{} {L3 Experimental system shell functions} % \end{macrocode} % @@ -328,9 +329,10 @@ % \end{macrocode} % \end{macro} % -% \begin{variable}{\l_@@_tmp_tl} +% \begin{variable}{\l_@@_tmp_seq, \l_@@_tmp_tl} % Scratch space. % \begin{macrocode} +\seq_new:N \l_@@_tmp_seq \tl_new:N \l_@@_tmp_tl % \end{macrocode} % \end{variable} @@ -366,6 +368,8 @@ % \end{macro} % % \begin{macro}{\sys_shell_split_ls:nN} +% \begin{macro}{\@@_shell_split_ls:nN} +% \begin{macro}{\@@_shell_split_ls:w} % 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 @@ -375,10 +379,11 @@ { \sys_if_shell_unrestricted:T { - \exp_not:N \sys_get_shell:nnN + \exp_not:N \exp_args:Ne \exp_not:N \sys_get_shell:nnN { \sys_if_platform_unix:T { ls~-1~ #1 } - \sys_if_platform_windows:T { dir~/b~ #1 } + \sys_if_platform_windows:T + { dir~/b~/s~ \exp_not:N \@@_path_to_win:n {#1} } } { \ExplSyntaxOff @@ -395,10 +400,42 @@ \seq_pop_right:NN #2 \exp_not:N \l_@@_tmp_tl \exp_not:N \tl_if_blank:eTF { \exp_not:N \seq_item:Nn #2 { 1 } } { \seq_clear:N #2 } + \sys_if_platform_windows:T + { + \sys_get_shell_pwd:N \exp_not:N \l_@@_tmp_tl + \exp_not:N \exp_args:NV \exp_not:N \@@_shell_split_ls:nN + \exp_not:N \l_@@_tmp_tl #2 + } + } + } +% \end{macrocode} +% On Windows, we can either get just file names (|dir /b|) or file names with +% complete paths (|dir /s /b|), but not file names with relative paths in +% a simple way. So we take the full paths and trim off the current working +% directory. Normalization gives the same results as |ls|, hopefully. +% \begin{macrocode} +\sys_if_platform_windows:T + { + \cs_new_protected:Npe \@@_shell_split_ls:nN #1#2 + { + \cs_set:Npn \exp_not:N \@@_shell_split_ls:w #1 \c_backslash_str { } + \seq_set_eq:NN \exp_not:N \l_@@_tmp_seq #2 + \seq_clear:N #2 + \seq_map_inline:Nn \exp_not:N \l_@@_tmp_seq + { + \tl_set:Ne \exp_not:N \l_@@_tmp_tl + { \exp_not:N \@@_shell_split_ls:w ##1 } + \tl_replace_all:Nnn \exp_not:N \l_@@_tmp_tl + { \c_backslash_str } { / } + \seq_put_right:NV #2 \exp_not:N \l_@@_tmp_tl + } } + \cs_new:Npn \@@_shell_split_ls:w { } } % \end{macrocode} % \end{macro} +% \end{macro} +% \end{macro} % % \begin{macrocode} %</package> |