#!/usr/bin/perl -w # autolatex - autolatex_has_index # Copyright (C) 1998-07 Stephane Galland # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; see the file COPYING. If not, write to # the Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. use strict; use strict; use File::Basename; use File::Spec; my @indexes = (); my $changed = undef; my $currentDefs = ''; my $filename = File::Spec->catfile(dirname("$ARGV[0]"),"autolatex_makeindex.stamp"); #use Data::Dumper; #die(Dumper(\@ARGV)); if ( -f "$ARGV[0]") { local *FILE; open(*FILE, "< $ARGV[0]") or die("$ARGV[0]: $!\n"); while (my $line = ) { $line =~ s/%.*$//; if ($line =~ /\\indexentry/) { $line =~ s/\s+//g; push @indexes, "$line"; } } close(*FILE); @indexes = sort @indexes; $currentDefs = join('|',@indexes); if ( -f "$filename") { open(*FILE,"< $filename") or die("$filename: $!\n"); my @content = ; close(*FILE); my $oldDefs = join('|',@content); $changed = ($oldDefs ne $currentDefs); } else { $changed = 1; } if (-f "$ARGV[1]") { my (undef,undef,undef,undef,undef,undef,undef, undef,undef,$mtime1,$ctime1,undef,undef) = stat("$ARGV[0]"); my (undef,undef,undef,undef,undef,undef,undef, undef,undef,$mtime2,$ctime2,undef,undef) = stat("$ARGV[1]"); my $min1 = ($mtime1>$ctime1) ? $mtime1 : $ctime1; my $min2 = ($mtime2>$ctime2) ? $mtime2 : $ctime2; if ($min1<$min2) { $changed = 1; } } else { $changed = 1; } } if ($changed) { open(*FILE,"> $filename") or die("$filename: $!\n"); print FILE $currentDefs; close(*FILE); exit(0); } exit(1);