chiark / gitweb /
more templates plus support code changes
[disorder] / scripts / macro-docs
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 for 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 =~ /^- /) {
44       $d = $';
45       print ".TP\n";
46       print ".B .\n";
47     }
48     if($d eq '') {
49       print ".PP\n";
50     } else {
51       # Keep sentence-ending full stops at end of line
52       $d =~ s/\.  /\.\n/g;
53       print "$d\n";
54     }
55   }
56 }