This is a follow up to a previous post I made on comparing
two memory buffers. I wanted to write a utility which could
search for a pattern in a file from beginning to end, and
from end to beginning, as desired.
After abandoning the project for some weeks I finally picked
it up again, and decided to do it differently. Instead of
just trying to implement all functionality in one procedure
I now wrote a library with a few routines that are dedicated
to the task of reading a file forward or backward, and
managing the buffer it writes to.
Here's a slightly simplified version of the calling code,
it searches the file from tail to head:
It's no Boyer-Moore string searching... but it works for me.
If anybody would like the library source, just ask.
two memory buffers. I wanted to write a utility which could
search for a pattern in a file from beginning to end, and
from end to beginning, as desired.
After abandoning the project for some weeks I finally picked
it up again, and decided to do it differently. Instead of
just trying to implement all functionality in one procedure
I now wrote a library with a few routines that are dedicated
to the task of reading a file forward or backward, and
managing the buffer it writes to.
Here's a slightly simplified version of the calling code,
it searches the file from tail to head:
Code:
call BUFFER_READFIRST_BACK
jcxz end
lea si,searchpattern+sizeof searchpattern-1
std
lodsb
lp:
repnz scasb
jnz nomatch
cmp cx,sizeof searchpattern-1
jb nomatch
push si
push di
push cx
mov cx,sizeof searchpattern-1
repz cmpsb
pop cx
pop di
pop si
jnz lp
; match found!
inc cx
call BUFFER_GETFILEOFFSET_BACK
jmp end
nomatch:
call BUFFER_READNEXT_BACK
test cx,cx
jnz lp
end:
; no match found.
If anybody would like the library source, just ask.