#! /usr/bin/perl -w # $Cambridge: exim/doc/doc-docbook/x2man,v 1.1 2005/06/16 10:32:31 ph10 Exp $ # Script to find the command line options in the DocBook source of the Exim # spec, and turn them into a man page, because people like that. ################################################## # Main Program # ################################################## open(IN, "spec.xml") || die "Can't open spec.xml\n"; open(OUT, ">exim.8" ) || die "Can't open exim.8\n"; print OUT <) { last if /^\s*$/; } die "Can't find start of options\n" if ! defined $_; $optstart = 0; $indent = ""; # Loop for each individual option $next = ; while ($next) { $_ = $next; $next = ; last if /^\s*$/; # Start of new option if (/^$/) { print OUT ".TP 10\n"; $optstart = 1; next; } # If a line contains text that is not in <>, read subsequent lines of the # same form, so that we get whole sentences for matching on references. if (/^ (?> (<[^>]+>)* ) \s*\S/x) { while ($next =~ /^ (?> (<[^>]+>)* ) \s*\S/x) { $_ .= $next; $next = ; } } # Remove sentences or parenthetical comments that refer to chapters or # sections. The order of these changes is very important: # # (1) Remove any parenthetical comments first. # (2) Then remove any sentences that start after a full stop. # (3) Then remove any sentences that start at the beginning or a newline. s/\s?\( [^()]+ \)//xg; s/\s?\. [^.]+ [^.]*? \././xg; s/(^|\n) [^.]+ [^.]*? \./$1/xg; # Handle paragraph starts; skip the first one encountered for an option if ($optstart && /<(sim)?para>/) { s/<(sim)?para>//; $optstart = 0; } # Literal layout needs to be treated as a paragraph, and indented if (/]*>/.P/; $indent = " "; } $indent = "" if (/<\/literallayout>/); # Others get marked s//.P/; s//.P/; # Skip index entries s/.*?<\/primary>//g; s/.*?<\/secondary>//g; # Convert all occurrences of backslash into \e s/\\/\\e/g; # Handle bold and italic s//\\fI/g; s//\\fB/g; s/<\/emphasis>/\\fP/g; s/