diff options
Diffstat (limited to 'Master/texmf-dist/tex/latex/texosquery/texosquery.tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/texosquery/texosquery.tex | 231 |
1 files changed, 198 insertions, 33 deletions
diff --git a/Master/texmf-dist/tex/latex/texosquery/texosquery.tex b/Master/texmf-dist/tex/latex/texosquery/texosquery.tex index d004f4503c2..85bfe6470b2 100644 --- a/Master/texmf-dist/tex/latex/texosquery/texosquery.tex +++ b/Master/texmf-dist/tex/latex/texosquery/texosquery.tex @@ -42,6 +42,7 @@ %% Grave accent \` Left brace \{ Vertical bar \| %% Right brace \} Tilde \~} + \ifnum\catcode`\@=11\relax \def\@texosquery@restore@at{}% \else @@ -54,7 +55,7 @@ \@texosquery@restore@at \expandafter\endinput \fi -\expandafter\def\csname ver@texosquery.tex\endcsname{2017/03/31 v1.3 (NLCT)} +\expandafter\def\csname ver@texosquery.tex\endcsname{2017/05/05 v1.4 (NLCT)} \ifx\@tracklang@pkgwarn\undefined \ifx\PackageWarning\undefined \def\@texosquery@warn#1{% @@ -74,6 +75,19 @@ \@tracklang@pkgwarn{texosquery}{#1}% } \fi +\ifx\PackageInfo\undefined + \def\@texosquery@info#1{% + {% + \newlinechar=`\^^J + \def\MessageBreak{^^J}% + \message{^^Jtexosquery Info: #1^^J}% + }% + } +\else + \def\@texosquery@info#1{% + \PackageInfo{texosquery}{#1}% + } +\fi \ifx\PackageError\undefined \def\@texosquery@err#1#2{% \errhelp{#2}% @@ -107,10 +121,11 @@ \fi \def\TeXOSInvokerName{texosquery} \ifx\@@input\undefined - \def\TeXOSQueryInvoker#1{\input|"\TeXOSInvokerName\space#1" } + \let\texosquery@input\input \else - \def\TeXOSQueryInvoker#1{\@@input|"\TeXOSInvokerName\space#1" } + \let\texosquery@input\@@input \fi +\def\TeXOSQueryInvoker#1{\texosquery@input|"\TeXOSInvokerName\space#1" } \newif\ifTeXOSQueryDryRun \TeXOSQueryDryRuntrue \def\TeXOSQueryAllowRestricted{% \def\@texosquery@allowrestricted##1##2{##1}% @@ -119,11 +134,20 @@ \def\@texosquery@allowrestricted##1##2{##2}% } \def\@texosquery@allowrestricted#1#2{#2}% +\def\TeXOSInvokerRestrictedMessage{% + \string\TeXOSQuery\space doesn't work in dry run mode. + \MessageBreak + If `\TeXOSInvokerName' has been added to the \MessageBreak + restricted list, make sure that + \MessageBreak \string\TeXOSQueryAllowRestricted\space + \MessageBreak has been uncommented in the configuration file + \MessageBreak (texosquery.cfg) otherwise you need to use the + \MessageBreak unrestricted shell escape} +\let\@texosquery@dorestrictedmessage\relax \openin0=texosquery.cfg \ifeof0\relax \else \closein0\relax \begingroup - \newlinechar=`\^^J - \message{^^JTeXOSQuery: reading configuration file^^J}% + \@texosquery@info{reading configuration file}% \endgroup \input texosquery.cfg \fi @@ -135,33 +159,137 @@ \@texosquery@warn{\string\TeXOSQueryDenyRestricted\space ignored (only allowed in texosquery.cfg)}% } +\chardef\texosquery@shellescape=0 \ifx\shellescape\undefined \ifx\pdfshellescape\undefined - \else - \ifnum\pdfshellescape=1\relax - \TeXOSQueryDryRunfalse + \ifx\pdf@shellescape\undefined + \ifx\directlua\undefined + \else + \edef\texosquery@shellescape{\directlua0{ + if os.execute then + if status + and status.luatex_version + and status.luatex_version >= 68 then + tex.write(os.execute()) + else + local result = os.execute() + if result == 0 then + tex.write("0") + else + if result == nil then + tex.write("0") + else + tex.write("1") + end + end + end + else + tex.write("0") + end + }} + \fi \else - \@texosquery@allowrestricted - {% - \ifnum\pdfshellescape=2\relax - \TeXOSQueryDryRunfalse + \let\texosquery@shellescape\pdf@shellescape + \fi + \else + \ifx\pdfshellescape\relax + \ifx\pdf@shellescape\undefined + \ifx\directlua\undefined + \else + \edef\texosquery@shellescape{\directlua0{ + if os.execute then + if status + and status.luatex_version + and status.luatex_version >= 68 then + tex.write(os.execute()) + else + local result = os.execute() + if result == 0 then + tex.write("0") + else + if result == nil then + tex.write("0") + else + tex.write("1") + end + end + end + else + tex.write("0") + end + }} \fi - } - {} + \else + \let\texosquery@shellescape\pdf@shellescape + \fi + \else + \let\texosquery@shellescape\pdfshellescape \fi \fi \else - \ifnum\shellescape=1\relax - \TeXOSQueryDryRunfalse + \ifx\shellescape\relax + \ifx\pdfshellescape\undefined + \else + \ifx\pdfshellescape\relax + \ifx\pdf@shellescape\undefined + \ifx\directlua\undefined + \else + \edef\texosquery@shellescape{\directlua0{ + if os.execute then + if status + and status.luatex_version + and status.luatex_version >= 68 then + tex.write(os.execute()) + else + local result = os.execute() + if result == 0 then + tex.write("0") + else + if result == nil then + tex.write("0") + else + tex.write("1") + end + end + end + else + tex.write("0") + end + }} + \fi + \else + \let\texosquery@shellescape\pdf@shellescape + \fi + \else + \let\texosquery@shellescape\pdfshellescape + \fi + \fi \else - \@texosquery@allowrestricted - {% - \ifnum\shellescape=2\relax - \TeXOSQueryDryRunfalse + \let\texosquery@shellescape\shellescape + \fi +\fi +\ifcase\texosquery@shellescape + \@texosquery@info{shell escape disabled, dry-run mode on} +\or + \TeXOSQueryDryRunfalse +\or + \@texosquery@allowrestricted + {% + \TeXOSQueryDryRunfalse + } + {% + \@texosquery@info{shell escape restricted, dry-run mode on.} + \def\@texosquery@dorestrictedmessage{% + \ifx\TeXOSInvokerRestrictedMessage\empty + \else + \ifx\TeXOSInvokerRestrictedMessage\relax + \else + \@texosquery@warn{\TeXOSInvokerRestrictedMessage}% + \fi \fi + \let\@texosquery@dorestrictedmessage\relax } - {} - \fi + } \fi \ifx\@texosquery@edef\undefined \ifx\protected@edef\undefined @@ -359,6 +487,7 @@ } \def\TeXOSQuery#1#2{% \ifTeXOSQueryDryRun + \@texosquery@dorestrictedmessage \begingroup \newlinechar=`\^^J \message{^^JTeXOSQuery: \TeXOSInvokerName\space#2^^J}% @@ -385,6 +514,32 @@ \@texosquery@edef\x{\endgroup\def\noexpand#1{\TeXOSQueryInvoker{#2}}}\x \fi } +\def\TeXOSQueryFromFile#1#2{% + \openin0=#2 + \ifeof0\relax + \def#1{}% + \else + \closein0\relax + \begingroup + \endlinechar=-1\relax + \@texosquery@enableshortcs + \catcode`\-=12\relax + \catcode`\_=12\relax + \catcode`\^=12\relax + \catcode`\~=12\relax + \catcode`\$=12\relax + \catcode`\&=12\relax + \catcode`\.=12\relax + \catcode`\/=12\relax + \catcode`\:=12\relax + \catcode`\"=12\relax + \catcode`\'=12\relax + \catcode`\;=12\relax + \catcode`\%=12\relax + \everyeof{\noexpand}\relax + \@texosquery@edef\x{\endgroup\def\noexpand#1{\texosquery@input #2 }}\x + \fi +} \def\texosquerycurrency#1{% \expandafter\noexpand\csname texosquerycurrency#1\endcsname } @@ -544,18 +699,24 @@ \def\@@texosquery@stripquotes#1\@mid@texosquery@stripquotes#2\@end@texosquery@stripquotes{% #1% } +\ifnum\texosquery@shellescape=2\relax + \def\@texosquery@argquote#1{#1} +\else + \def\@texosquery@argquote#1{\string'#1\string'} +\fi \def\TeXOSQueryFileDate#1#2{% \edef\@texosquery@restore@D{% \noexpand\catcode`\noexpand\D=\the\catcode`\D\relax}% \catcode`\D=12\relax - \TeXOSQuery{#1}{\string-d \string'\texosquerystripquotes{#2}\string'}% + \TeXOSQuery{#1}{\string-d + \@texosquery@argquote{\texosquerystripquotes{#2}}}% \@texosquery@restore@D } \def\TeXOSQueryFileSize#1#2{\TeXOSQuery{#1}{\string-s - \string'\texosquerystripquotes{#2}\string'}} + \@texosquery@argquote{\texosquerystripquotes{#2}}}} \def\@texosquery@filelist#1#2#3#4#5{\TeXOSQuery{#1}{% - \string#2 \string'#3\string' - \string'\texosquerystripquotes{#4}\string' #5}} + \string#2 \@texosquery@argquote{#3} + \@texosquery@argquote{\texosquerystripquotes{#4}} #5}} \def\TeXOSQueryFileList#1#2#3{% \@texosquery@filelist{#1}{-i}{#2}{#3}{}% } @@ -658,8 +819,10 @@ \def\@texosquery@filterfilelist#1#2#3#4#5#6{% \TeXOSQuery{#1}% {% - \string#2 \string'#3\string' \string'#4\string' - \string'\texosquerystripquotes{#5}\string' #6% + \string#2 + \@texosquery@argquote{#3} + \@texosquery@argquote{#4} + \@texosquery@argquote{\texosquerystripquotes{#5}} #6% }% } \def\TeXOSQueryFilterFileList#1#2#3#4{% @@ -764,8 +927,10 @@ \def\@texosquery@walk#1#2#3#4#5{% \TeXOSQuery{#1}% {% - \string-w \string'#2\string' \string'#3\string' - \string'\texosquerystripquotes{#4}\string' #5% + \string-w + \@texosquery@argquote{#2} + \@texosquery@argquote{#3} + \@texosquery@argquote{\texosquerystripquotes{#4}} #5% }% } \def\TeXOSQueryWalk#1#2#3#4{% @@ -802,11 +967,11 @@ \@texosquery@walk{#1}{#2}{#3}{#4}{ext\string-des}% } \def\TeXOSQueryFileURI#1#2{\TeXOSQuery{#1}{\string-u - \string'\texosquerystripquotes{#2}\string'}} + \@texosquery@argquote{\texosquerystripquotes{#2}}}} \def\TeXOSQueryFilePath#1#2{\TeXOSQuery{#1}{\string-p - \string'\texosquerystripquotes{#2}\string'}} + \@texosquery@argquote{\texosquerystripquotes{#2}}}} \def\TeXOSQueryDirName#1#2{\TeXOSQuery{#1}{\string-e - \string'\texosquerystripquotes{#2}\string'}} + \@texosquery@argquote{\texosquerystripquotes{#2}}}} \def\texosquerydtf#1#2{% \ifcase#1 \or |