From: cuz Date: Sat, 8 Sep 2001 14:00:41 +0000 (+0000) Subject: Use constants for the bits in the _ctype array. X-Git-Tag: V2.12.0~2714 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=def6300556bdac6413368874912c9c41e0343fec;p=cc65 Use constants for the bits in the _ctype array. git-svn-id: svn://svn.cc65.org/cc65/trunk@865 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/libsrc/common/ctype.inc b/libsrc/common/ctype.inc new file mode 100644 index 000000000..e8a41dabc --- /dev/null +++ b/libsrc/common/ctype.inc @@ -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) + + diff --git a/libsrc/common/isalnum.s b/libsrc/common/isalnum.s index 8c29964ed..26fd7a24c 100644 --- a/libsrc/common/isalnum.s +++ b/libsrc/common/isalnum.s @@ -5,14 +5,14 @@ ; .export _isalnum - .import __ctype + .include "ctype.inc" _isalnum: cpx #$00 ; Char range ok? bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification - and #$07 ; Mask character/digit bits + and #CT_ALNUM ; Mask character/digit bits rts @L1: lda #$00 ; Return false diff --git a/libsrc/common/isalpha.s b/libsrc/common/isalpha.s index d0fcf97b2..624dec682 100644 --- a/libsrc/common/isalpha.s +++ b/libsrc/common/isalpha.s @@ -5,14 +5,14 @@ ; .export _isalpha - .import __ctype + .include "ctype.inc" _isalpha: cpx #$00 ; Char range ok? bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification - and #$03 ; Mask character bits + and #CT_ALPHA ; Mask character bits rts @L1: lda #$00 ; Return false diff --git a/libsrc/common/isblank.s b/libsrc/common/isblank.s index 5568a547d..6da645a92 100644 --- a/libsrc/common/isblank.s +++ b/libsrc/common/isblank.s @@ -7,14 +7,14 @@ ; .export _isblank - .import __ctype + .include "ctype.inc" _isblank: cpx #$00 ; Char range ok? bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification - and #$80 ; Mask blank bit + and #CT_SPACE_TAB ; Mask blank bit rts @L1: lda #$00 ; Return false diff --git a/libsrc/common/iscntrl.s b/libsrc/common/iscntrl.s index 55307bd5a..d94fddc27 100644 --- a/libsrc/common/iscntrl.s +++ b/libsrc/common/iscntrl.s @@ -5,14 +5,14 @@ ; .export _iscntrl - .import __ctype + .include "ctype.inc" _iscntrl: cpx #$00 ; Char range ok? bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification - and #$10 ; Mask control character bit + and #CT_CTRL ; Mask control character bit rts @L1: lda #$00 ; Return false diff --git a/libsrc/common/isdigit.s b/libsrc/common/isdigit.s index b0608ba72..339fef61f 100644 --- a/libsrc/common/isdigit.s +++ b/libsrc/common/isdigit.s @@ -5,14 +5,14 @@ ; .export _isdigit - .import __ctype + .include "ctype.inc" _isdigit: cpx #$00 ; Char range ok? bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification - and #$04 ; Mask digit bit + and #CT_DIGIT ; Mask digit bit rts @L1: lda #$00 ; Return false diff --git a/libsrc/common/isgraph.s b/libsrc/common/isgraph.s index e2073aea2..e52ae3485 100644 --- a/libsrc/common/isgraph.s +++ b/libsrc/common/isgraph.s @@ -5,15 +5,15 @@ ; .export _isgraph - .import __ctype + .include "ctype.inc" _isgraph: cpx #$00 ; Char range ok? bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification - eor #$30 ; NOT control and NOT space - and #$30 ; Mask character bits + eor #CT_CTRL_SPACE ; NOT control and NOT space + and #CT_CTRL_SPACE ; Mask character bits rts @L1: lda #$00 ; Return false diff --git a/libsrc/common/islower.s b/libsrc/common/islower.s index c8b131600..0078366b8 100644 --- a/libsrc/common/islower.s +++ b/libsrc/common/islower.s @@ -5,14 +5,14 @@ ; .export _islower - .import __ctype + .include "ctype.inc" _islower: cpx #$00 ; Char range ok? bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification - and #$01 ; Mask lower char bit + and #CT_LOWER ; Mask lower char bit rts @L1: lda #$00 ; Return false diff --git a/libsrc/common/isprint.s b/libsrc/common/isprint.s index 37657df92..956b54b88 100644 --- a/libsrc/common/isprint.s +++ b/libsrc/common/isprint.s @@ -5,15 +5,15 @@ ; .export _isprint - .import __ctype + .include "ctype.inc" _isprint: cpx #$00 ; Char range ok? bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification - eor #$10 ; NOT a control char - and #$10 ; Mask control char bit + eor #CT_CTRL ; NOT a control char + and #CT_CTRL ; Mask control char bit rts @L1: lda #$00 ; Return false diff --git a/libsrc/common/ispunct.s b/libsrc/common/ispunct.s index c2d6c2338..380cf38cc 100644 --- a/libsrc/common/ispunct.s +++ b/libsrc/common/ispunct.s @@ -5,15 +5,15 @@ ; .export _ispunct - .import __ctype + .include "ctype.inc" _ispunct: cpx #$00 ; Char range ok? bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification - eor #$37 ; NOT (space | control | digit | char) - and #$37 ; Mask relevant bits + eor #CT_NOT_PUNCT ; NOT (space | control | digit | alpha) + and #CT_NOT_PUNCT ; Mask relevant bits rts @L1: lda #$00 ; Return false diff --git a/libsrc/common/isspace.s b/libsrc/common/isspace.s index 62be7d59e..67530c95e 100644 --- a/libsrc/common/isspace.s +++ b/libsrc/common/isspace.s @@ -5,14 +5,14 @@ ; .export _isspace - .import __ctype + .include "ctype.inc" _isspace: cpx #$00 ; Char range ok? bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification - and #$60 ; Mask space bits + and #(CT_SPACE | CT_OTHER_WS) ; Mask space bits rts @L1: lda #$00 ; Return false diff --git a/libsrc/common/isupper.s b/libsrc/common/isupper.s index 0eb4915c6..b9d53a614 100644 --- a/libsrc/common/isupper.s +++ b/libsrc/common/isupper.s @@ -5,14 +5,14 @@ ; .export _isupper - .import __ctype + .include "ctype.inc" _isupper: cpx #$00 ; Char range ok? bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification - and #$02 ; Mask upper char bit + and #CT_UPPER ; Mask upper char bit rts @L1: lda #$00 ; Return false diff --git a/libsrc/common/isxdigit.s b/libsrc/common/isxdigit.s index 91b041ca7..50146e82e 100644 --- a/libsrc/common/isxdigit.s +++ b/libsrc/common/isxdigit.s @@ -5,14 +5,14 @@ ; .export _isxdigit - .import __ctype + .include "ctype.inc" _isxdigit: cpx #$00 ; Char range ok? bne @L1 ; Jump if no tay lda __ctype,y ; Get character classification - and #$08 ; Mask xdigit bit + and #CT_XDIGIT ; Mask xdigit bit rts @L1: lda #$00 ; Return false