--- test/html-webhacc/cc.cgi 2007/06/30 14:51:10 1.6 +++ test/html-webhacc/cc.cgi 2007/07/01 10:02:24 1.8 @@ -23,6 +23,11 @@ ## TODO: _charset_ + if ($http->meta_variable ('PATH_INFO') ne '/') { + print STDOUT "Status: 404 Not Found\nContent-Type: text/plain; charset=us-ascii\n\n400"; + exit; + } + my $input_format = $http->parameter ('i') || 'text/html'; my $inner_html_element = $http->parameter ('e'); my $input_uri = 'thismessage:/'; @@ -33,6 +38,8 @@ exit; } + load_text_catalog ('en'); ## TODO: conneg + my @nav; print STDOUT qq[Content-Type: text/html; charset=utf-8 @@ -88,13 +95,17 @@ my $onerror = sub { my (%opt) = @_; + my ($cls, $msg) = get_text ($opt{type}, $opt{level}); if ($opt{column} > 0) { - print STDOUT qq[
Line $opt{line} column $opt{column}
\n]; + print STDOUT qq[
Line $opt{line} column $opt{column}
\n]; } else { - $opt{line}--; - print STDOUT qq[
Line $opt{line}
\n]; + $opt{line} = $opt{line} - 1 || 1; + print STDOUT qq[
Line $opt{line}
\n]; } - print STDOUT qq[
@{[htescape $opt{type}]}
\n]; + $opt{type} =~ tr/ /-/; + $opt{type} =~ s/\|/%7C/g; + $msg .= qq[ [Description]]; + print STDOUT qq[
$msg
\n]; }; $doc = $dom->create_document; @@ -133,8 +144,7 @@

Parse Errors

-
-]; +
]; push @nav, ['#parse-errors' => 'Parse Error']; my $onerror = sub { @@ -150,8 +160,7 @@ $doc = Message::DOM::XMLParserTemp->parse_byte_stream ($fh => $dom, $onerror, charset => 'utf-8'); - print STDOUT qq[ -
+ print STDOUT qq[
]; } else { @@ -182,15 +191,19 @@

Document Errors

-
-]; +
]; push @nav, ['#document-errors' => 'Document Error']; require Whatpm::ContentChecker; my $onerror = sub { my %opt = @_; - print STDOUT qq[
] . get_node_link ($opt{node}) . - "
\n
", htescape $opt{type}, "
\n"; + my ($cls, $msg) = get_text ($opt{type}, $opt{level}); + $opt{type} = $opt{level} . ':' . $opt{type} if defined $opt{level}; + $opt{type} =~ tr/ /-/; + $opt{type} =~ s/\|/%7C/g; + $msg .= qq[ [Description]]; + print STDOUT qq[
] . get_node_link ($opt{node}) . + qq[
\n
], $msg, "
\n"; }; my $elements; @@ -200,8 +213,7 @@ $elements = Whatpm::ContentChecker->check_document ($doc, $onerror); } - print STDOUT qq[ -
+ print STDOUT qq[
]; @@ -295,12 +307,16 @@ my $s = $_[0]; my $i = 1; print STDOUT qq[
    \n]; - while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) { - print STDOUT qq[
  1. ], htescape $1, "
  2. \n"; - $i++; - } - if ($$s =~ /\G([^\x0A]+)/gc) { - print STDOUT qq[
  3. ], htescape $1, "
  4. \n"; + if (length $$s) { + while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) { + print STDOUT qq[
  5. ], htescape $1, "
  6. \n"; + $i++; + } + if ($$s =~ /\G([^\x0A]+)/gc) { + print STDOUT qq[
  7. ], htescape $1, "
  8. \n"; + } + } else { + print STDOUT q[
  9. ]; } print STDOUT "
"; } # print_input_string @@ -334,7 +350,7 @@ $r .= ''; } - if ($node->has_child_nodes) { + if ($child->has_child_nodes) { $r .= '
    '; unshift @node, @{$child->child_nodes}, '
'; } else { @@ -348,8 +364,12 @@ $r .= qq'
  • <!--' . htescape ($child->data) . '-->
  • '; } elsif ($nt == $child->DOCUMENT_NODE) { $r .= qq'
  • Document'; + $r .= qq[]; if ($child->has_child_nodes) { - $r .= '
      '; + $r .= '
        '; unshift @node, @{$child->child_nodes}, '
      '; } } elsif ($nt == $child->DOCUMENT_TYPE_NODE) { @@ -400,6 +420,40 @@ htescape (get_node_path ($_[0])) . qq[]; } # get_node_link +{ + my $Msg = {}; + +sub load_text_catalog ($) { + my $lang = shift; # MUST be a canonical lang name + open my $file, '<', "cc-msg.$lang.txt" or die "$0: cc-msg.$lang.txt: $!"; + while (<$file>) { + if (s/^([^;]+);([^;]*);//) { + my ($type, $cls, $msg) = ($1, $2, $_); + $msg =~ tr/\x0D\x0A//d; + $Msg->{$type} = [$cls, $msg]; + } + } +} # load_text_catalog + +sub get_text ($) { + my ($type, $level) = @_; + $type = $level . ':' . $type if defined $level; + my @arg; + { + if (defined $Msg->{$type}) { + my $msg = $Msg->{$type}->[1]; + $msg =~ s/\$([0-9]+)/defined $arg[$1] ? htescape ($arg[$1]) : '(undef)'/ge; + return ($Msg->{$type}->[0], $msg); + } elsif ($type =~ s/:([^:]*)$//) { + unshift @arg, $1; + redo; + } + } + return ('', htescape ($_[0])); +} # get_text + +} + =head1 AUTHOR Wakaba . @@ -413,4 +467,4 @@ =cut -## $Date: 2007/06/30 14:51:10 $ +## $Date: 2007/07/01 10:02:24 $