home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 4
/
FreshFish_May-June1994.bin
/
bbs
/
may94
/
util
/
moni
/
snoopy.lha
/
Snoopy
/
Sources
/
parse.asm
< prev
next >
Wrap
Assembly Source File
|
1993-12-30
|
45KB
|
1,814 lines
incpath include:
maclib sm.mac
macfile macro.i
macfile snoopy.i
macfile macros/parse
macfile extern/main
macfile extern/misc
section main,code
ERROR_NONE equ 0
ERROR_INVALID_LINE equ 1
ERROR_INTERNAL equ 2
ERROR_NOT_ENOUGH_MEMORY equ 3
ERROR_ABORT equ 4
ASSUME_LONG equ 0
ASSUME_WORD equ 1
ASSUME_BYTE equ 2
***********************************************************************************
;-------------- parse a scriptfile with a given name. Note that this parser
;-------------- is re-entrant, which means that includes are just normal scriptfiles
;-------------- like the main scriptfile.
;--------------
;-------------- => a0: APTR filename of scriptfile
;-------------- <= d0: BOOL success
STRUCTURE psfStack,0
APTR psf_Filename
APTR psf_FileHandle
LONG psf_Line
LABEL psf_SIZEOF
ENTRY ParseScriptFile,d1-d7/a0-a6,psf_SIZEOF,a5
move.l a0,(psf_Filename,a5)
clr.b (includeLevel)
clr.l (flagSkipSimilar)
clr.l (priority)
clr.b (outputMemory)
clr.l (timeout)
clr.l (structureOffset)
move.b #ASSUME_WORD,(assume)
move.l (argNoSegTracker),d0
not.l d0
move.l d0,(flagSegTracker)
;-------------- copy command line incdir
tst.l (argIncdir)
beq.b .NOINCDIR
lea (incdirBuffer),a1
movea.l (argIncdir),a0
move.w #MAX_INCDIRNAME-1,d0
STRCPY a0,a1
.NOINCDIR
;-------------- open file
move.l (psf_Filename,a5),d1
move.l d1,(outputArgs)
move.l #MODE_OLDFILE,d2
CALL Open,dosBase
move.l d0,(psf_FileHandle,a5)
beq.b .NoFile
;-------------- read all lines one-by-one
.LOOP move.l (psf_FileHandle,a5),d1
move.l #inputMemory,d2
move.l #MAX_INPUT,d3
CALL FGets
tst.l d0
beq.b .DONE
addq.l #1,(psf_Line,a5)
move.l (psf_Line,a5),(currentLine)
bsr.b ProcessInput
tst.l d0
bne.b .FAIL
bra.b .LOOP
;-------------- FGets() returned NULL; so we have to check if it was EOF or an error
.DONE CALL IoErr
move.l d0,d1
beq.b .ReallyDone
;-------------- it WAS an error, so show it and exit
jsr ShowDosError
.FAIL move.l (psf_FileHandle,a5),d1
CALL Close
moveq #ERROR_INVALID_LINE,d0
bra.b ParseScriptFile_done
;-------------- return to sender
.ReallyDone move.l (psf_FileHandle,a5),d1
CALL Close
moveq #ERROR_NONE,d0
bra.b ParseScriptFile_done
;-------------- some error message
.NoFile lea (openfileErr,pc),a0
jsr ShowErrorMessage
moveq #ERROR_INTERNAL,d0
DONE ParseScriptFile
***********************************************************************************
;-------------- process current input data line (in 'input' buffer)
;--------------
;-------------- <= d0: BOOL success
;--------------
ENTRY ProcessInput,d1-d7/a0-a6
bsr PrepareInput
tst.b (input)
beq .DONE
;-------------- see if it is one of the codewords we need
lea (KeywordTable),a0
.CodewordLoop tst.l (a0)
beq.b .InvalidLine
;-------------- compare codeword and inputline
move.l (a0),a1
lea (input),a2
.STRICMP move.b (a1)+,d0
beq.b .Found
move.b (a2)+,d1
UCASE d1
cmp.b d1,d0
beq.b .STRICMP
.NotFound addq.l #8,a0
bra.b .CodewordLoop
;-------------- codeword found -> call function !
.Found tst.b (a2)
beq.b .FOUND
cmpi.b #"=",(a2)+
bne.b .NotFound
.FOUND tst.l (4,a0)
beq.b .DONE
move.l (4,a0),a1
movea.l a2,a0 ; a0 = start of current line
jsr a1 ; a1 = code for handler function
tst.l d0
beq.b ProcessInput_done
cmpi.l #ERROR_NOT_ENOUGH_MEMORY,d0
beq.b .NOMEMORY
;-------------- invalid input line
cmpi.l #ERROR_INVALID_LINE,d0
bne.b ProcessInput_done
.InvalidLine lea (invalidlineErr,pc),a0
bsr ParserError
bra.b ProcessInput_done
;-------------- not enough memory, display alert (because it doesn't eat up memory)
.NOMEMORY move.l #RECOVERY_ALERT,d0 ; AlertNumber
lea (memoryError,pc),a0 ; String
moveq #50,d1 ; Height
CALL DisplayAlert,intBase
moveq #ERROR_NOT_ENOUGH_MEMORY,d0
bne.b ProcessInput_done
.DONE moveq #ERROR_NONE,d0
DONE ProcessInput
***********************************************************************************
;-------------- define a new library base
;--------------
;-------------- => a0: APTR current string position
ENTRY SetBase,d1-d7/a0-a6
;-------------- create new list entry
move.l #sbase_SIZEOF,d0
lea (bases),a1
bsr CreateEntry
tst.l d0
beq .NoMemory
;-------------- copy base
lea (sbase_Name,a5),a1
moveq #MAX_BASENAME-2,d1
.CopyBaseName move.b (a0)+,d0
beq .FAILURE
cmpi.b #",",d0
beq.b .NameFound
UCASE d0
move.b d0,(a1)+
dbra d1,.CopyBaseName
bra .BaseTooLong
.NameFound clr.b (a1)+
move.l a0,d7 ; d7 = library name
.FindEnd move.b (a0)+,d0
beq.b .EndFound
;-------------- another comma indicates the user wants to give a version description
cmpi.b #",",d0
bne.b .FindEnd
.Version clr.b (-1,a0)
moveq #STVFORMAT_DEC,d0
jsr StringToValue
move.l d0,d6
bra.b .GoOn
;-------------- we have to remove trailing whitespaces because the library name
;-------------- is to be directly transfered to OpenLibrary() which otherwise
;-------------- could fail
.EndFound subq.l #1,a0
.WhileIsWhite cmpa.l d7,a0
beq.b .WhiteIsDone
move.b -(a0),d0
cmpi.b #" ",d0
beq.b .WhileIsWhite
cmpi.b #" ",d0
beq.b .WhileIsWhite
.WhiteIsDone clr.b (1,a0)
;-------------- now try to open the library
.GoOn movea.l d7,a1
move.l d6,d0
CALL OpenLibrary,<(execBase).w>
move.l d0,(sbase_Library,a5)
beq.b .CannotOpenLib
.DONE moveq #ERROR_NONE,d0
bra.b SetBase_done
;-------------- base name exceeds MAX_BASENAME
.BaseTooLong lea (basesizeErr,pc),a0
bra.b .SHOWERROR
;-------------- unable to OpenLibrary()
.CannotOpenLib lea (openlibErr,pc),a0
move.l d7,outputArgs+4
.SHOWERROR bsr ParserError
bra.b SetBase_done
.NoMemory moveq #ERROR_NOT_ENOUGH_MEMORY,d0
bra.b SetBase_done
.FAILURE moveq #ERROR_INVALID_LINE,d0
DONE SetBase
***********************************************************************************
;-------------- define a new resource base
;--------------
;-------------- => a0: APTR current string position
ENTRY SetResource,d1-d7/a0-a6
;-------------- create new list entry
move.l #sbase_SIZEOF,d0
lea (resources),a1
bsr CreateEntry
tst.l d0
beq .NoMemory
;-------------- copy base
lea (sbase_Name,a5),a1
moveq #MAX_BASENAME-2,d1
.CopyBaseName move.b (a0)+,d0
beq .FAILURE
cmpi.b #",",d0
beq.b .NameFound
UCASE d0
move.b d0,(a1)+
dbra d1,.CopyBaseName
bra .BaseTooLong
.NameFound clr.b (a1)+
move.l a0,d7 ; d7 = library name
.FindEnd subq.l #1,a0
;-------------- we have to remove trailing whitespaces because the library name
;-------------- is to be directly transfered to OpenResource() which otherwise
;-------------- could fail
.WhileIsWhite cmpa.l d7,a0
beq.b .WhiteIsDone
move.b -(a0),d0
cmpi.b #" ",d0
beq.b .WhileIsWhite
cmpi.b #" ",d0
beq.b .WhileIsWhite
.WhiteIsDone clr.b (1,a0)
;-------------- now try to open the library
.GoOn movea.l d7,a1
CALL OpenResource,<(execBase).w>
move.l d0,(sbase_Library,a5)
beq.b .CannotOpenRes
.DONE moveq #ERROR_NONE,d0
bra.b SetBase_done
;-------------- base name exceeds MAX_BASENAME
.BaseTooLong lea (basesizeErr,pc),a0
bra.b .SHOWERROR
;-------------- unable to OpenLibrary()
.CannotOpenRes lea (openresErr,pc),a0
move.l d7,outputArgs+4
.SHOWERROR bsr ParserError
bra.b SetResource_done
.NoMemory moveq #ERROR_NOT_ENOUGH_MEMORY,d0
bra.b SetResource_done
.FAILURE moveq #ERROR_INVALID_LINE,d0
DONE SetResource
***********************************************************************************
;-------------- define a new library base
;--------------
;-------------- => a0: APTR current string position
ENTRY SetDevice,d1-d7/a0-a6
;-------------- create new list entry
move.l #sdevbase_SIZEOF,d0
lea (deviceBases),a1
bsr CreateEntry
tst.l d0
beq .NoMemory
;-------------- setup list header
lea (sdevbase_Patches,a5),a1
NEWLIST a1
;-------------- creatup message port **NOT SUPPORTED YET**
;push a0
;CALL CreateMsgPort,<(execBase).w>
;pop a0
;move.l d0,(sdevbase_MsgPort,a5)
;beq .NOMSGPORT
;push a0
;movea.l d0,a1
;move.l #NULL,(LN_NAME,a1)
;CALL AddPort
;pop a0
;-------------- copy base
lea (sdevbase_Name,a5),a1
mov