Automatic counting of lines for error reporting

Counting lines in a file is not that expensive operation, so do that on the fly in case precalculated counts are not available.