; This example writes multiple device= lines to the SYSTEM.INI
; It is *very* fast
NewDevice1 = "DEVICE=COOLone.386"
NewDevice2 = "DEVICE=COOLtwo.386"
NewDevice3 = "DEVICE=COOLthree.386"
;
; Change to the Windows Directory
DirChange(DirWindows(0))
;
For x = 1 to 3 by 1
;message("times through", x) ;for debugging
if x==1 then sysname="system.ini"
else sysname="system.tst"
; Obtain filesize and allocate binary buffers
fs1=FileSize(sysname)
srcbuf = BinaryAlloc(fs1)
editbuf = BinaryAlloc(fs1+100)
;
; Read existing system.ini into memory
BinaryRead( srcbuf, sysname)
;
; See if this change was already installed. If so, quit
a = BinaryIndexNc( srcbuf, 0, newdevice%x%, @FWDSCAN)
if a != 0 then goto AlreadyDone
;
; Find 386Enh section.
a = BinaryIndexNc( srcbuf, 0, "[386Enh]", @FWDSCAN)
;
; Find beginning of next line ( add 2 to skip over our crlf )
cuthere = BinaryIndexNc( srcbuf, a, @CRLF, @FWDSCAN) + 2
;
; Copy data from beginning of file to just after [386Enh}
; to the edit buffer
BinaryCopy( editbuf, 0, srcbuf, 0, cuthere)
;
; Add the device= line to the end of the edit buffer, and add a CRLF
BinaryPokeStr(editbuf,BinaryEodGet(editbuf), Strcat(NewDevice%x%,@CRLF))
;
; Copy remaining part of source buffer to the edit buffer
a = BinaryEodGet(editbuf)
b = BinaryEodGet(srcbuf)
BinaryCopy( editbuf, a, srcbuf, cuthere, b-cuthere)
;
; Save file out to disk. Use system.tst until it is
; completely debugged
BinaryWrite( editbuf, "system.tst")
;
; Close binary buffers
:AlreadyDone
BinaryFree(editbuf)
BinaryFree(srcbuf)
Next