From 4958e3c432507c1dcd6883984d4ff45b38ba7d72 Mon Sep 17 00:00:00 2001 From: Curtis F Kaylor Date: Tue, 31 Aug 2021 21:08:21 -0400 Subject: [PATCH] Added alphanumunder to ctype module --- doc/ctype.txt | 12 ++++++++++-- include/ctype.a02 | 9 +++++++-- include/ctype.h02 | 6 ++++++ test/ctypetst.c02 | 4 +++- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/doc/ctype.txt b/doc/ctype.txt index c7c686f..162ef5f 100644 --- a/doc/ctype.txt +++ b/doc/ctype.txt @@ -20,6 +20,14 @@ The following functions are defined: Note: Calls internal routine isaln, which in turn calls internal routines isdgt and isalp. + b = isalnu(c); Returns TRUE if c is an alphanumunder, otherwise FALSE. + + An alphanumunder character is a letter (A-Z or a-z), + a digit (0-9), or an underline (_). + + Note: Calls internal routine isalu, which in turn + calls internal routines isdgt and isalp. + b = isalph(c); Returns TRUE if c is alphabetic, otherwise FALSE. An alphabetic character is a letter (A-Z or a-z). @@ -116,6 +124,6 @@ Implementation: The standard method of implementing the ctype library is to use a bit mask table of 128 bytes (one for each standard ASCII character). This library instead uses a series of comparisons in the internal routines, -which leave the accumulator unmodified, and occupies approximately 128 bytes -of memory. +which leave the accumulator unmodified, and generates approximately 128 bytes +of machine code. diff --git a/include/ctype.a02 b/include/ctype.a02 index 1304d76..2fe64d0 100644 --- a/include/ctype.a02 +++ b/include/ctype.a02 @@ -11,6 +11,8 @@ SUBROUTINE CTYPE ;Character Test Functions - Set Accumulator +ISALNU: JSR ISANU ;Is Alphanumunder + BVC .ISBTF ISALNM: JSR ISALN ;Is Alphanumeric Character BVC .ISBTF ISALPH: JSR ISALP ;Is Alphabetic Character @@ -55,10 +57,13 @@ TOUPPR: JSR ISLWR ;If Char IS Not Lower Case RTS ; and Return ;Machine Language Subroutines - Set/Clear Carry, Preserve Accumulator -ISALN: JSR ISDGT ;If Char IS Digit +ISANU: CMP #$5F ;If Char = '_' + BEQ .ISSEC ; Return Carry Set + ;Else +ISALN: JSR ISDGT ;If Char IS Digit BCS .ISRTS ; Return Carry Set ;Else -ISALP: JSR ISUPR ;If Char IS Upper Case +ISALP: JSR ISUPR ;If Char IS Upper Case BCS .ISRTS ; Return Carry Set ;Else ISLWR: CMP #$61 ;If Char < 'a' diff --git a/include/ctype.h02 b/include/ctype.h02 index ba908b4..49e4bf4 100644 --- a/include/ctype.h02 +++ b/include/ctype.h02 @@ -8,6 +8,12 @@ * Returns: TRUE or FALSE */ char isalnm(); +/* Check for Alphanumunder Character * + * (Alphabetic, Digit, or '_') * + * Args: c - Character to Check * + * Returns: TRUE or FALSE */ +char isalnu(); + /* Checks for Alphabetic Character * * (Upper Case or Lower Case) * * Args: c - Character to Check * diff --git a/test/ctypetst.c02 b/test/ctypetst.c02 index 2ab68a2..49a3e79 100644 --- a/test/ctypetst.c02 +++ b/test/ctypetst.c02 @@ -21,6 +21,7 @@ head: putchr('L'); //Lower Case putchr('A'); //Alphabetic putchr('N'); //Alphanumeric + putchr('M'); //Alphanumunder putchr('G'); //Graphic putchr('R'); //Printable putchr('B'); //Binary @@ -43,6 +44,7 @@ loop: c = islowr(i) & $0A | $20; putchr(c); c = isalph(i) & $0A | $20; putchr(c); c = isalnm(i) & $0A | $20; putchr(c); + c = isalnu(i) & $0A | $20; putchr(c); c = isgrph(i) & $0A | $20; putchr(c); c = isprnt(i) & $0A | $20; putchr(c); c = isbdgt(i) & $0A | $20; putchr(c); @@ -51,6 +53,6 @@ loop: if (i == 0) goto exit; if (i & $0F <> 0) goto loop; newlin(); - c = getkey(); + c = getchr(); if (c == $1B) goto exit; goto head;