annotate lispref/tindex.pl @ 43248:9e2bfc2d4d23

*** empty log message ***
author Miles Bader <miles@gnu.org>
date Tue, 12 Feb 2002 02:59:39 +0000
parents 8cd1df305566
children 23a1cea22d13
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
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
3 # Copyright (C) 2000 Free Software Foundation, Inc.
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4 #
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5 # This file is part of GNU Emacs.
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6 #
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 # GNU Emacs is free software; you can redistribute it and/or modify
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 # 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
9 # the Free Software Foundation; either version 2, or (at your option)
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 # any later version.
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 #
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 # GNU Emacs is distributed in the hope that it will be useful,
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 # GNU General Public License for more details.
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 #
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 # You should have received a copy of the GNU General Public License
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 # along with GNU Emacs; see the file COPYING. If not, write to the
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 # Boston, MA 02111-1307, USA.
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 require 5;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23 use Getopt::Long;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25 my $USAGE = <<ENDUSAGE;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26 Remove \@tindex lines from files that were already present in previous
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 versions.
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 Usage: $0 [--old=EXT] FILE...
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 $0 --help
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 $0 --version
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 --help display this help and exit
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 --version print version and exit
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 --old=DIR find old files in DIR
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 The script performs two passes. In the first pass, Texinfo files from
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 DIR are scanned for \@tindex lines, and identifiers in them are
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 recorded. In a second pass, Texinfo files in the current directory
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 are scanned, and \@tindex lines for identifiers that were recorded in
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 the first pass are removed. Old file contents are saved in files
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 with extension ".orig". A list of modified files and removed \@tindex
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 identifiers is printed to stdout at the end.
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 ENDUSAGE
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 sub fatal {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 print STDERR "$0: ", @_, ".\n";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 exit 1;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 }
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 my $help = 0;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 my $version = 0;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 my $old;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 my $rc = GetOptions ('help' => \$help, 'version' => \$version,
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 'old=s' => \$old);
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 if ($version) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 print "0.1\n";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 exit 0;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 } elsif (!$rc || !$old || @ARGV) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 print $USAGE;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 exit 1;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 } elsif ($help) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 print $USAGE;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 exit 0;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 }
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 # Fill the hash %tindex with associations VAR -> COUNT where
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 # the keys VAR are identifiers mentioned in @tindex lines in the older
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 # 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
71 # the files.
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 my %tindex;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 my %removed;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 my @old_files = glob "$old/*.texi";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 my @new_files = glob "*.texi";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 fatal ("No Texinfo files found in `$old'") unless @old_files;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 fatal ("No Texinfo files found in current directory") unless @new_files;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 print "Scanning old files for \@tindex lines\n";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 foreach $file (@old_files) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 open (IN, "<$file") or fatal "Cannot open $file: $!";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 while (<IN>) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 ++$tindex{$1} if /^\s*\@tindex\s+(\S+)/;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 }
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 close IN;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 }
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 # Process current files and remove those @tindex lines which we
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 # know were already present in the files scanned above.
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 print "Removing old \@tindex lines\n";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 foreach $file (@new_files) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 my $modified = 0;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 my $contents = "";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 open (IN, "< $file") or fatal "Cannot open $file.orig for reading: $!";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 while (<IN>) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 if (/^\s*\@tindex\s+(\S+)/ && $tindex{$1}) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 ++$removed{$1};
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 $modified = 1;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 } else {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 $contents = $contents . $_;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 }
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
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107 close IN;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 if ($modified) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 print " $file\n";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111 system ("cp $file $file.orig") == 0 or fatal "Cannot backup $file: $!";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112 open (OUT, ">$file") or fatal "Cannot open $file for writing: $!";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 print OUT $contents;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114 close OUT;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 }
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 # Print a list of identifiers removed.
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 print "Removed \@tindex commands for:\n";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121 my $key;
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122 foreach $key (keys %removed) {
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 print " $key\n";
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 }
8cd1df305566 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125