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 >
Assembly Source File  |  1993-12-20  |  4KB  |  148 lines

  1. ;--------------    same as EXAMPLE.C, but in assembler
  2.  
  3.         incpath    include:
  4.         maclib    sm.mac
  5.         macfile    macro.i
  6.         macfile    /lvo/ini.i
  7.         macfile    /libraries/ini.i
  8.  
  9. ;--------------    open ini.library
  10.         lea    iniName(pc),a1        ; libName
  11.         moveq    #0,d0            ; version
  12.         movea.l    4,a6            ; execBase
  13.         jsr    _LVOOpenLibrary(a6)
  14.         move.l    d0,iniBase        ; save library
  15.         beq    NOINILIBRARY
  16.  
  17. ;--------------    setup pointer to dos.library
  18.         movea.l    d0,a0
  19.         move.l    iniBase_DosBase(a0),dosBase
  20.  
  21. ;--------------    open the ini file
  22.         lea    fileName(pc),a0        ; fileName
  23.         lea    myParser(pc),a1        ; iniParser
  24.         movea.l    iniBase(pc),a6
  25.         jsr    _LVOini_New(a6)
  26.         tst.l    d0            ; fail if not INIERROR_NONE
  27.         bne    INIERROR
  28.  
  29. ;--------------    same as EXAMPLE.C; we now loop through all entries in the ini file
  30.         lea    myParser(pc),a5        ; a5 = myParser
  31.         movea.l    LH_HEAD(a5),a5        ; a5 = INILINEINFO *
  32. FORLOOP:    tst.l    LN_SUCC(a5)        ; fail if no successor
  33.         beq    FORDONE
  34.  
  35. ;--------------    a5 now is current INILINEINFO; see what it contains
  36.  
  37.         cmpi.b    #INIFLAG_VARIABLE,ili_flags(a5)
  38.         beq    ISVAR
  39.         cmpi.b    #INIFLAG_HEADER,ili_flags(a5)
  40.         beq    ISHEAD
  41.         cmpi.b    #INIFLAG_COMMENT,ili_flags(a5)
  42.         beq    ISCOMMENT
  43.  
  44. ;--------------    default: invalid INILINEINFO (should NOT come up normally)
  45.         move.l    #errorInvalidILI,d1
  46.         move.l    a5,formatArgs
  47.         move.l    #formatArgs,d2
  48.         bsr    printf
  49.         bra    FORDONE
  50.  
  51. ;--------------    print out comment
  52. ISCOMMENT    move.l    #commentMsg,d1
  53.         move.l    ili_allocated(a5),formatArgs
  54.         move.l    #formatArgs,d2
  55.         bsr    printf
  56.         bra    FORNEXT
  57.  
  58. ;--------------    print out section header
  59. ISHEAD        move.l    #headerMsg,d1
  60.         move.l    ili_contents(a5),formatArgs
  61.         move.l    #formatArgs,d2
  62.         bsr    printf
  63.         bra    FORNEXT
  64.  
  65. ;--------------    print out section variable
  66. ISVAR        move.l    #variableMsg,d1
  67.         move.l    ili_variable(a5),formatArgs
  68.         move.l    ili_contents(a5),formatArgs+4
  69.         move.l    #formatArgs,d2
  70.         bsr    printf
  71.         ;bra    FORNEXT
  72.  
  73. ;--------------    get next INILINEINFO
  74. FORNEXT:    movea.l    LN_SUCC(a5),a5        ; get next successor
  75.         bra    FORLOOP            ; continue looping
  76.  
  77. FORDONE:
  78.  
  79. ;--------------    close the INIFILE. This must be called ALWAYS after calling ini_New,
  80. ;--------------    regardless if that function returned an error or not!
  81. CLOSEINIFILE:    lea    myParser(pc),a0        ; iniParser
  82.         movea.l    iniBase(pc),a6
  83.         jsr    _LVOini_Delete(a6)
  84.  
  85. ;--------------    close the ini.library
  86.         movea.l    iniBase(pc),a1        ; libBase
  87.         movea.l    4,a6            ; execBase
  88.         jsr    _LVOCloseLibrary(a6)
  89.  
  90. ;--------------    return to the system
  91. NOINILIBRARY:    moveq    #0,d0
  92.         rts
  93.  
  94. ;--------------    failure to load ini file, print out error message and return
  95. INIERROR:    movea.l    iniBase(pc),a6
  96.         jsr    _LVOini_ErrorString(a6)
  97.         move.l    d0,formatArgs
  98.         move.l    #errorMsg,d1
  99.         move.l    #formatArgs,d2
  100.         bsr    printf
  101.         bra    CLOSEINIFILE
  102.  
  103. ;--------------    printf - print out arguments to CLI (needs OS2). This function
  104. ;--------------    saves all registers, so you don't have to keep in mind which
  105. ;--------------    regs you are scratching
  106. ;--------------    
  107. ;--------------    => d1: STRPTR string to print
  108. ;--------------       d2: LONG *argument array (only if required by %-style string)
  109. ;--------------    
  110. printf        movem.l    d0-d7/a0-a6,-(sp)
  111.         movea.l    dosBase(pc),a6
  112.         jsr    _LVOVPrintf(a6)
  113.         movem.l    (sp)+,d0-d7/a0-a6
  114.         rts
  115.  
  116. ;--------------    messages used throughout this example program
  117. welcomeMsg    dc.b    "This is a test for the ini.library",10,0
  118. errorMsg    dc.b    "%s",10,0
  119. errorInvalidILI    dc.b    "UNKNOWN ENTRY AT %0x08lx, PLEASE REPORT",10,0
  120. variableMsg    dc.b    'VARIABLE="%s", CONTENTS="%s"',10,0
  121. headerMsg    dc.b    'HEADER="%s"',10,0
  122. commentMsg    dc.b    'COMMENT="%s"',10,0
  123.  
  124. ;--------------    name of the example ini.file
  125. fileName    dc.b    "test.ini",0
  126.  
  127. ;--------------    name of the ini.library used for OpenLibrary()
  128. iniName:    dc.b    "ini.library",0
  129.         even
  130.  
  131. ;--------------    ini.library base adress used to call the library functions
  132. iniBase:    dc.l    0
  133.  
  134. ;--------------    dos.library base adress (no OpenLibrary because ini.library opens one for us)
  135. dosBase:    dc.l    0
  136.  
  137. ;--------------    Parser structure used by the ini functions. This structure
  138. ;--------------    does not have to be initialized prior to calling ini_New(),
  139. ;--------------    so you could place it in a BSS section to save some memory
  140. myParser    ds.b    ip_SIZEOF
  141.  
  142. ;--------------    room for up to 10 printf() args
  143. formatArgs    ds.l    10
  144.         end
  145.  
  146. **************************************************************************
  147. ;--------------    
  148.