#!/usr/bin/perl -w use strict; use warnings; use diagnostics; use Getopt::Std; 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; my ($found, $indent, $idpath); $idpath = ''; $indent = ''; while (<>) { my $end = s/\s*\*+\//\n/ ? 'yes' : undef; # Match: # IDENT, /*:: ... */ # IDENT = value, /*:: ... */ # type ident; /*:: ... */ if ($end and /^(\s|[^\s=]+)*[\s*]([A-Za-z0-9_]+)(\s+=\s+[^,;]+)?[,;]\s*\/\*::\s*(.*)/) { print "\nid:[$idpath$2]::\n\t$4\n"; next; } if ($found) { s/^(\s|\*)*/$indent/; s/^$indent$/\n/; } elsif (/^\s*\/\*\*\s(.*)/) { $_ = $1; if (/struct:[[]([^\]]+)[\]]/) { $idpath = "$1."; } else { $idpath = ''; } if (/::/) { $_ = "\n$_\n\n"; $indent = "\t"; } else { my $dash; for (my $x = 0; $x < length($_); $x++) { $dash .= '-'; } $_ = "\n$_\n$dash\n"; $indent = ""; } $found = 'jep'; } next if not $found; $found = undef if $end; print STDOUT $_; }