[latex3-commits] [git/LaTeX3-latex3-latex3] main: Implement functions to show a single ior/iow stream (see #241) (e5d95c350)

Joseph Wright joseph.wright at morningstar2.co.uk
Wed May 12 14:36:30 CEST 2021


Repository : https://github.com/latex3/latex3
On branch  : main
Link       : https://github.com/latex3/latex3/commit/e5d95c3502791b682c5d04755fef8bbb308e2191

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

commit e5d95c3502791b682c5d04755fef8bbb308e2191
Author: Bruno Le Floch <blflatex at gmail.com>
Date:   Tue May 11 13:34:41 2021 +0200

    Implement functions to show a single ior/iow stream (see #241)


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

e5d95c3502791b682c5d04755fef8bbb308e2191
 l3kernel/CHANGELOG.md                  |  1 +
 l3kernel/l3file.dtx                    | 68 ++++++++++++++++++++++++++++++++++
 l3kernel/testfiles/m3ior002.lvt        |  5 +++
 l3kernel/testfiles/m3ior002.tlg        |  7 ++++
 l3kernel/testfiles/m3iow001.luatex.tlg | 11 ++++++
 l3kernel/testfiles/m3iow001.lvt        |  3 ++
 l3kernel/testfiles/m3iow001.ptex.tlg   | 11 ++++++
 l3kernel/testfiles/m3iow001.tlg        | 11 ++++++
 l3kernel/testfiles/m3iow001.uptex.tlg  | 11 ++++++
 l3kernel/testfiles/m3iow001.xetex.tlg  | 11 ++++++
 10 files changed, 139 insertions(+)

diff --git a/l3kernel/CHANGELOG.md b/l3kernel/CHANGELOG.md
index 678849bf3..658ed3b6e 100644
--- a/l3kernel/CHANGELOG.md
+++ b/l3kernel/CHANGELOG.md
@@ -11,6 +11,7 @@ this project uses date-based 'snapshot' version identifiers.
 - `\sys_timer:`
 - `\color_log:n`, `\tl_log_analysis:N`, `\tl_log_analysis:n` (issue #241)
 - `\coffin_show:Nnn` and related functions (issue #241)
+- `\ior_show:N`, `\iow_show:N` and log functions (issue #241)
 
 ## [2021-05-11]
 
diff --git a/l3kernel/l3file.dtx b/l3kernel/l3file.dtx
index a89f6540c..a5ab4bf3f 100644
--- a/l3kernel/l3file.dtx
+++ b/l3kernel/l3file.dtx
@@ -151,6 +151,21 @@
 %   to other programmers.
 % \end{function}
 %
+% \begin{function}[added = 2021-05-11]
+%   {
+%     \ior_show:N, \ior_show:c, \ior_log:N, \ior_log:c,
+%     \iow_show:N, \iow_show:c, \iow_log:N, \iow_log:c
+%   }
+%   \begin{syntax}
+%     \cs{ior_show:N} \meta{stream}
+%     \cs{ior_log:N} \meta{stream}
+%     \cs{iow_show:N} \meta{stream}
+%     \cs{iow_log:N} \meta{stream}
+%   \end{syntax}
+%   Display (to the terminal or log file) the file name associated to
+%   the (read or write) \meta{stream}.
+% \end{function}
+%
 % \begin{function}[added = 2017-06-27]
 %   {
 %     \ior_show_list:, \ior_log_list:,
@@ -1118,6 +1133,29 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\ior_show:N, \ior_log:N, \@@_show:NN}
+%   Seek the stream in the \cs{g_@@_streams_prop} list, then show the
+%   stream as open or closed accordingly.
+%    \begin{macrocode}
+\cs_new_protected:Npn \ior_show:N { \@@_show:NN \tl_show:n }
+\cs_generate_variant:Nn \ior_show:N { c }
+\cs_new_protected:Npn \ior_log:N { \@@_show:NN \tl_log:n }
+\cs_generate_variant:Nn \ior_log:N { c }
+\cs_new_protected:Npn \@@_show:NN #1#2
+  {
+    \__kernel_chk_defined:NT #2
+      {
+        \prop_get:NVNTF \g_@@_streams_prop #2 \l_@@_internal_tl
+          {
+            \exp_args:Nx #1
+              { \token_to_str:N #2 ~ open: ~ \l_@@_internal_tl }
+          }
+          { \exp_args:Nx #1 { \token_to_str:N #2 ~ closed } }
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+%
 % \begin{macro}{\ior_show_list:, \ior_log_list:}
 % \begin{macro}{\@@_list:N}
 %   Show the property lists, but with some \enquote{pretty printing}.
@@ -1354,6 +1392,13 @@
 %
 % \subsubsection{Variables and constants}
 %
+% \begin{variable}{\l_@@_internal_tl}
+%   Used as a short-term scratch variable.
+%    \begin{macrocode}
+\tl_new:N  \l_@@_internal_tl
+%    \end{macrocode}
+% \end{variable}
+%
 % \begin{variable}{\c_log_iow, \c_term_iow}
 %   Here we allocate two output streams for writing to the transcript
 %   file only (\cs{c_log_iow}) and to both the terminal and transcript
@@ -1520,6 +1565,29 @@
 %    \end{macrocode}
 % \end{macro}
 %
+% \begin{macro}{\iow_show:N, \iow_log:N, \@@_show:NN}
+%   Seek the stream in the \cs{g_@@_streams_prop} list, then show the
+%   stream as open or closed accordingly.
+%    \begin{macrocode}
+\cs_new_protected:Npn \iow_show:N { \@@_show:NN \tl_show:n }
+\cs_generate_variant:Nn \iow_show:N { c }
+\cs_new_protected:Npn \iow_log:N { \@@_show:NN \tl_log:n }
+\cs_generate_variant:Nn \iow_log:N { c }
+\cs_new_protected:Npn \@@_show:NN #1#2
+  {
+    \__kernel_chk_defined:NT #2
+      {
+        \prop_get:NVNTF \g_@@_streams_prop #2 \l_@@_internal_tl
+          {
+            \exp_args:Nx #1
+              { \token_to_str:N #2 ~ open: ~ \l_@@_internal_tl }
+          }
+          { \exp_args:Nx #1 { \token_to_str:N #2 ~ closed } }
+      }
+  }
+%    \end{macrocode}
+% \end{macro}
+%
 % \begin{macro}{\iow_show_list:, \iow_log_list:}
 % \begin{macro}{\@@_list:N}
 %   Done as for input, but with a copy of the auxiliary so the name is correct.
diff --git a/l3kernel/testfiles/m3ior002.lvt b/l3kernel/testfiles/m3ior002.lvt
index 01d6231e7..02032ed1e 100644
--- a/l3kernel/testfiles/m3ior002.lvt
+++ b/l3kernel/testfiles/m3ior002.lvt
@@ -23,6 +23,9 @@
   {
     \OMIT
     \ior_new:N \test
+    \TIMO
+    \ior_show:N \test
+    \OMIT
     \ior_open:Nn \test  { filetest.txt }
     \int_zero:N \l_tmpa_int
     \TIMO
@@ -36,11 +39,13 @@
     \ior_open:Nn \test { filetest.txt }
     \int_zero:N \l_tmpa_int
     \TIMO
+    \ior_show:c { test }
     \ior_str_map_inline:Nn \test
       {
         \TYPE {|#1|}
         \int_incr:N \l_tmpa_int
       }
+    \ior_log:c { test }
     \TYPE { \int_use:N \l_tmpa_int \c_space_tl lines }
   }
 
diff --git a/l3kernel/testfiles/m3ior002.tlg b/l3kernel/testfiles/m3ior002.tlg
index 3e6e0bbe6..9e4906eab 100644
--- a/l3kernel/testfiles/m3ior002.tlg
+++ b/l3kernel/testfiles/m3ior002.tlg
@@ -4,15 +4,22 @@ Author: Bruno Le Floch
 ============================================================
 TEST 1: Mapping
 ============================================================
+> \test closed.
+<recently read> }
+l. ...  }
 |\ExplSyntaxOff |
 |Thisfileisneededbym3file001.lvt,m3ior001.lvtandm3ior002.lvt:|
 |Pleaseleaveitalone!|
 |\ExplSyntaxOn |
 4 lines
+> \test open: filetest.txt.
+<recently read> }
+l. ...  }
 |\ExplSyntaxOff|
 |This file is needed by m3file001.lvt, m3ior001.lvt and m3ior002.lvt:|
 |Please leave it alone!|
 |\ExplSyntaxOn|
+> \test open: filetest.txt.
 4 lines
 ============================================================
 ============================================================
diff --git a/l3kernel/testfiles/m3iow001.luatex.tlg b/l3kernel/testfiles/m3iow001.luatex.tlg
index b01fbd2c8..50f8050fe 100644
--- a/l3kernel/testfiles/m3iow001.luatex.tlg
+++ b/l3kernel/testfiles/m3iow001.luatex.tlg
@@ -4,7 +4,15 @@ Author: Joseph Wright
 ============================================================
 TEST 1: Name a stream
 ============================================================
+! LaTeX3 Error: Variable \testa undefined.
+For immediate help type H <return>.
+ ...                                              
+l. ...}
+This is a coding error.
+LaTeX has been asked to show a variable \testa, but this has not been defined
+yet.
 Defining \testa on line ...
+> \testa closed.
 Defining \testb on line ...
 ! LaTeX3 Error: Control sequence \testa already defined.
 For immediate help type H <return>.
@@ -31,6 +39,9 @@ Defining \testb on line ...
 TEST 2: Open a write
 ============================================================
 \test=\write...
+> \test open: rubbish.log.
+<recently read> }
+l. ...}
 ============================================================
 ============================================================
 TEST 3: Close a write
diff --git a/l3kernel/testfiles/m3iow001.lvt b/l3kernel/testfiles/m3iow001.lvt
index 2518bbaf6..d1f9dec7d 100644
--- a/l3kernel/testfiles/m3iow001.lvt
+++ b/l3kernel/testfiles/m3iow001.lvt
@@ -34,7 +34,9 @@
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \TEST{Name~a~stream}{
+  \iow_show:c { testa }
   \iow_new:N \testa
+  \iow_log:c { testa }
   \iow_new:c {testb}
   \iow_new:N \testa
   \iow_new:c {testb}
@@ -45,6 +47,7 @@
 \TIMO
 \TEST{Open~a~write}{
   \iow_open:Nn \test { rubbish.log }
+  \iow_show:N \test
   \iow_open:cn {test} { rubbish.log }
 }
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/l3kernel/testfiles/m3iow001.ptex.tlg b/l3kernel/testfiles/m3iow001.ptex.tlg
index 3562cd543..24b1cf57a 100644
--- a/l3kernel/testfiles/m3iow001.ptex.tlg
+++ b/l3kernel/testfiles/m3iow001.ptex.tlg
@@ -4,7 +4,15 @@ Author: Joseph Wright
 ============================================================
 TEST 1: Name a stream
 ============================================================
+! LaTeX3 Error: Variable \testa undefined.
+For immediate help type H <return>.
+ ...                                              
+l. ...}
+This is a coding error.
+LaTeX has been asked to show a variable \testa, but this has not been defined
+yet.
 Defining \testa on line ...
+> \testa closed.
 Defining \testb on line ...
 ! LaTeX3 Error: Control sequence \testa already defined.
 For immediate help type H <return>.
@@ -31,6 +39,9 @@ Defining \testb on line ...
 TEST 2: Open a write
 ============================================================
 \test=\write...
+> \test open: rubbish.log.
+<recently read> }
+l. ...}
 ============================================================
 ============================================================
 TEST 3: Close a write
diff --git a/l3kernel/testfiles/m3iow001.tlg b/l3kernel/testfiles/m3iow001.tlg
index ac275f10c..9713628d8 100644
--- a/l3kernel/testfiles/m3iow001.tlg
+++ b/l3kernel/testfiles/m3iow001.tlg
@@ -4,7 +4,15 @@ Author: Joseph Wright
 ============================================================
 TEST 1: Name a stream
 ============================================================
+! LaTeX3 Error: Variable \testa undefined.
+For immediate help type H <return>.
+ ...                                              
+l. ...}
+This is a coding error.
+LaTeX has been asked to show a variable \testa, but this has not been defined
+yet.
 Defining \testa on line ...
+> \testa closed.
 Defining \testb on line ...
 ! LaTeX3 Error: Control sequence \testa already defined.
 For immediate help type H <return>.
@@ -31,6 +39,9 @@ Defining \testb on line ...
 TEST 2: Open a write
 ============================================================
 \test=\write...
+> \test open: rubbish.log.
+<recently read> }
+l. ...}
 ============================================================
 ============================================================
 TEST 3: Close a write
