summaryrefslogtreecommitdiff
path: root/Master/bin/i386-darwin
diff options
context:
space:
mode:
authorNorbert Preining <preining@logic.at>2007-12-12 08:04:29 +0000
committerNorbert Preining <preining@logic.at>2007-12-12 08:04:29 +0000
commit5b8032cb4ddc1d209cdd00c675f0c1c170b80f02 (patch)
tree0d76052c1032f37e7f2a212bdfed53b54a606d86 /Master/bin/i386-darwin
parentda4daf1b676263905e7f04bb64e9878508c1ee97 (diff)
update perltex script
git-svn-id: svn://tug.org/texlive/trunk@5763 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/bin/i386-darwin')
-rwxr-xr-xMaster/bin/i386-darwin/perltex117
1 files changed, 101 insertions, 16 deletions
diff --git a/Master/bin/i386-darwin/perltex b/Master/bin/i386-darwin/perltex
index dd8dda2804b..9c85ef94500 100755
--- a/Master/bin/i386-darwin/perltex
+++ b/Master/bin/i386-darwin/perltex
@@ -15,7 +15,7 @@
#
# This is a generated file.
#
-# Copyright (C) 2006, Scott Pakin <scott+pt@pakin.org>
+# Copyright (C) 2007 Scott Pakin <scott+pt@pakin.org>
#
# 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<program>]
[B<-->[B<no>]B<safe>]
[B<--permit>=I<feature>]
+[B<--makesty>]
[I<latex options>]
=head1 DESCRIPTION
@@ -280,21 +350,32 @@ B<pdflatex> instead of ordinary B<latex>.
=item B<-->[B<no>]B<safe>
-Enable or disable sandboxing. With the default of C<--safe>,
+Enable or disable sandboxing. With the default of B<--safe>,
B<perltex> 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<carte blanche> to execute any arbitrary Perl code, including that
which can harm the user's files. See L<Safe> for more information.
=item B<--permit>=I<feature>
-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<perltex> sandbox. See
L<Opcode> for more information.
+=item B<--makesty>
+
+Generate a LaTeX style file called F<noperltex.sty>. 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<noperltex.sty> is specific to
+the document that produced it. Any changes to the document's PerlTeX
+macro definitions or macro invocations necessitates rerunning
+B<perltex> 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<perltex> is run just like B<latex>:
perltex myfile.tex
-To use B<pdflatex> instead of regular B<latex>, use the C<--latex>
+To use B<pdflatex> instead of regular B<latex>, use the B<--latex>
option:
perltex --latex=pdflatex myfile.tex
@@ -316,7 +397,7 @@ option:
If LaTeX gives a ``C<trapped by operation mask>'' 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<perltex>'s safety mechansisms with C<--nosafe>:
+B<perltex>'s safety mechansisms with B<--nosafe>:
perltex --nosafe myfile.tex
@@ -337,7 +418,7 @@ B<perltex> honors the following environment variables:
Specify the filename of the LaTeX compiler. The LaTeX compiler
defaults to ``C<latex>''. The C<PERLTEX> 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</OPTIONS>) overrides that.
=back
@@ -376,6 +457,10 @@ valid data
``flag'' file whose existence indicates that F<jobname.ffpl> has been
deleted
+=item F<noperltex-#.tex>
+
+file generated by F<noperltex.sty> for each PerlTeX macro invocation
+
=back
=head1 NOTES