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
|
#!/usr/bin/perl
#
# A filter script for doxygen to make it understand kerneldoc
# written by Jan Engelhardt, 2008
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the WTF Public License version 2 or
# (at your option) any later version.
#
use strict;
use warnings;
my $within_comment = 0;
my @collect = ();
while (<>) {
my $s = $_;
chomp $s;
if ($s eq "/**") {
$within_comment = 1;
print;
next;
}
if (!$within_comment) {
print;
next;
}
if ($s eq " */") {
&proc(\@collect);
@collect = ();
$within_comment = 0;
print;
next;
}
$s =~ s/^ \* ?//;
push(@collect, $s);
}
sub proc
{
my $brief = [];
my $args = [];
my $desc = shift @_;
#
# Split off brief description
#
my $args_at = -1;
for (my $i = 0; $i < scalar(@$desc); ++$i) {
if ($desc->[$i] =~ /^[\@\%]\w+:(?:\s+.*)?$/) {
$args_at = $i;
last;
}
}
if ($args_at != -1) {
@$brief = splice(@$desc, 0, $args_at);
}
while (scalar(@$desc) > 0 && $desc->[-1] eq "") {
pop(@$desc);
}
#
# Split off args and unwrap their description.
#
my $desc_at = scalar(@$desc);
for (my $i = 0; $i < scalar(@$desc); ++$i)
{
if ($desc->[$i] !~ /^[\@\%\s]/) {
$desc_at = $i;
last;
}
while ($#$desc > $i && substr($desc->[$i+1], 0, 1) =~ /^\s/) {
my($line) = splice(@$desc, $i+1, 1);
$line =~ s/^\s+//;
$desc->[$i] .= " $line";
}
}
@$args = splice(@$desc, 0, $desc_at);
while (scalar(@$desc) > 0 && $desc->[0] eq "") {
shift(@$desc);
}
#
# Some postprocessing
#
if (scalar(@$brief) == 0 && scalar(@$args) == 0 &&
scalar(@$desc) > 3 && $desc->[0] =~ /^\S/ &&
$desc->[1] eq "")
{
push(@$brief, shift(@$desc));
shift(@$desc);
}
#
# Output
#
if (scalar(@$args) > 0) {
for $_ (@$args) {
my($type, $key, $description) =
($_ =~ /^([\@\%])(.*?):(?:\s+(.*))?/);
if (!defined($description)) {
$description = "";
} else {
$description =~ s/[\@\%](\w+)/$1/g;
}
if (!defined($key)) {
print STDERR "kerneldoc-filter: bogus line: $_\n";
} elsif ($type eq '@') {
print " * \\param $key\n * $description\n *\n";
} elsif ($type eq '%') {
print " * \\var $key\n * $description\n */\n/**\n";
}
}
}
if (scalar(@$brief) > 0) {
print " * \\brief\n";
print " * $_\n" for @$brief;
print " *\n";
}
if (scalar(@$desc) > 0) {
foreach my $line (@$desc) {
$line =~ s/[\@\%](\w+)/$1/g;
print " * $line\n";
}
}
}
|