Page 1 of 1
Posted: Thu Oct 31, 2002 2:24 pm
by BackupUser
Restored from previous forum. Originally posted by Harry.
Hi,
maybe a newbie question.
I want to parse a file for count the occurences of a specific HEX pattern, i. e. X'5A xx yy D3 A8 AF', where xx and yy can be any hex value. How can I do this?
Thanx, Harry
Posted: Thu Oct 31, 2002 3:05 pm
by BackupUser
Restored from previous forum. Originally posted by fweil.
Hello Harry,
You will open your file and read each line, using something like :
... set your pattern to match in YourPattern.s
... set your file name to parse in YourFile.s
If readFile(0, YourFile)
Repeat
a$ = ReadString()
If FindString(a$, YourPattern, 1) 0
Count + 1
EndIf
Until Eof(0)
CloseFile(0)
EndIf
Allright, I am assuming your file is a text file.
If it is not the case, you will not use ReadString() but ReadByte() for example and test each byte. Or maybe you will use a buffer and ReadData().
Does it help ?
Francois Weil
14, rue Douer
F64100 Bayonne
Posted: Thu Oct 31, 2002 6:05 pm
by BackupUser
Restored from previous forum. Originally posted by Justin.
I have faced this problem some times, let's say you have a 1MB ascii or binary file and you want to parse it.
The options with PB are reading line by line or peeking bytes, this can be very very slow.
So we need a function that searches a buffer for a string and returns the address of the string or -1 if not fouund, first we read the file into a buffer, something like:
Memoryfind(bufferaddres,string,mode) , where mode is 1/0 case sensitive/insensitive
Then we can use peeks to extract the string an work with it with the string functions if needed.
Here is an asm source that does it, maybe some asm expert can implement it or do a lib with it:
http://www.collakesoftware.com/files/bmstr04.zip