Debian Codegraph @

debian/xdvi-pl

raw
1 #! /usr/bin/perl -w
2
3 # This is the xdvi wrapper script for Debian, based on Thomas Esser's
4 # teTeX version 0.2.
5 # Debian version: Copyright Julian Gilbey, 2002. Lots of modifications
6 # by Chung-chieh Shan <[email protected]>.
7 # Also by TSUCHIYA Masatoshi <[email protected]>.
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.
11
12 # Thomas writes:
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
19 # files.
20
21 # Julian writes:
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.
25
26 # Stephen Gildea writes:
27 # Debian distributes X11R6, therefore this script should not clobber
28 # XAPPLRESDIR, which is for user customizations.
29
30 use strict;
31 use FileHandle;
32 use File::Basename;
33 use File::Spec;
34 use File::Temp qw/ tempfile /;
35
36 my @NAMEOPT;
37 if (@ARGV == 1 and ($ARGV[0] eq '-help' or $ARGV[0] eq '-version')) {
38 @NAMEOPT=();
39 } else {
40 @NAMEOPT=qw(-name xdvi);
41 }
42
43 $ENV{'XDVIINPUTS'} .= ":\$TEXMF/{xdvi,web2c}";
44
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";
50
51 if (exists $ENV{'XFILESEARCHPATH'}) {
52 $ENV{'XFILESEARCHPATH'} = "$xdviapppath:$ENV{'XFILESEARCHPATH'}";
53 } else {
54 $ENV{'XFILESEARCHPATH'} = "$xdviapppath:%D";
55 }
56 }
57
58 my $status;
59 if (@ARGV) {
60 my $filename = pop @ARGV;
61
62 if ($filename =~ /\.(gz|Z|bz2)$/) {
63 my @command = $1 eq 'bz2' ? qw(bzip2 -d -c) : qw(gzip -d -c);
64
65 require Fcntl;
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";
70
71 if (my $child = fork) {
72 1 while wait != $child;
73 if ($? & 255) {
74 die "xdvi: $command[0] terminated abnormally: $?\n";
75 } elsif ($?) {
76 my $code = $? >> 8;
77 die "xdvi: $command[0] terminated with exit code $code\n";
78 }
79 } elsif (defined $child) {
80 STDOUT->fdopen( $fh, "w" );
81 exec @command, $filename;
82 } else {
83 die "xdvi: fork: $!\n";
84 }
85 $status = system('xdvi.bin', @NAMEOPT, @ARGV, '/dev/fd/'.fileno($fh));
86 } else {
87 $status = system('xdvi.bin', @NAMEOPT, @ARGV, $filename);
88 }
89 } else {
90 $status = system('xdvi.bin', @NAMEOPT);
91 }
92
93 if ($status & 255) {
94 die "xdvi: xdvi.bin terminated abnormally: $?\n";
95 } else {
96 my $code = $? >> 8;
97 exit $code;
98 }