summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/tools/shellesc.sty
blob: d5df721ffc15a9b62a71515d17a7f62e136b47a6 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
%%
%% This is file `shellesc.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% shellesc.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% The source is maintained by the LaTeX Project team and bug
%% reports for it can be opened at https://latex-project.org/bugs/
%% (but please observe conditions on bug reports sent to that address!)
%% 
%% 
%% Copyright (C) 1993-2021
%% The LaTeX Project and any individual authors listed elsewhere
%% in this file.
%% 
%% This file was generated from file(s) of the Standard LaTeX `Tools Bundle'.
%% --------------------------------------------------------------------------
%% 
%% It may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3c
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%    https://www.latex-project.org/lppl.txt
%% and version 1.3c or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% 
%% This file may only be distributed together with a copy of the LaTeX
%% `Tools Bundle'. You may however distribute the LaTeX `Tools Bundle'
%% without such generated files.
%% 
%% The list of all files belonging to the LaTeX `Tools Bundle' is
%% given in the file `manifest.txt'.
%% 
%% Source File: shellesc.dtx
%% Copyright (C) 2015-2021
%%
%% The LaTeX Project and any individual authors listed elsewhere
%% in this file.
%%
%% This file may be distributed under the terms of the LPPL.
%% See README for details.
\ifx\ProvidesPackage\undefined
\def\next#1#2[#3]{\wlog{#2 #3}}
\ifx\PackageInfo\undefined\def\PackageInfo#1#2{\wlog{#1: #2}}\fi
\ifx\PackageWarning\undefined\def\PackageWarning#1#2{\wlog{#1: #2}}\fi
\expandafter\next\fi
\ProvidesPackage{shellesc}
       [2019/11/08 v1.0c unified shell escape interface for LaTeX]
\chardef\shellesc@quotecat\catcode`\"
\chardef\shellesc@underscorecat\catcode`\_
\@makeother\"
\@makeother\_
\chardef\ShellEscapeStatus
  \ifx\pdfshellescape\@undefined
    \ifx\shellescape\@undefined
      \ifx\directlua\@undefined
        \z@
      \else
        \directlua{%
          tex.sprint((status.shell_escape or os.execute()) .. " ")}
      \fi
    \else
      \shellescape
    \fi
  \else
    \pdfshellescape
  \fi
\ifcase\ShellEscapeStatus
  \PackageWarning{shellesc}{Shell escape disabled}
\or
  \PackageInfo   {shellesc}{Unrestricted shell escape enabled}
\else
  \PackageInfo   {shellesc}{Restricted shell escape enabled}
\fi
\ifx\lastsavedimageresourcepages\@undefined
  \protected\def\ShellEscape{\immediate\write18 }
\else
  \protected\def\ShellEscape{\directlua\ShellEscape@Lua}
\fi
\ifx\lastsavedimageresourcepages\@undefined
  \protected\def\DelayedShellEscape{\relax\write18 }
\else
  \protected\def\DelayedShellEscape{\latelua\ShellEscape@Lua}
\fi
\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
\ifx\lastsavedimageresourcepages\@undefined
 \catcode`\"\shellesc@quotecat
 \catcode`\_\shellesc@underscorecat
 \expandafter\endinput
\fi
\directlua{%
shellesc = shellesc or {}
local function write_or_execute()
  local s = token.scan_int()
  if (s==18) then
     tex.sprint(\the\numexpr\catcodetable@atletter\relax,
                "\string\\ShellEscape ")
  else
     tex.sprint(\the\numexpr\catcodetable@atletter\relax,
                "\string\\shellesc@write " .. s)
  end
end
shellesc.write_or_execute=write_or_execute
}
\let\shellesc@write\write
\protected\def\write{\directlua{shellesc.write_or_execute()}}
\catcode`\"\shellesc@quotecat
\catcode`\_\shellesc@underscorecat
\endinput
%%
%% End of file `shellesc.sty'.