chiark / gitweb /
Script to generate -man documentation for expansions from comments in
[disorder] / scripts / macro-docs
CommitLineData
cf451c90
RK
1#! /usr/bin/perl -w
2use strict;
3
4my %macros = ();
5my $name;
6my $docs;
7while(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
30for my $m (sort keys %macros) {
31 my @docs = @{$macros{$m}};
32 my $heading = shift @docs;
33 # Strip leading and trailing blanks
34 while(@docs > 0 and $docs[0] eq '') {
35 shift @docs;
36 }
37 while(@docs > 0 and $docs[$#docs] eq '') {
38 pop @docs;
39 }
40 print ".TP\n";
41 print ".B $heading\n";
42 for my $d (@docs) {
43 if($d eq '') {
44 print ".PP\n";
45 } else {
46 # Keep sentence-ending full stops at end of line
47 $d =~ s/\. /\.\n/g;
48 print "$d\n";
49 }
50 }
51}