Use constants for the bits in the _ctype array.

git-svn-id: svn://svn.cc65.org/cc65/trunk@865 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2001-09-08 14:00:41 +00:00
parent d799cc283f
commit def6300556
13 changed files with 55 additions and 27 deletions

28
libsrc/common/ctype.inc Normal file
View File

@@ -0,0 +1,28 @@
;
; Definitions for the character type tables
;
; Ullrich von Bassewitz, 08.09.2001
;
; Make the __ctype table an exported/imported symbol
.global __ctype
; Define bitmapped constants for the table entries
CT_LOWER = $01 ; 0 - Lower case char
CT_UPPER = $02 ; 1 - Upper case char
CT_DIGIT = $04 ; 2 - Numeric digit
CT_XDIGIT = $08 ; 3 - Hex digit (both, lower and upper)
CT_CTRL = $10 ; 4 - Control character
CT_SPACE = $20 ; 5 - The space character itself
CT_OTHER_WS = $40 ; 6 - Other whitespace ('\f', '\n', '\r', '\t' and '\v')
CT_SPACE_TAB = $80 ; 7 - Space or tab character
; Combined stuff
CT_ALNUM = (CT_LOWER | CT_UPPER | CT_DIGIT)
CT_ALPHA = (CT_LOWER | CT_UPPER)
CT_CTRL_SPACE = (CT_CTRL | CT_SPACE)
CT_NOT_PUNCT = (CT_SPACE | CT_CTRL | CT_DIGIT | CT_UPPER | CT_LOWER)

View File

@@ -5,14 +5,14 @@
; ;
.export _isalnum .export _isalnum
.import __ctype .include "ctype.inc"
_isalnum: _isalnum:
cpx #$00 ; Char range ok? cpx #$00 ; Char range ok?
bne @L1 ; Jump if no bne @L1 ; Jump if no
tay tay
lda __ctype,y ; Get character classification lda __ctype,y ; Get character classification
and #$07 ; Mask character/digit bits and #CT_ALNUM ; Mask character/digit bits
rts rts
@L1: lda #$00 ; Return false @L1: lda #$00 ; Return false

View File

@@ -5,14 +5,14 @@
; ;
.export _isalpha .export _isalpha
.import __ctype .include "ctype.inc"
_isalpha: _isalpha:
cpx #$00 ; Char range ok? cpx #$00 ; Char range ok?
bne @L1 ; Jump if no bne @L1 ; Jump if no
tay tay
lda __ctype,y ; Get character classification lda __ctype,y ; Get character classification
and #$03 ; Mask character bits and #CT_ALPHA ; Mask character bits
rts rts
@L1: lda #$00 ; Return false @L1: lda #$00 ; Return false

View File

@@ -7,14 +7,14 @@
; ;
.export _isblank .export _isblank
.import __ctype .include "ctype.inc"
_isblank: _isblank:
cpx #$00 ; Char range ok? cpx #$00 ; Char range ok?
bne @L1 ; Jump if no bne @L1 ; Jump if no
tay tay
lda __ctype,y ; Get character classification lda __ctype,y ; Get character classification
and #$80 ; Mask blank bit and #CT_SPACE_TAB ; Mask blank bit
rts rts
@L1: lda #$00 ; Return false @L1: lda #$00 ; Return false

View File

@@ -5,14 +5,14 @@
; ;
.export _iscntrl .export _iscntrl
.import __ctype .include "ctype.inc"
_iscntrl: _iscntrl:
cpx #$00 ; Char range ok? cpx #$00 ; Char range ok?
bne @L1 ; Jump if no bne @L1 ; Jump if no
tay tay
lda __ctype,y ; Get character classification lda __ctype,y ; Get character classification
and #$10 ; Mask control character bit and #CT_CTRL ; Mask control character bit
rts rts
@L1: lda #$00 ; Return false @L1: lda #$00 ; Return false

View File

@@ -5,14 +5,14 @@
; ;
.export _isdigit .export _isdigit
.import __ctype .include "ctype.inc"
_isdigit: _isdigit:
cpx #$00 ; Char range ok? cpx #$00 ; Char range ok?
bne @L1 ; Jump if no bne @L1 ; Jump if no
tay tay
lda __ctype,y ; Get character classification lda __ctype,y ; Get character classification
and #$04 ; Mask digit bit and #CT_DIGIT ; Mask digit bit
rts rts
@L1: lda #$00 ; Return false @L1: lda #$00 ; Return false

