swarm-support
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

A handy(?) script for printing class hierarchies


From: Gary Polhill
Subject: A handy(?) script for printing class hierarchies
Date: Fri, 11 Sep 1998 14:28:15 +0100

I've written a short Perl script for printing a class hierarchy in a
fairly basic fashion from a grep of @interface in header files.
The script can be called with the -header option, which will
print the header file the class appears in, and/or the -html
option, which generates output in the form of an HTML table.

Here's some example output from the collections directory
in the Swarm source:

% grep '@interface' collections/*.h | objcclasshier.pl
CreateDrop_s --> Collection_any
CreateDrop_s --> Collection_any --> Array_c
CreateDrop_s --> Collection_any --> List_any
CreateDrop_s --> Collection_any --> List_any --> TARGET
CreateDrop_s --> Collection_any --> Map_c
CreateDrop_s --> Collection_any --> Set_c
CreateDrop_s --> InputStream_c
CreateDrop_s --> OutputStream_c
CreateDrop_s --> String_c
ListIndex_mlinks --> OrderedSetIndex_c
List_mlinks --> OrderedSet_c
Object_s --> Index_any
Object_s --> Index_any --> ArrayIndex_c
Object_s --> Index_any --> ListIndex_any
Object_s --> Index_any --> ListIndex_any --> TINDEX
Object_s --> Index_any --> MapIndex_c
Object_s --> Index_any --> SetIndex_c

And here's the script, in case you think it'll be useful:

#!/usr/bin/perl -s

while(<STDIN>) {
    if(/^(\S+):address@hidden(\S+)\s*:\s+(\S+)/) {
 if(defined($superclassof{$2}) && ($superclassof{$2} ne $3)) {
     $i = 1;
     $k = "$1".("!" x $i);
     while(defined($superclassof{$k})) {
  $i++;
  $k = "$1".("!" x $i);
     }
     $superclassof{$k} = $3;
     $headerfileof{$k} = $1;
 }
 else {
     $superclassof{$2} = $3;
     $headerfileof{$2} = $1;
 }
    }
    elsif(/^(\S+):address@hidden(\S+)/) {
 $superclassof{$2} = $2;
 $headerfileof{$2} = $1;
    }
}

@subclasses = keys(%superclassof);
for($i = 0; $i <= $#subclasses; $i++) {
    $classhier[$i] = $subclasses[$i];
    $class = $subclasses[$i];
    while(defined($superclassof{$class}) &&
   !($superclassof{$class} eq $class)) {
 $class = $superclassof{$class};
 if(defined($html)) {
     $classhier[$i] = "$class<TD>$classhier[$i]";
 }
 else {
     $classhier[$i] = "$class --> $classhier[$i]";
 }
    }
}
@classhier = sort  @classhier;
if(defined($html)) {
    print "<TABLE>\n";
}
for($i = 0; $i <= $#classhier; $i++) {
    print "<TR><TD>" if defined $html;
    if($classhier[$i] =~ /([^ >]+)$/) {
 $class = $1;
 print "$headerfileof{$class}<TD>"
     if (defined($html) && defined($header));
    }
    print "$classhier[$i]";
    if(!defined($html) && defined($header)) {
 print " ($headerfileof{$class})";
    }
    print "\n";
}
if(defined($html)) {
    print "</TABLE>\n";
}

sub leavesfirst {
    local($na) = scalar(split('>', $a));
    local($nb) = scalar(split('>', $b));
    if($na < $nb) {
 return(1);
    }
    elsif($na > $nb) {
 return(-1);
    }
    else {
 return($a cmp $b);
    }
}

Of course, neither I nor the MLURI will accept any
responsibility or liability for any loss or damage occurring
as a consequence of using the above.

--

Macaulay Land Use Research Institute, Craigiebuckler, Aberdeen. AB15 8QH
Tel: +44 (0) 1224 318611               Email: address@hidden




                  ==================================
   Swarm-Support is for discussion of the technical details of the day
   to day usage of Swarm.  For list administration needs (esp.
   [un]subscribing), please send a message to <address@hidden>
   with "help" in the body of the message.
                  ==================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]