Hi

I read the instring function, but i couldn?t figure it out how to make it get a specific string on a file outside the main program.

For example, i have a file with the following data inside (let?s call it test.txt):

WM_CLOSE 150
WM_SETTEXT 222
.....

(The values are not exactlly as their equates, it?s just an example)

How can i make the function instring (or another function), search for WM_CLOSE on the external file, and grab it?s value (150) ?

Taking in account that the WM_CLOSE data will be displayed after i load a file through an editor.

For example, loading an asm file in asmedit or in radasm, or in quickeditor. He will display:

.486
.....

call...........

.if WM_CLOSE == 0
...

Then when i right click on the word (WM_CLOSE) it display a messagebox showing The equate name and it?s value ?


It has necessarily to create an database inside the main asm file, like:

equatelist db "WM_CLOSE, WM_SETTEXT...."

Or it?s better checking the WM_CLOSE only when the cursor is over the text ? (I mean then, he will search for the first space betwen and the first after, and on the middle is the word to be checked, and then point to the external file to grab it?s value ?

I need a fast and more reliabale way to do this, because the target file (text.txt) can be very big, so when searching, the less amount of memory used to do that, the better.


Regards

Beyond2000!
Posted on 2002-08-15 14:35:41 by Beyond2000!
If you want to use Instring, just read the file into memory. Then just pass the memory block to InString and treat the file as one big long string (cause, that's all it really is).

However, if you're going for performance I would probably do something like this:

--When you load the file, parse it for all values and build a table of pointers to the substrings.
--Sort the table of substrings pointers alphabetically
--Every time you want a word checked, use a simple binary search to find the appropriate string.
--Parse out the numeric value

--Chorus
Posted on 2002-08-15 16:25:41 by chorus
Tks chorus

yes, i.m looking for performance.

Can you post an example on how to make the parsing based on a external file ?



regards

Beyond2000!
Posted on 2002-08-15 16:49:08 by Beyond2000!
Well, unfortunately, I don't have one handy.

I imagine it would go something like this though:




invoke CreateFile,addr YourFileName,...
mov hFile,eax
invoke GetProcessHeap
mov hHeap,eax
invoke GetFileSize,hFile,NULL
mov dwFileSize,eax
invoke HeapAlloc,hHeap,HEAP_ZERO_MEMORY,[eax+1]
mov pMemory,eax
invoke ReadFile,hFile,pMemory,dwFileSize,addr BytesRead,NULL
invoke CloseHandle,hFile

;allocate a table of dwords
;scan file for strings and add pointers to table
;sort the table

;write a proc accepting a pointer to a string value
;that scans through the pointer table for a matching
;string. Use a good search routine because the table
;should be sorted

;etc.
;etc.



--Chorus
Posted on 2002-08-15 17:28:28 by chorus
Number one, don't use InString for searching binary filkes, it is designed to search text that is zero terminated only, use a normal byte scanner that specifies the length of both the source and the pattern you are searching for.

Find out what the exact byte sequence is for the message you want to find, then search for that byte sequence, it should be a DWORD size number and it will be in the Windows.inc file. Remember that the number will be in reverse order in memory .

Regards,

hutch@movsd.com
Posted on 2002-08-15 21:44:33 by hutch--
hutch--, I don't believe he is searching a binary file. I believe he is searching a text file. Like a grocery list with prices next to each item, separated by new lines. At least, that's what I'm gathering from his original email.

--Chorus
Posted on 2002-08-15 22:23:55 by chorus
Hi Hutch

yes, Chorus is right. I'm looking for text searching and not binary.

I just want to separate the text as different blocks, like in a database, but for text.

I'm assuming that 150 as string not binary number.

The target file is the following style.

text1 (space) text2
....
Posted on 2002-08-15 23:08:12 by Beyond2000!
OK,

I think I get what you are doing, have a look at the Boyer Moore algos in version 7 of MASM32 as they are well suited for doing this type of search and are faster than byte scanners. Same stuff, you will have to set both lengths of the source and pattern (WM_CLOSE etc ..) but for repeated searching the same string, the BM algos should be very fast.

Regards,

hutch@movsd.com
Posted on 2002-08-16 01:02:39 by hutch--