- From: Terje Bless <link@hutz.w3.org>
- Date: Fri, 21 May 2004 15:42:53 +0000
- To: www-validator-cvs@w3.org
Update of /sources/public/validator/httpd/cgi-bin In directory hutz:/tmp/cvs-serv12819 Modified Files: check Log Message: Sub()routine-ize line splitting (and some minor reindent). Index: check =================================================================== RCS file: /sources/public/validator/httpd/cgi-bin/check,v retrieving revision 1.329 retrieving revision 1.330 diff -u -d -r1.329 -r1.330 --- check 11 May 2004 17:48:21 -0000 1.329 +++ check 21 May 2004 15:42:50 -0000 1.330 @@ -1455,9 +1455,6 @@ if ($err->{type} eq 'E' or $err->{type} eq 'X' or $err->{type} eq 'Q') { $err->{msg} = join ':', @errors[6 .. $#errors]; } elsif ($err->{type} eq 'W') { - &add_warning($File, 'fake', 'Warning:', - "Line $err->{line}, column $err->{char}: $errors[6]", - ); $err->{msg} = join ':', @errors[6 .. $#errors]; } else { $err->{type} = 'I'; @@ -1506,10 +1503,12 @@ a DOCTYPE</a>". </p> .EOF. - } - else { - $message .= <<".EOF."; - <p>So what should I do? <a href="docs/help.html#faq-doctype">Tell me more...</a></p> + } else { + $message .= <<".EOF."; + <p> + So what should I do? + <a href="docs/help.html#faq-doctype">Tell me more...</a> + </p> .EOF. } &add_warning($File, $class, $title, $message); @@ -1541,72 +1540,7 @@ my $adjcol = $col; #DEBUG; - # - # Chop the source line into 3 pieces; the character at which the error - # was detected, and everything to the left and right of that position. - # That way we can add markup to the relevant char without breaking &ent(). - # - - # - # Left side... - my $left; - { - my $offset = 0; # Left side allways starts at 0. - my $length; - - if ($col - 1 < 0) { # If error is at start of line... - $length = 0; # ...floor to 0 (no negative offset). - } elsif ($col == length $line) { # If error is at EOL... - $length = $col - 1; # ...leave last char to indicate position. - } else { # Otherwise grab everything up to pos of error. - $length = $col; - } - $left = substr $line, $offset, $length; - $left = &ent($left); - } - - # - # The character where the error was detected. - my $char; - { - my $offset; - my $length = 1; # Length is always 1; the char where error was found. - - if ($col == length $line) { # If err is at EOL... - $offset = $col - 1; # ...then grab last char on line instead. - } else { - $offset = $col; # Otherwise just grab the char. - } - $char = substr $line, $offset, $length; - $char = &ent($char); - } - - # - # The right side up to the end of the line... - my $right; - { - my $offset; - my $length; - - # Offset... - if ($col == length $line) { # If at EOL... - $offset = 0; # Don't bother as there is nothing left to grab. - } else { - $offset = $col + 1; # Otherwise get everything from char-after-error. - } - - # Length... - if ($col == length $line) { # If at end of line... - $length = 0; # ...then don't grab anything. - } else { - $length = length($line) - ($col - 1); # Otherwise get the rest of the line. - } - $right = substr $line, $offset, $length; - $right = &ent($right); - } - - $char = qq(<strong title="Position where error was detected.">$char</strong>); - $line = $left . $char . $right; + $line = &mark_error($line, $col); #DEBUG: Print misc. vars relevant to source display. if ($DEBUG) { @@ -1614,10 +1548,10 @@ } #DEBUG; - if (defined $CFG->{Error_to_URI}->{$err->{idx}}) { - $err->{uri} = $CFG->{Msg_FAQ_URI} . '#' - . $CFG->{Error_to_URI}->{$err->{idx}}; - } +# if (defined $CFG->{Error_to_URI}->{$err->{idx}}) { +# $err->{uri} = $CFG->{Msg_FAQ_URI} . '#' +# . $CFG->{Error_to_URI}->{$err->{idx}}; +# } $err->{src} = $line; $err->{col} = ' ' x $col; @@ -1627,6 +1561,78 @@ return $Errors; } +# +# Chop the source line into 3 pieces; the character at which the error +# was detected, and everything to the left and right of that position. +# That way we can add markup to the relevant char without breaking &ent(). +sub mark_error (\$\$) { + my $line = shift; + my $col = shift; + + # + # Left side... + my $left; + { + my $offset = 0; # Left side allways starts at 0. + my $length; + + if ($col - 1 < 0) { # If error is at start of line... + $length = 0; # ...floor to 0 (no negative offset). + } elsif ($col == length $line) { # If error is at EOL... + $length = $col - 1; # ...leave last char to indicate position. + } else { # Otherwise grab everything up to pos of error. + $length = $col; + } + $left = substr $line, $offset, $length; + $left = &ent($left); + } + + # + # The character where the error was detected. + my $char; + { + my $offset; + my $length = 1; # Length is always 1; the char where error was found. + + if ($col == length $line) { # If err is at EOL... + $offset = $col - 1; # ...then grab last char on line instead. + } else { + $offset = $col; # Otherwise just grab the char. + } + $char = substr $line, $offset, $length; + $char = &ent($char); + } + + # + # The right side up to the end of the line... + my $right; + { + my $offset; + my $length; + + # Offset... + if ($col == length $line) { # If at EOL... + $offset = 0; # Don't bother as there is nothing left to grab. + } else { + $offset = $col + 1; # Otherwise get everything from char-after-error. + } + + # Length... + if ($col == length $line) { # If at end of line... + $length = 0; # ...then don't grab anything. + } else { + $length = length($line) - ($col - 1); # Otherwise get the rest of the line. + } + $right = substr $line, $offset, $length; + $right = &ent($right); + } + + $char = qq(<strong title="Position where error was detected.">$char</strong>); + $line = $left . $char . $right; + + return $line; +} + # # Produce an outline of the document based on Hn elements from the ESIS.
Received on Friday, 21 May 2004 11:45:21 UTC