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