annotate doc/lispref/tindex.pl @ 95656:32785fc68f99

(Ffontset_info): Fix typo.
author Andreas Schwab <schwab@suse.de>
date Sun, 08 Jun 2008 09:01:28 +0000
parents fde6f792a832
children cb5d2387102c
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
95035
fde6f792a832 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
3 # Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
fde6f792a832 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
4 # 2008 Free Software Foundation, Inc.
fde6f792a832 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
5
84104
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
6 # This file is part of GNU Emacs.
95035
fde6f792a832 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
7
fde6f792a832 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
8 # GNU Emacs is free software: you can redistribute it and/or modify
84104
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
95035
fde6f792a832 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
10 # the Free Software Foundation, either version 3 of the License, or
fde6f792a832 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
11 # (at your option) any later version.
fde6f792a832 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
12
84104
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.
95035
fde6f792a832 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
17
84104
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
95035
fde6f792a832 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
19 # along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
fde6f792a832 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 87649
diff changeset
20
84104
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
21
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
22 require 5;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
23 use Getopt::Long;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
24
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
25 my $USAGE = <<ENDUSAGE;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
26 Remove \@tindex lines from files that were already present in previous
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
27 versions.
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
28
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
29 Usage: $0 [--old=EXT] FILE...
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
30 $0 --help
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
31 $0 --version
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
32
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
33 --help display this help and exit
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
34 --version print version and exit
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
35 --old=DIR find old files in DIR
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
36
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
37 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
38 DIR are scanned for \@tindex lines, and identifiers in them are
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
39 recorded. In a second pass, Texinfo files in the current directory
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
40 are scanned, and \@tindex lines for identifiers that were recorded in
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
41 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
42 with extension ".orig". A list of modified files and removed \@tindex
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
43 identifiers is printed to stdout at the end.
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
44 ENDUSAGE
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
45
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
46 sub fatal {
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
47 print STDERR "$0: ", @_, ".\n";
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
48 exit 1;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
49 }
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 my $help = 0;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
52 my $version = 0;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
53 my $old;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
54
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
55 my $rc = GetOptions ('help' => \$help, 'version' => \$version,
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
56 'old=s' => \$old);
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
57 if ($version) {
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
58 print "0.1\n";
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
59 exit 0;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
60 } elsif (!$rc || !$old || @ARGV) {
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
61 print $USAGE;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
62 exit 1;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
63 } elsif ($help) {
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
64 print $USAGE;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
65 exit 0;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
66 }
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 # Fill the hash %tindex with associations VAR -> COUNT where
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
69 # 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
70 # 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
71 # the files.
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
72
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
73 my %tindex;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
74 my %removed;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
75 my @old_files = glob "$old/*.texi";
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
76 my @new_files = glob "*.texi";
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
77 fatal ("No Texinfo files found in `$old'") unless @old_files;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
78 fatal ("No Texinfo files found in current directory") unless @new_files;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
79
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
80 print "Scanning old files for \@tindex lines\n";
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
81 foreach $file (@old_files) {
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
82 open (IN, "<$file") or fatal "Cannot open $file: $!";
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
83 while (<IN>) {
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
84 ++$tindex{$1} if /^\s*\@tindex\s+(\S+)/;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
85 }
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
86 close IN;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
87 }
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 # Process current files and remove those @tindex lines which we
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
90 # know were already present in the files scanned above.
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
91
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
92 print "Removing old \@tindex lines\n";
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
93 foreach $file (@new_files) {
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
94 my $modified = 0;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
95 my $contents = "";
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
96
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
97 open (IN, "< $file") or fatal "Cannot open $file.orig for reading: $!";
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
98 while (<IN>) {
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
99 if (/^\s*\@tindex\s+(\S+)/ && $tindex{$1}) {
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
100 ++$removed{$1};
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
101 $modified = 1;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
102 } else {
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
103 $contents = $contents . $_;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
104 }
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 close IN;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
108
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
109 if ($modified) {
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
110 print " $file\n";
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
111 system ("cp $file $file.orig") == 0 or fatal "Cannot backup $file: $!";
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
112 open (OUT, ">$file") or fatal "Cannot open $file for writing: $!";
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
113 print OUT $contents;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
114 close OUT;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
115 }
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 # Print a list of identifiers removed.
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
119
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
120 print "Removed \@tindex commands for:\n";
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
121 my $key;
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
122 foreach $key (keys %removed) {
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
123 print " $key\n";
d49f27fa41ce Move here from ../../lispref
Glenn Morris <rgm@gnu.org>
parents:
diff changeset
124 }
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 # arch-tag: f8460df6-6bef-4c98-8555-e2c63a88b0fa