#!/usr/bin/perl -w use strict; while (<>) { if (/^\/\*\*/) { my @doc; my @def; my $stop; # Capture comments. INNER: { do { chomp; last INNER if /^[ \t]*\*\/[ \t]*$/; $stop = 1 if /\*\//; s/^\/?[ \t]*\*+ ?//; s/^[ \t]+/\t/; s/^\t- *([^:-]+) *:/\t[$1]/; s/[ \t]*\*\///; push @doc, $_; last INNER if defined $stop; } while (<>); } # Capture definition. $_ = <>; if (/^# *define /) { INNER: { do { chomp; push @def, $_ . ' '; if ($#def > 5) { push @def, '...'; last; } last unless /\\$/ } while (<>); } } else { INNER: { do { chomp; s/\)[^)]*$/);/; push @def, $_; last if /\)/; } while (<>); } } print join "\n", @doc, '', '^<<', @def, '^>>', '', ''; } }