From 025f7bfee79d7817a876831bb19f34a2dfb1b2e2 Mon Sep 17 00:00:00 2001
From: Norbert Preining <norbert@preining.info>
Date: Tue, 19 Nov 2019 03:02:21 +0000
Subject: CTAN sync 201911190302

---
 macros/latex-dev/required/tools/shellesc.dtx | 82 ++++++++++++++++++++++++----
 1 file changed, 70 insertions(+), 12 deletions(-)

(limited to 'macros/latex-dev/required/tools/shellesc.dtx')

diff --git a/macros/latex-dev/required/tools/shellesc.dtx b/macros/latex-dev/required/tools/shellesc.dtx
index 061ea4457c..9706c5aa03 100644
--- a/macros/latex-dev/required/tools/shellesc.dtx
+++ b/macros/latex-dev/required/tools/shellesc.dtx
@@ -20,7 +20,7 @@
 %<driver> \ProvidesFile{shellesc.drv}
 % \fi
 %         \ProvidesFile{shellesc.dtx}
-       [2016/06/07 v0.02b unified shell escape interface for LaTeX]
+       [2019/11/08 v1.0c unified shell escape interface for LaTeX]
 %
 % \iffalse
 %<*driver>
@@ -36,10 +36,15 @@
 % \title{The \textsf{shellesc} Package\thanks{This file
 %        has version number \fileversion, last
 %        revised \filedate.}}
-% \author{LaTeX3 project}
+% \author{\LaTeX3 project}
 % \date{\filedate}
+%
+%
 % \maketitle
 %
+% \vspace*{-\baselineskip}
+% \enlargethispage{\baselineskip}
+%
 % \changes{v0.1b}{2016/02/02}{Doc typo fixes (JB)}
 % \changes{v0.2a}{2016/06/07}{Improve use with plain TeX}
 % \section{Introduction}
@@ -57,7 +62,7 @@
 % so a command to remove a file on a unix-like system could be
 % specified  using \verb|\ShellEscape{rm file.txt}| (or \verb|del| in
 % windows). Note that by default system access is not allowed and
-% latex will typically need to be called with the \verb|--shell-escape|
+% \LaTeX\ will typically need to be called with the \verb|--shell-escape|
 % command line option.
 %
 % The package may be used with standard \texttt{latex} or
@@ -76,6 +81,9 @@
 % (\verb|\latelua|). This package provides \verb|\DelayedShellEscape|
 % as a common syntax for this use.
 %
+% The shell escape status may be queried by checking the integer (chardef)
+% command \verb|\ShellEscapeStatus|, 0 (disabled) 1 (enabled) 2 (restricted).
+%
 % To aid porting existing documents to Lua\TeX~0.87 this package does
 % overload the \verb|\write| command so that
 % \verb|\write18{rm file.txt}|
@@ -95,12 +103,25 @@
 %<*package>
 %    \end{macrocode}
 %
+% \changes{v1.0b}{2019/10/17}{Catcode protection}
+%    \begin{macrocode}
+\chardef\shellesc@quotecat\catcode`\"
+\chardef\shellesc@underscorecat\catcode`\_
+\@makeother\"
+\@makeother\_
+%    \end{macrocode}
+%
 % \subsection{Status Check}
 %
 %
-% \changes{v0.2a}{2016/06/07}{spelling in messages}
+% \subsection{The shellesc package interface}
+%
+% \begin{macro}{\ShellEscapeStatus}
+% \changes{v1.0a}{2019/10/13}{Command Introduced}
+% Integer value with meanings 0 (shell escape disabled), 1 (shell escape allowed), 2 (Restricted shell escape).
+%
 %    \begin{macrocode}
-\ifcase
+\chardef\ShellEscapeStatus
   \ifx\pdfshellescape\@undefined
     \ifx\shellescape\@undefined
       \ifx\directlua\@undefined
@@ -115,6 +136,12 @@
   \else
     \pdfshellescape
   \fi
