%%
%% This is file `scrlfile-hook.sty',
%% generated with the docstrip utility, extended by scrdocstrip.
%%
%% The original source files were:
%%
%% scrlfile-hook.dtx  (with options: `package,current')
%% scrlogo.dtx  (with options: `logo')
%% 
%% Copyright (c) 2002-2022 Markus Kohm [komascript at gmx info]
%% 
%% This file was generated from file(s) of the KOMA-Script bundle.
%% ---------------------------------------------------------------
%% 
%% It may be distributed under the conditions of the
%% LaTeX Project Public License in the version distributed together
%% with KOMA-Script, see file `lppl.txt' or `lppl-de.txt'.
%% 
%% This file may only be distributed together with a copy of the
%% KOMA-Script bundle.  You may however distribute the
%% KOMA-Script bundle without all such generated files.  See also
%% `lppl.txt' or `lppl-de.txt' for additional information.
%% 
%% The list of files belonging to KOMA-Script distribution is given in
%% the file `MANIFEST.md'.  See also `lppl.txt' or `lppl-de.txt' for
%% additional information.
%% 
%% If this file is a beta version, you may not be allowed to distribute
%% it.  Look at the comments below to see if this is the case.
%% 
%% English and German manuals are part of KOMA-Script bundle.
%% ----------------------------------------------------------
%% 
%% See `README'.
%% 
%% The KOMA-Script bundle (but maybe not this file) was based upon the
%% LaTeX 2.09 Script family created by Frank Neukam 1993 and the LaTeX2e
%% standard classes created by The LaTeX3 Project 1994-1996.  You can
%% find a complete unmodified copy of LaTeX2e at
%% <http://mirror.ctan.org/tex-archive/macros/latex/base/>.
%% 
%%% From File: $Id: scrlfile-hook.dtx$
\ProvidesPackage{scrlfile-hook}[%
  2022/10/12 v3.38 KOMA-Script
  package
  (using LaTeX hooks)]
\@ifundefined{IfFormatAtLeastTF}{%
  \PackageError{scrlfile-hook}{not recommended usage of package}{%
    It seems this package has been loaded directly using a LaTeX
    version\MessageBreak
    prior to 2020-10-01. This is not recommended. Please always load
    package\MessageBreak
    scrlfile instead of scrlfile-hook.\MessageBreak
    If you would continue, I will try to load scrlfile-patcholdlatex%
  }%
  \RequirePackage{scrlfile-patcholdlatex}\endinput
}{%
  \IfFormatAtLeastTF{2020/10/01}{%
    \IfFormatAtLeastTF{2021/11/15}{%
    }{%
      \PackageError{scrlfile-hook}{LaTeX too old for this package}{%
        It seems this package has been loaded directly using LaTeX
        version\MessageBreak
        prior to 2021-11-15. This is not recommended. Please always load
        package\MessageBreak
        scrlfile instead of scrlfile-hook.\MessageBreak
        If you would continue, I will try to load scrlfile-hook-3.34%
      }%
      \RequirePackage{scrlfile-hook-3.34}\endinput
    }%
  }{%
    \PackageError{scrlfile-hook}{LaTeX too old for this package}{%
      It seems this package has been loaded directly using a LaTeX
      version\MessageBreak
      prior to 2020-10-01. This is not recommended. Please always load
      package\MessageBreak
      scrlfile instead of scrlfile-hook.\MessageBreak
      If you would continue, I will try to load scrlfile-patcholdlatex%
    }%
    \RequirePackage{scrlfile-patcholdlatex}\endinput
  }%
}
\ExplSyntaxOn
\NewDocumentCommand \BeforeFile { m }
  {
    \AddToHook { file / #1 / before }
  }
\NewDocumentCommand \AfterFile { m }
  {
    \AddToHook { file / #1 / after }
  }
\NewDocumentCommand \BeforeClass { m }
  {
    \BeforeFile { #1.\@clsextension }
  }
\NewDocumentCommand \BeforePackage { m }
  {
    \BeforeFile { #1.\@pkgextension }
  }
\NewDocumentCommand \AfterAtEndOfClass { s m o +m }
  {
    \IfBooleanTF { #1 }
      {
        \scrlfile_if_class_loaded:nTF { #2 }
          { #4 }
          { \hook_gput_code:nnn { class / #2 / after } { #3 } { #4 } }
      }
      {
        \scrlfile_if_class_loaded:nF
          { #2 }
          { \hook_gput_code:nnn { class / #2 / after } { #3 } { #4 } }
      }
  }
\NewDocumentCommand \AfterAtEndOfPackage { s m o +m }
  {
    \IfBooleanTF { #1 }
      {
        \scrlfile_if_package_loaded:nTF { #2 }
          { #4 }
          { \hook_gput_code:nnn { package / #2 / after } { #3 } { #4 } }
      }
      {
        \scrlfile_if_package_loaded:nF
          { #2 }
          { \hook_gput_code:nnn { package / #2 / after } { #3 } { #4 } }
      }
  }
\seq_new:N \g__scrlfile_input_file_seq
\hook_gput_code:nnn { file / before } { . }
  { \seq_gpush:Nx \g__scrlfile_input_file_seq { \CurrentFile }  }
\msg_new:nnn { scrlfile-hook } { too-many-pops }
  {
    More~file~names~popped~from~stack~than~put~to.~
    This~should~never~happen.~
    However,~it~could~happen~if~scrlfile-hook~is~loaded~by~another~
    package~or~class.~In~this~case~some~packages~or~classes~are~not~
    recognised~correctly.
  }
\hook_gput_code:nnn { file / after } { . }
  {
    \seq_gpop:NNF \g__scrlfile_input_file_seq \l_tmpa_seq
      {
        \msg_warning:nn { scrlfile-hook } { too-many-pops }
      }
  }
\cs_if_exist:NTF \g__filehook_input_file_seq
  {
    \seq_map_inline:Nn \g__filehook_input_file_seq
      {
        \seq_gput_right:Nx \g__scrlfile_input_file_seq
          { \tl_item:nn { #1 } { 2 } }
      }
  }
  {
    \seq_gpush:Nx \g__scrlfile_input_file_seq { }
    \cs_if_exist:NTF \CurrentFileUsed
      { \seq_gpush:Nx \g__scrlfile_input_file_seq { \CurrentFileUsed } }
      { \seq_gpush:Nx \g__scrlfile_input_file_seq { \CurrentFile } }
  }
\prg_new_protected_conditional:Npnn \__scrlfile_if_loading:n #1 { T, F, TF }
  {
    \str_set:Nx \l_tmpa_str { #1 }
    \seq_if_in:NxTF \g__scrlfile_input_file_seq { \str_use:N \l_tmpa_str }
      { \prg_return_true: }
      { \prg_return_false: }
  }
\prg_new_protected_conditional:Npnn \scrlfile_if_class_loaded:n #1 { T, F, TF }
  {
    \@ifclassloaded { #1 }
      {
        \__scrlfile_if_loading:nTF { #1.\@clsextension }
          { \prg_return_false: }
          { \prg_return_true: }
      }
      {
        \prg_return_false:
      }
  }
\prg_new_protected_conditional:Npnn \scrlfile_if_package_loaded:n #1 { T, F, TF }
  {
    \@ifpackageloaded { #1 }
      {
        \__scrlfile_if_loading:nTF { #1.\@pkgextension }
          { \prg_return_false: }
          { \prg_return_true: }
      }
      {
        \prg_return_false:
      }
  }
\NewDocumentCommand \scrlfile@AfterClass { s m o +m }
  {
    \IfBooleanTF { #1 }
      {
        \@ifclassloaded{ #2 }
          { #4 }
          {
            \hook_gput_code:nnn
              { file / #2.\@clsextension / after }
              { #3 }
              { #4 }
          }
      }
      {
        \hook_gput_code:nnn { file / #2.\@clsextension / after } { #3 } { #4 }
      }
  }
\NewDocumentCommand \AfterClass { } { \scrlfile@AfterClass }
\NewDocumentCommand \scrlfile@AfterPackage { s m o +m }
  {
    \IfBooleanTF { #1 }
      {
        \@ifpackageloaded{ #2 }
          { #4 }
          {
            \hook_gput_code:nnn
              { file / #2.\@pkgextension / after }
              { #3 }
              { #4 }
          }
      }
      {
        \hook_gput_code:nnn { file / #2.\@pkgextension / after } { #3 } { #4 }
      }
  }
\NewDocumentCommand \AfterPackage { } { \scrlfile@AfterPackage }
\NewDocumentCommand{\ReplaceInput}{}{\declare@file@substitution}
\NewDocumentCommand\ReplaceClass{mm}{%
  \declare@file@substitution{#1.\@clsextension}{#2.\@clsextension}%
}
\NewDocumentCommand\ReplacePackage{mm}{%
  \declare@file@substitution{#1.\@pkgextension}{#2.\@pkgextension}%
}
\NewDocumentCommand{\UnReplaceInput}{}{\undeclare@file@substitution}
\NewDocumentCommand\UnReplaceClass{m}{%
  \undeclare@file@substitution{#1.\@clsextension}%
}
\NewDocumentCommand\UnReplacePackage{mm}{%
  \undeclare@file@substitution{#1.\@pkgextension}%
}
\clist_new:N \g__scrlfile_prevent_clist
\NewDocumentCommand \PreventPackageFromLoading { s +o m }
  {
    \clist_set:Nx \l__scrlfile_package_clist { #3 }
    \clist_map_inline:Nn \l__scrlfile_package_clist
      {
        \@ifpackageloaded { ##1 }
          {
            \IfBooleanTF { #1 } { \msg_info:nnn } { \msg_warning:nnn }
              { scrlfile } { no-prevent-for-already-loaded } { ##1 }
          }
          {
            \clist_if_in:NnF \g__scrlfile_prevent_clist { ##1 }
              { \clist_gput_right:Nn \g__scrlfile_prevent_clist { ##1 } }
            \tl_if_exist:cF { g__scrlfile_exclude_package_##1_tl }
              {
                \tl_new:c { g__scrlfile_exclude_package_##1_tl }
              }
            \IfValueT { #2 }
              {
                \tl_gput_right:cn { g__scrlfile_exclude_package_##1_tl } { #2 }
              }
            \disable@package@load { ##1 }
              { \tl_use:c { g__scrlfile_exclude_package_##1_tl } }
          }
      }
    \clist_clear:N \l__scrlfile_package_clist
  }
\clist_new:N \l__scrlfile_package_clist
\msg_new:nnn { scrlfile } { no-prevent-for-already-loaded }
  {
    Cannot~prevent~package~`#1'~from~being~loaded,~
    because~it~has~been~loaded~already~before~line~\msg_line_number:
  }
