News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Reading a file one line at a time

Started by white scorpion, August 16, 2005, 02:07:37 PM

Previous topic - Next topic

white scorpion

Hi all,

It's been a while since i've been here since i'm awfully busy the last couple of months, but now i have another question to ask:

I'm writing a program which needs to read from a ini file one line at the time.
I know i am able to read the file until the newline character is reached but i was actually hoping for a function that already has that ability since i need to make the code as easy to understand for others as possible. Especially for people with no coding experience it is hard to understand such a function.

Anyone knows of such a function i can invoke which is already part of the windows API's or part of the masm library?

Thanks in advance!

Kind regards,

Mark

hutch--

This procedure in the masm32 library is designed for that purpose.

readline proc source:DWORD,buffer:DWORD,spos:DWORD


Have a look at the example in the service pack called GETINI, it uses the macro for the same procedure "linein$" and it shows you how to use it.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

white scorpion

Thanks hutch!

Btw, i just had to re-download masm32 after a reinstall and i saw that you haven't got a mirror in the Netherlands yet. Let me know if you are interested then i will put it on my site as well.

Regards,

Mark

Vortex

Here is a quick example :

.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\masm32.lib

.data
spos    dd  0
source  db 'This is line 1 , ',13,10,'This one is line 2 , '
        db 'Finally, this is line 3',13,10
.data?
buffer  db  100 dup(?)
.code
start:
    invoke  readline,ADDR source,ADDR buffer,spos
    or      eax,eax
    jz      @f
    mov     spos,eax
    invoke  StdOut,ADDR buffer
    jmp     start
@@:   
    invoke  ExitProcess,0
END start

ToutEnMasm

Hello,
You can also have a look on my site,The source of my library (coming with the download of editmasm) contain proc usable to load a textfile,call the lines of the textfiles by there numbers, in any order that you want and with saving time of scrutation.
                                               ToutEnMasm

white scorpion

Thanks guys, but the following lines already work like they should:


mov hFile, InputFile("inifile.ini")
mov rpos,0

my_loop:
mov rpos,linein$(hFile,ADDR buffer,rpos)
lea eax,buffer
cmp byte ptr [eax],'#'
jz my_loop
invoke lstrlen,addr buffer
.IF eax==0
    jmp next
.ENDIF
invoke MessageBoxA,NULL,addr buffer,addr buffer,MB_OK   
jmp my_loop
next:
invoke CloseHandle,hFile
invoke ExitProcess,0

If the first character of a line contains a # then it is seen as comment and not used.