From 09db320caf1490e42da924b8386dcf8ef4a04af0 Mon Sep 17 00:00:00 2001
From: Karl Berry <karl@freefriends.org>
Date: Mon, 3 Feb 2020 22:31:24 +0000
Subject: filehook (3feb20)

git-svn-id: svn://tug.org/texlive/trunk@53655 c570f23f-e606-0410-a88d-b1316a301751
---
 Master/texmf-dist/tex/latex/filehook/filehook.sty | 203 ++++++++--------------
 1 file changed, 77 insertions(+), 126 deletions(-)

(limited to 'Master/texmf-dist/tex/latex/filehook/filehook.sty')

diff --git a/Master/texmf-dist/tex/latex/filehook/filehook.sty b/Master/texmf-dist/tex/latex/filehook/filehook.sty
index 5f03b9827e9..d71145b6007 100644
--- a/Master/texmf-dist/tex/latex/filehook/filehook.sty
+++ b/Master/texmf-dist/tex/latex/filehook/filehook.sty
@@ -1,4 +1,4 @@
-%% Copyright (C) 2011-2019 by Martin Scharrer <martin@scharrer-online.de>
+%% Copyright (C) 2011-2020 by Martin Scharrer <martin@scharrer-online.de>
 %% ----------------------------------------------------------------------
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3
@@ -19,12 +19,45 @@
 %%
 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
 \ProvidesPackage{filehook}[%
-    2019/10/03
-    v0.6
+    2020/02/03
+    v0.7
     Hooks for input files]
 \newif\iffilehook@force
 \DeclareOption{force}{\filehook@forcetrue}
 \ProcessOptions\relax
+\newif\iffilehook@newfmt
+\@ifl@t@r\fmtversion{2019/10/01}{\filehook@newfmttrue}{\filehook@newfmtfalse}
+\def\filehook@let#1#2{%
+  \expandafter\ifx\csname #2\space\endcsname\relax
+    \expandafter\let\csname #1\expandafter\endcsname\csname #2\endcsname
+  \else
+    \expandafter\def\csname #1\expandafter\endcsname\expandafter{\expandafter\protect\csname #1\space\endcsname}%
+    \expandafter\let\csname #1\space\expandafter\endcsname\csname #2\space\endcsname
+  \fi
+}
+\def\filehook@glet#1#2{%
+  \expandafter\ifx\csname #2\space\endcsname\relax
+    \expandafter\global\expandafter\let\csname #1\expandafter\endcsname\csname #2\endcsname
+  \else
+    \expandafter\global\expandafter\def\csname #1\expandafter\endcsname\expandafter{\expandafter\protect\csname #1\space\endcsname}%
+    \expandafter\global\expandafter\let\csname #1\space\expandafter\endcsname\csname #2\space\endcsname
+  \fi
+}
+\def\filehook@cmp#1#2{%
+  \expandafter\ifx\csname #2\space\endcsname\relax
+    \expandafter\ifx\csname #1\expandafter\endcsname\csname #2\endcsname
+      \expandafter\expandafter\expandafter\@firstoftwo
+    \else
+      \expandafter\expandafter\expandafter\@secondoftwo
+    \fi
+  \else
+    \expandafter\ifx\csname #1\space\expandafter\endcsname\csname #2\space\endcsname
+      \expandafter\expandafter\expandafter\@firstoftwo
+    \else
+      \expandafter\expandafter\expandafter\@secondoftwo
+    \fi
+  \fi
+}
 \begingroup
 \gdef\filehook@csuse#1{\ifcsname #1\endcsname\csname #1\expandafter\endcsname\fi}
 \expandafter\ifx\csname csuse\endcsname\relax
@@ -36,7 +69,7 @@
 \fi
 \endgroup
 \def\filehook@include@atbegin#1{%
-  \let\InputIfFileExists\filehook@@InputIfFileExists
+  \filehook@let{InputIfFileExists}{filehook@@InputIfFileExists}%
   \filehook@csuse{\filehook@include@atbegin@#1}%
   \filehook@include@@atbegin
 }
@@ -52,7 +85,7 @@
 }
 \def\filehook@include@@after{}
 \def\filehook@input@atbegin#1{%
-  \let\InputIfFileExists\filehook@@InputIfFileExists
+  \filehook@let{InputIfFileExists}{filehook@@InputIfFileExists}%
   \filehook@csuse{\filehook@input@atbegin@\filehook@ensureext{#1}}%
   \filehook@input@@atbegin
 }
@@ -245,10 +278,11 @@
     \expandafter\filehook@@ensuretex#1\empty.tex\empty\empty
 }
 \def\filehook@@ensuretex#1.tex\empty#2\empty{#1.tex}
-\newif\iffilehook@newfmt
-\@ifl@t@r\fmtversion{2019/10/01}{\filehook@newfmttrue}{\filehook@newfmtfalse}
 \iffilehook@newfmt
