summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2006-07-18 23:01:09 +0000
committerKarl Berry <karl@freefriends.org>2006-07-18 23:01:09 +0000
commit89128513e8c72c5c04c3284a7758fc333a761aec (patch)
treec64b7c4039d3f195ca5dd7adcb579209eab3bcd4 /Master/texmf-dist/doc/latex
parentfc2c7ab430ef4b878fd3455118daa831e76db681 (diff)
splitindex update (8mar06)
git-svn-id: svn://tug.org/texlive/trunk@1879 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/doc/latex')
-rw-r--r--Master/texmf-dist/doc/latex/splitindex/install.sh178
-rw-r--r--Master/texmf-dist/doc/latex/splitindex/splitidx.pdfbin0 -> 236481 bytes
-rw-r--r--Master/texmf-dist/doc/latex/splitindex/splitindex-Linux-i386bin0 -> 9924 bytes
-rw-r--r--Master/texmf-dist/doc/latex/splitindex/splitindex-OpenBSD-i386bin0 -> 16384 bytes
-rw-r--r--Master/texmf-dist/doc/latex/splitindex/splitindex.classbin0 -> 9303 bytes
-rw-r--r--Master/texmf-dist/doc/latex/splitindex/splitindex.exebin0 -> 18944 bytes
-rw-r--r--Master/texmf-dist/doc/latex/splitindex/splitindex.java415
-rw-r--r--Master/texmf-dist/doc/latex/splitindex/splitindex.pl186
8 files changed, 779 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/latex/splitindex/install.sh b/Master/texmf-dist/doc/latex/splitindex/install.sh
new file mode 100644
index 00000000000..5d75fb85f7e
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/splitindex/install.sh
@@ -0,0 +1,178 @@
+#!/bin/sh
+
+while [ $# -gt 0 ]; do
+ case $1 in
+ --prefix)
+ if [ $# -lt 2 ]; then
+ echo "$0: argument expected after --prefix" >&2
+ exit 1
+ else
+ prefix=$2
+ shift 2
+ fi
+ ;;
+ --prefix=*)
+ prefix=${1#--prefix=}
+ shift 1
+ ;;
+ --bindir)
+ if [ $# -lt 2 ]; then
+ echo "$0: argument expected after --bindir" >&2
+ exit 1
+ else
+ bindir=$2
+ shift 2
+ fi
+ ;;
+ --bindir=*)
+ bindir=${1#--bindir=}
+ shift 1
+ ;;
+ --mandir)
+ if [ $# -lt 2 ]; then
+ echo "$0: argument expected after --mandir" >&2
+ exit 1
+ else
+ mandir=$2
+ shift 2
+ fi
+ ;;
+ --mandir=*)
+ mandir=${1#--mandir=}
+ shift 1
+ ;;
+ --texmf)
+ if [ $# -lt 2 ]; then
+ echo "$0: argument expected after --texmf" >&2
+ exit 1
+ else
+ texmf=$2
+ shift 2
+ fi
+ ;;
+ --texmf=*)
+ texmf=${1#--texmf=}
+ shift 1
+ ;;
+ --version|-v)
+ echo "install.sh v0.1"
+ echo "Copyright (c) Markus Kohm 2002"
+ exit 0
+ ;;
+ --help|-h)
+ echo "Usage: install.sh [OPTIONS]"
+ echo
+ echo "Installs SplitIndex for all unix like environments."
+ echo
+ echo "OPTIONS:"
+ echo "--prefix=<DIR> install binaries at <DIR>/bin and manuals at <DIR>/man"
+ echo " (default: /usr/local)"
+ echo "--bindir=<DIR> install binaries at <DIR>"
+ echo "--mandir=<DIR> install manuals at <DIR>"
+ echo "--texmf=<DIR> install packages and TeX programs at <DIR>/tex/latex/misc,"
+ echo " documentation (dvi and pdf) at <DIR>/doc/latex/splitidx and"
+ echo " sources at <DIR>/source/latex/splitidx"
+ echo " (default: \$TEXMFLOCAL if you are root and \$HOMETEXMF if"
+ echo " you are not root)"
+ exit 0
+ ;;
+ --dist)
+ mkdir splitidx
+ cp -a splitindex splitindex-Linux-i386
+ cp -a splitindex.tex splitindex.pl splitindex.c splitindex.java \
+ splitindex.class splitindex.exe splitidx.dtx splitidx.ins \
+ splitindex-Linux-i386 splitindex-OpenBSD-i386 \
+ splitindex.1 install.txt manifest.txt install.sh \
+ README splitidx
+ tar jcvf splitidx-`date -I`.tar.bz2 splitidx
+ cd splitidx
+ ./install.sh --prefix ../chroot --texmf ../chroot/texmf
+ cd ..
+ rm -r splitidx
+ find chroot | sed 's/chroot\//+-/g;s/[a-z0-9]*\//-/g'
+ exit 0
+ ;;
+ *)
+ echo "unkown option \`$1'" >&2
+ echo "Try \`./install.sh --help' for more information." >&2
+ exit 1;
+ ;;
+ esac
+done
+
+case `uname -s -m` in
+ OpenBSD*i?86*)
+ cp -pf splitindex-OpenBSD-i386 splitindex
+ splitindex=splitindex
+ ;;
+ Linux*i?86*)
+ cp -pf splitindex-Linux-i386 splitindex
+ splitindex=splitindex
+ ;;
+ CYGWIN*i?86*)
+ splitindex=splitindex.exe
+ ;;
+ *)
+ if ! ./splitindex -V; then
+ echo 'Os '`uname -s -m`' not supported!'
+ echo 'Trying to compile the source:'
+ gcc -O3 -Wall -o splitindex splitindex.c || \
+ gcc -O3 -Wall -DNO_LONGOPT -o splitindex splitindex.c || \
+ echo 'You have to compile splitindex.c by your own!'
+ fi
+ if ./splitindex -V; then
+ splitindex=splitindex
+ fi
+ ;;
+esac
+
+if [ -z "$prefix" ]; then
+ prefix=/usr/local
+fi
+if [ -z "$bindir" ]; then
+ bindir=$prefix/bin
+fi
+if [ -z "$mandir" ]; then
+ mandir=$prefix/man
+fi
+if [ -z "$texmf" ]; then
+ if [ "r$USER" = "rroot" ]; then
+ texmf=`kpsexpand '$TEXMFLOCAL'`
+ else
+ texmf=`kpsexpand '$HOMETEXMF'`
+ fi
+ if [ -z "$texmf" ]; then
+ echo "kpsexpand '$TEXMFLOCAL' or kpsexpand '$HOMETEXMF' failed!" >&2
+ echo "You have to use option --texmf=<DIR>." >&2
+ echo "This error is fatal!" >&2
+ exit 1
+ fi
+fi
+
+latex splitidx.ins
+
+latex splitidx.dtx
+latex splitidx.dtx
+mkindex splitidx
+latex splitidx.dtx
+
+pdflatex splitidx.dtx
+pdflatex splitidx.dtx
+mkindex splitidx
+pdflatex splitidx.dtx
+
+install -m 755 -d $bindir
+install -m 755 -d $mandir/man1
+install -m 755 -d $texmf/tex/latex/misc
+install -m 755 -d $texmf/source/latex/splitidx
+install -m 755 -d $texmf/doc/latex/splitidx
+install -m 755 $splitindex splitindex.pl $bindir
+install -m 644 splitindex.class $bindir
+install -m 644 splitindex.1 $mandir/man1
+install -m 644 splitindex.tex splitidx.sty $texmf/tex/latex/misc
+install -m 644 splitidx.dvi splitidx.pdf $texmf/doc/latex/splitidx
+
+install README splitindex.c splitindex.java splitindex.exe \
+ splitindex-Linux-i386 splitindex-OpenBSD-i386 \
+ splitidx.dtx manifest.txt install.txt install.sh \
+ $texmf/source/latex/splitidx
diff --git a/Master/texmf-dist/doc/latex/splitindex/splitidx.pdf b/Master/texmf-dist/doc/latex/splitindex/splitidx.pdf
new file mode 100644
index 00000000000..c52c5d30486
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/splitindex/splitidx.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/splitindex/splitindex-Linux-i386 b/Master/texmf-dist/doc/latex/splitindex/splitindex-Linux-i386
new file mode 100644
index 00000000000..42566f25083
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/splitindex/splitindex-Linux-i386
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/splitindex/splitindex-OpenBSD-i386 b/Master/texmf-dist/doc/latex/splitindex/splitindex-OpenBSD-i386
new file mode 100644
index 00000000000..17e865dd061
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/splitindex/splitindex-OpenBSD-i386
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/splitindex/splitindex.class b/Master/texmf-dist/doc/latex/splitindex/splitindex.class
new file mode 100644
index 00000000000..288ad25d588
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/splitindex/splitindex.class
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/splitindex/splitindex.exe b/Master/texmf-dist/doc/latex/splitindex/splitindex.exe
new file mode 100644
index 00000000000..08aa74d1291
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/splitindex/splitindex.exe
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/splitindex/splitindex.java b/Master/texmf-dist/doc/latex/splitindex/splitindex.java
new file mode 100644
index 00000000000..9b52f9f7fdf
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/splitindex/splitindex.java
@@ -0,0 +1,415 @@
+/*
+ * splitindex.java
+ * Copyright (c) Markus Kohm, 2002
+ *
+ * $Id: splitindex.java,v 1.2 2003/01/05 15:05:46 mjk Exp $
+ *
+ * This file is part of the SplitIndex package
+ *
+ * This file can be redistributed and/or modified under the conditions
+ * of the LaTeX Project Public License, either version 1.2 of this
+ * license or (at your option) any later version.
+ * The latest version of this license is in
+ * http://www.latex-project.org/lppl.txt
+ * and version 1.2 or later is part of all distributions of LaTeX
+ * version 1999/12/01 or later.
+ *
+ * You are not allowed to redistribute this file without all the
+ * other files of the SplitIndex package
+ */
+
+/*
+ I know, I should never write an application in a single static class
+ like I do here. But I wanted the program at earch language to be one
+ file.
+*/
+
+import java.util.*;
+import java.util.regex.*;
+import java.io.*;
+
+public final class splitindex {
+ private static ArrayList MakeIndexArgs = new ArrayList();
+// private static String Identify = "^(.*)\\\\UseIndex *\\{([^\\}]*)\\}(.*)$";
+ private static String Identify = "^(\\\\indexentry)\\[([^\\]]*)\\](.*)$";
+ private static String ResultIs = "$1$3";
+ private static String SuffixIs = "-$2";
+ private static int Verbose = 0;
+ private static String IDX = null;
+ private static String Jobname = null;
+ private static HashMap IDXwriters = new HashMap();
+
+ private static void ShowHelp() {
+ String nl = System.getProperty( "line.separator" );
+ ShowVersion();
+ System.out.println();
+ ShowUsage();
+ System.out.println(
+ "Split a single raw index file into multiple raw index files." +nl+
+ "Example: java splitindex foo.idx." +nl+
+ nl+
+ "Options:" +nl+
+ " -h, --help " +
+ "\tshow this help and terminate" +nl+
+ " -m, --makeindex PROGNAME" +nl+
+ "\t\t\tcall PROGNAME instead of default `makeindex'." +nl+
+ " -i, --identify EXPRESSION" +nl+
+ "\t\t\tuse regular EXPRESSION to match entries" +nl+
+ "\t\t\t(see also option --resultis and --suffixis)." +nl+
+ "\t\t\tDefault is \'" + Identify + "\'." +nl+
+ " -r, --resultis PATTERN" +nl+
+ "\t\t\tcreate line to be written from PATTERN after matching" +nl+
+ "\t\t\tlines (see also option --identify)." +nl+
+ "\t\t\tDefault is \'" + ResultIs + "\'." +nl+
+ " -s, --suffixis PATTERN" +nl+
+ "\t\t\tcreate suffix to be used from PATTERN after matching" +nl+
+ "\t\t\tlines (see also option --identify)." +nl+
+ "\t\t\tDefault is \'" + SuffixIs +"\'." +nl+
+ " -v, --verbose " +
+ "\tbe more verbose" +nl+
+ "\t\t\t(can be used multiple to increase verbosity)" +nl+
+ " --version " +
+ "\tshow version and terminate"
+ );
+ System.exit( 0 );
+ }
+
+ private static void ShowVersion() {
+ System.out.println( "splitindex.pl 0.1" );
+ System.out.println( "Copyright (c) 2002 Markus Kohm <kohm@gmx.de>" );
+ }
+
+ private static void ShowUsage( PrintStream out ) {
+ out.println( "Usage: java splitindex [OPTION]... RAWINDEXFILE [MAKEINDEXOPTION]..." );
+ }
+
+ private static void ShowUsage() {
+ ShowUsage( System.out );
+ }
+
+ private static void UsageError( String msg ) {
+ System.err.println( msg );
+ System.err.println( "Try `java splitindex --help' for more information." );
+ System.exit( 1 );
+ }
+
+ private static void ScanArguments(String[] args) {
+ String MakeIndex = "makeindex";
+ for (int i = 0; i < args.length; i++) {
+ if ( args[i].charAt(0) == '-' ) {
+ // Option
+ if ( args[i].charAt(1) == '-' ) {
+ // Long Option
+ if ( args[i].substring(2).equals( "help" ) ) {
+ ShowHelp();
+ System.exit(0);
+ } else if ( args[i].substring(2).equals( "version" ) ) {
+ ShowVersion();
+ System.exit(0);
+ } else if ( args[i].substring(2).equals( "verbose" ) ) {
+ Verbose++;
+ } else if ( args[i].substring(2).equals( "makeindex" ) ) {
+ if ( ++i >= args.length ) {
+ UsageError( "Option makeindex requires an argument" );
+ }
+ MakeIndex = args[i];
+ } else if ( ( args[i].length() >= 11 ) &&
+ ( args[i].substring(2,11).equals( "makeindex=" ) ) ) {
+ MakeIndex = args[i].substring(12);
+ } else if ( args[i].substring(2).equals( "identify" ) ) {
+ if ( ++i >= args.length ) {
+ UsageError( "Option identify requires an argument" );
+ }
+ Identify = args[i];
+ } else if ( ( args[i].length() >= 10 ) &&
+ ( args[i].substring(2,10).equals( "identify=" ) ) ) {
+ Identify = args[i].substring(11);
+ } else if ( args[i].substring(2).equals( "resultis" ) ) {
+ if ( ++i >= args.length ) {
+ UsageError( "Option resultis requires an argument" );
+ }
+ ResultIs = args[i];
+ } else if ( ( args[i].length() >= 10 ) &&
+ ( args[i].substring(2,10).equals( "resultis=" ) ) ) {
+ ResultIs = args[i].substring(11);
+ } else if ( args[i].substring(2).equals( "suffixis" ) ) {
+ if ( ++i >= args.length ) {
+ UsageError( "Option suffixis requires an argument" );
+ }
+ SuffixIs = args[i];
+ } else if ( ( args[i].length() >= 10 ) &&
+ ( args[i].substring(2,10).equals( "suffixis=" ) ) ) {
+ SuffixIs = args[i].substring(11);
+ } else if ( args[i].equals( "--" ) ) {
+ while ( ++i < args.length ) {
+ MakeIndexArgs.add( args[i] );
+ }
+ } else {
+ UsageError( "Unknown option " + args[i].substring(2) );
+ }
+ } else {
+ // Short Option
+ for ( int n = 1; n < args[i].length(); ) {
+ switch( args[i].charAt(n++) ) {
+ case 'h':
+ ShowHelp();
+ System.exit(0);
+ case 'm':
+ if ( n >= args[i].length() ) {
+ if ( ++i >= args.length ) {
+ UsageError( "Option makeindex requires an argument" );
+ } else {
+ MakeIndex = args[i];
+ n = args[i].length();
+ }
+ } else {
+ MakeIndex = args[i].substring( n );
+ n = args[i].length();
+ }
+ break;
+ case 'i':
+ if ( n >= args[i].length() ) {
+ if ( ++i >= args.length ) {
+ UsageError( "Option identify requires an argument" );
+ } else {
+ Identify = args[i];
+ n = args[i].length();
+ }
+ } else {
+ Identify = args[i].substring( n );
+ n = args[i].length();
+ }
+ break;
+ case 'r':
+ if ( n >= args[i].length() ) {
+ if ( ++i >= args.length ) {
+ UsageError( "Option resultis requires an argument" );
+ } else {
+ ResultIs = args[i];
+ n = args[i].length();
+ }
+ } else {
+ ResultIs = args[i].substring( n );
+ n = args[i].length();
+ }
+ break;
+ case 's':
+ if ( n >= args[i].length() ) {
+ if ( ++i >= args.length ) {
+ UsageError( "Option suffixis requires an argument" );
+ } else {
+ SuffixIs = args[i];
+ n = args[i].length();
+ }
+ } else {
+ SuffixIs = args[i].substring( n );
+ n = args[i].length();
+ }
+ break;
+ case 'v':
+ Verbose++;
+ break;
+ }
+ }
+ }
+ } else {
+ MakeIndexArgs.add( args[i] );
+ }
+ }
+
+ // Args --> IDX + Stringarray
+ if ( MakeIndexArgs.isEmpty() ) {
+ UsageError( "missing raw index file" );
+ } else {
+ IDX = (String)MakeIndexArgs.get(0);
+ MakeIndexArgs.remove(0);
+ MakeIndexArgs.add( 0, MakeIndex );
+ }
+
+ if ( IDX.endsWith( ".idx" ) ) {
+ Jobname = IDX.substring( 0, IDX.length() - 4 );
+ } else {
+ Jobname = IDX;
+ }
+ }
+
+ public static void main(String[] args) {
+ ScanArguments(args);
+
+ if ( Verbose > 0 ) {
+ ShowVersion();
+ System.out.println();
+ if ( Verbose > 9 ) {
+ System.out.println( "Identify: \"" + Identify + "\"" );
+ System.out.println( "ResultIs: \"" + ResultIs + "\"" );
+ System.out.println( "SuffixIs: \"" + SuffixIs + "\"" );
+ System.out.println( "IDX: \"" + IDX + "\"" );
+ System.out.println( "Jobname: \"" + Jobname + "\"" );
+ System.out.print( "MakeIndex:" );
+ for ( int i = 0; i < MakeIndexArgs.size(); i++ )
+ System.out.print( " \"" + (String)MakeIndexArgs.get(i) + "\"" );
+ System.out.println();
+ }
+ }
+
+ ProcessIDXFile();
+ }
+
+ private static void ProcessIDXFile() {
+ File fIDX = new File( IDX );
+ LineNumberReader rIDX = null;
+ boolean error = false;
+ if ( !fIDX.canRead() ) {
+ if ( IDX.equals( Jobname ) ) {
+ IDX = IDX.concat( ".idx" );
+ fIDX = new File( IDX );
+ if ( !fIDX.canRead() ) {
+ System.err.println( "Can read neither file " + Jobname +
+ " nor file " + IDX );
+ System.exit( 1 );
+ }
+ } else {
+ System.err.println( "Can't read file " + Jobname );
+ System.exit( 1 );
+ }
+ }
+
+ try {
+ FileReader reader = new FileReader( fIDX );
+ rIDX = new LineNumberReader( reader );
+ } catch ( FileNotFoundException ex ) {
+ System.err.println( ex.getMessage() );
+ System.exit( 1 );
+ }
+
+ try {
+ Pattern search = Pattern.compile( Identify );
+ while ( rIDX.ready() ) {
+ String line = rIDX.readLine();
+ Matcher match = search.matcher( line );
+ String suffix, result;
+
+ try {
+ if ( match.find() ) {
+ suffix = match.replaceFirst( SuffixIs );
+ result = match.replaceFirst( ResultIs );
+ } else {
+ result = line;
+ suffix = SuffixIs.replaceFirst( "\\$\\d", "idx" );
+ }
+ WriteToIndex( Jobname + suffix + ".idx", result );
+ } catch ( Exception ex ) {
+ System.err.println( ex.getMessage() );
+ error = true;
+ break;
+ }
+ }
+
+ if ( ! CloseAllIndex() )
+ error = true;
+ else if ( ! CallAllMakeIndex() )
+ error = true;
+ } catch ( IOException ex ) {
+ System.err.println( ex.getMessage() );
+ }
+
+ try {
+ rIDX.close();
+ } catch ( IOException ex ) {
+ System.err.println( ex.getMessage() );
+ System.exit( 1 );
+ }
+
+ if ( error )
+ System.exit( 1 );
+
+ }
+
+ static void WriteToIndex( String Name, String line )
+ throws FileNotFoundException, SecurityException {
+ PrintWriter fOut;
+ if ( ( fOut = (PrintWriter)IDXwriters.get( Name ) ) == null ) {
+ if ( Verbose > 1 ) {
+ System.out.println( "New index file " + Name );
+ }
+ fOut = new PrintWriter( new FileOutputStream( Name ) );
+ IDXwriters.put( Name, fOut );
+ }
+ fOut.println( line );
+ }
+
+ static boolean CloseAllIndex() {
+ Iterator all = IDXwriters.entrySet().iterator();
+ boolean retVal = true;
+ while ( all.hasNext() ) {
+ Map.Entry entry = (Map.Entry)all.next();
+ PrintWriter writer = (PrintWriter)entry.getValue();
+ if ( Verbose > 1 ) {
+ System.out.println( "Close " + entry.getKey() );
+ }
+ writer.close();
+ if ( writer.checkError() ) {
+ System.err.println( "Error writing " + entry.getKey() );
+ retVal = false;
+ }
+ }
+ return retVal;
+ }
+
+ static boolean CallAllMakeIndex() {
+ Iterator all = IDXwriters.entrySet().iterator();
+ boolean retVal = true;
+ ArrayList processes = new ArrayList();
+ while ( all.hasNext() ) {
+ Map.Entry entry = (Map.Entry)all.next();
+ String name = (String)entry.getKey();
+ try {
+ MakeIndexArgs.add(name);
+ String Args[] = new String[MakeIndexArgs.size()];
+ Args = (String[])MakeIndexArgs.toArray( Args );
+ MakeIndexArgs.remove(MakeIndexArgs.size()-1);
+ if ( Verbose > 1 ) {
+ System.out.print( "MakeIndex:" );
+ for ( int i = 0; i < Args.length; i++ )
+ System.out.print( " \"" + Args[i] + "\"" );
+ System.out.println();
+ }
+ processes.add(Runtime.getRuntime().exec( Args ));
+ } catch ( Exception ex ) {
+ System.err.println( ex.getMessage() );
+ retVal = false;
+ }
+ }
+
+ for ( int i = 0; i < processes.size(); i++ ) {
+ Process p = (Process)processes.get( i );
+ InputStream out = p.getInputStream();
+ byte[] buffer = new byte[1024];
+ for ( boolean oncemore = true; oncemore; ) {
+ oncemore = false;
+ try {
+ while ( out.available() > 0 ) {
+ out.read( buffer );
+ System.out.print( new String(buffer) );
+ }
+ for ( out = p.getErrorStream();
+ out.available() > 0; ) {
+ out.read( buffer );
+ System.err.print( new String( buffer ) );
+ }
+ } catch ( Exception ex ) {
+ System.err.println( ex.getMessage() );
+ retVal = false;
+ }
+ try {
+ if ( p.exitValue() != 0 )
+ retVal = false;
+ } catch ( IllegalThreadStateException ex ) {
+ oncemore = true;
+ }
+ }
+ }
+
+ return retVal;
+ }
+}
diff --git a/Master/texmf-dist/doc/latex/splitindex/splitindex.pl b/Master/texmf-dist/doc/latex/splitindex/splitindex.pl
new file mode 100644
index 00000000000..378fb25e68c
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/splitindex/splitindex.pl
@@ -0,0 +1,186 @@
+#! /usr/bin/perl -w
+eval 'exec perl -S $0 ${1+"$@"}'
+ if 0; #$running_under_some_shell
+
+# ======================================================================
+# splitindex.pl
+# Copyright (c) Markus Kohm, 2002
+#
+# $Id: splitindex.pl,v 1.5 2002/11/05 10:54:27 mjk Exp $
+#
+# This file is part of the SplitIndex package
+#
+# This file can be redistributed and/or modified under the conditions
+# of the LaTeX Project Public License, either version 1.2 of this
+# license or (at your option) any later version.
+# The latest version of this license is in
+# http://www.latex-project.org/lppl.txt
+# and version 1.2 or later is part of all distributions of LaTeX
+# version 1999/12/01 or later.
+#
+# You are not allowed to redistribute this file without all the
+# other files of the SplitIndex package
+# ======================================================================
+
+use strict;
+use Getopt::Long;
+
+my $makeindex = "makeindex";
+# my $identify = "^(.*)\\\\UseIndex *\\{([^\\}]*)\\}(.*)\$";
+my $identify = "^(\\\\indexentry)\\[([^]]*)\\](.*)\$";
+my $suffixis = "-\$2";
+my $lineis = "\$1\$3";
+my $verbose = 0; # option verbose with default value
+my $result = GetOptions(
+ 'help' => sub { help() },
+ 'makeindex=s' => \$makeindex,
+ 'identify=s' => \$identify,
+ 'resultis=s' => \$lineis,
+ 'suffixis=s' => \$suffixis,
+ 'verbose|v+' => \$verbose,
+ 'version' => sub { version(); exit 0; }
+ );
+
+usage("missing raw index file") if ( $#ARGV < 0 );
+
+my $indexinput = shift;
+my $jobname = ( $indexinput =~ /^(.*)\.idx$/ ) ? $1 : $indexinput;
+
+my %idxfile;
+my %linesatidxfile;
+
+version() if ($verbose > 0);
+
+if ( !( open (IDX,"<$indexinput") ) ) {
+ if ( $indexinput ne "$jobname.idx" ) {
+ open (IDX,"<$jobname.idx") ||
+ die "Cannot read raw index file $indexinput nor $jobname.idx";
+ $indexinput = "$jobname.idx";
+ } else {
+ die "Cannot read raw index file $indexinput";
+ }
+}
+
+while (<IDX>) {
+ my $line;
+ my $suffix;
+ if ( /$identify/ ) {
+ my $eval = "\$line = \"$lineis\n\"";
+ eval $eval;
+ $eval = "\$suffix = \"$suffixis\"";
+ eval $eval;
+ } else {
+ $line = $_;
+ $suffix = "";
+ $suffix .= "$1" if ( $suffixis =~ /^(.*)\$/ );
+ $suffix .= "idx";
+ $suffix .= "$1" if ( $suffixis =~ /\$[123456789](.*)$/ );
+ }
+ while ( $suffix =~ /(^[^,]+)(.*)$/ ) {
+ $suffix = $2;
+ writetoidx ($1,$line);
+ }
+}
+
+closeallind();
+
+close(IDX);
+
+generateallind(@ARGV);
+
+exit 0;
+
+sub generateallind {
+ my $name;
+ my $file;
+
+ if ( $makeindex ne "" ) {
+ while (($name,$file) = each %idxfile) {
+ system( "$makeindex @ARGV $jobname$name.idx" );
+ }
+ }
+}
+
+sub closeallind {
+ my $name;
+ my $file;
+ my $lines;
+ while (($name,$file) = each %idxfile) {
+ print "Close $jobname$name.idx\n"
+ if ( $verbose > 1 );
+ close( $file );
+ $idxfile{$name}=0;
+ }
+ if ( $verbose > 0 ) {
+ print "\n";
+ while (($name,$lines) = each %linesatidxfile) {
+ print "$jobname$name.idx with $lines lines\n";
+ }
+ }
+}
+
+sub writetoidx {
+ my $suffix = $_[0];
+ my $line = $_[1];
+ my $file = $idxfile{$suffix};
+ if ( ! $file ) {
+ open ( $file, ">$jobname$suffix.idx" ) ||
+ die "Cannot write to file $jobname$suffix.idx";
+ $idxfile{$suffix} = $file;
+ $linesatidxfile{$suffix} = 0;
+ print( "New index file $jobname$suffix.idx\n" )
+ if ( $verbose > 1 );
+ }
+ print ($file $line);
+ $linesatidxfile{$suffix}++;
+}
+
+sub help {
+ version();
+ print "\n";
+ usage();
+ print
+ "Split a single raw index file into multiple raw index files.\n".
+ "Example: splitindex.pl foo.idx.\n".
+ "\n".
+ "Options:\n" .
+ " -h, --help " .
+ "\tshow this help and terminate\n" .
+ " -m, --makeindex PROGNAME\n" .
+ "\t\t\tcall PROGNAME instead of default \`makeindex\'.\n" .
+ " -i, --identify EXPRESSION\n" .
+ "\t\t\tuse regular EXPRESSION to match entries\n".
+ "\t\t\t(see also option --resultis and --suffixis).\n".
+ "\t\t\tDefault is \'$identify\'.\n".
+ " -r, --resultis PATTERN\n" .
+ "\t\t\tcreate line to be written from PATTERN after matching\n".
+ "\t\t\tlines (see also option --identify).\n".
+ "\t\t\tDefault is \'$lineis\'.\n".
+ " -s, --suffixis PATTERN\n" .
+ "\t\t\tcreate suffix to be used from PATTERN after matching\n".
+ "\t\t\tlines (see also option --identify).\n".
+ "\t\t\tDefault is \'$suffixis\'.\n".
+ " -v, --verbose " .
+ "\tbe more verbose\n".
+ "\t\t\t(can be used multiple to increase verbosity)\n" .
+ " --version " .
+ "\tshow version and terminate\n";
+ exit 0;
+}
+
+sub version {
+ print "splitindex.pl 0.1\n" .
+ "Copyright (c) 2002 Markus Kohm \<kohm\@gmx.de\>\n";
+}
+
+sub usage {
+ my $text = "Usage: splitindex.pl [OPTION]... RAWINDEXFILE [MAKEINDEXOPTION]...\n";
+ if ( $#_ >= 0 ) {
+ print STDERR @_;
+ print STDERR "\n$text";
+ print STDERR "Try \`splitindex.pl --help\' for more information.\n";
+ exit 1;
+ } else {
+ print $text;
+ }
+}