summaryrefslogtreecommitdiff
path: root/tools/docpercentages.pl
blob: de9325c8114678de288c73b75bf9b8073e95cfe7 (plain)
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/perl -w

#############################################################################
# Function    : CreateValidSGMLID
# Description : Creates a valid SGML 'id' from the given string.
#		NOTE: SGML ids are case-insensitive, so we have a few special
#		      cases to avoid clashes of ids.
# Arguments   : $id - the string to be converted into a valid SGML id.
#############################################################################

sub CreateValidSGMLID {
    my ($id) = $_[0];

    # Append -CAPS to all all-caps identifiers

    # Special case, '_' would end up as '' so we use 'gettext-macro' instead.
    if ($id eq "_") { return "gettext-macro"; }

    if ($id !~ /[a-z]/) { $id .= "-CAPS" };

    $id =~ s/[_ ]/-/g;
    $id =~ s/[,\.]//g;
    $id =~ s/^-*//;
    $id =~ s/::/-/g;

    return $id;
}

$BASEDIR=shift @ARGV;

print <<EOT;
<table cellspacing="0" cellpadding="2">
  <tr><th align="left">Module</th><th style="padding-left: 0.5em; padding-right: 0.5em" colspan="4">Documented</th></tr>
EOT

my $row = 0; 
while (@ARGV) {
    my $percentage;
    my $documented;
    my $undocumented;
    my @undocumented_symbols;
    
    my $module_name = shift @ARGV;
    my $file = shift @ARGV;
    my $indexfile = shift @ARGV;

    open DOCUMENTED, "<$file" or die "Cannot open $file: $!\n";

    while (<DOCUMENTED>) {
	if      (/(\d+)% (function|symbol) docs coverage/) {
	    $percentage = $1;
	} elsif (/(\d+) (function|symbol)s documented/) {
	    $documented = $1;
	} elsif (/(\d+) not documented/) {
	    $undocumented = $1;
	} elsif (/^\s*(\w+)\s*$/) {
	    push @undocumented_symbols, $1;
	}
    }

    close DOCUMENTED;

    my $complete = defined $percentage && defined $documented && defined $undocumented;
    if (!$complete) {
	die "Cannot parse documentation status file $file\n";
    }

    my $total = $documented + $undocumented;

    my $directory;
    ($directory = $indexfile) =~ s@/[^/]*$@@;
    
    $bgcolor = ($row % 2 == 0) ? "#f7ebd3" : "#fffcf4";

    print <<EOT;
  <tr bgcolor="$bgcolor">
    <td><a href="$indexfile">$module_name</a></td>
    <td align="right" style="padding-left: 0.5em">$documented</td>
	<td>/</td><td>$total</td>
    <td style="padding-right: 0.5em">($percentage%)</td>
EOT
    if ($undocumented != 0) {
	print <<EOT;
    <td><a href="$directory/undocumented.html"><small>[missing]<small></a></td>
EOT
    }
    print <<EOT;
  </tr>
EOT
    
    #
    # Print an index of undocumented symbols for this module
    #

    @undocumented_symbols = sort { uc($a) cmp uc($b) } @undocumented_symbols;

    my $base = "$BASEDIR/$directory";

    open INDEX_SGML, "<$base/index.sgml" or die "Cannot open $base/index.sgml: $!\n";

    my %index_symbols;
    
    while (<INDEX_SGML>) {
	if (/<ANCHOR\s+id="([^"]+)"\s+href="([^"]+)">/) {
	    $index_symbols{$1} = $2;
	}
    }

    close INDEX_SGML;

    open UNDOC_OUT, ">$base/undocumented.html" or die "Cannot open $base/undocumented.html: $!\n";
    print UNDOC_OUT <<EOT;
<html>
<head>
<title>Undocumented functions in $module_name</title>
</head>
<body bgcolor="#ffffff">
<table>
  <tr>
EOT
    my $i = 0;
    for $symbol (@undocumented_symbols) {
	my $id = CreateValidSGMLID($symbol);

	my $output;
	if (exists $index_symbols{$id}) {
	    my $href;
	    
	    ($href = $index_symbols{$id}) =~ s@.*/(.*)$@$1@; 
	    
	    $output = qq(<a href="$href">$symbol</a>);
	} else {
	    $output = qq($symbol);
	}
	print UNDOC_OUT "    <td>$output</td>\n";
	if ($i % 3 == 2) {
	    print UNDOC_OUT "  </tr><tr>\n";
	}
    
        $i++;
    }

    print UNDOC_OUT <<EOT;
  </tr>
</table>
</body>
</html>
EOT
    close UNDOC_OUT;
    $row++;
}

print <<EOT;
</table>
EOT