+%    \end{macrocode}
+% \end{macro}
+%
+% \changes{v0.2a}{2016/06/07}{spelling in messages}
+%    \begin{macrocode}
+\ifcase\ShellEscapeStatus
   \PackageWarning{shellesc}{Shell escape disabled}
 \or
   \PackageInfo   {shellesc}{Unrestricted shell escape enabled}
@@ -123,9 +150,9 @@
 \fi
 %    \end{macrocode}
 %
-% \subsection{The shellesc package interface}
 %
 % \begin{macro}{\ShellEscape}
+% \changes{v1.0a}{2019/10/13}{Lua logging for gh/195}
 % Execute the supplied tokens as a system dependent command, assuming 
 % such execution is allowed.
 %    \begin{macrocode}
@@ -135,14 +162,14 @@
 %
 %    \begin{macrocode}
 \else
-  \protected\def\ShellEscape#1{%
-    \directlua{os.execute("\luaescapestring{#1}")}}
+  \protected\def\ShellEscape{\directlua\ShellEscape@Lua}
 \fi
 %    \end{macrocode}
 % \end{macro}
 %
 % \begin{macro}{\DelayedShellEscape}
 % \changes{v0.1c}{2016/04/29}{Define \cs{DelayedShellEscape} not \cs{ShellEscape}(UF)}
+% \changes{v1.0a}{2019/10/13}{Lua logging for gh/195}
 % Execute the supplied tokens as a system dependent command, when this
 % node is shipped out with the completed page, assuming 
 % such execution is allowed.
@@ -153,14 +180,38 @@
 %
 %    \begin{macrocode}
 \else
-  \protected\def\DelayedShellEscape#1{%
-    \latelua{os.execute("\luaescapestring{#1}")}}
+  \protected\def\DelayedShellEscape{\latelua\ShellEscape@Lua}
 \fi
 %    \end{macrocode}
 % \end{macro}
 %
 %
 %
+% \begin{macro}{\ShellEscape@Lua}
+% \changes{v1.0a}{2019/10/13}{loging for gh/195}
+% Shared Lua code for \verb|\DelayedShellEscape| and \verb|\ShellEscape|.
+%    \begin{macrocode}
+\ifx\directlua\@undefined\else
+\protected\def\ShellEscape@Lua#1{{%
+local status, msg = os.execute("\luaescapestring{#1}")%
+if status == nil then
+    texio.write_nl("log",%
+      "runsystem(" .. "\luaescapestring{#1}"%
+       .. ")...(" .. msg .. ")\string\n")
+  elseif status == 0 then
+    texio.write_nl("log",%
+      "runsystem(" .. "\luaescapestring{#1}"%
+      .. ")...executed\string\n")
+  else
+    texio.write_nl("log",%
+      "runsystem(" .. "\luaescapestring{#1}"%
+       .. ")...failed " .. (msg or "") .. "\string\n")
+  end
+}}
+\fi
+%    \end{macrocode}
+% \end{macro}
+%
 % \subsection{The write18 package interface}
 %
 % In web2c based engines other than Lua\TeX, |\write18| may be used
@@ -189,7 +240,11 @@
 %
 % Stop at this point if not a recent Lua\TeX.
 %    \begin{macrocode}
-\ifx\lastsavedimageresourcepages\@undefined\expandafter\endinput\fi
+\ifx\lastsavedimageresourcepages\@undefined
+ \catcode`\"\shellesc@quotecat
+ \catcode`\_\shellesc@underscorecat
+ \expandafter\endinput
+\fi
 %    \end{macrocode}
 %
 %    \begin{macrocode}
@@ -233,7 +288,10 @@ shellesc.write_or_execute=write_or_execute
 \protected\def\write{\directlua{shellesc.write_or_execute()}}
 %    \end{macrocode}
 %
-%
+%    \begin{macrocode}
+\catcode`\"\shellesc@quotecat
+\catcode`\_\shellesc@underscorecat
+%    \end{macrocode}
 %
 %    \begin{macrocode}
 %</package>
-- 
cgit v1.2.3

