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