gather-docs 3.3 KB

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