2006-01-08 05:15:08 -05:00
|
|
|
#!/usr/bin/perl -w
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use diagnostics;
|
2006-01-08 22:49:26 -05:00
|
|
|
use Getopt::Std;
|
2006-01-08 05:15:08 -05:00
|
|
|
|
2006-01-09 05:01:36 -05:00
|
|
|
my $HELP = "Usage: $0 [FILE]...
|
2006-01-08 22:49:26 -05:00
|
|
|
Parses [FILE], outputing the result to stdout.";
|
|
|
|
|
|
|
|
sub usage {
|
|
|
|
print "@_\n";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2006-01-09 05:01:36 -05:00
|
|
|
our($opt_h, $opt_v, $title, $body, $indent, $idpath, $inblock);
|
|
|
|
|
2006-01-08 22:49:26 -05:00
|
|
|
getopts("hv") or usage($HELP);
|
|
|
|
$opt_v and usage("Copyleft (c) 2006, Russ Rowan (See `COPYING')");
|
|
|
|
usage($HELP) if $opt_h or @ARGV < 1;
|
2006-01-08 05:15:08 -05:00
|
|
|
|
2006-01-09 05:01:36 -05:00
|
|
|
sub put_section {
|
|
|
|
if ($title) {
|
|
|
|
print "\n$title\n";
|
2006-01-15 12:06:44 -05:00
|
|
|
$title =~ s/[^-]/-/g;
|
|
|
|
print "$title\n" if not $indent;
|
2006-01-09 05:01:36 -05:00
|
|
|
}
|
|
|
|
if ($body) {
|
2006-01-15 12:06:44 -05:00
|
|
|
$body =~ s/#newline#/$indent/g;
|
|
|
|
print "$body\n";
|
2006-01-09 05:01:36 -05:00
|
|
|
}
|
|
|
|
$title = $body = undef;
|
|
|
|
}
|
|
|
|
|
|
|
|
$idpath = $title = $body = "";
|
2006-01-08 22:49:26 -05:00
|
|
|
while (<>)
|
2006-01-08 05:15:08 -05:00
|
|
|
{
|
2006-01-09 00:49:15 -05:00
|
|
|
my $end = s/\s*\*+\//\n/ ? 'yes' : undef;
|
|
|
|
|
2006-01-13 06:14:05 -05:00
|
|
|
if ($end and /[^=]*[\s*](\w+)[\s:,;].*\/\*:\s*(.*)([.]\s*)?$/) {
|
2006-01-09 02:25:03 -05:00
|
|
|
# Implicit id for enum values and struct members.
|
2006-01-13 06:14:05 -05:00
|
|
|
print "\nid:[$idpath$1]::\n\t$2.\n";
|
2006-01-08 23:03:07 -05:00
|
|
|
|
2006-01-09 05:01:36 -05:00
|
|
|
} elsif ($inblock) {
|
2006-01-09 02:25:03 -05:00
|
|
|
# Redo the indentation, preserve empty lines.
|
2006-01-09 05:01:36 -05:00
|
|
|
s/^(\s|\*)*//;
|
|
|
|
s/^$/\n/;
|
|
|
|
$body .= "#newline#" . $_;
|
2006-01-09 02:25:03 -05:00
|
|
|
|
2006-01-09 06:46:13 -05:00
|
|
|
} elsif (s/\s*\/\*\*+\s*(.*)/$1/) {
|
2006-01-09 05:01:36 -05:00
|
|
|
# Found magic header; flush, record title and set indentation.
|
|
|
|
put_section;
|
|
|
|
$title = "$1";
|
|
|
|
$indent = /::/ ? "\t" : "";
|
2006-01-09 02:25:03 -05:00
|
|
|
|
|
|
|
} else {
|
2006-01-09 06:46:13 -05:00
|
|
|
next if not ($title or $body) or /^\s$/;
|
2006-01-09 05:01:36 -05:00
|
|
|
|
2006-01-09 06:46:13 -05:00
|
|
|
my $orig_title = $title;
|
|
|
|
|
2006-01-13 02:09:06 -05:00
|
|
|
|
|
|
|
# Combine multi-line declarations to one. Break at empty
|
|
|
|
# for #define ...
|
|
|
|
while (not /(struct|enum|typedef|[^=])*[\s*](\w+).*[\[:,;{]/) {
|
|
|
|
my $line = $_;
|
|
|
|
$_ .= <>;
|
2006-01-13 06:14:05 -05:00
|
|
|
last if $_ eq $line;
|
2006-01-09 06:46:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (/struct\s+(\w+)\s*{/) {
|
2006-01-09 05:01:36 -05:00
|
|
|
$title = "struct:$1" . "[$title]";
|
|
|
|
$idpath = "$1.";
|
|
|
|
|
2006-01-09 06:46:13 -05:00
|
|
|
} elsif (/enum\s+(\w+)\s*{/) {
|
2006-01-09 05:01:36 -05:00
|
|
|
$title = "enum:$1" . "[$title]";
|
|
|
|
$idpath = "";
|
|
|
|
|
2006-01-13 02:09:06 -05:00
|
|
|
} elsif (/#define/) {
|
|
|
|
if (/#define\s+(\w+)[(]/) {
|
|
|
|
$title = "func:$1" . "[$title]";
|
|
|
|
} elsif (/#define\s+(\w+)/) {
|
|
|
|
$title = "macro:$1" . "[$title]";
|
|
|
|
}
|
|
|
|
$idpath = "";
|
|
|
|
|
|
|
|
} elsif (/typedef/) {
|
|
|
|
if (/.*\(\*(\w+)\)\(/) {
|
|
|
|
$title = "typedef:$1" . "[$title]";
|
|
|
|
} elsif (/typedef.*\s(\w+);/) {
|
|
|
|
$title = "typedef:$1" . "[$title]";
|
|
|
|
}
|
2006-01-09 08:06:47 -05:00
|
|
|
$idpath = "";
|
|
|
|
|
2006-01-13 02:09:06 -05:00
|
|
|
} elsif (/.*[\s*](\w+)\(/) {
|
|
|
|
$title = "func:$1" . "[$title]";
|
2006-01-09 06:46:13 -05:00
|
|
|
$idpath = "";
|
|
|
|
|
2006-01-13 02:09:06 -05:00
|
|
|
} elsif (/.*\(\*(\w+)\)\(/) {
|
|
|
|
$body = "#newline#" . $title if not $body;
|
|
|
|
$title = "id:[$idpath$1]::";
|
|
|
|
$indent = "\t";
|
|
|
|
|
|
|
|
} elsif (/[^=]*[\s*](\w+)[\[\s,:;]/) {
|
|
|
|
$body = "#newline#" . $title if not $body;
|
|
|
|
$title = "id:[$idpath$1]::";
|
|
|
|
$indent = "\t";
|
2006-01-09 05:01:36 -05:00
|
|
|
}
|
2006-01-09 06:46:13 -05:00
|
|
|
put_section if $orig_title ne $title;
|
2006-01-09 02:25:03 -05:00
|
|
|
next;
|
2006-01-08 05:15:08 -05:00
|
|
|
}
|
2006-01-09 02:25:03 -05:00
|
|
|
|
2006-01-09 05:01:36 -05:00
|
|
|
$inblock = $end ? undef : 'yes';
|
2006-01-08 05:15:08 -05:00
|
|
|
}
|