[latex3-commits] [l3svn] branch master updated: Add new \file_parse_path:nNNN function
noreply at latex-project.org
noreply at latex-project.org
Tue Jun 20 23:54:02 CEST 2017
This is an automated email from the git hooks/post-receive script.
joseph pushed a commit to branch master
in repository l3svn.
The following commit(s) were added to refs/heads/master by this push:
new fb3725c Add new \file_parse_path:nNNN function
fb3725c is described below
commit fb3725c42db37f3a417a4a78591f0eb5179db7bc
Author: Joseph Wright <joseph.wright at morningstar2.co.uk>
Date: Tue Jun 20 22:52:50 2017 +0100
Add new \file_parse_path:nNNN function
This is similar to \filename at parse but
- does not leave a trailing "/" in the dir part
- allows for multi-dot names
- removes any surrounding quoting marks from the path
---
l3kernel/l3file.dtx | 93 +++++++++++++++++++++++++++++++
l3kernel/testfiles/m3expl001.luatex.tlg | 4 ++
l3kernel/testfiles/m3expl001.ptex.tlg | 4 ++
l3kernel/testfiles/m3expl001.tlg | 4 ++
l3kernel/testfiles/m3expl001.uptex.tlg | 4 ++
l3kernel/testfiles/m3expl001.xetex.tlg | 4 ++
l3kernel/testfiles/m3expl003.luatex.tlg | 4 ++
l3kernel/testfiles/m3expl003.ptex.tlg | 4 ++
l3kernel/testfiles/m3expl003.tlg | 4 ++
l3kernel/testfiles/m3expl003.uptex.tlg | 4 ++
l3kernel/testfiles/m3expl003.xetex.tlg | 4 ++
l3kernel/testfiles/m3file001.lvt | 34 ++++++++++-
l3kernel/testfiles/m3file001.ptex.tlg | 23 +++++++-
l3kernel/testfiles/m3file001.tlg | 23 +++++++-
l3kernel/testfiles/m3file001.uptex.tlg | 23 +++++++-
l3kernel/testfiles/m3file001.xetex.tlg | 23 +++++++-
16 files changed, 250 insertions(+), 9 deletions(-)
diff --git a/l3kernel/l3file.dtx b/l3kernel/l3file.dtx
index c7a3015..24cb485 100644
--- a/l3kernel/l3file.dtx
+++ b/l3kernel/l3file.dtx
@@ -112,6 +112,27 @@
% If the file is not found then the \meta{str var} will be empty.
% \end{function}
%
+% \begin{function}[added = 2017-06-20]{\file_parse_path:nNNN}
+% \begin{syntax}
+% \cs{file_parse_path:nNNN} \Arg{file path} \meta{dir} \meta{name} \meta{ext}
+% \end{syntax}
+% Parsers the \meta{file path} and splits it into three parts, each of
+% which is returned by settings the appropriate local string variable:
+% \begin{itemize}
+% \item The \meta{dir}: everything up to the last |/| (path separator}
+% in the \meta{file path}. As with system \texttt{PATH} variables
+% and related functions, the \meta{dir} will \emph{not} feature a trailing
+% |/| unless it points to the root directory. If there is no path (only
+% a file name), \meta{dir} will be empty.
+% \item The \meta{name}: everything after the last |/| up to the last |.|,
+% where both of those characters are optional. The \meta{name} may
+% contain multiple |.| characters.
+% \item The \meta{ext}: everything after the last |.| If there is no
+% \meta{ext} in the \meta{file path}, the \TeX{} standard value
+% \texttt{.tex} will be returned.
+% \end{itemize}
+% \end{function}
+%
% \begin{function}[updated = 2012-02-17]{\file_input:n}
% \begin{syntax}
% \cs{file_input:n} \Arg{file name}
@@ -967,6 +988,78 @@
% \end{macro}
% \end{macro}
%
+% \begin{macro}{\file_parse_path:nNNN}
+% \begin{macro}[aux]
+% {\@@_parse_path_auxi:w, \@@_parse_path_auxii:w, \@@_parse_path_auxiii:w}
+% Parsing starts by stripping off any surrounding quotes. Assuming there is
+% then something to read, the next step is to split off the directory.
+% We don't want to add |/| until at least one parent directory is found,
+% but that will loose a leading |/| (absolute path). To deal with that,
+% there is a second test for that construct at the end of directory
+% discovery.
+% \begin{macrocode}
+\cs_new_protected:Npn \file_parse_path:nNNN #1#2#3#4
+ {
+ \@@_parse_path_auxi:w #1 " #1 " \q_stop #2#3#4
+ }
+\cs_new_protected:Npn \@@_parse_path_auxi:w #1 " #2 " #3 \q_stop #4#5#6
+ {
+ \str_clear:N #4
+ \str_clear:N #5
+ \str_clear:N #6
+ \tl_if_blank:nF {#2}
+ { \@@_parse_path_auxii:w #2 / \q_mark #2 \q_stop #4#5#6 }
+ }
+\cs_new_protected:Npn \@@_parse_path_auxii:w #1 / #2 \q_mark #3 \q_stop #4#5#6
+ {
+ \tl_if_blank:nTF {#2}
+ {
+ \tl_if_head_eq_charcode:nNT {#3} { / }
+ { \str_set:Nx #4 { / #4 } }
+ \tl_if_blank:nF {#1}
+ { \@@_parse_path_auxiii:w #1 . \q_stop #5#6 }
+ }
+ {
+ \str_set:Nx #4
+ {
+ #4
+ \str_if_empty:NF #4 { / }
+ #1
+ }
+ \@@_parse_path_auxii:w #2 \q_mark #3 \q_stop #4#5#6
+ }
+ }
+% \end{macrocode}
+% For the file name, we again need to deal with the special case of no
+% extension given. That is handled by assuming under such circumstances
+% these are |.tex| files. We also use a loop here to deal with multi-dot
+% names, \emph{cf.}~how \tn{filename at parse} would deal with this.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_parse_path_auxiii:w #1 . #2 \q_stop #3#4
+ {
+ \tl_if_blank:nTF {#2}
+ {
+ \str_if_empty:NTF #3
+ {
+ \str_set:Nn #3 {#1}
+ \str_set:Nn #4 { .tex }
+ }
+ { \str_set:Nn #4 { . #1 } }
+ }
+ {
+ \str_set:Nx #3
+ {
+ #3
+ \str_if_empty:NF #3 { . }
+ #1
+ }
+ \@@_parse_path_auxiii:w #2 \q_stop #3#4
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
% \begin{macro}{\file_list:}
% A function to list all files used to the log, without duplicates.
% In package mode, if \cs{@filelist} is still defined, we need to take
diff --git a/l3kernel/testfiles/m3expl001.luatex.tlg b/l3kernel/testfiles/m3expl001.luatex.tlg
index ed4bd2c..86404f0 100644
--- a/l3kernel/testfiles/m3expl001.luatex.tlg
+++ b/l3kernel/testfiles/m3expl001.luatex.tlg
@@ -2864,6 +2864,10 @@ Defining \__file_input:n on line ...
Defining \__file_input:V on line ...
Defining \__file_input_aux:n on line ...
Defining \__file_input_aux:o on line ...
+Defining \file_parse_path:nNNN on line ...
+Defining \__file_parse_path_auxi:w on line ...
+Defining \__file_parse_path_auxii:w on line ...
+Defining \__file_parse_path_name:w on line ...
Defining \file_list: on line ...
Defining \c_term_ior on line ...
Defining \g__ior_streams_seq on line ...
diff --git a/l3kernel/testfiles/m3expl001.ptex.tlg b/l3kernel/testfiles/m3expl001.ptex.tlg
index afb193e..722c2b3 100644
--- a/l3kernel/testfiles/m3expl001.ptex.tlg
+++ b/l3kernel/testfiles/m3expl001.ptex.tlg
@@ -2852,6 +2852,10 @@ Defining \__file_input:n on line ...
Defining \__file_input:V on line ...
Defining \__file_input_aux:n on line ...
Defining \__file_input_aux:o on line ...
+Defining \file_parse_path:nNNN on line ...
+Defining \__file_parse_path_auxi:w on line ...
+Defining \__file_parse_path_auxii:w on line ...
+Defining \__file_parse_path_name:w on line ...
Defining \file_list: on line ...
Defining \c_term_ior on line ...
Defining \g__ior_streams_seq on line ...
diff --git a/l3kernel/testfiles/m3expl001.tlg b/l3kernel/testfiles/m3expl001.tlg
index 5dd5645..d6715d4 100644
--- a/l3kernel/testfiles/m3expl001.tlg
+++ b/l3kernel/testfiles/m3expl001.tlg
@@ -2852,6 +2852,10 @@ Defining \__file_input:n on line ...
Defining \__file_input:V on line ...
Defining \__file_input_aux:n on line ...
Defining \__file_input_aux:o on line ...
+Defining \file_parse_path:nNNN on line ...
+Defining \__file_parse_path_auxi:w on line ...
+Defining \__file_parse_path_auxii:w on line ...
+Defining \__file_parse_path_name:w on line ...
Defining \file_list: on line ...
Defining \c_term_ior on line ...
Defining \g__ior_streams_seq on line ...
diff --git a/l3kernel/testfiles/m3expl001.uptex.tlg b/l3kernel/testfiles/m3expl001.uptex.tlg
index bb0ab5b..27bddda 100644
--- a/l3kernel/testfiles/m3expl001.uptex.tlg
+++ b/l3kernel/testfiles/m3expl001.uptex.tlg
@@ -2852,6 +2852,10 @@ Defining \__file_input:n on line ...
Defining \__file_input:V on line ...
Defining \__file_input_aux:n on line ...
Defining \__file_input_aux:o on line ...
+Defining \file_parse_path:nNNN on line ...
+Defining \__file_parse_path_auxi:w on line ...
+Defining \__file_parse_path_auxii:w on line ...
+Defining \__file_parse_path_name:w on line ...
Defining \file_list: on line ...
Defining \c_term_ior on line ...
Defining \g__ior_streams_seq on line ...
diff --git a/l3kernel/testfiles/m3expl001.xetex.tlg b/l3kernel/testfiles/m3expl001.xetex.tlg
index 4bd556a..85d2652 100644
--- a/l3kernel/testfiles/m3expl001.xetex.tlg
+++ b/l3kernel/testfiles/m3expl001.xetex.tlg
@@ -2862,6 +2862,10 @@ Defining \__file_input:n on line ...
Defining \__file_input:V on line ...
Defining \__file_input_aux:n on line ...
Defining \__file_input_aux:o on line ...
+Defining \file_parse_path:nNNN on line ...
+Defining \__file_parse_path_auxi:w on line ...
+Defining \__file_parse_path_auxii:w on line ...
+Defining \__file_parse_path_name:w on line ...
Defining \file_list: on line ...
Defining \c_term_ior on line ...
Defining \g__ior_streams_seq on line ...
diff --git a/l3kernel/testfiles/m3expl003.luatex.tlg b/l3kernel/testfiles/m3expl003.luatex.tlg
index 4ca6756..4af6c0f 100644
--- a/l3kernel/testfiles/m3expl003.luatex.tlg
+++ b/l3kernel/testfiles/m3expl003.luatex.tlg
@@ -2865,6 +2865,10 @@ Defining \__file_input:n on line ...
Defining \__file_input:V on line ...
Defining \__file_input_aux:n on line ...
Defining \__file_input_aux:o on line ...
+Defining \file_parse_path:nNNN on line ...
+Defining \__file_parse_path_auxi:w on line ...
+Defining \__file_parse_path_auxii:w on line ...
+Defining \__file_parse_path_name:w on line ...
Defining \file_list: on line ...
Defining \c_term_ior on line ...
Defining \g__ior_streams_seq on line ...
diff --git a/l3kernel/testfiles/m3expl003.ptex.tlg b/l3kernel/testfiles/m3expl003.ptex.tlg
index ef1ce4b..aead851 100644
--- a/l3kernel/testfiles/m3expl003.ptex.tlg
+++ b/l3kernel/testfiles/m3expl003.ptex.tlg
@@ -2853,6 +2853,10 @@ Defining \__file_input:n on line ...
Defining \__file_input:V on line ...
Defining \__file_input_aux:n on line ...
Defining \__file_input_aux:o on line ...
+Defining \file_parse_path:nNNN on line ...
+Defining \__file_parse_path_auxi:w on line ...
+Defining \__file_parse_path_auxii:w on line ...
+Defining \__file_parse_path_name:w on line ...
Defining \file_list: on line ...
Defining \c_term_ior on line ...
Defining \g__ior_streams_seq on line ...
diff --git a/l3kernel/testfiles/m3expl003.tlg b/l3kernel/testfiles/m3expl003.tlg
index 05d4102..5dbccbe 100644
--- a/l3kernel/testfiles/m3expl003.tlg
+++ b/l3kernel/testfiles/m3expl003.tlg
@@ -2853,6 +2853,10 @@ Defining \__file_input:n on line ...
Defining \__file_input:V on line ...
Defining \__file_input_aux:n on line ...
Defining \__file_input_aux:o on line ...
+Defining \file_parse_path:nNNN on line ...
+Defining \__file_parse_path_auxi:w on line ...
+Defining \__file_parse_path_auxii:w on line ...
+Defining \__file_parse_path_name:w on line ...
Defining \file_list: on line ...
Defining \c_term_ior on line ...
Defining \g__ior_streams_seq on line ...
diff --git a/l3kernel/testfiles/m3expl003.uptex.tlg b/l3kernel/testfiles/m3expl003.uptex.tlg
index dd29e16..32dc827 100644
--- a/l3kernel/testfiles/m3expl003.uptex.tlg
+++ b/l3kernel/testfiles/m3expl003.uptex.tlg
@@ -2853,6 +2853,10 @@ Defining \__file_input:n on line ...
Defining \__file_input:V on line ...
Defining \__file_input_aux:n on line ...
Defining \__file_input_aux:o on line ...
+Defining \file_parse_path:nNNN on line ...
+Defining \__file_parse_path_auxi:w on line ...
+Defining \__file_parse_path_auxii:w on line ...
+Defining \__file_parse_path_name:w on line ...
Defining \file_list: on line ...
Defining \c_term_ior on line ...
Defining \g__ior_streams_seq on line ...
diff --git a/l3kernel/testfiles/m3expl003.xetex.tlg b/l3kernel/testfiles/m3expl003.xetex.tlg
index 61ffe0e..48491a1 100644
--- a/l3kernel/testfiles/m3expl003.xetex.tlg
+++ b/l3kernel/testfiles/m3expl003.xetex.tlg
@@ -2863,6 +2863,10 @@ Defining \__file_input:n on line ...
Defining \__file_input:V on line ...
Defining \__file_input_aux:n on line ...
Defining \__file_input_aux:o on line ...
+Defining \file_parse_path:nNNN on line ...
+Defining \__file_parse_path_auxi:w on line ...
+Defining \__file_parse_path_auxii:w on line ...
+Defining \__file_parse_path_name:w on line ...
Defining \file_list: on line ...
Defining \c_term_ior on line ...
Defining \g__ior_streams_seq on line ...
diff --git a/l3kernel/testfiles/m3file001.lvt b/l3kernel/testfiles/m3file001.lvt
index 22fc9ec..e974506 100644
--- a/l3kernel/testfiles/m3file001.lvt
+++ b/l3kernel/testfiles/m3file001.lvt
@@ -1,5 +1,5 @@
%
-% Copyright (C) 2009-2012,2015 The LaTeX3 Project
+% Copyright (C) 2009-2012,2015,2017 The LaTeX3 Project
%
\documentclass{minimal}
@@ -74,6 +74,38 @@
\file_if_exist_input:nTF { NotAFile.xxx.yyy.zzz } \ERROR \FALSE
}
+\TEST { File~name~parsing }
+ {
+ \OMIT
+ \str_new:N \l_tmpc_str
+ \cs_set_protected:Npn \test:n #1
+ {
+ \file_parse_path:nNNN {#1} \l_tmpa_str \l_tmpb_str \l_tmpc_str
+ \TYPE
+ {
+ Path:~" \l_tmpa_str ",~
+ Name:~" \l_tmpb_str ",~
+ Ext:~ " \l_tmpc_str "
+ }
+ }
+ \TIMO
+ \test:n { }
+ \test:n { test }
+ \test:n { test.tex }
+ \test:n { "test.tex" }
+ \test:n { test.file.tex }
+ \test:n { test~file.tex }
+ \test:n { ~test~file.tex }
+ \test:n { "~test~file.tex" }
+ \test:n { bar/test.tex }
+ \test:n { bar/baz/test.tex }
+ \test:n { bar/baz~bob/test.tex }
+ \test:n { /test.tex }
+ \test:n { /baz/ }
+ \test:n { /bar/baz~bob/test.tex }
+ \test:n { "bar/baz~bob/test.tex" }
+ }
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\TEST { File~listing }
{ \file_list: }
diff --git a/l3kernel/testfiles/m3file001.ptex.tlg b/l3kernel/testfiles/m3file001.ptex.tlg
index 8a7480f..87b6700 100644
--- a/l3kernel/testfiles/m3file001.ptex.tlg
+++ b/l3kernel/testfiles/m3file001.ptex.tlg
@@ -68,7 +68,26 @@ TRUE
FALSE
============================================================
============================================================
-TEST 5: File listing
+TEST 5: File name parsing
+============================================================
+Path: "", Name: "", Ext: ""
+Path: "", Name: "test", Ext: ".tex"
+Path: "", Name: "test", Ext: ".tex"
+Path: "", Name: "test", Ext: ".tex"
+Path: "", Name: "test.file", Ext: ".tex"
+Path: "", Name: "test file", Ext: ".tex"
+Path: "", Name: " test file", Ext: ".tex"
+Path: "", Name: " test file", Ext: ".tex"
+Path: "bar", Name: "test", Ext: ".tex"
+Path: "bar/baz", Name: "test", Ext: ".tex"
+Path: "bar/baz bob", Name: "test", Ext: ".tex"
+Path: "/", Name: "test", Ext: ".tex"
+Path: "/baz", Name: "", Ext: ""
+Path: "/bar/baz bob", Name: "test", Ext: ".tex"
+Path: "bar/baz bob", Name: "test", Ext: ".tex"
+============================================================
+============================================================
+TEST 6: File listing
============================================================
* File List *
pldefs.ltx
@@ -89,7 +108,7 @@ filetest.txt
*************
============================================================
============================================================
-TEST 6: File name quoting
+TEST 7: File name quoting
============================================================
> \l_tmpa_str=foo.bar.
<recently read> }
diff --git a/l3kernel/testfiles/m3file001.tlg b/l3kernel/testfiles/m3file001.tlg
index eae443d..59d37f3 100644
--- a/l3kernel/testfiles/m3file001.tlg
+++ b/l3kernel/testfiles/m3file001.tlg
@@ -68,7 +68,26 @@ TRUE
FALSE
============================================================
============================================================
-TEST 5: File listing
+TEST 5: File name parsing
+============================================================
+Path: "", Name: "", Ext: ""
+Path: "", Name: "test", Ext: ".tex"
+Path: "", Name: "test", Ext: ".tex"
+Path: "", Name: "test", Ext: ".tex"
+Path: "", Name: "test.file", Ext: ".tex"
+Path: "", Name: "test file", Ext: ".tex"
+Path: "", Name: " test file", Ext: ".tex"
+Path: "", Name: " test file", Ext: ".tex"
+Path: "bar", Name: "test", Ext: ".tex"
+Path: "bar/baz", Name: "test", Ext: ".tex"
+Path: "bar/baz bob", Name: "test", Ext: ".tex"
+Path: "/", Name: "test", Ext: ".tex"
+Path: "/baz", Name: "", Ext: ""
+Path: "/bar/baz bob", Name: "test", Ext: ".tex"
+Path: "bar/baz bob", Name: "test", Ext: ".tex"
+============================================================
+============================================================
+TEST 6: File listing
============================================================
* File List *
minimal.cls
@@ -83,7 +102,7 @@ filetest.txt
*************
============================================================
============================================================
-TEST 6: File name quoting
+TEST 7: File name quoting
============================================================
> \l_tmpa_str=foo.bar.
<recently read> }
diff --git a/l3kernel/testfiles/m3file001.uptex.tlg b/l3kernel/testfiles/m3file001.uptex.tlg
index d744ba7..70087d1 100644
--- a/l3kernel/testfiles/m3file001.uptex.tlg
+++ b/l3kernel/testfiles/m3file001.uptex.tlg
@@ -68,7 +68,26 @@ TRUE
FALSE
============================================================
============================================================
-TEST 5: File listing
+TEST 5: File name parsing
+============================================================
+Path: "", Name: "", Ext: ""
+Path: "", Name: "test", Ext: ".tex"
+Path: "", Name: "test", Ext: ".tex"
+Path: "", Name: "test", Ext: ".tex"
+Path: "", Name: "test.file", Ext: ".tex"
+Path: "", Name: "test file", Ext: ".tex"
+Path: "", Name: " test file", Ext: ".tex"
+Path: "", Name: " test file", Ext: ".tex"
+Path: "bar", Name: "test", Ext: ".tex"
+Path: "bar/baz", Name: "test", Ext: ".tex"
+Path: "bar/baz bob", Name: "test", Ext: ".tex"
+Path: "/", Name: "test", Ext: ".tex"
+Path: "/baz", Name: "", Ext: ""
+Path: "/bar/baz bob", Name: "test", Ext: ".tex"
+Path: "bar/baz bob", Name: "test", Ext: ".tex"
+============================================================
+============================================================
+TEST 6: File listing
============================================================
* File List *
upldefs.ltx
@@ -89,7 +108,7 @@ filetest.txt
*************
============================================================
============================================================
-TEST 6: File name quoting
+TEST 7: File name quoting
============================================================
> \l_tmpa_str=foo.bar.
<recently read> }
diff --git a/l3kernel/testfiles/m3file001.xetex.tlg b/l3kernel/testfiles/m3file001.xetex.tlg
index ca619be..e75f64d 100644
--- a/l3kernel/testfiles/m3file001.xetex.tlg
+++ b/l3kernel/testfiles/m3file001.xetex.tlg
@@ -68,7 +68,26 @@ TRUE
FALSE
============================================================
============================================================
-TEST 5: File listing
+TEST 5: File name parsing
+============================================================
+Path: "", Name: "", Ext: ""
+Path: "", Name: "test", Ext: ".tex"
+Path: "", Name: "test", Ext: ".tex"
+Path: "", Name: "test", Ext: ".tex"
+Path: "", Name: "test.file", Ext: ".tex"
+Path: "", Name: "test file", Ext: ".tex"
+Path: "", Name: " test file", Ext: ".tex"
+Path: "", Name: " test file", Ext: ".tex"
+Path: "bar", Name: "test", Ext: ".tex"
+Path: "bar/baz", Name: "test", Ext: ".tex"
+Path: "bar/baz bob", Name: "test", Ext: ".tex"
+Path: "/", Name: "test", Ext: ".tex"
+Path: "/baz", Name: "", Ext: ""
+Path: "/bar/baz bob", Name: "test", Ext: ".tex"
+Path: "bar/baz bob", Name: "test", Ext: ".tex"
+============================================================
+============================================================
+TEST 6: File listing
============================================================
* File List *
minimal.cls
@@ -83,7 +102,7 @@ filetest.txt
*************
============================================================
============================================================
-TEST 6: File name quoting
+TEST 7: File name quoting
============================================================
> \l_tmpa_str=foo.bar.
<recently read> }
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the latex3-commits
mailing list