1 1.1 tron #!/usr/bin/perl 2 1.1 tron 3 1.1 tron # postconf2man - convert postconf2html to nroff 4 1.1 tron 5 1.1 tron # Basic operation: 6 1.1 tron # 7 1.1 tron # - Process input as blocks of text separated by one or more empty 8 1.1 tron # (or all whitespace) lines. 9 1.1 tron # 10 1.1.1.4 christos # - Process <nroffescape> pass-through requests for things that this 11 1.1.1.4 christos # script cannot do automatically. 12 1.1.1.4 christos # 13 1.1 tron # Caution: this depends heavily on the postconf2html output format. 14 1.1 tron 15 1.1 tron #use Getopt::Std; 16 1.1 tron 17 1.1 tron #$opt_h = undef; 18 1.1 tron #$opt_v = undef; 19 1.1 tron #getopts("hv"); 20 1.1 tron 21 1.1 tron #die "Usage: $0 [-hv]\n" if ($opt_h); 22 1.1 tron 23 1.1 tron #push @ARGV, "/dev/null"; # XXX 24 1.1 tron 25 1.1 tron while(<>) { 26 1.1 tron 27 1.1 tron # Skip blank lines before text block. 28 1.1 tron next unless (/\S/); 29 1.1 tron 30 1.1 tron # Gobble up the next text block. 31 1.1 tron $block = ""; 32 1.1 tron do { 33 1.1 tron $_ =~ s/\s+\n$/\n/; 34 1.1 tron $block .= $_; 35 1.1 tron } while(($_ = <>) && /\S/); 36 1.1 tron 37 1.1 tron # How the %!#$^@ do I get a backslash substituted into a string? 38 1.1 tron # Even \134 comes out as \e. What brain damage is this? 39 1.1 tron #$block =~ s/\n\./\n\\\&./g; 40 1.1 tron $block =~ s/\n\./\n\134\&./g; 41 1.1.1.5 christos $block =~ s/\n'/\n\134\&'/g; 42 1.1 tron if ($block =~ /<H2>/) { 43 1.1 tron $block =~ s/<H2><a[^>]+>([^<]+)<\/a><\/H2>/\n.SH \1\n/g; 44 1.1 tron $block =~ tr/a-z/A-Z/; 45 1.1 tron } 46 1.1 tron $block =~ s/<DT><b><a[^>]+>([^<]+)<\/a>\n(.*)<\/b><\/DT><DD>/\n.SH \1 \2\n/g; 47 1.1.1.3 tron $block =~ s/<[Aa][ \n]+[Hh][Rr][Ee][Ff]="[^"]+">//g; 48 1.1.1.3 tron $block =~ s/<[Aa][ \n]+[Nn][Aa][Mm][Ee]="[^"]+">//g; 49 1.1 tron $block =~ s/<\/[Aa]>//g; 50 1.1 tron $block =~ s/<\/DD>/\n/g; 51 1.1 tron $block =~ s/<DL>/\n/g; 52 1.1 tron $block =~ s/<\/DL>/\n/g; 53 1.1 tron $block =~ s/\\/\\e/g; 54 1.1 tron $block =~ s/<b>/\\fB/g; 55 1.1 tron $block =~ s/<i>/\\fI/g; 56 1.1 tron $block =~ s/<\/b>/\\fR/g; 57 1.1 tron $block =~ s/<\/i>/\\fR/g; 58 1.1 tron $block =~ s/^(<p(re)?>)/.PP\n\1/ if ($wantpp); 59 1.1 tron $block =~ s/<p> */\n/g; 60 1.1 tron $block =~ s/ *<\/p>/\n/g; 61 1.1.1.6 christos $block =~ s/<pre>/\n.nf\n.na\n/g; 62 1.1.1.6 christos $block =~ s/<\/pre>/\n.fi\n.ad\n/g; 63 1.1 tron $block =~ s/<dl[^>]*>/\n/g; 64 1.1 tron $block =~ s/<ul>/\n/g; 65 1.1 tron #$block =~ s/<\/dl>/\n.PP\n/g; 66 1.1 tron #$block =~ s/<\/ul>/\n.PP\n/g; 67 1.1.1.2 tron $block =~ s/<\/dl>/\n.br\n/g; 68 1.1.1.2 tron $block =~ s/<\/ul>/\n.br\n/g; 69 1.1 tron $block =~ s/<dd>\s*/\n/g; 70 1.1.1.2 tron $block =~ s/<\/dd>/\n.br\n/g; 71 1.1 tron $block =~ s/<li>\s*/\n.IP \\(bu\n/g; 72 1.1 tron $block =~ s/<dt>\s*/\n.IP "/g; 73 1.1 tron $block =~ s/\s*<\/dt>/"/g; 74 1.1 tron $block =~ s/<tt>\s*//g; 75 1.1 tron $block =~ s/\s*<\/tt>//g; 76 1.1.1.4 christos # Munge "-" here, so that we don't screw up ".in -4". 77 1.1.1.4 christos $block =~ s/-/\\-/g; 78 1.1 tron $block =~ s/<blockquote>/\n.sp\n.in +4\n/g; 79 1.1 tron $block =~ s/<\/blockquote>/\n.in -4\n/g; 80 1.1 tron $block =~ s/\n<br>\s*/\n.br\n/g; 81 1.1 tron $block =~ s/<br>\s*/\n.br\n/g; 82 1.1 tron $block =~ s/≤/<=/g; 83 1.1 tron $block =~ s/</</g; 84 1.1 tron $block =~ s/≥/>=/g; 85 1.1 tron $block =~ s/>/>/g; 86 1.1 tron $block =~ s/&/\&/g; 87 1.1.1.3 tron $block =~ s/–/-/g; 88 1.1.1.3 tron $block =~ s/—/-/g; 89 1.1.1.6 christos $block =~ s/<sup>/^/g; 90 1.1.1.6 christos $block =~ s;</sup>;;g; 91 1.1 tron $block =~ s/\s+\n/\n/g; 92 1.1 tron $block =~ s/^\n//g; 93 1.1.1.4 christos $block =~ s/\s*<\s*nroffescape\s+([^ >]+)\s*>\s*/\n\1\n/g; 94 1.1.1.5 christos $block =~ s/([A-Za-z][_a-zA-Z0-9-]*)(\([0-9]\))/\\fB\1\\fR\2/g; 95 1.1 tron print $block; 96 1.1 tron $wantpp = !($block =~ /^\.(SH|IP)/); 97 1.1 tron } 98