\NewDocumentCommand \StorePreventPackageFromLoading { m }
  { \edef #1 { \clist_use:Nn \g__scrlfile_prevent_clist { , } } }
\NewDocumentCommand \ResetPreventPackageFromLoading {}
  {
    \clist_map_function:NN \g__scrlfile_prevent_clist \reenable@package@load
    \clist_gclear:N \g__scrlfile_prevent_clist
  }
\NewDocumentCommand \UnPreventPackageFromLoading { s m }
  {
    \clist_set:Nx \l__scrlfile_package_clist { #2 }
    \clist_map_inline:Nn \l__scrlfile_package_clist
      {
        \clist_if_in:NnT \g__scrlfile_prevent_clist { ##1 }
          {
            \clist_gremove_all:Nn \g__scrlfile_prevent_clist { ##1 }
            \reenable@package@load { ##1 }
            \IfBooleanT { #1 }
              { \cs_undefine:c { g__scrlfile_exclude_package_##1_tl } }
          }
      }
  }
\NewDocumentCommand \BeforeClosingMainAux { o m }
  {
    \hook_gput_code:nnn { enddocument / afterlastpage } { #1 }
      {
        \debug_suspend:
        \RenewDocumentCommand \BeforeClosingMainAux { m } { ##1 }
        \cs_set_eq:NN \__scrlfile_protected@write:Nnn \protected@write
        \cs_set_eq:NN \protected@write \protected@immediate@write
        #2
        \cs_set_eq:NN \protected@write \__scrlfile_protected@write:Nnn
        \debug_resume:
      }
  }
\NewDocumentCommand \AfterReadingMainAux { o m }
  {
    \hook_gput_code:nnn { enddocument / afteraux } { #1 }
      {
        \debug_suspend:
        \RenewDocumentCommand \AfterReadingMainAux { m } { ##1 }
        \cs_set_eq:NN \__scrlfile_protected@write:Nnn \protected@write
        \cs_set_eq:NN \protected@write \protected@immediate@write
        #2
        \cs_set_eq:NN \protected@write \__scrlfile_protected@write:Nnn
        \debug_resume:
      }
  }
\ExplSyntaxOff
\ProvideDocumentCommand\protected@immediate@write{m+m+m}
  {%
    \begingroup
      #2%
      \let\protect\@unexpandable@protect
      \edef\reserved@a{\immediate\write#1{#3}}%
      \reserved@a
    \endgroup
    \if@nobreak\ifvmode\nobreak\fi\fi
  }
%%% From File: $Id: scrlogo.dtx 3688 2022-02-10 08:26:37Z kohm $
\RequirePackage{scrlogo}
\endinput
%%
%% End of file `scrlfile-hook.sty'.
