*********************************************************************** *** *** parse.aii String parsing utilities *** Copyright 1994 Morgan Davis Group *** *** Command Syntax: *** *** & PARSE, 0, ch, op1, op2, old$, new$ escape backslashes *** & PARSE, 1, a$, n skip over variable name (n = length of variable) *** & PARSE, 2, q, old$, new$ fix quoted strings *** & PARSE, 3, old$, new$ compress space runs *** *** History: *** *** When Who Ver Description *** ------- --- --- --------------------------------------- *** 31dec93 mwd 1.0 Created out of necessity to clean up csh *** machine M65C02 case on include 'handy.mac' include 'mega2.equ' include 'omm.equ' start equ $00 end equ $01 inQ equ $02 lastch equ $03 quotechar equ $04 operand equ $05 *------------------------------* * Parse Module Header * *------------------------------* crc proc hVERS dc.w $0000 ;W: driver loader version hID dc.w '$ ' ;W: driver's two-byte signature hSIZE dc.w END-START ;W: size of driver (not including header) hORG dc.w START ;W: org of driver pc phase hAMPC dc.w AMPERCT ;W: ampersand command lookup table address hKIND dc.w $0000 ;W: driver kind hRSRV1 dc.w $0000 ;W: reserved 1 hRSRV2 dc.w $0000 ;W: reserved 2 START cmp #MSG_AMPR ;ampersand service call? beq doampr ;yes cmp #MSG_INFO ;get info string? bne donothing move word,a_info,a1 donothing rts *------------------------------* * Ampersand Command Dispatcher * *------------------------------* doampr jsr combyte txa asl a tax jmp (func,x) ****************************************************************************** doVarlen jsr common dey @next iny dex ;dec count bmi @stop lda (lowtr+1),y bmi @stop ;> $7F bad cmp #'_' ;_ = good beq @next cmp #'0' ;< '0' bad bcc @stop cmp #':' ;< ':' good bcc @next cmp #'A' bcc @stop ;':' => '@' bad and #$1f ;allow A-Z, a-z beq @stop ;@ and ` are bad cmp #$1b bcc @next @stop sty $3C stz $3D ldy #OMM_PUTWORD goOMM ldx #OMM_ID jmp OMMVEC ****************************************************************************** stuffit2 beq skipit stuffit phy ldy lowtr sta (lowtr+1),y inc lowtr ply skipit sta lastch skipit2 iny dex bne commonrts retpop pla pla retstop ldy #OMM_PUTSTR bra goOMM common jsr chrget ldy #OMM_GETSTR jsr goOMM jsr chrget stz lastch ldx lowtr beq retpop stz lowtr ldy #0 commonrts lda (lowtr+1),y cmp quotechar rts ****************************************************************************** doQuote jsr combyte ;check quote char stx quotechar stz inQ jsr common @loop bne @next cmp lastch ;last character "? (thus, "") beq @null lda inQ eor #$80 sta inQ lda quotechar jsr skipit bra @loop @null lda #128 ;null string meta character stz inQ @next cmp #' ' ;space? bne @stuff ;no ora inQ ;sets bit 7 if in quoted string @stuff jsr stuffit bra @loop ****************************************************************************** doEscape jsr combyte stx quotechar ;match character (e.g. '\') jsr combyte stx @op ;opcode (ORA zp = $05, AND zp = $25) jsr combyte stx operand ; operand (for \ = $80, for ^ = $1F) jsr common @loop bne @next jsr skipit2 @op ora operand @next jsr stuffit bra @loop ****************************************************************************** doSpaces jsr common @loop cmp #' ' bne @next cmp lastch ;last character spc? (thus, spc-spc) @next jsr stuffit2 bra @loop *------------------------------* * Data Section * *------------------------------* dc.b 0 ;flag start of immed mode table IMMED *------------------------------* * Immediate Mode Addresses * *------------------------------* a_info dc.w info func dc.w doEscape dc.w doVarlen dc.w doQuote dc.w doSpaces dc.w $0000 *------------------------------* * Main Program Data Section * *------------------------------* AMPERCT cstr 'PARSE' dc.b -1 msb on info cstr '&SYSDATE Parse 3.0' msb off END end