gather-docs revision 1.1.1.1.8.2 1 1.1.1.1.8.2 tls #!/usr/bin/perl
2 1.1.1.1.8.2 tls # -*- perl -*-
3 1.1.1.1.8.2 tls
4 1.1.1.1.8.2 tls # Copyright (C) 2001
5 1.1.1.1.8.2 tls # Free Software Foundation
6 1.1.1.1.8.2 tls #
7 1.1.1.1.8.2 tls # This file is part of the libiberty library.
8 1.1.1.1.8.2 tls # Libiberty is free software; you can redistribute it and/or
9 1.1.1.1.8.2 tls # modify it under the terms of the GNU Library General Public
10 1.1.1.1.8.2 tls # License as published by the Free Software Foundation; either
11 1.1.1.1.8.2 tls # version 2 of the License, or (at your option) any later version.
12 1.1.1.1.8.2 tls #
13 1.1.1.1.8.2 tls # Libiberty is distributed in the hope that it will be useful,
14 1.1.1.1.8.2 tls # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 1.1.1.1.8.2 tls # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 1.1.1.1.8.2 tls # Library General Public License for more details.
17 1.1.1.1.8.2 tls #
18 1.1.1.1.8.2 tls # You should have received a copy of the GNU Library General Public
19 1.1.1.1.8.2 tls # License along with libiberty; see the file COPYING.LIB. If not,
20 1.1.1.1.8.2 tls # write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
21 1.1.1.1.8.2 tls # Boston, MA 02110-1301, USA.
22 1.1.1.1.8.2 tls #
23 1.1.1.1.8.2 tls # Originally written by DJ Delorie <dj (at] redhat.com>
24 1.1.1.1.8.2 tls
25 1.1.1.1.8.2 tls
26 1.1.1.1.8.2 tls
27 1.1.1.1.8.2 tls # This program looks for texinfo snippets in source files and other
28 1.1.1.1.8.2 tls # files, and builds per-category files with entries sorted in
29 1.1.1.1.8.2 tls # alphabetical order.
30 1.1.1.1.8.2 tls
31 1.1.1.1.8.2 tls # The syntax it looks for is lines starting with '@def' in *.c and
32 1.1.1.1.8.2 tls # other files (see TEXIFILES in Makefile.in). Entries are terminated
33 1.1.1.1.8.2 tls # at the next @def* (which begins a new entry) or, for C files, a line
34 1.1.1.1.8.2 tls # that begins with '*/' without leading spaces (this assumes that the
35 1.1.1.1.8.2 tls # texinfo snippet is within a C-style /* */ comment).
36 1.1.1.1.8.2 tls
37 1.1.1.1.8.2 tls #
38 1.1.1.1.8.2 tls
39 1.1.1.1.8.2 tls
40 1.1.1.1.8.2 tls
41 1.1.1.1.8.2 tls if ($ARGV[0] eq "-v") {
42 1.1.1.1.8.2 tls $verbose = 1;
43 1.1.1.1.8.2 tls shift;
44 1.1.1.1.8.2 tls }
45 1.1.1.1.8.2 tls
46 1.1.1.1.8.2 tls $srcdir = shift;
47 1.1.1.1.8.2 tls $outfile = shift;
48 1.1.1.1.8.2 tls
49 1.1.1.1.8.2 tls if ($outfile !~ /\S/ || ! -f "$srcdir/Makefile.in" ) {
50 1.1.1.1.8.2 tls print STDERR "Usage: gather-docs [-v] srcdir outfile.txi [files with snippets in them ...]\n";
51 1.1.1.1.8.2 tls exit 1;
52 1.1.1.1.8.2 tls }
53 1.1.1.1.8.2 tls
54 1.1.1.1.8.2 tls $errors = 0;
55 1.1.1.1.8.2 tls
56 1.1.1.1.8.2 tls for $in (@ARGV) {
57 1.1.1.1.8.2 tls
58 1.1.1.1.8.2 tls if (!open(IN, "$srcdir/$in")) {
59 1.1.1.1.8.2 tls print STDERR "Cannot open $srcdir/$in for reading: $!\n";
60 1.1.1.1.8.2 tls $errors ++;
61 1.1.1.1.8.2 tls
62 1.1.1.1.8.2 tls } else {
63 1.1.1.1.8.2 tls $first = 1;
64 1.1.1.1.8.2 tls $pertinent = 0;
65 1.1.1.1.8.2 tls $man_mode = 0;
66 1.1.1.1.8.2 tls $line = 0;
67 1.1.1.1.8.2 tls
68 1.1.1.1.8.2 tls while (<IN>) {
69 1.1.1.1.8.2 tls $line ++;
70 1.1.1.1.8.2 tls $pertinent = 1 if /^\@def[a-z]*[a-wyz] /;
71 1.1.1.1.8.2 tls $pertinent = 0 if /^\*\//;
72 1.1.1.1.8.2 tls next unless $pertinent;
73 1.1.1.1.8.2 tls
74 1.1.1.1.8.2 tls if (/^\@def[a-z]*[a-wyz] /) {
75 1.1.1.1.8.2 tls
76 1.1.1.1.8.2 tls ($name) = m/[^\(]* ([^\( \t\r\n]+) *\(/;
77 1.1.1.1.8.2 tls $name =~ s/[ ]*$//;
78 1.1.1.1.8.2 tls $key = $name;
79 1.1.1.1.8.2 tls $key =~ tr/A-Z/a-z/;
80 1.1.1.1.8.2 tls $key =~ s/[^a-z0-9]+/ /g;
81 1.1.1.1.8.2 tls $name{$key} = $node;
82 1.1.1.1.8.2 tls $lines{$key} = '';
83 1.1.1.1.8.2 tls $src_file{$key} = $in;
84 1.1.1.1.8.2 tls $src_line{$key} = $line;
85 1.1.1.1.8.2 tls print "\nReading $in :" if $verbose && $first;
86 1.1.1.1.8.2 tls $first = 0;
87 1.1.1.1.8.2 tls print " $name" if $verbose;
88 1.1.1.1.8.2 tls $node_lines{$key} .= $_;
89 1.1.1.1.8.2 tls
90 1.1.1.1.8.2 tls } else {
91 1.1.1.1.8.2 tls $node_lines{$key} .= $_;
92 1.1.1.1.8.2 tls }
93 1.1.1.1.8.2 tls
94 1.1.1.1.8.2 tls $pertinent = 0 if /^\@end def/;
95 1.1.1.1.8.2 tls }
96 1.1.1.1.8.2 tls close (IN);
97 1.1.1.1.8.2 tls }
98 1.1.1.1.8.2 tls }
99 1.1.1.1.8.2 tls
100 1.1.1.1.8.2 tls print "\n" if $verbose;
101 1.1.1.1.8.2 tls exit $errors if $errors;
102 1.1.1.1.8.2 tls
103 1.1.1.1.8.2 tls if (!open (OUT, "> $outfile")) {
104 1.1.1.1.8.2 tls print STDERR "Cannot open $outfile for writing: $!\n";
105 1.1.1.1.8.2 tls $errors ++;
106 1.1.1.1.8.2 tls next;
107 1.1.1.1.8.2 tls }
108 1.1.1.1.8.2 tls print "Writing $outfile\n" if $verbose;
109 1.1.1.1.8.2 tls
110 1.1.1.1.8.2 tls print OUT "\@c Automatically generated from *.c and others (the comments before\n";
111 1.1.1.1.8.2 tls print OUT "\@c each entry tell you which file and where in that file). DO NOT EDIT!\n";
112 1.1.1.1.8.2 tls print OUT "\@c Edit the *.c files, configure with --enable-maintainer-mode,\n";
113 1.1.1.1.8.2 tls print OUT "\@c run 'make stamp-functions' and gather-docs will build a new copy.\n\n";
114 1.1.1.1.8.2 tls
115 1.1.1.1.8.2 tls for $key (sort keys %name) {
116 1.1.1.1.8.2 tls print OUT "\@c $src_file{$key}:$src_line{$key}\n";
117 1.1.1.1.8.2 tls print OUT $node_lines{$key};
118 1.1.1.1.8.2 tls print OUT "\n";
119 1.1.1.1.8.2 tls }
120 1.1.1.1.8.2 tls
121 1.1.1.1.8.2 tls if (! print OUT "\n") {
122 1.1.1.1.8.2 tls print STDERR "Disk full writing $srcdir/$cat.texi\n";
123 1.1.1.1.8.2 tls $errors ++;
124 1.1.1.1.8.2 tls }
125 1.1.1.1.8.2 tls
126 1.1.1.1.8.2 tls close (OUT);
127 1.1.1.1.8.2 tls
128 1.1.1.1.8.2 tls exit $errors;
129