diff options
Diffstat (limited to 'Master/texmf-dist/doc/latex/glossaries/scripts/makeglossaries')
-rwxr-xr-x | Master/texmf-dist/doc/latex/glossaries/scripts/makeglossaries | 210 |
1 files changed, 210 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/latex/glossaries/scripts/makeglossaries b/Master/texmf-dist/doc/latex/glossaries/scripts/makeglossaries new file mode 100755 index 00000000000..8da802b1791 --- /dev/null +++ b/Master/texmf-dist/doc/latex/glossaries/scripts/makeglossaries @@ -0,0 +1,210 @@ +#!/usr/bin/perl + +# File : makeglossaries +# Author : Nicola Talbot +# Version : 1.0 (2007/05/10) +# Description: simple Perl script that calls makeindex. +# Intended for use with "glossaries.sty" (saves having to remember +# all the various switches) + +use Getopt::Std; + +if ($#ARGV < 0) +{ + die "Syntax : $0 [-ilqrcg] [-s sty] [-o gls] [-t log] [-p num] <filename>\n"; +} + +getopt('sotp'); +getopts('ilqrcg'); + +# define known extensions + + %exttype = ( + main => {in=>'glo', out=>'gls', 'log'=>'glg'}, + ); + +$ext = ''; + +if (length(@ARGV[0]) < 4) +{ + $name = @ARGV[0]; +} +elsif (substr(@ARGV[0],-4,1) eq ".") +{ + $name = substr(@ARGV[0],0,length(@ARGV[0])-4); + + $ext = substr(@ARGV[0],-3,3); +} +else +{ + $name = @ARGV[0]; +} + +$istfile = "$name.ist"; + +# check log file for other glossary types +# and for ist file name + +if (open AUXFILE, "$name.aux") +{ + while (<AUXFILE>) + { + if (m/\\\@newglossary\s*\{(.*)\}{(.*)}{(.*)}{(.*)}/ + and ($1 ne 'main')) + { + $exttype{$1}{'log'} = $2; + $exttype{$1}{'out'} = $3; + $exttype{$1}{'in'} = $4; + + if (!$opt_q) + { + print "added glossary type '$1' ($2,$3,$4)\n"; + } + } + + if (m/\\\@istfilename\s*{([^}]*)}/) + { + $istfile = $1; + } + } + + close AUXFILE; +} +else +{ + print "unable to open $name.aux\n"; +} + +# save all the general makeindex switches + +$mkidxopts = ''; + +if ($opt_i) +{ + $mkidxopts .= " -i"; +} + +if ($opt_l) +{ + $mkidxopts .= " -l"; +} + +if ($opt_q) +{ + $mkidxopts .= " -q"; +} + +if ($opt_r) +{ + $mkidxopts .= " -r"; +} + +if ($opt_c) +{ + $mkidxopts .= " -c"; +} + +if ($opt_g) +{ + $mkidxopts .= " -g"; +} + +unless ($opt_p eq "") +{ + $mkidxopts .= " -p $opt_p"; +} + +unless ($opt_s eq "") +{ + $istfile = $opt_s; +} + +if ($ext ne '') +{ + %thistype = %{$exttype{'main'}}; #default + + foreach $type (keys %exttype) + { + if ($exttype{$type}{'in'} eq $ext) + { + %thistype = %{$exttype{$type}}; + + last; + } + } + + if ($opt_o eq "") + { + $outfile = "$name.$thistype{out}"; + } + else + { + $outfile = $opt_o; + } + + if ($opt_t eq "") + { + $transcript = "$name.$thistype{'log'}"; + } + else + { + $transcript = $opt_t; + } + + &makeindex("$name.$ext",$outfile,$transcript,$istfile, + $mkidxopts,$opt_q); +} +else +{ + foreach $type (keys %exttype) + { + %thistype = %{$exttype{$type}}; + + $inputfile = "$name.$thistype{in}"; + + if (-r $inputfile) + { + if ($opt_o eq "") + { + $outfile = "$name.$thistype{out}"; + } + else + { + $outfile = $opt_o; + } + + if ($opt_t eq "") + { + $transcript = "$name.$thistype{'log'}"; + } + else + { + $transcript = $opt_t; + } + + &makeindex($inputfile,$outfile,$transcript, + $istfile,$mkidxopts,$opt_q); + } + elsif (!$opt_q) + { + print "no read access for '$inputfile'\n"; + } + } +} + +sub makeindex{ + local($in,$out,$trans,$ist,$rest,$quiet) = @_; + local($name,$cmdstr,$buffer,$n,$i,$j); + local(@stuff,@item); + + $cmdstr = "$rest -s $ist -t $trans -o $out $in"; + + unless ($quiet) + { + print "makeindex $cmdstr\n"; + } + + `makeindex $cmdstr`; +} + +1; |