[NTG-pdftex] Re: Patch ShellEscape

Heiko Oberdiek oberdiek@uni-freiburg.de
Fri, 11 Jul 2003 01:37:20 +0200


--G4iJoqBmSsgzjUCe
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: 8bit

On Thu, Jul 10, 2003 at 10:05:25PM +0200, Olaf Weber wrote:

> Martin Schroeder writes:
> > On 2003-07-10 15:49:50 +0200, Heiko Oberdiek wrote:
> >> On Thu, Jul 10, 2003 at 02:57:25PM +0200, Martin Schroeder wrote:
> >> > On 2003-07-10 14:35:48 +0200, Martin Schröder wrote:
> >> > > - New readonly primitive \pdfshellescape which can be used to test if the
> >> > 
> >> > Thinking further (and being reminded by Rolf): Is there a reason
> >> > why this can _not_ be called \shellescape? It's got nothing to do
> >> > with pdf (and would be usefull in all web2c-based TeX engines, no
> >> > matter what they are called).
> >> 
> >> \write18 is a property of web2c-based TeX engines, so
> >> \shellescape is the better name and it would be even better,
> >> if this can be added to the other web2c-based TeX engines, too.
> 
> > Same here. Olaf? Or does this belong to tex-implementors?
> 
> \shellescape sits in Knuth's namespace.
> 
> This seems to have come up private mail as well, and there the
> suggestion was to use \ifeof18 instead.
> 
> For various reasons I still haven't been able to spend time on TeX.
> :-(

Ok, I have done it:

Patch ShellEscapeIfeof18

Packages such as pdftricks.sty, epstopdf.sty (or pdftex.def)
call external programs. They do not work at all, if the
\write18 feature is not enabled. Therefore a robust method
would be useful in order to inform the user. For security
reasons the \write18 feature must not be set by TeX macro
code.
  In opposite to patch "ShellEscape" this patch now uses
\ifeof18 for a test of the shell escape feature. Thus the
introduction of a new primitive is avoided. Also it works
now for other TeX engines (tex, etex, pdftex, pdfetex).

Use, for instance:

\ifeof18
  \message{The \string\write18 feature is disabled.}
\else
  \message{The \string\write18 feature is enabled.}
\fi

Patch files based on 2003/07/11 v1.11a:
  tex.ch.diff for TeX/texk/web2c/tex.ch

Attachted are files tex.ch.diff and a test file test.tex.

Yours sincerely
  Heiko <oberdiek@uni-freiburg.de>
-- 
--G4iJoqBmSsgzjUCe
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="tex.ch.diff"

*** tex.ch.org	Fri Jul 11 00:32:10 2003
--- tex.ch	Fri Jul 11 01:29:43 2003
***************
*** 1529,1534 ****
--- 1529,1563 ----
  absorbing:begin print(" while scanning text"); info(p):=right_brace_token+"}";
  @z
  
+ @x [26.435] l.8625 - Adding scan procedure for stream numbers including 18
+ procedure scan_four_bit_int;
+ @y
+ procedure scan_four_bit_int_or_xviii;
+ begin scan_int;
+ if (cur_val<0) or ((cur_val>15) and not(cur_val=18)) then
+   begin print_err("Bad number");
+ @.Bad number@>
+   {The help message text is not changed because of trip test.}
+   help2("Since I expected to read a number between 0 and 15,")@/
+     ("I changed this one to zero."); int_error(cur_val); cur_val:=0;
+   end;
+ end;
+ procedure scan_four_bit_int;
+ @z
+ 
+ @x [28.501] l.9746 - Extending ifeof test for shell escape feature
+ if_eof_code: begin scan_four_bit_int; b:=(read_open[cur_val]=closed);
+   end;
+ @y
+ if_eof_code: begin
+     scan_four_bit_int_or_xviii;
+     if (cur_val=18) then
+       b:=not shell_enabled_p
+     else
+       b:=(read_open[cur_val]=closed);
+   end;
+ @z
+ 
  @x [29.513] l.9951 - Area and extension rules for filenames.
  @ The file names we shall deal with for illustrative purposes have the
  following structure:  If the name contains `\.>' or `\.:', the file area

--G4iJoqBmSsgzjUCe
Content-Type: application/x-tex
Content-Disposition: attachment; filename="test.tex"
Content-Transfer-Encoding: quoted-printable

\def\println#{\immediate\write16}=0A\def\test#1{%=0A  \ifeof#1 %=0A    \pri=
ntln{* \number#1: EOF}%=0A  \else=0A    \println{* \number#1: NOT EOF}%=0A =
 \fi=0A}=0A=0A\test{18}=0A=0A\newread\foo=0A\test\foo=0A\println{* \number\=
foo: OPENIN}=0A\openin\foo=3D\jobname\relax=0A\test\foo=0A=0A\nonstopmode=
=0A\test{16}=0A\test{17}=0A\test{19}=0A=0A\csname @@end\endcsname=0A\end=0A
--G4iJoqBmSsgzjUCe--