-\DeclareRobustCommand \latex@InputIfFileExists[2]{%
+\expandafter\def\expandafter\latex@InputIfFileExists\expandafter{%
+  \expandafter\protect\csname InputIfFileExists\space\endcsname
+}
+\expandafter\long\expandafter\def\csname latex@InputIfFileExists\space\endcsname#1#2{%
   \IfFileExists{#1}%
     {%
   \expandafter\@swaptwoargs\expandafter
@@ -261,7 +295,7 @@
     }%
 }
 \fi
-\long\gdef\filehook@default@InputIfFileExists#1#2{%
+\DeclareRobustCommand\filehook@default@InputIfFileExists[2]{%
   \IfFileExists{#1}%
     {\expandafter\filehook@swap
      \expandafter{\@filef@und}%
@@ -273,8 +307,9 @@
      \filehook@every@atend{#1}%
     }%
 }
-\long\gdef\filehook@@default@InputIfFileExists#1#2{%
-  \let\InputIfFileExists\filehook@InputIfFileExists
+\filehook@glet{filehook@default@InputIfFileExists}{filehook@default@InputIfFileExists}%
+\DeclareRobustCommand\filehook@@default@InputIfFileExists[2]{%
+  \filehook@let{InputIfFileExists}{filehook@InputIfFileExists}%
   \IfFileExists{#1}%
     {\expandafter\filehook@swap
      \expandafter{\@filef@und}%
@@ -284,76 +319,9 @@
      \filehook@atend{#1}%
     }%
 }
-\long\def\scrlfile@InputIfFileExists#1#2{%
-  \begingroup\expandafter\expandafter\expandafter\endgroup
-  \expandafter\ifx\csname #1-@alias\endcsname\relax
-    \expandafter\@secondoftwo
-  \else
-    \scr@replacefile@msg{\csname #1-@alias\endcsname}{#1}%
-    \expandafter\@firstoftwo
-  \fi
-  {%
-    \expandafter\InputIfFileExists\expandafter{\csname
-      #1-@alias\endcsname}{#2}%
-  }%
-  {\IfFileExists{#1}{%
-      \scr@load@hook{before}{#1}%
-      #2\@addtofilelist{#1}%
-      \@@input \@filef@und
-      \scr@load@hook{after}{#1}%
-    }}%
-}
-\long\def\filehook@scrlfile@InputIfFileExists#1#2{%
-  \begingroup\expandafter\expandafter\expandafter\endgroup
-  \expandafter\ifx\csname #1-@alias\endcsname\relax
-    \expandafter\@secondoftwo
-  \else
-    \scr@replacefile@msg{\csname #1-@alias\endcsname}{#1}%
-    \expandafter\@firstoftwo
-  \fi
-  {%
-    \expandafter\InputIfFileExists\expandafter{\csname
-      #1-@alias\endcsname}{#2}%
-  }%
-  {\IfFileExists{#1}{%
-      \expandafter\filehook@swap
-      \expandafter{\@filef@und}%
-      {\scr@load@hook{before}{#1}%
-      #2\@addtofilelist{#1}%
-      \filehook@every@atbegin{#1}%
-      \filehook@atbegin{#1}%
-      \@@input}%
-      \filehook@atend{#1}%
-      \filehook@every@atend{#1}%
-      \scr@load@hook{after}{#1}%
-    }}%
-}
-\long\def\filehook@@scrlfile@InputIfFileExists#1#2{%
-  \let\InputIfFileExists\filehook@InputIfFileExists
-  \begingroup\expandafter\expandafter\expandafter\endgroup
-  \expandafter\ifx\csname #1-@alias\endcsname\relax
-    \expandafter\@secondoftwo
-  \else
-    \scr@replacefile@msg{\csname #1-@alias\endcsname}{#1}%
-    \expandafter\@firstoftwo
-  \fi
-  {%
-    \expandafter\InputIfFileExists\expandafter{\csname
-      #1-@alias\endcsname}{#2}%
-  }%
-  {\IfFileExists{#1}{%
-      \expandafter\filehook@swap
-      \expandafter{\@filef@und}%
-      {\scr@load@hook{before}{#1}%
-      #2\@addtofilelist{#1}%
-      \filehook@atbegin{#1}%
-      \@@input}%
-      \filehook@atend{#1}%
-      \scr@load@hook{after}{#1}%
-    }}%
-}
-\AtBeginOfPackageFile*{scrlfile}{%
-   \let\InputIfFileExists\latex@InputIfFileExists
+\filehook@glet{filehook@@default@InputIfFileExists}{filehook@@default@InputIfFileExists}%
+\AtBeginOfPackageFile{scrlfile}{%
+   \filehook@glet{InputIfFileExists}{latex@InputIfFileExists}%
 }%
 \AtEndOfPackageFile*{scrlfile}{%
    \RequirePackage{filehook-scrlfile}%
@@ -361,67 +329,50 @@
 \AtBeginOfPackageFile*{fink}{%
    \RequirePackage{kvoptions}%
    \begingroup
-   \let\InputIfFileExists\latex@InputIfFileExists
+   \filehook@let{InputIfFileExists}{latex@InputIfFileExists}%
 }%
 \AtEndOfPackageFile*{fink}{%
    \edef\@tempa{\noexpand\PassOptionsToPackage{mainext=\fnk@mainext,maindir=\fnk@maindir}{currfile}}%
    \expandafter\endgroup\@tempa
    \RequirePackage{filehook-fink}%
 }%
-\AtBeginOfClassFile*{memoir}{%
-  \let\filehook@@InputIfFileExists\latex@InputIfFileExists
-  \let\InputIfFileExists\latex@InputIfFileExists
+\AtBeginOfClassFile{memoir}{%
+  \filehook@let{InputIfFileExists}{latex@InputIfFileExists}%
   \let\@iinput\filehook@orig@@iinput
 }%
 \AtEndOfClassFile*{memoir}{%
   \let\@iinput\filehook@@iinput
   \RequirePackage{filehook-memoir}%
 }%
-\def\@tempa{9}%
-\ifx\InputIfFileExists\filehook@InputIfFileExists
-    \def\@tempa{0}%
-\else
-    \iffilehook@force
-        \def\@tempa{1}%
-    \else
-        \iffilehook@newfmt
-            % check if both the robust \InputIfFileExist and its internal macro match the default LaTeX definition
-            \edef\@tempb{\noexpand\protect\expandafter\noexpand\csname InputIfFileExists\space\endcsname}%
-            \ifx\InputIfFileExists\@tempb
-                \expandafter\ifx\csname InputIfFileExists\space\expandafter\endcsname\csname latex@InputIfFileExists\space\endcsname
-                    \def\@tempa{1}%
-                \fi
-            \fi
-        \else\ifx\InputIfFileExists\latex@InputIfFileExists
-            \def\@tempa{1}%
-        \fi\fi
-    \fi
-\fi
-\ifcase\@tempa
-\relax% 0
-\or% 1
-    \let\filehook@InputIfFileExists\filehook@default@InputIfFileExists
-    \let\filehook@@InputIfFileExists\filehook@@default@InputIfFileExists
-    \iffilehook@newfmt
-        \expandafter\let\csname InputIfFileExists\space\endcsname\filehook@InputIfFileExists
-    \else
-        \let\InputIfFileExists\filehook@InputIfFileExists
-    \fi
-    \iffilehook@force
-      \PackageWarning{filehook}{Detected unknown definition of \string\InputIfFileExists.^^J%
-                                The 'force' option of 'filehook' is in effect. Macro is overwritten with default!}%
-    \fi
-\else
-    \PackageError{filehook}{Detected unknown definition of \string\InputIfFileExists.^^J%
-                            Use the 'force' option of 'filehook' to overwrite it.}{}%
-\fi
+\filehook@cmp{InputIfFileExists}{filehook@InputIfFileExists}%
+  {}% already set up
+  {%
+    \filehook@cmp{InputIfFileExists}{latex@InputIfFileExists}%
+      {%
+        \filehook@let{filehook@InputIfFileExists}{filehook@default@InputIfFileExists}%
+        \filehook@let{filehook@@InputIfFileExists}{filehook@@default@InputIfFileExists}%
+        \filehook@let{InputIfFileExists}{filehook@InputIfFileExists}%
+      }%
+      {%
+        \iffilehook@force
+          \filehook@let{filehook@InputIfFileExists}{filehook@default@InputIfFileExists}%
+          \filehook@let{filehook@@InputIfFileExists}{filehook@@default@InputIfFileExists}%
+          \filehook@let{InputIfFileExists}{filehook@InputIfFileExists}%
+          \PackageWarning{filehook}{Detected unknown definition of \string\InputIfFileExists.^^J%
+                                    The 'force' option of 'filehook' is in effect. Macro is overwritten with default!}%
+        \else
+          \PackageError{filehook}{Detected unknown definition of \string\InputIfFileExists.^^J%
+                                  Use the 'force' option of 'filehook' to overwrite it.}{}%
+        \fi
+      }%
+  }%
 \AtBeginDocument{%
     % Check if definition got changed again. For the new LaTeX format we check again \InputIfFileExists<space>,
     % for the old format to \InputIfFileExists directly.
-    \expandafter\ifx\csname InputIfFileExists\iffilehook@newfmt\space\fi\endcsname\filehook@InputIfFileExists\else
+    \filehook@cmp{InputIfFileExists}{filehook@InputIfFileExists}{}{%
         \PackageWarning{filehook}{Macro \string\InputIfFileExists\space got redefined after 'filehook' was loaded.^^J%
-                                  Certain file hooks might now be dysfunctional!}
-    \fi
+                                  Certain file hooks might now be dysfunctional!}%
+    }%
 }
 \endinput
 %%
-- 
cgit v1.2.3

