3
# This is the xdvi wrapper script for Debian, based on Thomas Esser's
5
# Debian version: Copyright Julian Gilbey, 2002. Lots of modifications
6
# by Chung-chieh Shan <ken@digitas.harvard.edu>.
7
# Also by TSUCHIYA Masatoshi <tsuchiya@pine.kuee.kyoto-u.ac.jp>.
8
# Original version: Copyright Thomas Esser, 1998.
9
# Permission to distribute this software is given under the terms of
10
# the GNU general public license version 2 or later.
13
# This script sets some environment variables to make sure that xdvi's
14
# resource file in $XDVIINPUTS/xdvi is read by xdvi.bin.
15
# Special care was taken to make this work for old R3, too. Therefore,
16
# we need to modify XAPPLRESDIR. If you are running R4 or later, you
17
# can set XUSERFILESEARCHPATH for user specific application default
18
# files. You cannot use XAPPLRESDIR for user specific application default
22
# This has been rewritten in Perl so that we can mangle the arguments
23
# to handled gzipped dvi files, which not have errors if there are
24
# spaces in some arguments. XAPPLRESDIR is no longer modified.
26
# Stephen Gildea writes:
27
# Debian distributes X11R6, therefore this script should not clobber
28
# XAPPLRESDIR, which is for user customizations.
34
use File::Temp qw/ tempfile /;
37
if (@ARGV == 1 and ($ARGV[0] eq '-help' or $ARGV[0] eq '-version')) {
40
@NAMEOPT=qw(-name xdvi);
43
$ENV{'XDVIINPUTS'} .= ":\$TEXMF/{xdvi,web2c}";
45
my ($xdviappfile, $xdviappdir, $xdviapppath);
46
$xdviappfile=`kpsewhich -progname=xdvi --format='other text files' XDvi`;
47
if ("$xdviappfile" ne '') {
48
$xdviappdir=dirname($xdviappfile);
49
$xdviapppath="$xdviappdir/%N";
51
if (exists $ENV{'XFILESEARCHPATH'}) {
52
$ENV{'XFILESEARCHPATH'} = "$xdviapppath:$ENV{'XFILESEARCHPATH'}";
54
$ENV{'XFILESEARCHPATH'} = "$xdviapppath:%D";
60
my $filename = pop @ARGV;
62
if ($filename =~ /\.(gz|Z|bz2)$/) {
63
my @command = $1 eq 'bz2' ? qw(bzip2 -d -c) : qw(gzip -d -c);
66
my $fh = tempfile( UNLINK => 1 )
67
or die "xdvi: cannot create temporary file: $!\n";
68
fcntl $fh, Fcntl::F_SETFD(), 0
69
or die "xdvi: disabling close-on-exec for temporary file: $!\n";
71
if (my $child = fork) {
72
1 while wait != $child;
74
die "xdvi: $command[0] terminated abnormally: $?\n";
77
die "xdvi: $command[0] terminated with exit code $code\n";
79
} elsif (defined $child) {
80
STDOUT->fdopen( $fh, "w" );
81
exec @command, $filename;
83
die "xdvi: fork: $!\n";
85
$status = system('xdvi.bin', @NAMEOPT, @ARGV, '/dev/fd/'.fileno($fh));
87
$status = system('xdvi.bin', @NAMEOPT, @ARGV, $filename);
90
$status = system('xdvi.bin', @NAMEOPT);
94
die "xdvi: xdvi.bin terminated abnormally: $?\n";