/usr/share/linuxdoc-tools/fmt/fmt_html.pl is in linuxdoc-tools 0.9.72-4build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | #
# fmt_html.pl
#
# -----------------------------------------------------------------
# HTML-specific driver stuff
#
# Copyright © 1996, Cees de Groot
# Copyright © 2008, Agustin Martin (Minor changes)
# -----------------------------------------------------------------
package LinuxDocTools::fmt_html;
use strict;
use LinuxDocTools::CharEnts;
use LinuxDocTools::Vars;
use LinuxDocTools::FixRef;
my $fixref = $LinuxDocTools::FixRef::fixref;
use LinuxDocTools::Html2Html;
my $html2html = $LinuxDocTools::Html2Html::html2html;
my $html = {};
$html->{NAME} = "html";
$html->{HELP} = "";
$html->{OPTIONS} = [
{ option => "split",
type => "l",
'values' => [ "0", "1", "2" ],
short => "s" },
{ option => "toc",
type => "l",
'values' => [ "0", "1", "2" ],
short => "T" },
{ option => "dosnames",
type => "f",
short => "h" },
{ option => "imagebuttons",
type => "f",
short => "I"},
{ option => "header",
type => "s",
short => "H"},
{ option => "footer",
type => "s",
short => "F"}
];
$html->{'split'} = 1;
$html->{'toc'} = -1;
$html->{dosnames} = 0;
$html->{imagebuttons} = 0;
$html->{header} = "";
$html->{footer} = "";
$Formats{$html->{NAME}} = $html;
# -----------------------------------------------------------------
$html->{preNSGMLS} = sub {
# -----------------------------------------------------------------
$global->{NsgmlsOpts} .= " -ifmthtml ";
$global->{NsgmlsPrePipe} = "cat $global->{file}";
};
# -----------------------------------------------------------------
my $html_escape = sub {
# -----------------------------------------------------------------
# HTML escape sub. Called-back by `parse_data' below in `html_preASP'
# to properly escape `<' and `&' characters coming from the SGML source.
# -----------------------------------------------------------------
my ($data) = @_;
my %html_escapes = ( '&' => '&',
'<' => '<');
# Replace the char with it's HTML equivalent
$data =~ s|([&<])|$html_escapes{$1}|ge;
return ($data);
};
# -----------------------------------------------------------------
$html->{preASP} = sub {
# -----------------------------------------------------------------
# Translate character entities and escape HTML special chars.
# -----------------------------------------------------------------
my ($infile, $outfile) = @_;
my $inheading = '';
# `sdata_dirs' list is passed as anonymous array to make a single argument
my $char_maps = load_char_maps ('.2html', [ Text::EntityMap::sdata_dirs() ]);
while (<$infile>){
if (s/^-//){
chomp;
s/([^\\])\\n/$1 /g if $inheading; # Remove spurious \n in headings
print $outfile "-" . parse_data ($_, $char_maps, $html_escape) . "\n";
} elsif (/^A/){
/^A(\S+) (IMPLIED|CDATA|NOTATION|ENTITY|TOKEN)( (.*))?$/
|| die "bad attribute data: $_\n";
my ($name,$type,$value) = ($1,$2,$4);
if ($type eq "CDATA"){
# CDATA attributes get translated also
$value = parse_data ($value, $char_maps, $html_escape);
}
print $outfile "A$name $type $value\n";
} else {
if (/^\(HEADING/){
$inheading = 1;
} elsif (/^\)HEADING/){
$inheading = '';
}
print $outfile $_;
}
}
return 0;
};
# -----------------------------------------------------------------
$html->{postASP} = sub {
# -----------------------------------------------------------------
# Take the sgmlsasp output, and make something useful from it.
# -----------------------------------------------------------------
my $infile = shift;
my $filename = $global->{filename};
# Set various stuff as a result of option processing.
my $ext = $html->{dosnames} ? "htm" : "html";
my $img = $html->{imagebuttons} ? 1 : 0;
# Bring in file
my @file = <$infile>;
# Find references
&{$fixref->{init}}($html->{'split'});
LINE: foreach (@file) {
foreach my $pat (keys %{$fixref->{rules}}) {
if (/$pat/) {
# Call rule function then skip to next line
&{$fixref->{rules}->{$pat}}; next LINE;
}
}
&{$fixref->{defaultrule}};
}
&{$fixref->{finish}};
#
# Run through html2html, preserving stdout
# Also, handle prehtml.sed's tasks
#
my $filter = "";
# $filter = "|$main::progs->{NKF} -e" if ($global->{language} eq "ja");
open SAVEOUT, ">&STDOUT";
open STDOUT, "$filter>$filename.$ext" or die qq(Cannot open "$filename.$ext");
&{$html2html->{init}}($html->{'split'}, $ext, $img, $filename,
$fixref->{filenum}, $fixref->{lrec},
$html->{'header'}, $html->{'footer'}, $html->{'toc'},
$global->{tmpbase}, $global->{debug});
LINE: foreach (@file) {
s,<P></P>,,g; # remove empty <P></P> containers
foreach my $pat (keys %{$html2html->{rules}}) {
if (/$pat/) {
# Call rule function then skip to next line
&{$html2html->{rules}->{$pat}}; next LINE;
}
}
&{$html2html->{defaultrule}};
}
&{$html2html->{finish}};
close STDOUT;
open STDOUT, ">&SAVEOUT";
return 0;
};
1;
|