3 # Copyright (C) 2000-2011 Free Software Foundation, Inc.
5 # This file is part of GNU Emacs.
7 # GNU Emacs is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # GNU Emacs is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 my $USAGE = <<ENDUSAGE;
25 Remove \@tindex lines from files that were already present in previous
28 Usage: $0 [--old=EXT] FILE...
32 --help display this help and exit
33 --version print version and exit
34 --old=DIR find old files in DIR
36 The script performs two passes. In the first pass, Texinfo files from
37 DIR are scanned for \@tindex lines, and identifiers in them are
38 recorded. In a second pass, Texinfo files in the current directory
39 are scanned, and \@tindex lines for identifiers that were recorded in
40 the first pass are removed. Old file contents are saved in files
41 with extension ".orig". A list of modified files and removed \@tindex
42 identifiers is printed to stdout at the end.
46 print STDERR
"$0: ", @_, ".\n";
54 my $rc = GetOptions
('help' => \
$help, 'version' => \
$version,
59 } elsif (!$rc || !$old || @ARGV) {
67 # Fill the hash %tindex with associations VAR -> COUNT where
68 # the keys VAR are identifiers mentioned in @tindex lines in the older
69 # files to process and COUNT is the number of times they are seen in
74 my @old_files = glob "$old/*.texi";
75 my @new_files = glob "*.texi";
76 fatal
("No Texinfo files found in `$old'") unless @old_files;
77 fatal
("No Texinfo files found in current directory") unless @new_files;
79 print "Scanning old files for \@tindex lines\n";
80 foreach $file (@old_files) {
81 open (IN
, "<$file") or fatal
"Cannot open $file: $!";
83 ++$tindex{$1} if /^\s*\@tindex\s+(\S+)/;
88 # Process current files and remove those @tindex lines which we
89 # know were already present in the files scanned above.
91 print "Removing old \@tindex lines\n";
92 foreach $file (@new_files) {
96 open (IN
, "< $file") or fatal
"Cannot open $file.orig for reading: $!";
98 if (/^\s*\@tindex\s+(\S+)/ && $tindex{$1}) {
102 $contents = $contents . $_;
110 system ("cp $file $file.orig") == 0 or fatal
"Cannot backup $file: $!";
111 open (OUT
, ">$file") or fatal
"Cannot open $file for writing: $!";
117 # Print a list of identifiers removed.
119 print "Removed \@tindex commands for:\n";
121 foreach $key (keys %removed) {