From 3b81d48f27e024a113ec63bdfa0b762808d5291c Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Tue, 17 Oct 2000 21:23:48 +0000 Subject: Fix up ctype.h --- include/ctype.h | 71 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 29 deletions(-) (limited to 'include/ctype.h') diff --git a/include/ctype.h b/include/ctype.h index ed22ef786..ddfb1094a 100644 --- a/include/ctype.h +++ b/include/ctype.h @@ -1,38 +1,51 @@ -/* - * ctype.h Character classification and conversion - */ +/* ctype.h + * Character classification and conversion */ #ifndef __CTYPE_H #define __CTYPE_H -extern unsigned char __ctype[]; +#ifdef USE_CTYPE_C_FUNCTIONS +/* function prototpes */ +extern int isalnum(int c); +extern int isalpha(int c); +extern int isascii(int c); +extern int iscntrl(int c); +extern int isdigit(int c); +extern int isgraph(int c); +extern int islower(int c); +extern int isprint(int c); +extern int ispunct(int c); +extern int isspace(int c); +extern int isupper(int c); +extern int isxdigit(int c); +extern int isxlower(int c); +extern int isxupper(int c); +extern int toascii(int c); +extern int tolower(int c); +extern int toupper(int c); -#define __CT_d 0x01 /* numeric digit */ -#define __CT_u 0x02 /* upper case */ -#define __CT_l 0x04 /* lower case */ -#define __CT_c 0x08 /* control character */ -#define __CT_s 0x10 /* whitespace */ -#define __CT_p 0x20 /* punctuation */ -#define __CT_x 0x40 /* hexadecimal */ +#else -#define toupper(c) (islower(c) ? (c)^0x20 : (c)) -#define tolower(c) (isupper(c) ? (c)^0x20 : (c)) -#define _toupper(c) ((c)^0x20) -#define _tolower(c) ((c)^0x20) -#define toascii(c) ((c)&0x7F) +/* macro definitions */ +#define isalnum(c) (isalpha(c) || isdigit(c)) +#define isalpha(c) (isupper(c) || islower(c)) +#define isascii(c) (c > 0 && c <= 0x7f) +#define iscntrl(c) ((c > 0) && ((c <= 0x1F) || (c == 0x7f))) +#define isdigit(c) (c >= '0' && c <= '9') +#define isgraph(c) (c != ' ' && isprint(c)) +#define islower(c) (c >= 'a' && c <= 'z') +#define isprint(c) (c >= ' ' && c <= '~') +#define ispunct(c) ((c > ' ' && c <= '~') && !isalnum(c)) +#define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' ||\ + c == '\t' || c == '\v') +#define isupper(c) (c >= 'A' && c <= 'Z') +#define isxdigit(c) (isxupper(c) || isxlower(c)) +#define isxlower(c) (isdigit(c) || (c >= 'a' && c <= 'f')) +#define isxupper(c) (isdigit(c) || (c >= 'A' && c <= 'F')) +#define toascii(c) (c & 0x7f) +#define tolower(c) (isupper(c) ? ( c - 'A' + 'a') : (c)) +#define toupper(c) (islower(c) ? (c - 'a' + 'A') : (c)) -/* Note the '!!' is a cast to 'bool' and even BCC deletes it in an if() */ -#define isalnum(c) (!!(__ctype[(int) c]&(__CT_u|__CT_l|__CT_d))) -#define isalpha(c) (!!(__ctype[(int) c]&(__CT_u|__CT_l))) -#define isascii(c) (!((c)&~0x7F)) -#define iscntrl(c) (!!(__ctype[(int) c]&__CT_c)) -#define isdigit(c) (!!(__ctype[(int) c]&__CT_d)) -#define isgraph(c) (!(__ctype[(int) c]&(__CT_c|__CT_s))) -#define islower(c) (!!(__ctype[(int) c]&__CT_l)) -#define isprint(c) (!(__ctype[(int) c]&__CT_c)) -#define ispunct(c) (!!(__ctype[(int) c]&__CT_p)) -#define isspace(c) (!!(__ctype[(int) c]&__CT_s)) -#define isupper(c) (!!(__ctype[(int) c]&__CT_u)) -#define isxdigit(c) (!!(__ctype[(int) c]&__CT_x)) +#endif #endif /* __CTYPE_H */ -- cgit v1.2.3