7 my $HELP = "Usage: $0 [FILE]...
8 Parses [FILE], outputing the result to stdout.";
15 our($opt_h, $opt_v, $title, $body, $indent, $idpath, $inblock);
17 getopts
("hv") or usage
($HELP);
18 $opt_v and usage
("Copyleft (c) 2006, Russ Rowan (See `COPYING')");
19 usage
($HELP) if $opt_h or @ARGV < 1;
25 print "$title\n" if not $indent;
28 $body =~ s/#newline#/$indent/g;
31 $title = $body = undef;
34 $idpath = $title = $body = "";
37 my $end = s/\s*\*+\//\n/ ?
'yes' : undef;
39 if ($end and /[^=]*[\s*](\w+)[\s:,;].*\/\
*:\s
*(.*)([.]\s
*)?
$/) {
40 # Implicit id for enum values and struct members.
41 print "\nid:[$idpath$1]::\n\t$2.\n";
44 # Redo the indentation, preserve empty lines.
47 $body .= "#newline#" . $_;
49 } elsif (s/\s*\/\*\*+\s*(.*)/$1/) {
50 # Found magic header; flush, record title and set indentation.
53 $indent = /::/ ?
"\t" : "";
56 next if not ($title or $body) or /^\s$/;
58 my $orig_title = $title;
61 # Combine multi-line declarations to one. Break at empty
63 while (not /(struct|enum|typedef|[^=])*[\s*](\w+).*[\[:,;{]/) {
69 if (/struct\s+(\w+)\s*{/) {
70 $title = "struct:$1" . "[$title]";
73 } elsif (/enum\s+(\w+)\s*{/) {
74 $title = "enum:$1" . "[$title]";
78 if (/#define\s+(\w+)[(]/) {
79 $title = "func:$1" . "[$title]";
80 } elsif (/#define\s+(\w+)/) {
81 $title = "macro:$1" . "[$title]";
86 if (/.*\(\*(\w+)\)\(/) {
87 $title = "typedef:$1" . "[$title]";
88 } elsif (/typedef.*\s(\w+);/) {
89 $title = "typedef:$1" . "[$title]";
93 } elsif (/.*[\s*](\w+)\(/) {
94 $title = "func:$1" . "[$title]";
97 } elsif (/.*\(\*(\w+)\)\(/) {
98 $body = "#newline#" . $title if not $body;
99 $title = "id:[$idpath$1]::";
102 } elsif (/[^=]*[\s*](\w+)[\[\s,:;]/) {
103 $body = "#newline#" . $title if not $body;
104 $title = "id:[$idpath$1]::";
107 put_section
if $orig_title ne $title;
111 $inblock = $end ?
undef : 'yes';