summaryrefslogtreecommitdiff
path: root/Build/source/utils/xindy-new/xindy-2.4-pre2-PATCHES/patch-26-TL-texindy_pl
blob: 2e7fc76ce0c03390b674694ece428364649afd91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
	Determine cmd_dir (for VERSION) and xindy.

	Call xindy via 'exec' (Unix) or 'system $^X' (Windows).

	Also implement symlinks, e.g., in /usr/local/bin/ for
	standalone version.

diff -ur -x Makefile.in -x autom4te.cache xindy.orig/user-commands/texindy.in xindy/user-commands/texindy.in
--- xindy.orig/user-commands/texindy.in	2009-12-03 01:27:06.000000000 +0100
+++ xindy/user-commands/texindy.in	2009-12-11 18:02:58.000000000 +0100
@@ -306,10 +306,44 @@
 # Determine environment. Where is our library directory, and our modules?
 
 use File::Basename;
+use Cwd;
+our ($isW32, $isTL);
+our $xindy;
 our ($cmd_dir, $cmd);
 BEGIN {
-    $cmd_dir = dirname($0);
+    $isW32 = ($^O =~ /^MSWin/i) ? 1 : 0;
+    my $r0 = Cwd::realpath($0);
+    $cmd_dir = dirname($r0);
+    $isTL = (basename($r0) =~ /\.pl/) ? 1 : 0;
+
     $cmd = basename($0);
+
+    if ($isTL) {
+	if ($isW32) {
+	    $xindy = "$cmd_dir/xindy.pl";
+	} else {
+	    die "$cmd: not a symlink as required for TeX Live"  unless -l $0;
+	    $r0 = $0;
+	    $cmd_dir = dirname($r0);
+	    # Follow symlinks, but remember last one
+	    my $lcmd_dir;
+	    while ( -l $r0 ) {
+		$lcmd_dir = $cmd_dir;
+		$r0 = readlink($r0);
+		$r0 = "$lcmd_dir/$r0"  unless $r0 =~ m,^[\\/],; # relative link
+		$cmd_dir = dirname($r0);
+	    }
+	    $xindy = "$lcmd_dir/xindy";
+	}
+	$cmd_dir = Cwd::realpath("$cmd_dir/../../xindy/modules");
+	die "Cannot locate xindy modules directory"  unless -f "$cmd_dir/../VERSION";
+    } else {
+	# FIXME: For win32 there should be wrapper scripts 'xindy.bat' or 'xindy.cmd'
+	# FIXME: invoking 'perl xindy' and similar for texindy.
+	# FIXME: When calling xindy from texindy we bypass this wrapper.
+	$xindy = "$cmd_dir/xindy";
+    }
+    die "$cmd: cannot locate xindy\n"  unless -f $xindy && ($isW32 || -x $xindy);
 }
 
 
@@ -359,15 +393,6 @@
 $codepage = 'latin';
 $input_markup = 'latex';
 
-our $xindy;
-if ( -f "$cmd_dir/xindy" && -x _ ) {
-    $xindy = "$cmd_dir/xindy";
-} elsif ( -f "$cmd_dir/xindy.pl" && -x _ ) {
-    $xindy = "$cmd_dir/xindy.pl";
-} else {
-    die "$cmd: cannot locate xindy\n";
-}
-
 parse_options();
 output_version()  if $output_version;	# will not return
 usage(1)  if ( ! $stdin && @ARGV == 0 ); # brain damaged, but like makeindex
@@ -388,21 +413,36 @@
 				@modules));
 push (@opt, '-I', $input_markup);
 
-print "Calling xindy as: $cmd_dir/xindy @opt @ARGV\n"  if (grep /^script$/, @debug);
-
-exec $xindy, @opt, @ARGV;
-die "$cmd: could not execute xindy: $!\n";
+print "Calling xindy as: $xindy @opt @ARGV\n"  if (grep /^script$/, @debug);
+call_xindy(@opt, @ARGV);
 
 
 # ------------------------------------------------------------
 
 
+sub call_xindy {
+    if ($isW32) {
+	system ($^X, $xindy, @_);
+	if ($? == -1) {
+	    die "$cmd: could not execute xindy: $!\n";
+	} elsif ($? & 127) {
+	    die "xindy died with signal " . ($? & 127) ."\n";
+	} else {
+	    exit ($? >> 8);
+	}
+    } else {
+	exec ($xindy, @_);
+	die "$cmd: could not execute xindy: $!\n";
+    }
+}
+
+
 sub parse_options() {
 
     my ($german, $letter_ordering, $no_ranges);
     GetOptions(
 	       'version|V'          => \$output_version,
-	       'help|h|?'           => \&usage,
+
 	       'quiet|q'            => \$quiet,
 	       'verbose|v'          => \$verbose,
 	       'stdin|i'            => \$stdin,
@@ -450,9 +490,9 @@
 sub output_version () {
     output_xindy_release();
     print "$cmd script version: $VERSION\n";
-    my @xindy_cmd = ($xindy, '--internal-version');
+    my @xindy_cmd = ('--internal-version');
     push (@xindy_cmd, qw(-d script --foobar))  if grep(/^script$/, @debug);
-    exec @xindy_cmd;
+    call_xindy(@xindy_cmd);
 }