From 64c1175f7b42ee84e0ffe3cb3b2f244fc718d760 Mon Sep 17 00:00:00 2001 From: Olaf Barthel Date: Sun, 9 Jan 2005 15:20:33 +0000 Subject: [PATCH] - Made the macros more robust. git-svn-id: file:///Users/olsen/Code/migration-svn-zu-git/logical-line-staging/clib2/trunk@14797 87f5fb63-7c3d-0410-a384-fd976d0f7a62 --- library/changes | 2 ++ library/ctype_table.c | 22 ++-------------------- library/include/ctype.h | 29 ++++++++++++++--------------- 3 files changed, 18 insertions(+), 35 deletions(-) diff --git a/library/changes b/library/changes index 8f953ee..19c2da1 100644 --- a/library/changes +++ b/library/changes @@ -29,6 +29,8 @@ tracks whether or not console output is possible. We now use the global "__no_standard_io" instead. +- Made the macros more robust. + c.lib 1.185 (2.1.2005) diff --git a/library/ctype_table.c b/library/ctype_table.c index 3e5e875..3dda739 100644 --- a/library/ctype_table.c +++ b/library/ctype_table.c @@ -1,5 +1,5 @@ /* - * $Id: ctype_table.c,v 1.2 2005-01-02 09:07:07 obarthel Exp $ + * $Id: ctype_table.c,v 1.3 2005-01-09 15:20:31 obarthel Exp $ * * :ts=4 * @@ -36,22 +36,8 @@ /****************************************************************************/ -/* The construction of this table is rather peculiar. The assumption is that - the table index from which a flag value could be fetched is in the range - -128..255 since the character to be tested could be a signed or unsigned - 8 bit value. The table access pointer (declared below) therefore points - to the 128th byte of '__ctype_data[]'. */ -static const unsigned char __ctype_data[3 * 128] = +const unsigned char __ctype_table[2 * 128] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - /* 0 */ __CTYPE_CONTROL, /* 1 */ __CTYPE_CONTROL, /* 2 */ __CTYPE_CONTROL, @@ -190,7 +176,3 @@ static const unsigned char __ctype_data[3 * 128] = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - -/****************************************************************************/ - -const unsigned char * const __ctype_table = &__ctype_data[128]; diff --git a/library/include/ctype.h b/library/include/ctype.h index 39d3ed1..8fd6589 100644 --- a/library/include/ctype.h +++ b/library/include/ctype.h @@ -1,5 +1,5 @@ /* - * $Id: ctype.h,v 1.4 2005-01-02 09:07:21 obarthel Exp $ + * $Id: ctype.h,v 1.5 2005-01-09 15:20:33 obarthel Exp $ * * :ts=4 * @@ -66,15 +66,14 @@ extern int toupper(int c); /* * If requested, reimplement the character classification functions as macros; * note that the macro variants ignore the current locale and default to the - * 'C' locale rules. Note that the characters to be tested must be either - * signed or unsigned 8 bit values. + * 'C' locale rules. */ #ifdef __C_MACROS__ /****************************************************************************/ -extern const unsigned char * const __ctype_table; +extern const unsigned char __ctype_table[]; /****************************************************************************/ @@ -89,17 +88,17 @@ extern const unsigned char * const __ctype_table; /****************************************************************************/ -#define isalnum(c) ((__ctype_table[c] & (__CTYPE_DIGIT|__CTYPE_LOWER_CASE|__CTYPE_UPPER_CASE)) != 0) -#define isalpha(c) ((__ctype_table[c] & (__CTYPE_LOWER_CASE|__CTYPE_UPPER_CASE)) != 0) -#define iscntrl(c) ((__ctype_table[c] & __CTYPE_CONTROL) != 0) -#define isdigit(c) ((__ctype_table[c] & __CTYPE_DIGIT) != 0) -#define isxdigit(c) ((__ctype_table[c] & __CTYPE_HEX_DIGIT) != 0) -#define isgraph(c) ((__ctype_table[c] & (__CTYPE_DIGIT|__CTYPE_PUNCTUATION|__CTYPE_LOWER_CASE|__CTYPE_UPPER_CASE)) != 0) -#define ispunct(c) ((__ctype_table[c] & __CTYPE_PUNCTUATION) != 0) -#define isprint(c) ((__ctype_table[c] & __CTYPE_PRINTABLE) != 0) -#define islower(c) ((__ctype_table[c] & __CTYPE_LOWER_CASE) != 0) -#define isupper(c) ((__ctype_table[c] & __CTYPE_UPPER_CASE) != 0) -#define isspace(c) ((__ctype_table[c] & __CTYPE_WHITE_SPACE) != 0) +#define isalnum(c) ((__ctype_table[(c) & 255] & (__CTYPE_DIGIT|__CTYPE_LOWER_CASE|__CTYPE_UPPER_CASE)) != 0) +#define isalpha(c) ((__ctype_table[(c) & 255] & (__CTYPE_LOWER_CASE|__CTYPE_UPPER_CASE)) != 0) +#define iscntrl(c) ((__ctype_table[(c) & 255] & __CTYPE_CONTROL) != 0) +#define isdigit(c) ((__ctype_table[(c) & 255] & __CTYPE_DIGIT) != 0) +#define isxdigit(c) ((__ctype_table[(c) & 255] & __CTYPE_HEX_DIGIT) != 0) +#define isgraph(c) ((__ctype_table[(c) & 255] & (__CTYPE_DIGIT|__CTYPE_PUNCTUATION|__CTYPE_LOWER_CASE|__CTYPE_UPPER_CASE)) != 0) +#define ispunct(c) ((__ctype_table[(c) & 255] & __CTYPE_PUNCTUATION) != 0) +#define isprint(c) ((__ctype_table[(c) & 255] & __CTYPE_PRINTABLE) != 0) +#define islower(c) ((__ctype_table[(c) & 255] & __CTYPE_LOWER_CASE) != 0) +#define isupper(c) ((__ctype_table[(c) & 255] & __CTYPE_UPPER_CASE) != 0) +#define isspace(c) ((__ctype_table[(c) & 255] & __CTYPE_WHITE_SPACE) != 0) /****************************************************************************/