A Textfile like this:

This is test one.
This is test two.
This is test three.

How can I readfile to get one text line("This is test one")
by one time?HOr get one word ("This")

How can I know the eof of text line ?
Sorry my English not well?I
Posted on 2002-06-24 00:53:21 by fox
There are a number of ways of doing this but unless you have truly enormous files, I would be inclined to read it fully into memory and then scan through it from the start to the next CRLF (13,10) copying the data into a seperate buffer, line by line. Then you can sub process it for individual words and write each line back to a file or another buffer.

Regards,

hutch@movsd.com
Posted on 2002-06-24 02:42:22 by hutch--
Thank you very much!
Could you tell me more detail,
such as by windows api (CreateFile,ReadFile,...)
to deal with this problem?
Posted on 2002-06-24 04:38:29 by fox
This is what hutch is saying:
1) use CreateFile to open the file
2) use GetFileSize to get the size of the file
3) use the value returned from step two to allocate a buffer
4) Use ReadFile to read the entire contents into above buffer
5) Do pparsing ojn the buffer in windows a crlf pair indicates the end of a line
Posted on 2002-06-24 06:30:52 by MArtial_Code

This is what hutch is saying:
1) use CreateFile to open the file
2) use GetFileSize to get the size of the file
3) use the value returned from step two to allocate a buffer
4) Use ReadFile to read the entire contents into above buffer
5) Do pparsing ojn the buffer in windows a crlf pair indicates the end of a line


thanks.

invoke CreateFile,ADDR buffer,\
GENERIC_READ or GENERIC_WRITE ,\
FILE_SHARE_READ or FILE_SHARE_WRITE,\
NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,\
NULL
mov hFile,eax
invoke GetFileSize,hFile,0
mov fsize,eax
invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,fsize
mov hMemory,eax
invoke GlobalLock,hMemory
mov pMemory,eax
;invoke ReadFile,hFile,pMemory,fsize,ADDR SizeRead,NULL
invoke ReadFile,hFile,pMemory,4,ADDR SizeRead,NULL

After the four step,How can I show pMemory to MessageBox?
?????
invoke MessageBox, NULL,addr pMemory, addr pMemory, MB_OK
?????

invoke CloseHandle,hFile
invoke GlobalUnlock,pMemory
invoke GlobalFree,hMemory
Posted on 2002-06-25 22:48:28 by fox
pMemory is allready the address of the text read from the file so you don't need to use addr

invoke MessageBox, NULL,pMemory, pMemory, MB_OK 
Posted on 2002-06-26 01:01:45 by Kudos
Thanks.

now read it fully into memory.

invoke ReadFile,hFile,pMemory,fsize,ADDR SizeRead,NULL

Last step.

1)How do I get one byte from pMemory?

2)when I get byte one to byte1 and the next byte to byte2,
is following scan correct?

.IF (byte1== 0dh && byte2 == 0Ah)
...
.ENDIF
Posted on 2002-06-27 00:52:14 by fox
fox,

use the search engine and search for "line input". This will bring up some examples.
When I am back at home, I can post some source if you want me to.

Regards,
bAZiK
Posted on 2002-06-27 00:53:44 by bazik
bAZiK,
Thank you very much.
Post some source ,please!

Regards,
Fox
Posted on 2002-06-27 01:11:21 by fox

bAZiK,
Thank you very much.
Post some source ,please!

Regards,
Fox


Before I post you the solution, you should use the search engine as I suggested and try to find it our yourself:

http://www.asmcommunity.net/board/index.php?topic=523&highlight=line+input

This is the way to go if you want to learn Win32ASM ;)
Posted on 2002-06-27 01:25:13 by bazik
bAZiK,
Thank you very much.
I will try my best to use the search engine,
And find problem out myself.
Posted on 2002-06-27 02:18:18 by fox
Method #1: Reading full file into memory and scanning for CR+LF
Pros: pretty fast
Cons: not good for large files

Method #2: memory mapped files
Pros: as easy as method #1, can handle "larger text files than you'll ever need"
Cons: memory mapped files are slow (slower than direct filereading anyway)

Method #3: processing file in chunks
Pros: pretty fast, can handle any size files, not too bad memory overhead
Cons: more complicated to code, as you need to handle lines that span buffersize.

Method #4: getting one byte at a time
Pros: a bit easier to code than method #3
Cons: slow, even if you buffer the input

...
Any other ideas?
Posted on 2002-06-27 13:14:54 by f0dder