David,
I got rid of a lot of redundancy. This is so short and sweet, I think
it will be easy for you to follow. This replaces the one FN in the
code I sent earlier.
I notice this omits the check for uppercase. It will only match words
with the same capitalization. Do you need the extra check?
e-e
=J= a y
"
local
dim as ptr p1, p2, c1, c2, end1, end2
local fn matchFiles( file1H as long, file2H as long, delim )
' Jay Reeve, May 2006
'~'9
dim L
p1 = [ file1H ] : p2 = [ file2H ]
end1 = p1 + fn gethandlesize( file1H ) - 2
end2 = p2 + fn gethandlesize( file2H ) - 2
while ( p1 < end1 ) and ( p2 < end2 )
'We're at the beginning of a line in both files
c1 = p1 : c2 = p2 ' Start comparing chars here
while c1.0`` == c2.0`` ' Check for match
long if c1.0`` == delim
' MATCH FOUND -- Make a record of it
gMatches.offset1( gMatchCount ) = p1 - [ file1H ]
gMatches.offset2( gMatchCount ) = p2 - [ file2H ]
gMatches.wordLen( gMatchCount ) = c1 - p1
gMatchCount ++
exit while
end if
c1 ++ : c2 ++
wend
/* If a match was found, c1 & c2 both point to delims,
so we'll get next line for both files.
If no match, c1 & c2 point to the first char that's different.
we'll get the next line for whichever points to the smaller
char . */
if c2.0`` <= c1.0`` then p2 = fn nextLine( c2, end2 )
if c1.0`` <= c2.0`` then p1 = fn nextLine( c1, end1 )
wend
end fn