1 |
#!/usr/bin/perl |
#!/usr/bin/perl |
2 |
use strict; |
use strict; |
3 |
|
use utf8; |
4 |
|
|
5 |
use lib qw[/home/httpd/html/www/markup/html/whatpm |
use lib qw[/home/httpd/html/www/markup/html/whatpm |
6 |
/home/wakaba/work/manakai2/lib]; |
/home/wakaba/work/manakai2/lib]; |
110 |
print_source_string_section (\($input->{s}), 'utf-8'); |
print_source_string_section (\($input->{s}), 'utf-8'); |
111 |
} else { |
} else { |
112 |
## TODO: Change HTTP status code?? |
## TODO: Change HTTP status code?? |
113 |
print_result_unknown_type_section ($input); |
print_result_unknown_type_section ($input, $result); |
114 |
} |
} |
115 |
|
|
116 |
if (defined $doc or defined $el) { |
if (defined $doc or defined $el) { |
143 |
</html> |
</html> |
144 |
]; |
]; |
145 |
|
|
146 |
for (qw/decode parse parse_xml parse_manifest check check_manifest/) { |
for (qw/decode parse parse_html parse_xml parse_manifest |
147 |
|
check check_manifest/) { |
148 |
next unless defined $time{$_}; |
next unless defined $time{$_}; |
149 |
open my $file, '>>', ".cc-$_.txt" or die ".cc-$_.txt: $!"; |
open my $file, '>>', ".cc-$_.txt" or die ".cc-$_.txt: $!"; |
150 |
print $file $char_length, "\t", $time{$_}, "\n"; |
print $file $char_length, "\t", $time{$_}, "\n"; |
219 |
|
|
220 |
require Encode; |
require Encode; |
221 |
require Whatpm::HTML; |
require Whatpm::HTML; |
|
|
|
|
$input->{charset} ||= 'ISO-8859-1'; ## TODO: for now. |
|
222 |
|
|
|
my $time1 = time; |
|
|
my $t = Encode::decode ($input->{charset}, $input->{s}); |
|
|
$time{decode} = time - $time1; |
|
|
|
|
223 |
print STDOUT qq[ |
print STDOUT qq[ |
224 |
<div id="parse-errors" class="section"> |
<div id="parse-errors" class="section"> |
225 |
<h2>Parse Errors</h2> |
<h2>Parse Errors</h2> |
239 |
$type =~ tr/ /-/; |
$type =~ tr/ /-/; |
240 |
$type =~ s/\|/%7C/g; |
$type =~ s/\|/%7C/g; |
241 |
$msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; |
$msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; |
242 |
print STDOUT qq[<dd class="$cls">$msg</dd>\n]; |
print STDOUT qq[<dd class="$cls">], get_error_level_label (\%opt); |
243 |
|
print STDOUT qq[$msg</dd>\n]; |
244 |
|
|
245 |
add_error ('syntax', \%opt => $result); |
add_error ('syntax', \%opt => $result); |
246 |
}; |
}; |
247 |
|
|
248 |
my $doc = $dom->create_document; |
my $doc = $dom->create_document; |
249 |
my $el; |
my $el; |
|
$time1 = time; |
|
250 |
if (defined $inner_html_element and length $inner_html_element) { |
if (defined $inner_html_element and length $inner_html_element) { |
251 |
|
$input->{charset} ||= 'ISO-8859-1'; ## TODO: for now. |
252 |
|
my $time1 = time; |
253 |
|
my $t = Encode::decode ($input->{charset}, $input->{s}); |
254 |
|
$time{decode} = time - $time1; |
255 |
|
|
256 |
$el = $doc->create_element_ns |
$el = $doc->create_element_ns |
257 |
('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]); |
('http://www.w3.org/1999/xhtml', [undef, $inner_html_element]); |
258 |
|
$time1 = time; |
259 |
Whatpm::HTML->set_inner_html ($el, $t, $onerror); |
Whatpm::HTML->set_inner_html ($el, $t, $onerror); |
260 |
|
$time{parse} = time - $time1; |
261 |
} else { |
} else { |
262 |
Whatpm::HTML->parse_string ($t => $doc, $onerror); |
my $time1 = time; |
263 |
|
Whatpm::HTML->parse_byte_string |
264 |
|
($input->{charset}, $input->{s} => $doc, $onerror); |
265 |
|
$time{parse_html} = time - $time1; |
266 |
} |
} |
267 |
$time{parse} = time - $time1; |
|
|
|
|
268 |
print STDOUT qq[</dl></div>]; |
print STDOUT qq[</dl></div>]; |
269 |
|
|
270 |
return ($doc, $el); |
return ($doc, $el); |
329 |
$type =~ tr/ /-/; |
$type =~ tr/ /-/; |
330 |
$type =~ s/\|/%7C/g; |
$type =~ s/\|/%7C/g; |
331 |
$msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; |
$msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; |
332 |
print STDOUT qq[<dd class="$cls">$msg</dd>\n]; |
print STDOUT qq[<dd class="$cls">], get_error_level_label (\%opt); |
333 |
|
print STDOUT qq[$msg</dd>\n]; |
334 |
|
|
335 |
add_error ('syntax', \%opt => $result); |
add_error ('syntax', \%opt => $result); |
336 |
}; |
}; |
512 |
$type =~ s/\|/%7C/g; |
$type =~ s/\|/%7C/g; |
513 |
$msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; |
$msg .= qq[ [<a href="../error-description#@{[htescape ($type)]}">Description</a>]]; |
514 |
print STDOUT qq[<dt class="$cls">] . get_error_label (\%opt) . |
print STDOUT qq[<dt class="$cls">] . get_error_label (\%opt) . |
515 |
qq[</dt>\n<dd class="$cls">], $msg, "</dd>\n"; |
qq[</dt>\n<dd class="$cls">], get_error_level_label (\%opt); |
516 |
|
print STDOUT $msg, "</dd>\n"; |
517 |
add_error ('structure', \%opt => $result); |
add_error ('structure', \%opt => $result); |
518 |
}; |
}; |
519 |
|
|
698 |
print STDOUT qq[<table> |
print STDOUT qq[<table> |
699 |
<colgroup><col><colgroup><col><col><col><colgroup><col> |
<colgroup><col><colgroup><col><col><col><colgroup><col> |
700 |
<thead> |
<thead> |
701 |
<tr><th scope=col></th><th scope=col><em class=rfc2119>MUST</em>-level |
<tr><th scope=col></th> |
702 |
Errors</th><th scope=col><em class=rfc2119>SHOULD</em>-level |
<th scope=col><a href="../error-description#level-m"><em class=rfc2119>MUST</em>‐level |
703 |
Errors</th><th scope=col>Warnings</th><th scope=col>Score</th></tr> |
Errors</a></th> |
704 |
</thead><tbody>]; |
<th scope=col><a href="../error-description#level-s"><em class=rfc2119>SHOULD</em>‐level |
705 |
|
Errors</a></th> |
706 |
|
<th scope=col><a href="../error-description#level-w">Warnings</a></th> |
707 |
|
<th scope=col>Score</th></tr></thead><tbody>]; |
708 |
|
|
709 |
my $must_error = 0; |
my $must_error = 0; |
710 |
my $should_error = 0; |
my $should_error = 0; |
762 |
push @nav, ['#result-summary' => 'Result']; |
push @nav, ['#result-summary' => 'Result']; |
763 |
} # print_result_section |
} # print_result_section |
764 |
|
|
765 |
sub print_result_unknown_type_section ($) { |
sub print_result_unknown_type_section ($$) { |
766 |
my $input = shift; |
my ($input, $result) = @_; |
767 |
|
|
768 |
|
my $euri = htescape ($input->{uri}); |
769 |
print STDOUT qq[ |
print STDOUT qq[ |
770 |
<div id="result-summary" class="section"> |
<div id="parse-errors" class="section"> |
771 |
<p><em>Media type <code class="MIME" lang="en">@{[htescape $input->{media_type}]}</code> is not supported!</em></p> |
<h2>Errors</h2> |
772 |
|
|
773 |
|
<dl> |
774 |
|
<dt class=unsupported><code><<a href="$euri">$euri</a>></code></dt> |
775 |
|
<dd class=unsupported><strong><a href="../error-description#level-u">Not |
776 |
|
supported</a></strong>: |
777 |
|
Media type |
778 |
|
<code class="MIME" lang="en">@{[htescape $input->{media_type}]}</code> |
779 |
|
is not supported.</dd> |
780 |
|
</dl> |
781 |
</div> |
</div> |
782 |
]; |
]; |
783 |
push @nav, ['#result-summary' => 'Result']; |
push @nav, ['#parse-errors' => 'Errors']; |
784 |
|
add_error (char => {level => 'unsupported'} => $result); |
785 |
|
add_error (syntax => {level => 'unsupported'} => $result); |
786 |
|
add_error (structure => {level => 'unsupported'} => $result); |
787 |
} # print_result_unknown_type_section |
} # print_result_unknown_type_section |
788 |
|
|
789 |
sub print_result_input_error_section ($) { |
sub print_result_input_error_section ($) { |
810 |
|
|
811 |
if (defined $err->{node}) { |
if (defined $err->{node}) { |
812 |
$r .= ' ' if length $r; |
$r .= ' ' if length $r; |
813 |
$r = get_node_path ($err->{node}); |
$r = get_node_link ($err->{node}); |
814 |
} |
} |
815 |
|
|
816 |
if (defined $err->{index}) { |
if (defined $err->{index}) { |
826 |
return $r; |
return $r; |
827 |
} # get_error_label |
} # get_error_label |
828 |
|
|
829 |
|
sub get_error_level_label ($) { |
830 |
|
my $err = shift; |
831 |
|
|
832 |
|
my $r = ''; |
833 |
|
|
834 |
|
if (not defined $err->{level} or $err->{level} eq 'm') { |
835 |
|
$r = qq[<strong><a href="../error-description#level-m"><em class=rfc2119>MUST</em>‐level |
836 |
|
error</a></strong>: ]; |
837 |
|
} elsif ($err->{level} eq 's') { |
838 |
|
$r = qq[<strong><a href="../error-description#level-s"><em class=rfc2119>SHOULD</em>‐level |
839 |
|
error</a></strong>: ]; |
840 |
|
} elsif ($err->{level} eq 'w') { |
841 |
|
$r = qq[<strong><a href="../error-description#level-w">Warning</a></strong>: |
842 |
|
]; |
843 |
|
} elsif ($err->{level} eq 'unsupported') { |
844 |
|
$r = qq[<strong><a href="../error-description#level-u">Not |
845 |
|
supported</a></strong>: ]; |
846 |
|
} else { |
847 |
|
my $elevel = htescape ($err->{level}); |
848 |
|
$r = qq[<strong><a href="../error-description#level-$elevel">$elevel</a></strong>: |
849 |
|
]; |
850 |
|
} |
851 |
|
|
852 |
|
return $r; |
853 |
|
} # get_error_level_label |
854 |
|
|
855 |
sub get_node_path ($) { |
sub get_node_path ($) { |
856 |
my $node = shift; |
my $node = shift; |
857 |
my @r; |
my @r; |