19588ddcfSespie#!/usr/bin/perl 29588ddcfSespie# -*- perl -*- 39588ddcfSespie 49588ddcfSespie# Copyright (C) 2001 59588ddcfSespie# Free Software Foundation 69588ddcfSespie# 79588ddcfSespie# This file is part of the libiberty library. 89588ddcfSespie# Libiberty is free software; you can redistribute it and/or 99588ddcfSespie# modify it under the terms of the GNU Library General Public 109588ddcfSespie# License as published by the Free Software Foundation; either 119588ddcfSespie# version 2 of the License, or (at your option) any later version. 129588ddcfSespie# 139588ddcfSespie# Libiberty is distributed in the hope that it will be useful, 149588ddcfSespie# but WITHOUT ANY WARRANTY; without even the implied warranty of 159588ddcfSespie# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 169588ddcfSespie# Library General Public License for more details. 179588ddcfSespie# 189588ddcfSespie# You should have received a copy of the GNU Library General Public 199588ddcfSespie# License along with libiberty; see the file COPYING.LIB. If not, 20*20fce977Smiod# write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, 21*20fce977Smiod# Boston, MA 02110-1301, USA. 229588ddcfSespie# 239588ddcfSespie# Originally written by DJ Delorie <dj@redhat.com> 249588ddcfSespie 259588ddcfSespie 269588ddcfSespie 279588ddcfSespie# This program looks for texinfo snippets in source files and other 289588ddcfSespie# files, and builds per-category files with entries sorted in 299588ddcfSespie# alphabetical order. 309588ddcfSespie 319588ddcfSespie# The syntax it looks for is lines starting with '@def' in *.c and 329588ddcfSespie# other files (see TEXIFILES in Makefile.in). Entries are terminated 339588ddcfSespie# at the next @def* (which begins a new entry) or, for C files, a line 349588ddcfSespie# that begins with '*/' without leading spaces (this assumes that the 359588ddcfSespie# texinfo snippet is within a C-style /* */ comment). 369588ddcfSespie 379588ddcfSespie# 389588ddcfSespie 399588ddcfSespie 409588ddcfSespie 419588ddcfSespieif ($ARGV[0] eq "-v") { 429588ddcfSespie $verbose = 1; 439588ddcfSespie shift; 449588ddcfSespie} 459588ddcfSespie 469588ddcfSespie$srcdir = shift; 479588ddcfSespie$outfile = shift; 489588ddcfSespie 499588ddcfSespieif ($outfile !~ /\S/ || ! -f "$srcdir/Makefile.in" ) { 509588ddcfSespie print STDERR "Usage: gather-docs [-v] srcdir outfile.txi [files with snippets in them ...]\n"; 519588ddcfSespie exit 1; 529588ddcfSespie} 539588ddcfSespie 549588ddcfSespie$errors = 0; 559588ddcfSespie 569588ddcfSespiefor $in (@ARGV) { 579588ddcfSespie 589588ddcfSespie if (!open(IN, "$srcdir/$in")) { 599588ddcfSespie print STDERR "Cannot open $srcdir/$in for reading: $!\n"; 609588ddcfSespie $errors ++; 619588ddcfSespie 629588ddcfSespie } else { 639588ddcfSespie $first = 1; 649588ddcfSespie $pertinent = 0; 659588ddcfSespie $man_mode = 0; 669588ddcfSespie $line = 0; 679588ddcfSespie 689588ddcfSespie while (<IN>) { 699588ddcfSespie $line ++; 709588ddcfSespie $pertinent = 1 if /^\@def[a-z]*[a-wyz] /; 719588ddcfSespie $pertinent = 0 if /^\*\//; 729588ddcfSespie next unless $pertinent; 739588ddcfSespie 749588ddcfSespie if (/^\@def[a-z]*[a-wyz] /) { 759588ddcfSespie 769588ddcfSespie ($name) = m/[^\(]* ([^\( \t\r\n]+) *\(/; 779588ddcfSespie $name =~ s/[ ]*$//; 789588ddcfSespie $key = $name; 799588ddcfSespie $key =~ tr/A-Z/a-z/; 809588ddcfSespie $key =~ s/[^a-z0-9]+/ /g; 819588ddcfSespie $name{$key} = $node; 829588ddcfSespie $lines{$key} = ''; 839588ddcfSespie $src_file{$key} = $in; 849588ddcfSespie $src_line{$key} = $line; 859588ddcfSespie print "\nReading $in :" if $verbose && $first; 869588ddcfSespie $first = 0; 879588ddcfSespie print " $name" if $verbose; 889588ddcfSespie $node_lines{$key} .= $_; 899588ddcfSespie 909588ddcfSespie } else { 919588ddcfSespie $node_lines{$key} .= $_; 929588ddcfSespie } 939588ddcfSespie 949588ddcfSespie $pertinent = 0 if /^\@end def/; 959588ddcfSespie } 969588ddcfSespie close (IN); 979588ddcfSespie } 989588ddcfSespie} 999588ddcfSespie 1009588ddcfSespieprint "\n" if $verbose; 1019588ddcfSespieexit $errors if $errors; 1029588ddcfSespie 1039588ddcfSespieif (!open (OUT, "> $outfile")) { 1049588ddcfSespie print STDERR "Cannot open $outfile for writing: $!\n"; 1059588ddcfSespie $errors ++; 1069588ddcfSespie next; 1079588ddcfSespie} 1089588ddcfSespieprint "Writing $outfile\n" if $verbose; 1099588ddcfSespie 1109588ddcfSespieprint OUT "\@c Automatically generated from *.c and others (the comments before\n"; 1119588ddcfSespieprint OUT "\@c each entry tell you which file and where in that file). DO NOT EDIT!\n"; 1129588ddcfSespieprint OUT "\@c Edit the *.c files, configure with --enable-maintainer-mode,\n"; 1139588ddcfSespieprint OUT "\@c and let gather-docs build you a new copy.\n\n"; 1149588ddcfSespie 1159588ddcfSespiefor $key (sort keys %name) { 1169588ddcfSespie print OUT "\@c $src_file{$key}:$src_line{$key}\n"; 1179588ddcfSespie print OUT $node_lines{$key}; 1189588ddcfSespie print OUT "\n"; 1199588ddcfSespie} 1209588ddcfSespie 1219588ddcfSespieif (! print OUT "\n") { 1229588ddcfSespie print STDERR "Disk full writing $srcdir/$cat.texi\n"; 1239588ddcfSespie $errors ++; 1249588ddcfSespie} 1259588ddcfSespie 1269588ddcfSespieclose (OUT); 1279588ddcfSespie 1289588ddcfSespieexit $errors; 129