A read through that page indicates matchinfo(offset)
would be most appropriate.
If you have
scanmatch $scanContext "some pattern" {nextLines 5 $fileName $matchinfo(offset)}
So nextLines
could perhaps return the next number of lines. The magic here is the seek
command to jump right to the line that matched.
proc nextLines {numLines fileName offset} {
set fid [open $fileName r]
seek $fid $offset
for {set i 0} {$i < $numLines} {incr i} {
if {[gets $fid line] == -1} break
lappend lines $line
}
close $fid
return $lines
}
You could experiment by passing $matchinfo(handle)
instead of the filename, and reading the next few lines directly (without having to seek). However I don't know how scanfile will react if the position into the file is changed by some other code.
Just did some quick experimentation, and scanfile is not bothered if you read ahead in the scanmatch code. scanfile will pick up at the new location in the file. This would be similar to using getline
in awk code.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…