-
Notifications
You must be signed in to change notification settings - Fork 0
/
designdoc.pl
executable file
·109 lines (84 loc) · 1.93 KB
/
designdoc.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/perl
use strict;
use warnings;
use List::Util qw/first/;
open OUT, ">", "doc.html" or die $!;
foreach(@ARGV) {
#Read file
open FILE, "<", $_ or die $!;
my @lines = <FILE>;
#Find class name
my @cl =
map { split /\s+/, $_ }
grep { /class/ }
@lines;
my $cidx = first { $cl[$_] eq "class" } 0..$#cl;
my $classname = $cl[$cidx + 1] || die $!;
my @variables = ();
my @functions = ();
my $desc = "";
#Find parts of class
foreach(@lines) {
s/^\s+//g;
if($_ !~ /^(public|protected|private)/) {
next unless /^\*/;
s/\*//g;
s/@(.*?)//g;
$desc .= $_;
next;
}
next if /public class/;
chomp;
my @parts = grep { length $_ > 0 }
split /\s+/, $_;
my $access = shift @parts;
shift @parts while $parts[0] =~ /(static|final)/;
my $type = shift @parts;
my $name = shift @parts;
if((index $name, "(") + 1) { #Non-zero if found
#function found
/\((.*?)\)/;
my @params = split ',', $1;
my @paramtypes = map { $_ * 2 } @params / 2;
push @functions, [
(split /\Q(\E/, $name)[0], #name
$type,
join ", ", @paramtypes,
$desc
];
} else {
#variable found
push @variables, [
$name,
$type,
$desc
];
}
$desc = "";
}
close FILE;
printinfo($classname, Variables => \@variables, Functions => \@functions);
}
close OUT;
sub printinfo {
my $classname = shift;
my %things = @_;
print OUT "<h1>$classname</h1><table>\n";
foreach(sort keys %things) {
my $ref = $things{$_};
print OUT "<tr><th colspan=3>$_</th></tr>";
foreach(sort { $a->[0] cmp $b->[1] } @$ref) {
my @t = @$_;
print OUT "<tr>";
print OUT (map {"<td>" . $_ . "</td>" } @t);
print OUT "</tr>\n";
}
}
print OUT "</table>\n\n";
}
sub firstindex {
my $search = shift;
my %idx;
@idx{@_} = (0..$#_);
return $idx{$search};
}