On 2003-02-04T11:05:16+0900, Atsuhito Kohda wrote: > I believe that it is much better that tetex-bin doesn't > depend on a particular version of Perl. Absolutely! I have some very minor suggestions though: I would prefer for xdvi.bin to be invoked on a file in /dev/fd rather than a "real" file name, so that we do not rely on the user to set TMPDIR to a sane value. (It is also more consistent with how gzip is invoked.) Making this change means that we no longer need a file name for the temporary file, so $tmpname and UNLINK can go away. Finally, DIR is tmpdir by default, so we can simply omit it and File::Spec. Since multiple versions of this script are being sent around, and it is not very big, I am attaching my revised version. The code as well as my suggestions are based only on perl 5.8, though, so it would be great to check with a pre-5.8 perl. Thanks, Ken -- Edit this signature at http://www.digitas.harvard.edu/cgi-bin/ken/sig "Ok, now time to be clever...damn." - N. Karlsson
#! /usr/bin/perl -w # This is the xdvi wrapper script for Debian, based on Thomas Esser's # teTeX version 0.2. # Debian version: Copyright Julian Gilbey, 2002. Lots of modifications # by Chung-chieh Shan <ken@digitas.harvard.edu>. # Original version: Copyright Thomas Esser, 1998. # Permission to distribute this software is given under the terms of # the GNU general public license version 2 or later. # Thomas writes: # This script sets some environment variables to make sure that xdvi's # resource file in $XDVIINPUTS/xdvi is read by xdvi.bin. # Special care was taken to make this work for old R3, too. Therefore, # we need to modify XAPPLRESDIR. If you are running R4 or later, you # can set XUSERFILESEARCHPATH for user specific application default # files. You cannot use XAPPLRESDIR for user specific application default # files. # Julian writes: # While Debian runs X11R6, we keep the XAPPLRESDIR part of the code for # consistency. This has been rewritten in Perl so that we can mangle # the arguments to handled gzipped dvi files, which not have errors if # there are spaces in some arguments. use strict; use FileHandle; use File::Basename; use File::Temp qw/ tempfile /; my @NAMEOPT; if (@ARGV == 1 and ($ARGV[0] eq '-help' or $ARGV[0] eq '-version')) { @NAMEOPT=(); } else { @NAMEOPT=qw(-name xdvi); } $ENV{'XDVIINPUTS'} .= ":\$TEXMF/{xdvi,web2c}"; my ($xdviappfile, $xdviappdir, $xdviapppath); $xdviappfile=`kpsewhich -progname=xdvi --format='other text files' XDvi`; if ("$xdviappfile" ne '') { $xdviappdir=dirname($xdviappfile); $xdviapppath="$xdviappdir/%N"; # For R3, we have to set XAPPLRESDIR. $ENV{'XAPPLRESDIR'}=$xdviappdir; # For R4 or later, we have to set XFILESEARCHPATH, since XAPPLRESDIR might # be ignored (if XUSERFILESEARCHPATH is set) if (exists $ENV{'XFILESEARCHPATH'}) { $ENV{'XFILESEARCHPATH'} = "$xdviapppath:$ENV{'XFILESEARCHPATH'}"; } else { $ENV{'XFILESEARCHPATH'} = $xdviapppath; } } my $status; if (@ARGV) { my $filename = pop @ARGV; if ($filename =~ /\.(gz|Z|bz2)$/) { my @command = $1 eq 'bz2' ? qw(bzip2 -d -c) : qw(gzip -d -c); require Fcntl; my $fh = tempfile( "tetexXXXXXX", SUFFIX => ".dvi" ) or die "xdvi: cannot create temporary file: $!\n"; fcntl $fh, Fcntl::F_SETFD(), 0 or die "xdvi: disabling close-on-exec for temporary file: $!\n"; if (my $child = fork) { 1 while wait != $child; if ($? & 255) { die "xdvi: $command[0] terminated abnormally: $?\n"; } elsif ($?) { my $code = $? >> 8; die "xdvi: $command[0] terminated with exit code $code\n"; } } elsif (defined $child) { STDOUT->fdopen( $fh, "w" ); exec @command, $filename; } else { die "xdvi: fork: $!\n"; } $status = system('xdvi.bin', @NAMEOPT, @ARGV, "/dev/fd/".fileno($fh)); } else { $status = system('xdvi.bin', @NAMEOPT, @ARGV, $filename); } } else { $status = system('xdvi.bin', @NAMEOPT); } if ($status & 255) { die "xdvi: xdvi.bin terminated abnormally: $?\n"; } else { my $code = $? >> 8; exit $code; }
Attachment:
pgpARmW_SjGp9.pgp
Description: PGP signature