4 # Copyright (C) 2001-2024 Free Software Foundation, Inc.
6 # This file is part of the libiberty library.
7 # Libiberty is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Library General Public
9 # License as published by the Free Software Foundation; either
10 # version 2 of the License, or (at your option) any later version.
12 # Libiberty is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Library General Public License for more details.
17 # You should have received a copy of the GNU Library General Public
18 # License along with libiberty; see the file COPYING.LIB. If not,
19 # write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
20 # Boston, MA 02110-1301, USA.
22 # Originally written by DJ Delorie <dj@redhat.com>
26 # This program looks for texinfo snippets in source files and other
27 # files, and builds per-category files with entries sorted in
30 # The syntax it looks for is lines starting with '@def' in *.c and
31 # other files (see TEXIFILES in Makefile.in). Entries are terminated
32 # at the next @def* (which begins a new entry) or, for C files, a line
33 # that begins with '*/' without leading spaces (this assumes that the
34 # texinfo snippet is within a C-style /* */ comment).
40 if ($ARGV[0] eq "-v") {
48 if ($outfile !~ /\S/ || ! -f
"$srcdir/Makefile.in" ) {
49 print STDERR
"Usage: gather-docs [-v] srcdir outfile.txi [files with snippets in them ...]\n";
57 if (!open(IN
, "$srcdir/$in")) {
58 print STDERR
"Cannot open $srcdir/$in for reading: $!\n";
69 $pertinent = 1 if /^\@def[a-z]*[a-wyz] /;
70 $pertinent = 0 if /^\*\//;
71 next unless $pertinent;
73 if (/^\@def[a-z]*[a-wyz] /) {
75 ($name) = m/[^\(]* ([^\( \t\r\n\@]+) *(\(|\@?$)/;
76 $name =~ s/[ ]*\@?$//;
79 $key =~ s/[^a-z0-9]+/ /g;
82 $src_file{$key} = $in;
83 $src_line{$key} = $line;
84 print "\nReading $in :" if $verbose && $first;
86 print " $name" if $verbose;
87 $node_lines{$key} .= $_;
90 $node_lines{$key} .= $_;
93 $pertinent = 0 if /^\@end def/;
99 print "\n" if $verbose;
100 exit $errors if $errors;
102 if (!open (OUT
, "> $outfile")) {
103 print STDERR
"Cannot open $outfile for writing: $!\n";
107 print "Writing $outfile\n" if $verbose;
109 print OUT
"\@c Automatically generated from *.c and others (the comments before\n";
110 print OUT
"\@c each entry tell you which file and where in that file). DO NOT EDIT!\n";
111 print OUT
"\@c Edit the *.c files, configure with --enable-maintainer-mode,\n";
112 print OUT
"\@c run 'make stamp-functions' and gather-docs will build a new copy.\n\n";
114 for $key (sort keys %name) {
115 print OUT
"\@c $src_file{$key}:$src_line{$key}\n";
116 print OUT
$node_lines{$key};
120 if (! print OUT
"\n") {
121 print STDERR
"Disk full writing $srcdir/$cat.texi\n";