I need to open a saved newsgroup article and read-in each line, one at a time. What functions would best do this? Thanks, Xtreme
Posted on 2001-03-05 21:32:00 by xtreme
Hi xtreme, I have a small program on my website that is called Fill a Listview with a TXT file and it does nearly the thing you want. It takes a txt file, reads in the complete content and afterwards breaks the buffer down to single lines as strings. Maybe you want to take a look at it? Stefan Normally I would explain how to do it but I have no time anymore because I have to go to school now. Sorry! This message was edited by Stefan Krause, on 3/6/2001 3:01:40 AM
Posted on 2001-03-06 02:52:00 by Stefan Krause
greetings xtreme, I've made a library called GetSeg, it has a function that allows you to parse strings into segments. The function can also parse data loaded from textfiles and it would allow you to read the textfile's contents by line (it only reads and processes 1024 bytes though). There's an example included with the package that demonstrates this. I'll send it to you as soon as I get home :) cheers, DM
Posted on 2001-03-06 23:15:00 by dm
xtreme, The mechanics of what you need to do is to set up a byte read algorithm and scan for the first occurrence of ascii 13. The logic is something like this, Make a spare buffer at least long enough to take the longest string and load its address into EDI. Put your source address into ESI, copy it into EDI until you find the next ascii 13. Do wha you need to do with the data in the buffer in EDI, then inc ESI, reset the buffer address into EDI and do it again until the end occurs. You will need to keep track of the total byte length to get the exit condition. It sounds complicated but it is a reasonably simple algo once you get it going. Regards, hutch@pbq.com.au
Posted on 2001-03-07 03:31:00 by hutch--
This works some. I'm getting single chars from the file and detecting the "\r" but placing the chars in edi is giving me problems...

ReadLine proc

    LOCAL szBuffer[1024]        :BYTE
    LOCAL bTemp[2]              :BYTE
    LOCAL hFile                 :DWORD
    LOCAL dwread                :DWORD

    szText szFilename, "C:\WINDOWS\Desktop\Articles\ART1C2.TMP",0

    mov hFile, eax

    lea edi, szBuffer

    .while TRUE
        invoke ReadFile, hFile, addr bTemp, 1, addr dwread, 0
        mov bTemp[1],0

        mov edi,byte ptr ]      ;DOESN'T WORK
        inc edi

        .break .if byte ptr ] == 13

    invoke MessageBox, 0, addr szBuffer, 0, 0
    invoke CloseHandle,hFile


ReadLine endp
Posted on 2001-03-11 17:34:00 by xtreme
hi, i wrote this from mind so expect some errors... the following procedure should read your file into a mem buffer, then it should read out every line via msgbox.

ReadLine proc
    LOCAL hFile                 :DWORD
    LOCAL dwread                :DWORD

    LOCAL hMemory               :DWORD
    LOCAL buffer                :DWORD

    szText szFilename, "C:\WINDOWS\Desktop\Articles\ART1C2.TMP",0
    caption szFilename, "this msgbox displays single lines from a file",0

;---===open existing file===---

    invoke CreateFile, addr szFilename, GENERIC_READ, NULL, NULL, OPEN_EXISTING,         FILE_ATTRIBUTE_NORMAL, NULL
    mov hFile, eax

;---===get its size and pop it ===---

    invoke GetFileSize,hFile,NULL
    push eax

;---===allocate memory===---

        invoke GlobalAlloc, GHND, eax
        mov hMemory,eax 
        invoke GlobalLock, eax 
        mov buffer,eax 

    pop ebx
    push ebx ;don't know if ebx is destroyed by api's (?)

;---===read file to allocated buffer===---

    invoke ReadFile, hFile, buffer, ebx, addr dwread, 0
    pop eax
    add eax,esi

;---===1st loop to destroy carriageret & linefeed===---

    xor ebx,ebx
    cmp byte ptr ,13
    jz @null
    cmp byte ptr ,10
    jz @null
    jmp @continue
    mov byte ptr ,0
    inc ebx
    inc esi
    cmp esi,eax
    jnz @@loop1

    shr ebx,1 ;must be divided by 2 because of crlf

;---===2nd loop to show every single line===---

    push ebx ;ebx should now contain the line number!!!
    invoke MessageBox,NULL,buffer,addr caption,MB_OK
    invoke lstrlen,buffer
    pop ebx
    inc eax ;because of cr lf = 00 00
    add buffer,eax
    dec ebx
    jnz @@loop2

;---===unlock memory region===---

        invoke GlobalUnlock, buffer 
        invoke GlobalFree, hMemory 
ReadLine endp
ahm by the way, you can't give a 32bit register a 8bit value. -you can but not the way you did- This message was edited by drcmda, on 3/11/2001 10:02:58 PM
Posted on 2001-03-11 20:26:00 by drcmda
Thank you so much!!! Just add another
inc eax
, below the one already there. Without it a blank Message Box appears between lines. ...

        push ebx
        invoke MessageBox,NULL,buffer,addr caption,MB_OK
        invoke lstrlen,buffer
        pop ebx


        add buffer,eax
        dec ebx
        jnz @@loop2
... Xtreme This message was edited by xtreme, on 3/12/2001 12:05:27 AM
Posted on 2001-03-11 22:03:00 by xtreme
uhm... my fault. great to help you :)
Posted on 2001-03-12 04:22:00 by drcmda