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