[latex3-commits] [latex3/l3sys-query] 2e: prototype 2e interface (abdd93f)

github at latex-project.org github at latex-project.org
Fri Mar 8 16:13:25 CET 2024


Repository : https://github.com/latex3/l3sys-query
On branch  : 2e
Link       : https://github.com/latex3/l3sys-query/commit/abdd93f2de54feb081adb3589d7a5625cdbdffce

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

commit abdd93f2de54feb081adb3589d7a5625cdbdffce
Author: David Carlisle <d.p.carlisle at gmail.com>
Date:   Fri Mar 8 15:13:25 2024 +0000

    prototype 2e interface


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

abdd93f2de54feb081adb3589d7a5625cdbdffce
 l3sys-query.sty | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 test-2e-01.tex  | 22 ++++++++++++++++++
 2 files changed, 94 insertions(+)

diff --git a/l3sys-query.sty b/l3sys-query.sty
new file mode 100644
index 0000000..6c6651a
--- /dev/null
+++ b/l3sys-query.sty
@@ -0,0 +1,72 @@
+
+\ProvidesPackage{l3sys-query}[2024-03-08 v0.01 LaTeX2e interface for l3sys file queries]
+
+% Copyright 2024  The LaTeX Project
+% License: LPPL 1.3c
+
+% Defines:
+
+% \QueryPWD {<result>}
+% defines the command passed in as #1 to be the current working directory
+
+% \QueryFiles[<options>]{<args>}{function}
+% produces a file list based on args and the options then applies function to each one.
+% function should be a macro body which will be passed the file path as  #1
+% on each iteration.
+% For options and details see l3sys.dtx
+
+\ExplSyntaxOn
+
+\NewDocumentCommand\QueryPWD {m} {
+  \sys_get_query:nnnN {pwd} {} {} #1
+}
+
+
+\NewDocumentCommand\QueryFiles {} {
+  \group_begin:
+    \char_set_catcode_other:N \~
+    \char_set_catcode_other:N \%
+    \QueryFiles_inner
+ }
+\NewDocumentCommand\QueryFiles_inner {O{}mm}{
+  \group_end:
+  \tl_set:Nn\l_tmpa_tl{}
+  \keys_set:nn{QueryFiles}{#1}
+  \exp_args:NnV\sys_split_query:nnnN {ls} \l_tmpa_tl {#2} \l_tmpa_seq
+  \seq_map_inline:Nn\l_tmpa_seq{#3}
+}
+
+\keys_define:nn {QueryFiles} {
+recursive .code:n  =\tl_put_right:Nn \l_tmpa_tl {--recursive ~ } ,
+recursive .value_forbidden:n = true ,
+
+all .code:n  =\tl_put_right:Nn \l_tmpa_tl {--all ~ } ,
+all .value_forbidden:n = true ,
+
+ignore-case .code:n  =\tl_put_right:Nn \l_tmpa_tl {--ignore-case ~ } ,
+ignore-case .value_forbidden:n = true ,
+
+reverse-sort .code:n  =\tl_put_right:Nn \l_tmpa_tl {--reverse-sort ~ } ,
+reverse-sort .value_forbidden:n = true ,
+
+exclude .code:n  =\tl_put_right:Ne \l_tmpa_tl {
+  --exclude ~
+  \sys_if_shell_restricted:TF: :'
+  \exp_not:n{#1}
+  \sys_if_shell_restricted:TF: :'
+  ~ } ,
+exclude .value_required:n = true ,
+
+type .choices:nn = {d,f}
+                   {\tl_put_right:Nn \l_tmpa_tl {--type ~ #1 ~ }} ,
+sort .choices:nn = {date,name}
+{\tl_put_right:Nn \l_tmpa_tl {--sort ~ #1 ~ }} ,
+
+
+pattern .code:n  =\tl_put_right:Nn \l_tmpa_tl {--pattern ~ } ,
+pattern .value_forbidden:n = true ,
+
+}
+
+
+\ExplSyntaxOff
diff --git a/test-2e-01.tex b/test-2e-01.tex
new file mode 100644
index 0000000..c457bec
--- /dev/null
+++ b/test-2e-01.tex
@@ -0,0 +1,22 @@
+\documentclass{article}
+\usepackage{l3sys-query}
+
+\errorcontextlines888
+\QueryPWD \thisdir
+
+\typeout{PWD: \thisdir}
+
+\QueryFiles{*.tex}{\typeout{A: #1}}
+
+\QueryFiles[recursive,type=d]{}{\typeout{B: #1}}% . ought to work
+\QueryFiles[recursive,]{.}{\typeout{BB: #1}}% . ought to work
+
+\QueryFiles[sort=date]{*.tex}{\typeout{C: #1}}
+
+\QueryFiles[pattern]{^[0-9].*.tex}{\typeout{D: #1}}
+
+
+\QueryFiles[pattern]{^%d.*.tex}{\typeout{E: #1}}
+
+\stop
+





More information about the latex3-commits mailing list.