#!/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 ($header, $indent, $idpath); $idpath = ''; $indent = ''; while (<>) { my $end = s/\s*\*+\//\n/ ? 'yes' : undef; if ($end and /[^=]*[\s*](\w+)[\s,;].*\/\*::\s*(.*)/) { # Implicit id for enum values and struct members. $_ = "\nid:[$idpath$1]::\n\t$2\n"; } elsif ($header) { # Redo the indentation, preserve empty lines. s/^(\s|\*)*/$indent/; s/^$indent$/\n/; } 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; } $header = undef if $end; print STDOUT $_; }