annotate doc/lispref/tindex.pl @ 84104:d49f27fa41ce

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