diff options
-rwxr-xr-x | httpd/cgi-bin/check | 69 |
1 files changed, 14 insertions, 55 deletions
diff --git a/httpd/cgi-bin/check b/httpd/cgi-bin/check index 0355d9b..3befcfd 100755 --- a/httpd/cgi-bin/check +++ b/httpd/cgi-bin/check @@ -14,7 +14,7 @@ # This source code is available under the license at: # http://www.w3.org/Consortium/Legal/copyright-software # -# $Id: check,v 1.707 2009-10-04 20:42:01 ville Exp $ +# $Id: check,v 1.708 2009-10-04 20:43:29 ville Exp $ # # Disable buffering on STDOUT! $| = 1; @@ -208,7 +208,7 @@ Directory not readable (permission denied): @_r # # Strings - $VERSION = q$Revision: 1.707 $; + $VERSION = q$Revision: 1.708 $; $VERSION =~ s/Revision: ([\d\.]+) /$1/; # @@ -2185,66 +2185,25 @@ sub report_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(). +# Expects 1-based column indexes. sub mark_error ($$) { my $line = shift; my $col = shift; + my $linelen = length($line); - # - # Left side... - my $left; - { - my $offset = 0; # Left side always 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-1; - } - $left = substr $line, $offset, $length; + # Coerce column into an index valid within the line. + if ($col < 1) { + $col = 1; + } elsif ($col > $linelen) { + $col = $linelen; } + $col--; - # - # 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-1; # 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; # 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; - } + my $left = substr($line, 0, $col); + my $char = substr($line, $col, 1); + my $right = substr($line, $col + 1); + $char = &ent($char); $char = qq(<strong title="Position where error was detected.">$char</strong>); $line = &ent($left) . $char . &ent($right); |