#!/usr/bin/perl # Mohsin Ahmed, 1999-06-29 use strict; my $USAGE="USAGE: classhier FILES SYNOPSIS: grep and find the class hierarchy for derived relations. NOTES: cross check the output manually. Examples: classhier `ff \\\\.h\$` classhier `find . -name '*.h' -print ` "; die $USAGE . "Need filename as arg\n" unless @ARGV; undef $/; $* = 0; my( %printedfn ); while( <> ){ CLASS: while( m/\nclass[^{;]+{/g ){ my $match = $&; # print $match; $match =~ s/[\s\W]+/:/g; $match =~ s/\A:+//x; $match =~ s/:+\Z//x; $match =~ s/(class|public|protected|private|void|int|virtual)://gx; # print $match,"\n"; next CLASS; die $match if $match =~ /public/; next CLASS unless $match =~ m/:./; print "\nFile:",$ARGV, "\n\n" unless $printedfn{$ARGV}++; my( $classname, @bases ) = split( /:/, $match ); printf "class %20s derived from %s\n", $classname, join(',',@bases); # foreach $base (@bases) { # print "$classname derived from $base\n"; # } } }