summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/tcolorbox/tcbprocessing.code.tex
blob: ce0ae4307576d68be2a60dd0a04ebeb3e467a54b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
%% The LaTeX package tcolorbox - version 6.2.0 (2024/01/10)
%% tcbprocessing.code.tex: Code for conditional processing
%%
%% -------------------------------------------------------------------------------------------
%% Copyright (c) 2006-2024 by Prof. Dr. Dr. Thomas F. Sturm <thomas dot sturm at unibw dot de>
%% -------------------------------------------------------------------------------------------
%%
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%%
%% This work has the LPPL maintenance status `author-maintained'.
%%
%% This work consists of all files listed in README
%%
\tcb@set@library@version{6.2.0}

\ExplSyntaxOn

\bool_new:N \l__tcobox_proc_hash_equal_bool

\cs_new_protected:Npn \__tcobox_proc_compute_hash:nn #1#2
  {
    \tl_set:Ne \l__tcobox_tmpa_tl { \file_mdfive_hash:n { #1 } }
    \file_get:nnN { #2 } { } \l__tcobox_tmpb_tl
    \str_if_eq:eeTF { \l__tcobox_tmpa_tl } { \tl_trim_spaces:o { \l__tcobox_tmpb_tl } }
      {
        \bool_set_true:N \l__tcobox_proc_hash_equal_bool
      }
      {
        \bool_set_false:N \l__tcobox_proc_hash_equal_bool
        \iow_open:Nn \g__tcobox_out_iow { #2 }
        \iow_now:NV \g__tcobox_out_iow \l__tcobox_tmpa_tl
        \iow_close:N \g__tcobox_out_iow
      }
  }

\prg_new_protected_conditional:Npnn \__tcobox_if_file_process:nnnn #1#2#3#4 { TF }
  {
    \__tcobox_proc_compute_hash:nn {#2} {#3}
    \int_case:nn {#1}
      {
        {0} { \prg_return_true: }
        {1}
          {
            \bool_if:NTF \l__tcobox_proc_hash_equal_bool
              {
                \file_if_exist:nTF {#4}
                  {
                    \file_compare_timestamp:nNnTF {#4} < {#3}
                      { \prg_return_true: }
                      { \prg_return_false: }
                  }
                  { \prg_return_true: }
              }
              {
                \prg_return_true:
              }
          }
        {2} { \prg_return_false: }
      }
  }

\cs_gset_eq:NN \tcbiffileprocess \__tcobox_if_file_process:nnnnTF

\ExplSyntaxOff