gather-docs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #!/usr/bin/perl
  2. # -*- perl -*-
  3. # Copyright (C) 2001, 2009, 2011
  4. # Free Software Foundation
  5. #
  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.
  11. #
  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.
  16. #
  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.
  21. #
  22. # Originally written by DJ Delorie <dj@redhat.com>
  23. # This program looks for texinfo snippets in source files and other
  24. # files, and builds per-category files with entries sorted in
  25. # alphabetical order.
  26. # The syntax it looks for is lines starting with '@def' in *.c and
  27. # other files (see TEXIFILES in Makefile.in). Entries are terminated
  28. # at the next @def* (which begins a new entry) or, for C files, a line
  29. # that begins with '*/' without leading spaces (this assumes that the
  30. # texinfo snippet is within a C-style /* */ comment).
  31. #
  32. if ($ARGV[0] eq "-v") {
  33. $verbose = 1;
  34. shift;
  35. }
  36. $srcdir = shift;
  37. $outfile = shift;
  38. if ($outfile !~ /\S/ || ! -f "$srcdir/Makefile.in" ) {
  39. print STDERR "Usage: gather-docs [-v] srcdir outfile.txi [files with snippets in them ...]\n";
  40. exit 1;
  41. }
  42. $errors = 0;
  43. for $in (@ARGV) {
  44. if (!open(IN, "$srcdir/$in")) {
  45. print STDERR "Cannot open $srcdir/$in for reading: $!\n";
  46. $errors ++;
  47. } else {
  48. $first = 1;
  49. $pertinent = 0;
  50. $man_mode = 0;
  51. $line = 0;
  52. while (<IN>) {
  53. $line ++;
  54. $pertinent = 1 if /^\@def[a-z]*[a-wyz] /;
  55. $pertinent = 0 if /^\*\//;
  56. next unless $pertinent;
  57. if (/^\@def[a-z]*[a-wyz] /) {
  58. ($name) = m/[^\(]* ([^\( \t\r\n\@]+) *(\(|\@?$)/;
  59. $name =~ s/[ ]*\@?$//;
  60. $key = $name;
  61. $key =~ tr/A-Z/a-z/;
  62. $key =~ s/[^a-z0-9]+/ /g;
  63. $name{$key} = $node;
  64. $lines{$key} = '';
  65. $src_file{$key} = $in;
  66. $src_line{$key} = $line;
  67. print "\nReading $in :" if $verbose && $first;
  68. $first = 0;
  69. print " $name" if $verbose;
  70. $node_lines{$key} .= $_;
  71. } else {
  72. $node_lines{$key} .= $_;
  73. }
  74. $pertinent = 0 if /^\@end def/;
  75. }
  76. close (IN);
  77. }
  78. }
  79. print "\n" if $verbose;
  80. exit $errors if $errors;
  81. if (!open (OUT, "> $outfile")) {
  82. print STDERR "Cannot open $outfile for writing: $!\n";
  83. $errors ++;
  84. next;
  85. }
  86. print "Writing $outfile\n" if $verbose;
  87. print OUT "\@c Automatically generated from *.c and others (the comments before\n";
  88. print OUT "\@c each entry tell you which file and where in that file). DO NOT EDIT!\n";
  89. print OUT "\@c Edit the *.c files, configure with --enable-maintainer-mode,\n";
  90. print OUT "\@c run 'make stamp-functions' and gather-docs will build a new copy.\n\n";
  91. for $key (sort keys %name) {
  92. print OUT "\@c $src_file{$key}:$src_line{$key}\n";
  93. print OUT $node_lines{$key};
  94. print OUT "\n";
  95. }
  96. if (! print OUT "\n") {
  97. print STDERR "Disk full writing $srcdir/$cat.texi\n";
  98. $errors ++;
  99. }
  100. close (OUT);
  101. exit $errors;