chiark / gitweb /
Script to generate -man documentation for expansions from comments in
authorRichard Kettlewell <rjk@greenend.org.uk>
Mon, 5 May 2008 10:24:21 +0000 (11:24 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Mon, 5 May 2008 10:24:21 +0000 (11:24 +0100)
source code.

scripts/Makefile.am
scripts/macro-docs [new file with mode: 0755]

index 620c8f49dab121f1576ed2ace234040a72df8905..81574db6ae58032cd5c0d948f22da75278f588ef 100644 (file)
@@ -26,6 +26,6 @@ SEDFILES=setup teardown
 include ${top_srcdir}/scripts/sedfiles.make
 
 EXTRA_DIST=htmlman sedfiles.make text2c oggrename make-unidata \
 include ${top_srcdir}/scripts/sedfiles.make
 
 EXTRA_DIST=htmlman sedfiles.make text2c oggrename make-unidata \
-       format-gcov-report make-version-string setup.in teardown.in
+       format-gcov-report make-version-string setup.in teardown.in macro-docs
 
 CLEANFILES=$(SEDFILES)
 
 CLEANFILES=$(SEDFILES)
diff --git a/scripts/macro-docs b/scripts/macro-docs
new file mode 100755 (executable)
index 0000000..46b2a6e
--- /dev/null
@@ -0,0 +1,51 @@
+#! /usr/bin/perl -w
+use strict;
+
+my %macros = ();
+my $name;
+my $docs;
+while(defined($_ = <>)) {
+  chomp;
+  if(!defined $name and m,^/\* (\@([a-z\-]+).*),) {
+    $name = $2;
+    my $heading = $1;
+    $docs = [$heading];
+    $macros{$name} = $docs;
+    next;
+  }
+  if(defined $name) {
+    # Identify and strip trailing */
+    my $last = m,\*/ *$,;
+    s,\*/ *$,,;
+    # Strip trailing spaces
+    s,\s*$,,;
+    # Strip leading comment indicator and spaces
+    s,^ *\* *,,;
+    push(@$docs, $_);
+    undef $name if $last;
+  }
+}
+
+# Generate docs in name order
+for my $m (sort keys %macros) {
+  my @docs = @{$macros{$m}};
+  my $heading = shift @docs;
+  # Strip leading and trailing blanks
+  while(@docs > 0 and $docs[0] eq '') {
+    shift @docs;
+  }
+  while(@docs > 0 and $docs[$#docs] eq '') {
+    pop @docs;
+  }
+  print ".TP\n";
+  print ".B $heading\n";
+  for my $d (@docs) {
+    if($d eq '') {
+      print ".PP\n";
+    } else {
+      # Keep sentence-ending full stops at end of line
+      $d =~ s/\.  /\.\n/g;
+      print "$d\n";
+    }
+  }
+}