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