home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 4 / FreshFish_May-June1994.bin / new / util / moni / snoopy / sources / parse.asm < prev    next >
Assembly Source File  |  1993-12-30  |  45KB  |  1,814 lines

  1.  
  2.  
  3.         incpath    include:
  4.         maclib    sm.mac
  5.         macfile    macro.i
  6.         macfile    snoopy.i
  7.         macfile    macros/parse
  8.         macfile    extern/main
  9.         macfile    extern/misc
  10.  
  11.         section    main,code
  12.  
  13. ERROR_NONE            equ    0
  14. ERROR_INVALID_LINE        equ    1
  15. ERROR_INTERNAL            equ    2
  16. ERROR_NOT_ENOUGH_MEMORY        equ    3
  17. ERROR_ABORT            equ    4
  18.  
  19. ASSUME_LONG    equ    0
  20. ASSUME_WORD    equ    1
  21. ASSUME_BYTE    equ    2
  22.     
  23. ***********************************************************************************
  24. ;--------------    parse a scriptfile with a given name. Note that this parser
  25. ;--------------    is re-entrant, which means that includes are just normal scriptfiles
  26. ;--------------    like the main scriptfile.
  27. ;--------------    
  28. ;--------------    => a0: APTR filename of scriptfile
  29. ;--------------    <= d0: BOOL success
  30.         STRUCTURE psfStack,0
  31.         APTR    psf_Filename
  32.         APTR    psf_FileHandle
  33.         LONG    psf_Line
  34.         LABEL    psf_SIZEOF
  35.  
  36.         ENTRY    ParseScriptFile,d1-d7/a0-a6,psf_SIZEOF,a5
  37.         move.l    a0,(psf_Filename,a5)
  38.         clr.b    (includeLevel)
  39.         clr.l    (flagSkipSimilar)
  40.         clr.l    (priority)
  41.         clr.b    (outputMemory)
  42.         clr.l    (timeout)
  43.         clr.l    (structureOffset)
  44.         move.b    #ASSUME_WORD,(assume)
  45.         move.l    (argNoSegTracker),d0
  46.         not.l    d0
  47.         move.l    d0,(flagSegTracker)
  48.  
  49. ;--------------    copy command line incdir
  50.         tst.l    (argIncdir)
  51.         beq.b    .NOINCDIR
  52.         lea    (incdirBuffer),a1
  53.         movea.l    (argIncdir),a0
  54.         move.w    #MAX_INCDIRNAME-1,d0
  55.         STRCPY    a0,a1
  56. .NOINCDIR    
  57. ;--------------    open file
  58.         move.l    (psf_Filename,a5),d1
  59.         move.l    d1,(outputArgs)
  60.         move.l    #MODE_OLDFILE,d2
  61.         CALL    Open,dosBase
  62.         move.l    d0,(psf_FileHandle,a5)
  63.         beq.b    .NoFile
  64.  
  65. ;--------------    read all lines one-by-one
  66. .LOOP        move.l    (psf_FileHandle,a5),d1
  67.         move.l    #inputMemory,d2
  68.         move.l    #MAX_INPUT,d3
  69.         CALL    FGets
  70.         tst.l    d0
  71.         beq.b    .DONE
  72.         addq.l    #1,(psf_Line,a5)
  73.         move.l    (psf_Line,a5),(currentLine)
  74.         bsr.b    ProcessInput
  75.         tst.l    d0
  76.         bne.b    .FAIL
  77.         bra.b    .LOOP
  78.  
  79. ;--------------    FGets() returned NULL; so we have to check if it was EOF or an error
  80. .DONE        CALL    IoErr
  81.         move.l    d0,d1
  82.         beq.b    .ReallyDone
  83.  
  84. ;--------------    it WAS an error, so show it and exit
  85.         jsr    ShowDosError
  86. .FAIL        move.l    (psf_FileHandle,a5),d1
  87.         CALL    Close
  88.         moveq    #ERROR_INVALID_LINE,d0
  89.         bra.b    ParseScriptFile_done
  90.  
  91. ;--------------    return to sender
  92. .ReallyDone    move.l    (psf_FileHandle,a5),d1
  93.         CALL    Close
  94.         moveq    #ERROR_NONE,d0
  95.         bra.b    ParseScriptFile_done
  96.  
  97. ;--------------    some error message
  98. .NoFile        lea    (openfileErr,pc),a0
  99.         jsr    ShowErrorMessage
  100.         moveq    #ERROR_INTERNAL,d0
  101.         DONE    ParseScriptFile
  102.  
  103. ***********************************************************************************
  104. ;--------------    process current input data line (in 'input' buffer)
  105. ;--------------    
  106. ;--------------    <= d0: BOOL success
  107. ;--------------    
  108.         ENTRY    ProcessInput,d1-d7/a0-a6
  109.         bsr    PrepareInput
  110.         tst.b    (input)
  111.         beq    .DONE
  112.  
  113. ;--------------    see if it is one of the codewords we need 
  114.         lea    (KeywordTable),a0
  115. .CodewordLoop    tst.l    (a0)
  116.         beq.b    .InvalidLine
  117.  
  118. ;--------------    compare codeword and inputline
  119.         move.l    (a0),a1
  120.         lea    (input),a2
  121. .STRICMP    move.b    (a1)+,d0
  122.         beq.b    .Found
  123.         move.b    (a2)+,d1
  124.         UCASE    d1
  125.         cmp.b    d1,d0
  126.         beq.b    .STRICMP
  127.  
  128. .NotFound    addq.l    #8,a0
  129.         bra.b    .CodewordLoop        
  130.  
  131. ;--------------    codeword found -> call function !
  132. .Found        tst.b    (a2)
  133.         beq.b    .FOUND
  134.         cmpi.b    #"=",(a2)+
  135.         bne.b    .NotFound
  136. .FOUND        tst.l    (4,a0)
  137.         beq.b    .DONE
  138.         move.l    (4,a0),a1
  139.         movea.l    a2,a0        ; a0 = start of current line
  140.         jsr    a1        ; a1 = code for handler function
  141.         tst.l    d0
  142.         beq.b    ProcessInput_done
  143.         cmpi.l    #ERROR_NOT_ENOUGH_MEMORY,d0
  144.         beq.b    .NOMEMORY
  145.  
  146. ;--------------    invalid input line
  147.         cmpi.l    #ERROR_INVALID_LINE,d0
  148.         bne.b    ProcessInput_done
  149. .InvalidLine    lea    (invalidlineErr,pc),a0
  150.         bsr    ParserError
  151.         bra.b    ProcessInput_done
  152.  
  153. ;--------------    not enough memory, display alert (because it doesn't eat up memory)
  154. .NOMEMORY    move.l    #RECOVERY_ALERT,d0    ; AlertNumber
  155.         lea    (memoryError,pc),a0    ; String
  156.         moveq    #50,d1            ; Height
  157.         CALL    DisplayAlert,intBase
  158.         moveq    #ERROR_NOT_ENOUGH_MEMORY,d0
  159.         bne.b    ProcessInput_done
  160.  
  161. .DONE        moveq    #ERROR_NONE,d0
  162.         DONE    ProcessInput
  163.  
  164. ***********************************************************************************
  165. ;--------------    define a new library base
  166. ;--------------    
  167. ;--------------    => a0: APTR current string position
  168.  
  169.         ENTRY    SetBase,d1-d7/a0-a6
  170.  
  171. ;--------------    create new list entry
  172.         move.l    #sbase_SIZEOF,d0
  173.         lea    (bases),a1
  174.         bsr    CreateEntry
  175.         tst.l    d0
  176.         beq    .NoMemory
  177.  
  178. ;--------------    copy base
  179.         lea    (sbase_Name,a5),a1
  180.         moveq    #MAX_BASENAME-2,d1
  181. .CopyBaseName    move.b    (a0)+,d0
  182.         beq    .FAILURE
  183.         cmpi.b    #",",d0
  184.         beq.b    .NameFound
  185.         UCASE    d0
  186.         move.b    d0,(a1)+
  187.         dbra    d1,.CopyBaseName
  188.         bra    .BaseTooLong
  189. .NameFound    clr.b    (a1)+
  190.         move.l    a0,d7        ; d7 = library name
  191.  
  192. .FindEnd    move.b    (a0)+,d0
  193.         beq.b    .EndFound
  194.  
  195. ;--------------    another comma indicates the user wants to give a version description
  196.         cmpi.b    #",",d0
  197.         bne.b    .FindEnd
  198. .Version    clr.b    (-1,a0)
  199.         moveq    #STVFORMAT_DEC,d0
  200.         jsr    StringToValue
  201.         move.l    d0,d6
  202.         bra.b    .GoOn
  203.  
  204. ;--------------    we have to remove trailing whitespaces because the library name
  205. ;--------------    is to be directly transfered to OpenLibrary() which otherwise
  206. ;--------------    could fail
  207. .EndFound    subq.l    #1,a0
  208. .WhileIsWhite    cmpa.l    d7,a0
  209.         beq.b    .WhiteIsDone
  210.         move.b    -(a0),d0
  211.         cmpi.b    #" ",d0
  212.         beq.b    .WhileIsWhite
  213.         cmpi.b    #"    ",d0
  214.         beq.b    .WhileIsWhite
  215. .WhiteIsDone    clr.b    (1,a0)
  216.  
  217. ;--------------    now try to open the library
  218. .GoOn        movea.l    d7,a1
  219.         move.l    d6,d0
  220.         CALL    OpenLibrary,<(execBase).w>
  221.         move.l    d0,(sbase_Library,a5)
  222.         beq.b    .CannotOpenLib
  223. .DONE        moveq    #ERROR_NONE,d0
  224.         bra.b    SetBase_done
  225.  
  226. ;--------------    base name exceeds MAX_BASENAME
  227. .BaseTooLong    lea    (basesizeErr,pc),a0
  228.         bra.b    .SHOWERROR
  229.  
  230. ;--------------    unable to OpenLibrary()
  231. .CannotOpenLib    lea    (openlibErr,pc),a0
  232.         move.l    d7,outputArgs+4
  233. .SHOWERROR    bsr    ParserError
  234.         bra.b    SetBase_done
  235.  
  236. .NoMemory    moveq    #ERROR_NOT_ENOUGH_MEMORY,d0
  237.         bra.b    SetBase_done
  238.  
  239. .FAILURE    moveq    #ERROR_INVALID_LINE,d0
  240.         DONE    SetBase
  241.  
  242. ***********************************************************************************
  243. ;--------------    define a new resource base
  244. ;--------------    
  245. ;--------------    => a0: APTR current string position
  246.  
  247.         ENTRY    SetResource,d1-d7/a0-a6
  248.  
  249. ;--------------    create new list entry
  250.         move.l    #sbase_SIZEOF,d0
  251.         lea    (resources),a1
  252.         bsr    CreateEntry
  253.         tst.l    d0
  254.         beq    .NoMemory
  255.  
  256. ;--------------    copy base
  257.         lea    (sbase_Name,a5),a1
  258.         moveq    #MAX_BASENAME-2,d1
  259. .CopyBaseName    move.b    (a0)+,d0
  260.         beq    .FAILURE
  261.         cmpi.b    #",",d0
  262.         beq.b    .NameFound
  263.         UCASE    d0
  264.         move.b    d0,(a1)+
  265.         dbra    d1,.CopyBaseName
  266.         bra    .BaseTooLong
  267. .NameFound    clr.b    (a1)+
  268.         move.l    a0,d7        ; d7 = library name
  269. .FindEnd    subq.l    #1,a0
  270.  
  271. ;--------------    we have to remove trailing whitespaces because the library name
  272. ;--------------    is to be directly transfered to OpenResource() which otherwise
  273. ;--------------    could fail
  274. .WhileIsWhite    cmpa.l    d7,a0
  275.         beq.b    .WhiteIsDone
  276.         move.b    -(a0),d0
  277.         cmpi.b    #" ",d0
  278.         beq.b    .WhileIsWhite
  279.         cmpi.b    #"    ",d0
  280.         beq.b    .WhileIsWhite
  281. .WhiteIsDone    clr.b    (1,a0)
  282.  
  283. ;--------------    now try to open the library
  284. .GoOn        movea.l    d7,a1
  285.         CALL    OpenResource,<(execBase).w>
  286.         move.l    d0,(sbase_Library,a5)
  287.         beq.b    .CannotOpenRes
  288. .DONE        moveq    #ERROR_NONE,d0
  289.         bra.b    SetBase_done
  290.  
  291. ;--------------    base name exceeds MAX_BASENAME
  292. .BaseTooLong    lea    (basesizeErr,pc),a0
  293.         bra.b    .SHOWERROR
  294.  
  295. ;--------------    unable to OpenLibrary()
  296. .CannotOpenRes    lea    (openresErr,pc),a0
  297.         move.l    d7,outputArgs+4
  298. .SHOWERROR    bsr    ParserError
  299.         bra.b    SetResource_done
  300.  
  301. .NoMemory    moveq    #ERROR_NOT_ENOUGH_MEMORY,d0
  302.         bra.b    SetResource_done
  303.  
  304. .FAILURE    moveq    #ERROR_INVALID_LINE,d0
  305.         DONE    SetResource
  306.  
  307. ***********************************************************************************
  308. ;--------------    define a new library base
  309. ;--------------    
  310. ;--------------    => a0: APTR current string position
  311.  
  312.         ENTRY    SetDevice,d1-d7/a0-a6
  313.  
  314. ;--------------    create new list entry
  315.         move.l    #sdevbase_SIZEOF,d0
  316.         lea    (deviceBases),a1
  317.         bsr    CreateEntry
  318.         tst.l    d0
  319.         beq    .NoMemory
  320.  
  321. ;--------------    setup list header
  322.         lea    (sdevbase_Patches,a5),a1
  323.         NEWLIST    a1
  324.  
  325. ;--------------    creatup message port **NOT SUPPORTED YET**
  326.         ;push    a0
  327.         ;CALL    CreateMsgPort,<(execBase).w>
  328.         ;pop    a0
  329.         ;move.l    d0,(sdevbase_MsgPort,a5)
  330.         ;beq    .NOMSGPORT
  331.         ;push    a0
  332.         ;movea.l    d0,a1
  333.         ;move.l    #NULL,(LN_NAME,a1)
  334.         ;CALL    AddPort
  335.         ;pop    a0
  336.  
  337. ;--------------    copy base
  338.         lea    (sdevbase_Name,a5),a1
  339.         mov