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