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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
#!@XINDY_PERL@
# $Id: xindy.in,v 1.14 2005/05/02 19:16:27 jschrod Exp $
#------------------------------------------------------------
#
# This is the old perl-frontend to the xindy indexing system.
#
# It is kept for compatibility reasons and is named xindy.v2 in
# production. Most probably, you will not want to use it any more.
#
# This code is not supported. Don't report bugs, switch to the current
# xindy script.
#
($progname = $0) =~ s#.*/##;
$Date = `date`;
require "getopts.pl";
# $debug = 1;
$numArgs = $#ARGV; # save number of command line arguments
# parse for command-line options
&Getopts( "dtvnio:l:f:L:" );
$debug = $opt_d;
# some debug-output
print STDERR "progname: $progname\n" if $debug;
print STDERR "\@ARGV: @ARGV\n" if $debug;
print STDERR "\$#ARGV: $#ARGV\n" if $debug;
#
# Synopsis
#
sub usage {
print STDERR "\n$progname\t[-t] [-v] [-o output] [-l logfile] [-f filtprg] [-L n]
\tindexstyle raw-index\n";
print STDERR <<EOMSG;
options:
-t Enters tracing-mode for markup-tags.
-v Displays the current version of xindy.
-o Specifies the output-file for the tagged index. If omitted, the
name of the raw-index is taken, with its extension
substituted by \`.ind'.
-f filt Preprocess raw-index with \`filtprg' before reading.
-l file Logfile into which xindy writes useful information.
-L n Enter logging level \`n' = {1,2,3}.
EOMSG
exit(2);
}
#
# These functions check for the correct installation of the base
# system.
#
sub check_bin {
print "runfile = $runfile\n" if $debug;
if ( ! -e $runfile ) {
print "Can't find \`$runfile' !\n";
exit(3);
}
if ( ! -x $runfile ) {
print "File \`$runfile' not executable !\n";
exit(4);
}
}
sub check_mem {
print "memfile = $memfile\n" if $debug;
if ( ! -e $memfile ) {
print "Can't find \`$memfile' !";
exit(5);
}
}
#
# This function takes a string and quotes the `"' and '\' characters
# with a leading backslash.
#
sub quote_string {
local($str) = @_;
$str =~ s#\\#\\\\#g;
$str =~ s#"#\\\"#g;
return $str;
}
sub remove_suffix {
local($str) = @_;
$str =~ s#\.[^\.]*$##;
return $str;
}
#
# The generic signal handler that removes temporary files if
# necessary.
#
sub sig_catch {
unlink $tmpfile;
exit(9);
}
sub sig_setup {
$SIG{"HUP"} = "sig_catch"; # 1
$SIG{"INT"} = "sig_catch"; # 2
$SIG{"QUIT"} = "sig_catch"; # 3
$SIG{"TERM"} = "sig_catch"; # 15
$SigHandlerSet = 1;
}
#
# here we go...
#
$numArgs = $#ARGV; # number of Commandline-Arguments
if ( $numArgs eq 1 || $opt_v || $opt_i ) { # two arguments or -v,-i specified
$Idxsty = $ARGV[0];
$Rawidx = $ARGV[1];
} else {
&usage;
}
print "Idxsty = $Idxsty\n" if $debug;
print "Rawidx = $Rawidx\n" if $debug;
# Define the default xindy library directory. It should be in a
# sibling lib tree, maybe in a xindy subdirectory. Or the user may
# set XINDY_LIBDIR explicitely.
$0 =~ m:^(.*)/[^/]*$: ;
$cmd_dir = $1 || '.';
# library directory
if ( $ENV{XINDY_LIBDIR} ) {
$LibDir = $ENV{XINDY_LIBDIR};
print "XINDY_LIBDIR (from Environment) = $LibDir\n" if $debug;
} elsif ( -f "$cmd_dir/../lib/xindy.run" ) { # /opt style
$LibDir = "$cmd_dir/../lib";
} elsif ( -d "$cmd_dir/../lib/xindy" ) { # /usr or /usr/local style
$LibDir = "$cmd_dir/../lib/xindy";
} elsif ( -f "$cmd_dir/xindy.run" ) { # texlive style
$LibDir = $cmd_dir;
} else {
die "Cannot locate xindy library directory";
}
$XINDY_LIBDIR=$LibDir;
print "XINDY_LIBDIR = $XINDY_LIBDIR\n" if $debug;
# modules directory
if ( -d "$cmd_dir/../modules" ) { # /opt style
$modules_dir = "$cmd_dir/../modules";
} elsif ( -d "$LibDir/modules" ) { # /usr or /usr/local style
$modules_dir = "$LibDir/modules";
} elsif ( -d "$LibDir/../../texmf/scripts/xindy" ) { # texlive style
$modules_dir = "$LibDir/../../texmf/scripts/xindy";
} else {
die "Cannot locate xindy modules directory";
}
$memfile="$XINDY_LIBDIR/xindy.mem";
$runfile="$XINDY_LIBDIR/xindy.run";
# Set initial searchpath
$SEARCHPATH="(searchpath \".:$modules_dir\")";
# Add/replace (depends on the specification) the search path according
# to the environment variable
if ( $XINDY_SEARCHPATH ne "" ) {
$SEARCHPATH="$SEARCHPATH (searchpath \"$XINDY_SEARCHPATH\")";
}
print "SEARCHPATH = $SEARCHPATH\n" if $debug;
if ($opt_v) { $version = ":show-version t"; }
if ($opt_t) { $tracing = ":markup-trace t"; }
if ($opt_n) { $try = 1; }
if ($opt_c) { $compile = "on"; }
if ($opt_i) { $interactive = "on"; }
if ($opt_m) { $memfile = $opt_m; }
if ($opt_o) { $output = $opt_o; }
if ($opt_f) { $filtprg = $opt_f; }
if ($opt_l) { $logfile = $opt_l; }
if ($opt_L) { $level = $opt_L; }
# Now check if everything is present.
if ( ! $try ) {
&check_bin;
&check_mem;
}
$xindy_run = "$runfile -B $XINDY_LIBDIR -q -M $memfile -E iso-8859-1";
print "xindy_run = $xindy_run\n" if $debug;
# Run xindy interactive if this was specified via -i.
if ( $interactive ) {
print "$xindy_run\n" if $debug;
exec "$xindy_run";
}
# If specified via -v start xindy for showing the version-message.
if ( $version ) {
print "$xindy_run -x \"(progn (xindy:startup $version) (exit))\"" if $debug;
exec "$xindy_run -x \"(progn (xindy:startup $version) (exit))\"";
}
# Quote the filenames, such that LISP can read it.
$Idxsty = "e_string($Idxsty);
$Rawidx = "e_string($Rawidx);
# If no output-file was specified
if ( ! $output ) {
# remove the suffix, if one exists
$output = &remove_suffix($Rawidx);
# append suffix ".ind"
$output = "e_string("$output.ind");
}
# Run the intermediate filter if specified via -f.
if ( $filtprg ) {
# create tmpfile
$tmpfile = "/tmp/xindy.$$";
&sig_setup; # setup signal handler for cleanup
print "Running filter: $filtprg < $Rawidx > $tmpfile\n";
system "$filtprg < $Rawidx > $tmpfile";
print "Finished running filter.\n\n";
$Rawidx = "e_string($tmpfile);
}
# Prepare logfile option.
if ( $logfile ) {
$logfile = ":logfile \"" . "e_string($logfile) . "\"";
}
# Prepare trace-level.
if ( $level ) {
$logging = ":trace-level $level";
}
# This is the complete LISP-SEXP needed to start the system.
$xindy_cmd = "-x '(progn
$SEARCHPATH
(xindy:startup :idxstyle \"$Idxsty\"
:rawindex \"$Rawidx\"
:output \"$output\"
$logfile $version $tracing $logging)
(exit))'";
# Run program and do final cleanup
if ( $try ) {
print "$xindy_run $xindy_cmd";
} else {
if ( $SigHandlerSet ) {
system "$xindy_run $xindy_cmd";
unlink $tmpfile;
} else {
exec "$xindy_run $xindy_cmd";
}
}
#----------------------------------------------------------------------
#
# $Log: xindy.in,v $
# Revision 1.14 2005/05/02 19:16:27 jschrod
# Support new RTE 2.2, built with CLISP 2.33.2, that needs -E option
# to specify the default charset.
# xindy also has proper version output in Lisp now, no need for
# workarounds in script any more.
#
# Revision 1.13 2004/05/24 19:52:02 jschrod
# Pass -B option to CLISP.
# Change might be from Thomas Henlich <henlich@mmers1.mw.tu-dresden.de>,
# made at 1999-12-22.
#
# Revision 1.12 2004/05/24 19:47:13 jschrod
# Introduce new driver script, as part of the "Companion Release".
#
# Revision 1.11 1999/09/23 07:22:39 kehr
# Fixed an exit code problem reported by Peter Meszaros
# <pmeszaros@effice.hu>.
#
# Revision 1.10 1998/03/12 10:58:21 kehr
# Fixed bug with -f option.
#
# Revision 1.9 1997/04/03 13:23:51 kehr
# Many bugs fixed during testing.
#
# Revision 1.8 1997/04/03 09:38:54 kehr
# First check-in of the rewritten xindy script. The former shell-script
# has now been replaced by a perl-script.
#
# Local Variables:
# mode: perl
# End:
|