View File

@@ -5,15 +5,15 @@
; ;
.export _isgraph .export _isgraph
.import __ctype .include "ctype.inc"
_isgraph: _isgraph:
cpx #$00 ; Char range ok? cpx #$00 ; Char range ok?
bne @L1 ; Jump if no bne @L1 ; Jump if no
tay tay
lda __ctype,y ; Get character classification lda __ctype,y ; Get character classification
eor #$30 ; NOT control and NOT space eor #CT_CTRL_SPACE ; NOT control and NOT space
and #$30 ; Mask character bits and #CT_CTRL_SPACE ; Mask character bits
rts rts
@L1: lda #$00 ; Return false @L1: lda #$00 ; Return false

View File

@@ -5,14 +5,14 @@
; ;
.export _islower .export _islower
.import __ctype .include "ctype.inc"
_islower: _islower:
cpx #$00 ; Char range ok? cpx #$00 ; Char range ok?
bne @L1 ; Jump if no bne @L1 ; Jump if no
tay tay
lda __ctype,y ; Get character classification lda __ctype,y ; Get character classification
and #$01 ; Mask lower char bit and #CT_LOWER ; Mask lower char bit
rts rts
@L1: lda #$00 ; Return false @L1: lda #$00 ; Return false

View File

@@ -5,15 +5,15 @@
; ;
.export _isprint .export _isprint
.import __ctype .include "ctype.inc"
_isprint: _isprint:
cpx #$00 ; Char range ok? cpx #$00 ; Char range ok?
bne @L1 ; Jump if no bne @L1 ; Jump if no
tay tay
lda __ctype,y ; Get character classification lda __ctype,y ; Get character classification
eor #$10 ; NOT a control char eor #CT_CTRL ; NOT a control char
and #$10 ; Mask control char bit and #CT_CTRL ; Mask control char bit
rts rts
@L1: lda #$00 ; Return false @L1: lda #$00 ; Return false

View File

@@ -5,15 +5,15 @@
; ;
.export _ispunct .export _ispunct
.import __ctype .include "ctype.inc"
_ispunct: _ispunct:
cpx #$00 ; Char range ok? cpx #$00 ; Char range ok?
bne @L1 ; Jump if no bne @L1 ; Jump if no
tay tay
lda __ctype,y ; Get character classification lda __ctype,y ; Get character classification
eor #$37 ; NOT (space | control | digit | char) eor #CT_NOT_PUNCT ; NOT (space | control | digit | alpha)
and #$37 ; Mask relevant bits and #CT_NOT_PUNCT ; Mask relevant bits
rts rts
@L1: lda #$00 ; Return false @L1: lda #$00 ; Return false

View File

@@ -5,14 +5,14 @@
; ;
.export _isspace .export _isspace
.import __ctype .include "ctype.inc"
_isspace: _isspace:
cpx #$00 ; Char range ok? cpx #$00 ; Char range ok?
bne @L1 ; Jump if no bne @L1 ; Jump if no
tay tay
lda __ctype,y ; Get character classification lda __ctype,y ; Get character classification
and #$60 ; Mask space bits and #(CT_SPACE | CT_OTHER_WS) ; Mask space bits
rts rts
@L1: lda #$00 ; Return false @L1: lda #$00 ; Return false

View File

@@ -5,14 +5,14 @@
; ;
.export _isupper .export _isupper
.import __ctype .include "ctype.inc"
_isupper: _isupper:
cpx #$00 ; Char range ok? cpx #$00 ; Char range ok?
bne @L1 ; Jump if no bne @L1 ; Jump if no
tay tay
lda __ctype,y ; Get character classification lda __ctype,y ; Get character classification
and #$02 ; Mask upper char bit and #CT_UPPER ; Mask upper char bit
rts rts
@L1: lda #$00 ; Return false @L1: lda #$00 ; Return false

View File

@@ -5,14 +5,14 @@
; ;
.export _isxdigit .export _isxdigit
.import __ctype .include "ctype.inc"
_isxdigit: _isxdigit:
cpx #$00 ; Char range ok? cpx #$00 ; Char range ok?
bne @L1 ; Jump if no bne @L1 ; Jump if no
tay tay
lda __ctype,y ; Get character classification lda __ctype,y ; Get character classification
and #$08 ; Mask xdigit bit and #CT_XDIGIT ; Mask xdigit bit
rts rts
@L1: lda #$00 ; Return false @L1: lda #$00 ; Return false