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