1#!/usr/bin/perl 2 3# postconf2html - add HTML paragraphs 4 5# Basic operation: 6# 7# - Process input as text blocks separated by one or more empty 8# (or all whitespace) lines. 9# 10# - Remove text between <!-- and -->; each may be on a different line. 11# 12# - Optionally remove <nroffescape> pass-through requests (unless 13# the -n option is specified). 14# 15# - Don't touch blocks that start with `<' in column zero. 16# 17# The only changes made are: 18# 19# - Emit "<DT><a name="parametername">parametername</a>...</DT><DD>" at 20# the top of each parameter description. 21# 22# All other non-comment input is flagged as an error. 23 24use Getopt::Std; 25 26$opt_h = undef; 27$opt_v = undef; 28$opt_n = undef; 29getopts("hnv"); 30 31die "Usage: $0 [-nv]\n" if ($opt_h); 32 33#push @ARGV, "/dev/null"; # XXX 34 35while(<>) { 36 37 # Skip comments. 38 next if /^#/; 39 40 # Skip blank lines before text block. 41 next unless (/\S/); 42 43 # Gobble up the next text block. 44 $block = ""; 45 $comment = 0; 46 do { 47 $_ =~ s/\s+\n$/\n/; 48 $block .= $_; 49 if ($_ =~ /<!--/) 50 { $comment = 1; } 51 if ($comment && $_ =~ /-->/) 52 { $comment = 0; $block =~ s/<!--.*-->//sg; } 53 } while((($_ = <>) && /\S/) || $comment); 54 55 # Strip nroff escapes. 56 $block =~ s/<\s*nroffescape[^>]+>//g unless $opt_n; 57 58 # Skip blanks after comment elimination. 59 if ($block =~ /^\s/) { 60 $block =~ s/^\s+//s; 61 next if ($block eq ""); 62 } 63 64 # Don't touch a text block starting with < in column zero. 65 if ($block =~ /^</) { 66 print "$block\n"; 67 } 68 69 # Meta block. Emit upper case tags for html2man. 70 elsif ($block =~ /^%PARAM/) { 71 print "\n</DD>\n\n" if ($param); 72 print "\n<DL>\n\n" if ($need_dl); 73 $need_dl = 0; 74 ($junk, $param, $defval) = split(/\s+/, $block, 3); 75 $defval =~ s/\s+$//s; 76 $defval = "empty" if ($defval eq ""); 77 $defval = "default: $defval" unless ($defval eq "read-only"); 78 print "<DT><b><a name=\"$param\">$param</a>\n($defval)</b></DT><DD>\n\n"; 79 } 80 81 # Meta block. Emit upper case tags for html2man. 82 elsif ($block =~ /^%CLASS/) { 83 print "\n</DD>\n\n" if ($param); 84 print "\n</DL>\n\n" if ($class); 85 $param =""; 86 ($junk, $class, $text) = split(/\s+/, $block, 3); 87 $text =~ s/\s+$//s; 88 print "<H2><a name=\"$class\">$text</a></H2>\n\n"; 89 $need_dl = 1; 90 } 91 92 # Can't happen. 93 else { 94 die "Unrecognized text block:\n$block"; 95 } 96} 97 98print "\n</DD>\n\n" if ($param); 99print "\n</DL>\n\n" if ($class); 100