Wilson WindowWare Tech Support

WinBatch WinBatch+Compiler WebBatch
Home | Tech Database | Tech BBS | White Papers | Purchase


Syntax Checker

Keywords: 	 syntax checker

_Syntax checker                                             ; v1.00 17/09/1999 
    cancelactive=0                                          ; recovery setup
    xxact=wingetactive()                                    ; get edit window
    if iskeydown(@ctrl | @shift) then kino=1                ; cinema show ?
        else kino=0                                         ; not today
    if kino then AddExtender("wwsop32i.DLL")                ; get projector if nec. 
    lmax=500                                                ; max line length, should be enough
    if wgetselstate() then                                  ; anything selected
        xxcurl2=wgetlineno()                                ; get end of selection line number
        wcut()                                              ; yes, copy it to clipboard
        xxcurl1=wgetlineno()                                ; get start of selection line number
        else                                                ;  
        xxcurl1=1                                           ; line # 1 for all
        wSelectAll()                                        ; no, get the lot
        xxcurl2=wgetlineno()                                ; get end of selection line number
        wcut()                                              ; now
        endif                                               ;  
    afiles=(xxcurl2-xxcurl1+1)*lmax                         ; assuming max line lenght
    rbuf=binaryalloc(afiles)                                ; buf for current file
    cbuf=binaryalloc(afiles)                                ; buf in case of cancel
    nbuf=binaryalloc(afiles+10000)                          ; buf for modified selection + expansion
    :cancel                                                 ; like all good programs
    if cancelactive                                         ; oops time?
        if kino then astatusbar(2,"",""," ",0)              ; close show
        binaryfree(rbuf)                                    ; return to owner
        binaryfree(nbuf)                                    ; return to owner
        binaryclipput(cBuf, 1)                              ; restore text befor syntax check
        wpaste()                                            ; stick back in edit file
        wgotoline(xxcurl1)                                  ; point back at original location
        binaryfree(cbuf)                                    ; return to owner
        exit                                                ; emergency exit
        else                                                ;
        cancelactive=1                                      ; strap on parachute
        endif                                               ;
    binaryclipget(rBuf, 1)                                  ; and stick it in the buffer
    binaryclipget(cBuf, 1)                                  ; and stick it in recovery buffer
    ls=0                                                    ; starting point for unmodified lines
    if kino then astatusbar(0,"",""," ",0)                  ; start cinema show 
    totalbar=(xxcurl2-xxcurl1+1)                            ; total recs so far
    tsf=0                                                   ; total so far
    Brk = binaryeodget(rBuf)                                ; max buffer
    while ls < Brk                                          ; go through input buffer
        rc=0                                                ; no @crlf required
        le = binaryindexex(rbuf,ls,@crlf,@fwdscan,0)        ; find end of line
        if le < 0 then le = brk                             ; end of buffer; last line
            else rc=1                                       ; @crlf required 
        ll=le-ls                                            ; ll is length of current line 
        tsf=tsf+1                                           ; processed counter
        if ll <> 0                                          ;  
            dataline=binarypeekstr(rbuf,ls,ll)              ; process i/p record
            gosub checksynif                                ; check for if problems
            gosub checksynbrk                               ; check for odd delimiters
            ;add new subroutine here to cure YOUR problems return with dataline changed/unchanged ; 
            if rc then binarypokestr(nbuf,binaryeodget(nbuf),strcat(dataline,@crlf)) ; add to new buffer with @crlf
                else binarypokestr(nbuf,binaryeodget(nbuf),dataline) ; add to new buffer data only
            ls=ls+strlen(dataline)                          ; add length of old/modified data
            else                                            ;  
            binarypokestr(nbuf,binaryeodget(nbuf),@crlf)    ; add one blank line
            endif                                           ;  
        if rc then ls=ls+2                                  ; minimum increase in rbuf size
        if kino then astatusbar(1,totalbar,"",totalbar,tsf) ; enjoy
        endwhile                                            ;  
    binaryeodset(nbuf,ls)                                   ; set length of restore
    binaryclipput(nBuf, 1)                                  ; text format
    wpaste()                                                ; stick back in edit file
    wgotoline(xxcurl1)                                      ; point back at original location
    binaryfree(nbuf)                                        ; free output buffer
    binaryfree(rbuf)                                        ; free input buffer
    binaryfree(cbuf)                                        ; free original screen data
    if kino then astatusbar(2,"",""," ",0)                  ; close show
    ;winactivate(xxact)                                     ; get focus on edit window again
    drop(parms,lmax,xxcurl1,xxcurl2,brk,afiles,brks,nbuf,kino,tsf,totalbar) ; drop 'em
    drop(lmax,rbuf,ls,le,ll,xxact,x,dataline,dl2,x1,cancelactive,rc) ; drop 'em
    display(1,"Syntax","checks finished")                   ; finished
    exit                                                    ; finished syntax checking
    :checksynif                                             ; do some basic == v = syntax checking
    dl2=dataline                                            ; copy input
    x=strindex(dl2," ; ",0,@backscan)                       ; try cutting out the comment  
    if x then dl2=strsub(dl2,1,x)                           ; data to scan
    x=strindexnc(dl2,"if",0,@fwdscan)                       ; always confuse == with = 
    if x                                                    ; home in on trouble maker
        x1=strindexnc(dl2," then",x,@fwdscan)               ; look for then on if line
        x=strindex(dl2,"=",x+2,@fwdscan)                    ; find first = sign
        if x1


Article ID:   W14967