StrCommonSymbolsChars: dc.b "-"
StrFirstSymbolsChar: dc.b "\_@:.",0
StrLettersAndFigures: dc.b "09"
StrLetters: dc.b "AZaz",0
;===============================================================================
;
; ValidateSymbolName
;
; in a0 char* str
; fp Stack frame
;
; out d0.w Number of valid chars
;
; destroy d0.w
;
;===============================================================================
ValidateSymbolName:
movem.l d1/a0-a2,-(sp)
;----------------------------------------------------------------------
; First char may be \ _ @ : . A-Z a-z
;----------------------------------------------------------------------
move.b (a0)+,d0
lea StrFirstSymbolsChars(pc),a1
lea StrLetters(pc),a2
bsr \CheckCharsAndIntervals
bne.s \End
;----------------------------------------------------------------------
; Other chars may be \ _ @ : . A-Z a-z 0-9 -
;----------------------------------------------------------------------
\NextChar:
lea StrCommonSymbolsChars(pc),a1
lea StrLettersAndFigures(pc),a2
bsr \CheckCharsAndIntervals
beq.s \NextChar
;----------------------------------------------------------------------
; Remove trailing ':' and return the number of valid chars
;----------------------------------------------------------------------
\End: move.l (sp)+,d1
\Loop: subq.l #1,a0 ; Point to the first invalid char
cmp.l (sp),a0 ; Return if it is the beginning of the string
beq.s \Ret
cmpi.b #':',-1(a0) ; Remove the last valid char if it is ':'
beq.s \Loop
\Ret: suba.l (sp),a0
move.w a0,d0
movem.l (sp)+,a0-a2
rts
;----------------------------------------------------------------------
; Check for chars and intervals
;----------------------------------------------------------------------
\CheckCharsAndIntervals: ; Return Z-Flag == 1 if found, else 0
move.b (a1)+,d1
beq.s \CheckIntervals
cmp.b d0,d1
bne.s \CheckCharsAndIntervals
\Found: moveq.l #0,d0
rts
\CheckIntervals:
move.b (a2)+,d1
beq.s \NotFound
cmp.b d1,d0
bcs.s \NotFound
cmp.b (a2)+,d0
bls.s \Found
bra.s \CheckIntervals
\NotFound:
moveq.l #1,d0
rts