From 5b8032cb4ddc1d209cdd00c675f0c1c170b80f02 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Wed, 12 Dec 2007 08:04:29 +0000 Subject: update perltex script git-svn-id: svn://tug.org/texlive/trunk@5763 c570f23f-e606-0410-a88d-b1316a301751 --- Master/bin/hppa-hpux/perltex | 117 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 101 insertions(+), 16 deletions(-) (limited to 'Master/bin/hppa-hpux') diff --git a/Master/bin/hppa-hpux/perltex b/Master/bin/hppa-hpux/perltex index dd8dda2804b..9c85ef94500 100755 --- a/Master/bin/hppa-hpux/perltex +++ b/Master/bin/hppa-hpux/perltex @@ -15,7 +15,7 @@ # # This is a generated file. # -# Copyright (C) 2006, Scott Pakin +# Copyright (C) 2007 Scott Pakin # # This file may be distributed and/or modified under the conditions # of the LaTeX Project Public License, either version 1.3c of this @@ -37,30 +37,39 @@ use Opcode; use Getopt::Long; use Pod::Usage; use File::Basename; +use Fcntl; use POSIX; use warnings; use strict; my $latexprog; my $runsafely = 1; my @permittedops; +my $usepipe = 1; my $progname = basename $0; my $jobname = "texput"; -my @latexcmdline; my $toperl; my $fromperl; my $toflag; my $fromflag; my $doneflag; my $logfile; +my $pipe; +my @latexcmdline; +my $styfile; +my @macroexpansions; my $sandbox = new Safe; my $sandbox_eval; my $latexpid; +my $pipestring = "\%\%\%\%\% Generated by $progname\n\\endinput\n"; $latexprog = $ENV{"PERLTEX"} || "latex"; Getopt::Long::Configure("require_order", "pass_through"); -GetOptions("help" => sub {pod2usage(-verbose => 1)}, - "latex=s" => \$latexprog, - "safe!" => \$runsafely, - "permit=s" => \@permittedops) || pod2usage(2); +GetOptions("help" => sub {pod2usage(-verbose => 1)}, + "latex=s" => \$latexprog, + "safe!" => \$runsafely, + "pipe!" => \$usepipe, + "synctext=s" => \$pipestring, + "makesty" => sub {$styfile = "noperltex.sty"}, + "permit=s" => \@permittedops) || pod2usage(2); @latexcmdline = @ARGV; my $firstcmd = 0; for ($firstcmd=0; $firstcmd<=$#latexcmdline; $firstcmd++) { @@ -83,19 +92,30 @@ $toflag = $jobname . ".tfpl"; $fromflag = $jobname . ".ffpl"; $doneflag = $jobname . ".dfpl"; $logfile = $jobname . ".lgpl"; +$pipe = $jobname . ".pipe"; $latexcmdline[$firstcmd] = - sprintf '\makeatletter' . '\def%s{%s}' x 6 . '\makeatother%s', + sprintf '\makeatletter' . '\def%s{%s}' x 7 . '\makeatother%s', '\plmac@tag', $separator, '\plmac@tofile', $toperl, '\plmac@fromfile', $fromperl, '\plmac@toflag', $toflag, '\plmac@fromflag', $fromflag, '\plmac@doneflag', $doneflag, + '\plmac@pipe', $pipe, $latexcmdline[$firstcmd]; -foreach my $file ($toperl, $fromperl, $toflag, $fromflag, $doneflag) { +foreach my $file ($toperl, $fromperl, $toflag, $fromflag, $doneflag, $pipe) { unlink $file while -e $file; } open (LOGFILE, ">$logfile") || die "open(\"$logfile\"): $!\n"; +if (defined $styfile) { + open (STYFILE, ">$styfile") || die "open(\"$styfile\"): $!\n"; +} +if (!$usepipe || !eval {mkfifo($pipe, 0600)}) { + sysopen PIPE, $pipe, O_WRONLY|O_CREAT, 0755; + print PIPE $pipestring; + close PIPE; + $usepipe = 0; +} defined ($latexpid = fork) || die "fork: $!\n"; unshift @latexcmdline, $latexprog; if (!$latexpid) { @@ -116,7 +136,7 @@ while (1) { sleep 0; if (waitpid($latexpid, &WNOHANG)==-1) { foreach my $file ($toperl, $fromperl, $toflag, - $fromflag, $doneflag) { + $fromflag, $doneflag, $pipe) { unlink $file while -e $file; } undef $latexpid; @@ -173,7 +193,7 @@ while (1) { print LOGFILE "# ===> $warningmsg\n\n"; } } - $result="" if !$result || $optag eq "RUN"; + $result = "" if !$result || $optag eq "RUN"; if ($@) { my $msg = $@; $msg =~ s/at \(eval \d+\) line \d+\W+//; @@ -202,6 +222,7 @@ while (1) { $helpstring =~ s/\. /.\\space\\space /g; $result .= "{$helpstring}"; } + push @macroexpansions, $result if defined $styfile && $optag eq "USE"; print LOGFILE "%" x 30, " LATEX RESULT ", "%" x 30, "\n"; print LOGFILE $result, "\n\n"; $result .= '\endinput'; @@ -213,10 +234,18 @@ while (1) { unlink $doneflag while -e $doneflag; open (FROMFLAG, ">$fromflag") || die "open($fromflag): $!\n"; close FROMFLAG; + if (open (PIPE, ">$pipe")) { + print PIPE $pipestring; + close PIPE; + } $awaitexists->($toperl); unlink $fromflag while -e $fromflag; open (DONEFLAG, ">$doneflag") || die "open($doneflag): $!\n"; close DONEFLAG; + if (open (PIPE, ">$pipe")) { + print PIPE $pipestring; + close PIPE; + } } END { close LOGFILE; @@ -224,6 +253,46 @@ END { kill (9, $latexpid); exit 1; } + + if (defined $styfile) { + print STYFILE <<"STYFILEHEADER1"; +\\NeedsTeXFormat{LaTeX2e}[1999/12/01] +\\ProvidesPackage{noperltex} + [2007/09/29 v1.4 Perl-free version of PerlTeX specific to $jobname.tex] +STYFILEHEADER1 + ; + print STYFILE <<'STYFILEHEADER2'; +\RequirePackage{filecontents} + +\let\noperltex@PackageError=\PackageError +\renewcommand{\PackageError}[3]{} +\RequirePackage{perltex} +\let\PackageError=\noperltex@PackageError + +\newcount\plmac@macro@invocation@num +\gdef\plmac@show@placeholder#1#2\@empty{% + \ifx#1U\relax + \endgroup + \advance\plmac@macro@invocation@num by 1\relax + \global\plmac@macro@invocation@num=\plmac@macro@invocation@num + \input{noperltex-\the\plmac@macro@invocation@num.tex}% + \else + \endgroup + \fi +} +STYFILEHEADER2 + ; + foreach my $e (0 .. $#macroexpansions) { + print STYFILE "\n"; + printf STYFILE "%% Invocation #%d\n", 1+$e; + printf STYFILE "\\begin{filecontents}{noperltex-%d.tex}\n", 1+$e; + print STYFILE $macroexpansions[$e], "\\endinput\n"; + print STYFILE "\\end{filecontents}\n"; + } + print STYFILE "\\endinput\n"; + close STYFILE; + } + exit 0; } @@ -240,6 +309,7 @@ perltex [B<--latex>=I] [B<-->[B]B] [B<--permit>=I] +[B<--makesty>] [I] =head1 DESCRIPTION @@ -280,21 +350,32 @@ B instead of ordinary B. =item B<-->[B]B -Enable or disable sandboxing. With the default of C<--safe>, +Enable or disable sandboxing. With the default of B<--safe>, B executes the code from a C<\perlnewcommand> or C<\perlrenewcommand> macro within a protected environment that prohibits ``unsafe'' operations such as accessing files or executing -external programs. Specifying C<--nosafe> gives the LaTeX document +external programs. Specifying B<--nosafe> gives the LaTeX document I to execute any arbitrary Perl code, including that which can harm the user's files. See L for more information. =item B<--permit>=I -Permit particular Perl operations to be performed. The C<--permit> +Permit particular Perl operations to be performed. The B<--permit> option, which can be specified more than once on the command line, enables finer-grained control over the B sandbox. See L for more information. +=item B<--makesty> + +Generate a LaTeX style file called F. Replacing the +document's C<\usepackage{perltex}> line with C<\usepackage{noperltex}> +produces the same output but does not require PerlTeX, making the +document suitable for distribution to people who do not have PerlTeX +installed. The disadvantage is that F is specific to +the document that produced it. Any changes to the document's PerlTeX +macro definitions or macro invocations necessitates rerunning +B with the B<--makesty> option. + =back These options are then followed by whatever options are normally @@ -308,7 +389,7 @@ In its simplest form, B is run just like B: perltex myfile.tex -To use B instead of regular B, use the C<--latex> +To use B instead of regular B, use the B<--latex> option: perltex --latex=pdflatex myfile.tex @@ -316,7 +397,7 @@ option: If LaTeX gives a ``C'' error and you trust the F<.tex> file you're trying to compile not to execute malicious Perl code (e.g., because you wrote it yourself), you can disable -B's safety mechansisms with C<--nosafe>: +B's safety mechansisms with B<--nosafe>: perltex --nosafe myfile.tex @@ -337,7 +418,7 @@ B honors the following environment variables: Specify the filename of the LaTeX compiler. The LaTeX compiler defaults to ``C''. The C environment variable -overrides this default, and the C<--latex> command-line option (see +overrides this default, and the B<--latex> command-line option (see L) overrides that. =back @@ -376,6 +457,10 @@ valid data ``flag'' file whose existence indicates that F has been deleted +=item F + +file generated by F for each PerlTeX macro invocation + =back =head1 NOTES -- cgit v1.2.3