| 1 | #! /usr/bin/perl -w |
| 2 | use strict; |
| 3 | |
| 4 | my %macros = (); |
| 5 | my $name; |
| 6 | my $docs; |
| 7 | while(defined($_ = <>)) { |
| 8 | chomp; |
| 9 | if(!defined $name and m,^/\*\$ (\@?([a-z\-]+).*),) { |
| 10 | $name = $2; |
| 11 | my $heading = $1; |
| 12 | $docs = [$heading]; |
| 13 | $macros{$name} = $docs; |
| 14 | next; |
| 15 | } |
| 16 | if(defined $name) { |
| 17 | # Identify and strip trailing */ |
| 18 | my $last = m,\*/ *$,; |
| 19 | s,\*/ *$,,; |
| 20 | # Strip trailing spaces |
| 21 | s,\s*$,,; |
| 22 | # Strip leading comment indicator and spaces |
| 23 | s,^ *\* *,,; |
| 24 | push(@$docs, $_); |
| 25 | undef $name if $last; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | # Generate docs in name order |
| 30 | my $indented = 0; |
| 31 | for my $m (sort keys %macros) { |
| 32 | my @docs = @{$macros{$m}}; |
| 33 | my $heading = shift @docs; |
| 34 | # Strip leading and trailing blanks |
| 35 | while(@docs > 0 and $docs[0] eq '') { |
| 36 | shift @docs; |
| 37 | } |
| 38 | while(@docs > 0 and $docs[$#docs] eq '') { |
| 39 | pop @docs; |
| 40 | } |
| 41 | print ".TP\n"; |
| 42 | print ".B $heading\n"; |
| 43 | for my $d (@docs) { |
| 44 | if($d =~ /^-\s*([^:]+):\s+(.*)/) { |
| 45 | if(!$indented) { |
| 46 | print ".RS\n"; |
| 47 | $indented = 1; |
| 48 | } |
| 49 | print ".TP 8\n"; |
| 50 | print ".B $1\n"; |
| 51 | $d = $2; |
| 52 | } |
| 53 | if($d =~ /^- /) { |
| 54 | $d = $'; |
| 55 | if(!$indented) { |
| 56 | print ".RS\n"; |
| 57 | $indented = 1; |
| 58 | } |
| 59 | print ".TP\n"; |
| 60 | print ".B .\n"; |
| 61 | } |
| 62 | if($d eq '') { |
| 63 | if($indented) { |
| 64 | print ".RE\n"; |
| 65 | $indented = 0; |
| 66 | } |
| 67 | print ".IP\n"; |
| 68 | } else { |
| 69 | # Keep sentence-ending full stops at end of line |
| 70 | $d =~ s/\. /\.\n/g; |
| 71 | print "$d\n"; |
| 72 | } |
| 73 | } |
| 74 | if($indented) { |
| 75 | print ".RE\n"; |
| 76 | $indented = 0; |
| 77 | } |
| 78 | } |