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