home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frozen Fish 2: PC
/
frozenfish_august_1995.bin
/
bbs
/
d09xx
/
d0948.lha
/
Snoopy
/
Ini
/
Examples
/
test.asm
< prev
next >
Wrap
Assembly Source File
|
1993-12-20
|
4KB
|
148 lines
;-------------- same as EXAMPLE.C, but in assembler
incpath include:
maclib sm.mac
macfile macro.i
macfile /lvo/ini.i
macfile /libraries/ini.i
;-------------- open ini.library
lea iniName(pc),a1 ; libName
moveq #0,d0 ; version
movea.l 4,a6 ; execBase
jsr _LVOOpenLibrary(a6)
move.l d0,iniBase ; save library
beq NOINILIBRARY
;-------------- setup pointer to dos.library
movea.l d0,a0
move.l iniBase_DosBase(a0),dosBase
;-------------- open the ini file
lea fileName(pc),a0 ; fileName
lea myParser(pc),a1 ; iniParser
movea.l iniBase(pc),a6
jsr _LVOini_New(a6)
tst.l d0 ; fail if not INIERROR_NONE
bne INIERROR
;-------------- same as EXAMPLE.C; we now loop through all entries in the ini file
lea myParser(pc),a5 ; a5 = myParser
movea.l LH_HEAD(a5),a5 ; a5 = INILINEINFO *
FORLOOP: tst.l LN_SUCC(a5) ; fail if no successor
beq FORDONE
;-------------- a5 now is current INILINEINFO; see what it contains
cmpi.b #INIFLAG_VARIABLE,ili_flags(a5)
beq ISVAR
cmpi.b #INIFLAG_HEADER,ili_flags(a5)
beq ISHEAD
cmpi.b #INIFLAG_COMMENT,ili_flags(a5)
beq ISCOMMENT
;-------------- default: invalid INILINEINFO (should NOT come up normally)
move.l #errorInvalidILI,d1
move.l a5,formatArgs
move.l #formatArgs,d2
bsr printf
bra FORDONE
;-------------- print out comment
ISCOMMENT move.l #commentMsg,d1
move.l ili_allocated(a5),formatArgs
move.l #formatArgs,d2
bsr printf
bra FORNEXT
;-------------- print out section header
ISHEAD move.l #headerMsg,d1
move.l ili_contents(a5),formatArgs
move.l #formatArgs,d2
bsr printf
bra FORNEXT
;-------------- print out section variable
ISVAR move.l #variableMsg,d1
move.l ili_variable(a5),formatArgs
move.l ili_contents(a5),formatArgs+4
move.l #formatArgs,d2
bsr printf
;bra FORNEXT
;-------------- get next INILINEINFO
FORNEXT: movea.l LN_SUCC(a5),a5 ; get next successor
bra FORLOOP ; continue looping
FORDONE:
;-------------- close the INIFILE. This must be called ALWAYS after calling ini_New,
;-------------- regardless if that function returned an error or not!
CLOSEINIFILE: lea myParser(pc),a0 ; iniParser
movea.l iniBase(pc),a6
jsr _LVOini_Delete(a6)
;-------------- close the ini.library
movea.l iniBase(pc),a1 ; libBase
movea.l 4,a6 ; execBase
jsr _LVOCloseLibrary(a6)
;-------------- return to the system
NOINILIBRARY: moveq #0,d0
rts
;-------------- failure to load ini file, print out error message and return
INIERROR: movea.l iniBase(pc),a6
jsr _LVOini_ErrorString(a6)
move.l d0,formatArgs
move.l #errorMsg,d1
move.l #formatArgs,d2
bsr printf
bra CLOSEINIFILE
;-------------- printf - print out arguments to CLI (needs OS2). This function
;-------------- saves all registers, so you don't have to keep in mind which
;-------------- regs you are scratching
;--------------
;-------------- => d1: STRPTR string to print
;-------------- d2: LONG *argument array (only if required by %-style string)
;--------------
printf movem.l d0-d7/a0-a6,-(sp)
movea.l dosBase(pc),a6
jsr _LVOVPrintf(a6)
movem.l (sp)+,d0-d7/a0-a6
rts
;-------------- messages used throughout this example program
welcomeMsg dc.b "This is a test for the ini.library",10,0
errorMsg dc.b "%s",10,0
errorInvalidILI dc.b "UNKNOWN ENTRY AT %0x08lx, PLEASE REPORT",10,0
variableMsg dc.b 'VARIABLE="%s", CONTENTS="%s"',10,0
headerMsg dc.b 'HEADER="%s"',10,0
commentMsg dc.b 'COMMENT="%s"',10,0
;-------------- name of the example ini.file
fileName dc.b "test.ini",0
;-------------- name of the ini.library used for OpenLibrary()
iniName: dc.b "ini.library",0
even
;-------------- ini.library base adress used to call the library functions
iniBase: dc.l 0
;-------------- dos.library base adress (no OpenLibrary because ini.library opens one for us)
dosBase: dc.l 0
;-------------- Parser structure used by the ini functions. This structure
;-------------- does not have to be initialized prior to calling ini_New(),
;-------------- so you could place it in a BSS section to save some memory
myParser ds.b ip_SIZEOF
;-------------- room for up to 10 printf() args
formatArgs ds.l 10
end
**************************************************************************
;--------------