diff --git a/l3kernel/testfiles/m3iow001.uptex.tlg b/l3kernel/testfiles/m3iow001.uptex.tlg
index 3562cd543..24b1cf57a 100644
--- a/l3kernel/testfiles/m3iow001.uptex.tlg
+++ b/l3kernel/testfiles/m3iow001.uptex.tlg
@@ -4,7 +4,15 @@ Author: Joseph Wright
 ============================================================
 TEST 1: Name a stream
 ============================================================
+! LaTeX3 Error: Variable \testa undefined.
+For immediate help type H <return>.
+ ...                                              
+l. ...}
+This is a coding error.
+LaTeX has been asked to show a variable \testa, but this has not been defined
+yet.
 Defining \testa on line ...
+> \testa closed.
 Defining \testb on line ...
 ! LaTeX3 Error: Control sequence \testa already defined.
 For immediate help type H <return>.
@@ -31,6 +39,9 @@ Defining \testb on line ...
 TEST 2: Open a write
 ============================================================
 \test=\write...
+> \test open: rubbish.log.
+<recently read> }
+l. ...}
 ============================================================
 ============================================================
 TEST 3: Close a write
diff --git a/l3kernel/testfiles/m3iow001.xetex.tlg b/l3kernel/testfiles/m3iow001.xetex.tlg
index 5c56d0327..90725fd0c 100644
--- a/l3kernel/testfiles/m3iow001.xetex.tlg
+++ b/l3kernel/testfiles/m3iow001.xetex.tlg
@@ -4,7 +4,15 @@ Author: Joseph Wright
 ============================================================
 TEST 1: Name a stream
 ============================================================
+! LaTeX3 Error: Variable \testa undefined.
+For immediate help type H <return>.
+ ...                                              
+l. ...}
+This is a coding error.
+LaTeX has been asked to show a variable \testa, but this has not been defined
+yet.
 Defining \testa on line ...
+> \testa closed.
 Defining \testb on line ...
 ! LaTeX3 Error: Control sequence \testa already defined.
 For immediate help type H <return>.
@@ -31,6 +39,9 @@ Defining \testb on line ...
 TEST 2: Open a write
 ============================================================
 \test=\write...
+> \test open: rubbish.log.
+<recently read> }
+l. ...}
 ============================================================
 ============================================================
 TEST 3: Close a write





More information about the latex3-commits mailing list.