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-08 22:49:26 -05:00
|
|
|
my $HELP = "Usage: $0 [FILE]
|
|
|
|
Parses [FILE], outputing the result to stdout.";
|
|
|
|
|
|
|
|
sub usage {
|
|
|
|
print "@_\n";
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
our($opt_h, $opt_v);
|
|
|
|
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 02:25:03 -05:00
|
|
|
my ($header, $indent, $idpath);
|
2006-01-09 00:24:00 -05:00
|
|
|
$idpath = ''; $indent = '';
|
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-09 02:25:03 -05:00
|
|
|
if ($end and /[^=]*[\s*](\w+)[\s,;].*\/\*::\s*(.*)/) {
|
|
|
|
# Implicit id for enum values and struct members.
|
|
|
|
$_ = "\nid:[$idpath$1]::\n\t$2\n";
|
2006-01-08 23:03:07 -05:00
|
|
|
|
2006-01-09 02:25:03 -05:00
|
|
|
} elsif ($header) {
|
|
|
|
# Redo the indentation, preserve empty lines.
|
2006-01-09 00:24:00 -05:00
|
|
|
s/^(\s|\*)*/$indent/;
|
|
|
|
s/^$indent$/\n/;
|
2006-01-09 02:25:03 -05:00
|
|
|
|
|
|
|
} elsif (s/^\s*\/\*\*\s(.*)$/$1/) {
|
|
|
|
# Found magic header; record idpath and underline title.
|
|
|
|
$header = "$1";
|
|
|
|
$idpath = /struct:[[]([^\]]+)[\]]/ ? "$1." : "";
|
|
|
|
$indent = /::/ ? "\t" : "";
|
|
|
|
|
|
|
|
$_ = '' if $indent;
|
|
|
|
s/[^-]/-/g; chop;
|
|
|
|
$_ = "\n$header\n$_\n";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
next;
|
2006-01-08 05:15:08 -05:00
|
|
|
}
|
2006-01-09 02:25:03 -05:00
|
|
|
|
|
|
|
$header = undef if $end;
|
2006-01-08 23:30:59 -05:00
|
|
|
print STDOUT $_;
|
2006-01-08 05:15:08 -05:00
|
|
|
}
|