annotate lispref/tindex.pl @ 69227:6c1428d2666e

(reftex-toc-map): Fixed typo, follow-mouse must be follow-link.
author Carsten Dominik <dominik@science.uva.nl>
date Wed, 01 Mar 2006 07:12:40 +0000
parents 067115a6e738
children 6d19c76d81c5 c5406394f567
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27188
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1 #! /usr/bin/perl
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
68648
067115a6e738 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64889
diff changeset
3 # Copyright (C) 2000, 2002, 2003, 2004, 2005,
067115a6e738 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64889
diff changeset
4 # 2006 Free Software Foundation, Inc.
27188
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5 #
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 # This file is part of GNU Emacs.
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 #
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 # GNU Emacs is free software; you can redistribute it and/or modify
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9 # it under the terms of the GNU General Public License as published by
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 # the Free Software Foundation; either version 2, or (at your option)
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 # any later version.
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 #
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 # GNU Emacs is distributed in the hope that it will be useful,
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 # GNU General Public License for more details.
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 #
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 # You should have received a copy of the GNU General Public License
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 # along with GNU Emacs; see the file COPYING. If not, write to the
64083
23a17af379b1 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
20 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23a17af379b1 Update FSF's address.
Lute Kamstra <lute@gnu.org>
parents: 52401
diff changeset
21 # Boston, MA 02110-1301, USA.
27188
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 require 5;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24 use Getopt::Long;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26 my $USAGE = <<ENDUSAGE;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 Remove \@tindex lines from files that were already present in previous
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 versions.
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 Usage: $0 [--old=EXT] FILE...
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 $0 --help
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 $0 --version
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 --help display this help and exit
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 --version print version and exit
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 --old=DIR find old files in DIR
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 The script performs two passes. In the first pass, Texinfo files from
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 DIR are scanned for \@tindex lines, and identifiers in them are
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 recorded. In a second pass, Texinfo files in the current directory
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 are scanned, and \@tindex lines for identifiers that were recorded in
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 the first pass are removed. Old file contents are saved in files
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 with extension ".orig". A list of modified files and removed \@tindex
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 identifiers is printed to stdout at the end.
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 ENDUSAGE
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 sub fatal {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 print STDERR "$0: ", @_, ".\n";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 exit 1;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 }
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 my $help = 0;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 my $version = 0;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 my $old;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 27188
diff changeset
56 my $rc = GetOptions ('help' => \$help, 'version' => \$version,
27188
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 'old=s' => \$old);
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 if ($version) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 print "0.1\n";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 exit 0;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 } elsif (!$rc || !$old || @ARGV) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 print $USAGE;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 exit 1;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 } elsif ($help) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 print $USAGE;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 exit 0;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 }
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 # Fill the hash %tindex with associations VAR -> COUNT where
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 # the keys VAR are identifiers mentioned in @tindex lines in the older
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 # files to process and COUNT is the number of times they are seen in
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 # the files.
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 my %tindex;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 my %removed;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 my @old_files = glob "$old/*.texi";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 my @new_files = glob "*.texi";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 fatal ("No Texinfo files found in `$old'") unless @old_files;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 fatal ("No Texinfo files found in current directory") unless @new_files;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 print "Scanning old files for \@tindex lines\n";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 foreach $file (@old_files) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 open (IN, "<$file") or fatal "Cannot open $file: $!";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 while (<IN>) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 ++$tindex{$1} if /^\s*\@tindex\s+(\S+)/;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 }
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 close IN;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 }
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 27188
diff changeset
90 # Process current files and remove those @tindex lines which we
27188
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 # know were already present in the files scanned above.
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 print "Removing old \@tindex lines\n";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 foreach $file (@new_files) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 my $modified = 0;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 my $contents = "";
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 27188
diff changeset
97
27188
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 open (IN, "< $file") or fatal "Cannot open $file.orig for reading: $!";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 while (<IN>) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 if (/^\s*\@tindex\s+(\S+)/ && $tindex{$1}) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 ++$removed{$1};
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 $modified = 1;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 } else {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 $contents = $contents . $_;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 }
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 }
49600
23a1cea22d13 Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 27188
diff changeset
107
27188
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 close IN;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 if ($modified) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111 print " $file\n";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 system ("cp $file $file.orig") == 0 or fatal "Cannot backup $file: $!";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 open (OUT, ">$file") or fatal "Cannot open $file for writing: $!";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114 print OUT $contents;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 close OUT;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116 }
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 }
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 # Print a list of identifiers removed.
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121 print "Removed \@tindex commands for:\n";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122 my $key;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 foreach $key (keys %removed) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 print " $key\n";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 }
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
127 # arch-tag: f8460df6-6bef-4c98-8555-e2c63a88b0fa