summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/knowledge/knowledge-utils.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/knowledge/knowledge-utils.dtx')
-rw-r--r--macros/latex/contrib/knowledge/knowledge-utils.dtx53
1 files changed, 49 insertions, 4 deletions
diff --git a/macros/latex/contrib/knowledge/knowledge-utils.dtx b/macros/latex/contrib/knowledge/knowledge-utils.dtx
index dc0f0deed7..477d57c188 100644
--- a/macros/latex/contrib/knowledge/knowledge-utils.dtx
+++ b/macros/latex/contrib/knowledge/knowledge-utils.dtx
@@ -323,11 +323,46 @@
\KAuxWrite*{}}
\NewDocumentCommand\KAuxClose{}
- {\iow_close:N\knowledge_kaux_iow
+ {\KAuxWrite*{\KAuxEOF {}}
+ \iow_close:N\knowledge_kaux_iow
\bool_gset_true:N\kaux_can_be_used_bool
\kaux_posttreatment_tl
}
% \end{macrocode}
+% Testing if the KAux file is complete.
+% |\kaux_if_exist_containline:nnTF| tests if a line of a file is equal to the argument.
+% This has to be used with care: the searched line is transformed into a str, thus introducing
+% potential extra spaces after the control sequences.
+% Also, when lines are read from the files, the trailing spaces are lost.
+% Anyway, |IfKAuxReadyTF| tests for the presence of |\KAuxEOF {}| in a proper way.
+% \begin{macrocode}
+\cs_new:Npn\kaux_if_exist_containline:nnTF#1#2{
+ \file_if_exist:nTF{#1}{
+ \ior_open:Nn\klg_tmpa_ior{#1}
+ \bool_gset_false:N\g_tmpa_bool
+ \bool_gset_false:N\g_tmpb_bool
+ \str_gset:Nn\g_tmpb_str{#2}
+ \bool_do_until:Nn\g_tmpa_bool{
+ \ior_if_eof:NTF\klg_tmpa_ior
+ {\bool_set_true:N\g_tmpa_bool}
+ {
+ \ior_str_get:NN\klg_tmpa_ior\g_tmpa_str
+ %\iow_term:x{(\exp_not:V\g_tmpa_str)=?(\exp_not:V\g_tmpb_str)}
+ \str_if_eq:NNTF\g_tmpa_str\g_tmpb_str
+ {\bool_gset_true:N\g_tmpa_bool
+ \bool_gset_true:N\g_tmpb_bool}
+ {}
+ }}
+ \ior_close:N\klg_tmpa_ior
+ %\bool_show:N\g_tmpb_bool
+ \bool_if:NTF\g_tmpb_bool
+ }
+ {\use_ii:nn}
+}
+
+\NewDocumentCommand\IfKAuxReadyTF{}
+ {\exp_args:Nx\kaux_if_exist_containline:nnTF{\c_sys_jobname_str.kaux}{\KAuxEOF {}}}
+% \end{macrocode}
%
%
%
@@ -386,6 +421,14 @@
\tl_gset:cn{kaux_\cs_to_str:N#1-args_tl}{#2}
\tl_gput_right:Nn\kaux_command_list_tl{#1}
}
+% \end{macrocode}
+% As an example, |\KAuxEOF| describes is used at the end of the Kaux file.
+% \begin{macrocode}
+\NewKAuxCommand\KAuxEOF{m}
+ {Does~nothing,~useless~empty~argument
+ ,~and~is~searched~for~knowing~if~the~kaux~file~was~written~till~the~end.}
+% \end{macrocode}
+% \begin{macrocode}
\NewDocumentCommand\KAuxCommand{mmm}
{ \cs_if_exist:NTF #1
{}
@@ -524,7 +567,7 @@
% \subsection{References}
%
% This is an old part of the code which is difficult to read.
-% It should probably be cleaned.
+% It should be cleaned. But this is a lot of work.
%
% When using \cs{\cell_new_type:nnn}, a new name space is created,
% in which can be stored information. The first parameter is the name space. The second
@@ -1010,7 +1053,8 @@
\ior_close:N\klg_tmpa_ior
\iow_close:N\klg_tmpa_iow
\group_end:}}
-
+% \end{macrocode}
+% \begin{macrocode}
\cs_new_protected_with_variants:Nnn\kl_compare_files:Nnn{NnV,NVn,NVV}
{\group_begin:
\bool_set_false:N\l_tmpa_bool% set when finished
@@ -1052,7 +1096,8 @@
{\group_end:\bool_set_true:N#1}
{\group_end:\bool_set_false:N#1}
}
-
+% \end{macrocode}
+% \begin{macrocode}
\cs_new_protected:Nn\kl_tl_to_file:nn
{\iow_open:Nn\klg_tmpa_iow{#1}
\iow_now:Nn\klg_tmpa_iow{#2}