summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/l3kernel/l3file.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/latex/l3kernel/l3file.dtx')
-rw-r--r--Master/texmf-dist/source/latex/l3kernel/l3file.dtx80
1 files changed, 78 insertions, 2 deletions
diff --git a/Master/texmf-dist/source/latex/l3kernel/l3file.dtx b/Master/texmf-dist/source/latex/l3kernel/l3file.dtx
index 75130a10858..1fc35e1cd1b 100644
--- a/Master/texmf-dist/source/latex/l3kernel/l3file.dtx
+++ b/Master/texmf-dist/source/latex/l3kernel/l3file.dtx
@@ -1,6 +1,8 @@
% \iffalse meta-comment
%
-%% File: l3file.dtx Copyright (C) 1990-2019 The LaTeX3 Project
+%% File: l3file.dtx
+%
+% Copyright (C) 1990-2019 The LaTeX3 Project
%
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
@@ -42,7 +44,7 @@
% }^^A
% }
%
-% \date{Released 2019-01-13}
+% \date{Released 2019-01-28}
%
% \maketitle
%
@@ -590,6 +592,21 @@
% \cs{l_file_search_path_seq}.
% \end{function}
%
+% \begin{function}[added = 2019-01-16]{\file_get:nnN}
+% \begin{function}[TF, added = 2019-01-16]{\file_get:nnN}
+% \begin{syntax}
+% \cs{file_get:nnN} \Arg{filename} \Arg{setup} \meta{tl}
+% \cs{file_get:nnNTF} \Arg{filename} \Arg{setup} \meta{tl} \Arg{true code} \Arg{false code}
+% \end{syntax}
+% Defines \meta{tl} to the contents of \meta{filename}.
+% Category codes may need to be set appropriately via the \meta{setup}
+% argument.
+% While \cs{file_get:nnN} produces an error if the file is not found,
+% \cs{file_get:nnNTF} runs the \meta{true code} (after the assignment
+% to \meta{tl}) if the file is found and \meta{false code} otherwise.
+% \end{function}
+% \end{function}
+%
% \begin{function}[updated = 2017-06-26]
% {\file_get_full_name:nN, \file_get_full_name:VN}
% \begin{syntax}
@@ -2152,6 +2169,65 @@
% \end{macro}
% \end{macro}
%
+% \begin{variable}{\c_@@_marker_tl}
+% The same idea as the marker for rescanning token lists: this pair of
+% tokens cannot appear in a file that is being input.
+% \begin{macrocode}
+\tl_const:Nx \c_@@_marker_tl { : \token_to_str:N : }
+% \end{macrocode}
+% \end{variable}
+%
+% \begin{macro}[TF]{\file_get:nnN}
+% \begin{macro}{\file_get:nnN,\@@_get_aux:nnN,\@@_get_do:Nw}
+% The approach here is similar to that for \cs{tl_set_rescan:Nnn}.
+% The file contents are grabbed as an argument delimited by
+% \cs{c_@@_marker_tl}. A few subtleties: braces in \cs{if_false:}
+% \ldots{} \cs{fi:} to deal with possible alignment tabs,
+% \tn{tracingnesting} to avoid a warning about a group being closed
+% inside the \tn{scantokens}, and \cs{prg_return_true:} is placed
+% after the end-of-file marker.
+% \begin{macrocode}
+\cs_new_protected:Npn \file_get:nnN #1#2#3
+ {
+ \file_get:nnNF {#1} {#2} #3
+ { \__kernel_file_missing:n {#1} }
+ }
+\prg_new_protected_conditional:Npnn \file_get:nnN #1#2#3 { T , F , TF }
+ {
+ \file_get_full_name:nN {#1} \l_@@_full_name_str
+ \str_if_empty:NTF \l_@@_full_name_str
+ { \prg_return_false: }
+ {
+ \exp_args:NV \@@_get_aux:nnN
+ \l_@@_full_name_str
+ {#2} #3
+ \prg_return_true:
+ }
+ }
+\cs_new_protected:Npn \@@_get_aux:nnN #1#2#3
+ {
+ \if_false: { \fi:
+ \group_begin:
+ \int_set_eq:NN \tex_tracingnesting:D \c_zero_int
+ \exp_args:No \tex_everyeof:D { \c_@@_marker_tl }
+ #2 \scan_stop:
+ \exp_after:wN \@@_get_do:Nw
+ \exp_after:wN #3
+ \exp_after:wN \prg_do_nothing:
+ \tex_input:D #1 \scan_stop:
+ \if_false: } \fi:
+ }
+\exp_args:Nno \use:nn
+ { \cs_new_protected:Npn \@@_get_do:Nw #1#2 }
+ { \c_@@_marker_tl }
+ {
+ \group_end:
+ \tl_set:No #1 {#2}
+ }
+% \end{macrocode}
+% \end{macro}
+% \end{macro}
+%
% \begin{macro}{\file_get_full_name:nN, \file_get_full_name:VN}
% \begin{macro}{\@@_get_full_name_search:nN}
% The way to test if a file exists is to try to open it: if it does