o Fix namespace scope issues in <ctype.h> by using the relatively new

visibility primitives.
o Implement _tolower() and _toupper() POSIX.1-2001 (XSI) macros in
  <ctype.h>.
o Reduce pollution in <runetype.h> by removing typedefs and using
  implementation namespaced types.
o Add a typedef in <rune.h> to compensate for <runetype.h> losing its
  typedefs.

Reviewed by:	bde
This commit is contained in:
mike 2002-09-06 04:22:54 +00:00
parent a6cef6d872
commit bd35b3e920
4 changed files with 72 additions and 44 deletions

View File

@ -46,8 +46,7 @@
#define _CTYPE_H_
/*
* XXX <runetype.h> brings massive namespace pollution (rune_t and struct
* member names).
* XXX <runetype.h> brings namespace pollution (struct member names).
*/
#include <runetype.h>
@ -85,9 +84,15 @@ int isxdigit(int);
int tolower(int);
int toupper(int);
#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
int digittoint(int);
#if __XSI_VISIBLE
int _tolower(int);
int _toupper(int);
int isascii(int);
int toascii(int);
#endif
#if __BSD_VISIBLE
int digittoint(int);
int isblank(int);
int ishexnumber(int);
int isideogram(int);
@ -95,7 +100,6 @@ int isnumber(int);
int isphonogram(int);
int isrune(int);
int isspecial(int);
int toascii(int);
#endif
__END_DECLS
@ -113,9 +117,26 @@ __END_DECLS
#define tolower(c) __tolower(c)
#define toupper(c) __toupper(c)
#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
#define digittoint(c) __maskrune((c), 0xFF)
#if __XSI_VISIBLE
/*
* POSIX.1-2001 specifies _tolower() and _toupper() to be macros equivalent to
* tolower() and toupper() respectively, minus extra checking to ensure that
* the argument is a lower or uppercase letter respectively. We've chosen to
* implement these macros with the same error checking as tolower() and
* toupper() since this doesn't violate the specification itself, only its
* intent. We purposely leave _tolower() and _toupper() undocumented to
* discourage their use.
*
* XXX isascii() and toascii() should similarly be undocumented.
*/
#define _tolower(c) __tolower(c)
#define _toupper(c) __toupper(c)
#define isascii(c) (((c) & ~0x7F) == 0)
#define toascii(c) ((c) & 0x7F)
#endif
#if __BSD_VISIBLE
#define digittoint(c) __maskrune((c), 0xFF)
#define isblank(c) __istype((c), _CTYPE_B)
#define ishexnumber(c) __istype((c), _CTYPE_X)
#define isideogram(c) __istype((c), _CTYPE_I)
@ -123,10 +144,9 @@ __END_DECLS
#define isphonogram(c) __istype((c), _CTYPE_Q)
#define isrune(c) __istype((c), 0xFFFFFF00L)
#define isspecial(c) __istype((c), _CTYPE_T)
#define toascii(c) ((c) & 0x7F)
#endif
/* See comments in <machine/_types.h> about __ct_rune_t. */
/* See comments in <sys/_types.h> about __ct_rune_t. */
__BEGIN_DECLS
unsigned long ___runetype(__ct_rune_t);
__ct_rune_t ___tolower(__ct_rune_t);

View File

@ -46,8 +46,7 @@
#define _CTYPE_H_
/*
* XXX <runetype.h> brings massive namespace pollution (rune_t and struct
* member names).
* XXX <runetype.h> brings namespace pollution (struct member names).
*/
#include <runetype.h>
@ -85,9 +84,15 @@ int isxdigit(int);
int tolower(int);
int toupper(int);
#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
int digittoint(int);
#if __XSI_VISIBLE
int _tolower(int);
int _toupper(int);
int isascii(int);
int toascii(int);
#endif
#if __BSD_VISIBLE
int digittoint(int);
int isblank(int);
int ishexnumber(int);
int isideogram(int);
@ -95,7 +100,6 @@ int isnumber(int);
int isphonogram(int);
int isrune(int);
int isspecial(int);
int toascii(int);
#endif
__END_DECLS
@ -113,9 +117,26 @@ __END_DECLS
#define tolower(c) __tolower(c)
#define toupper(c) __toupper(c)
#if !defined(_ANSI_SOURCE) && !defined(_POSIX_SOURCE)
#define digittoint(c) __maskrune((c), 0xFF)
#if __XSI_VISIBLE
/*
* POSIX.1-2001 specifies _tolower() and _toupper() to be macros equivalent to
* tolower() and toupper() respectively, minus extra checking to ensure that
* the argument is a lower or uppercase letter respectively. We've chosen to
* implement these macros with the same error checking as tolower() and
* toupper() since this doesn't violate the specification itself, only its
* intent. We purposely leave _tolower() and _toupper() undocumented to
* discourage their use.
*
* XXX isascii() and toascii() should similarly be undocumented.
*/
#define _tolower(c) __tolower(c)
#define _toupper(c) __toupper(c)
#define isascii(c) (((c) & ~0x7F) == 0)
#define toascii(c) ((c) & 0x7F)
#endif
#if __BSD_VISIBLE
#define digittoint(c) __maskrune((c), 0xFF)
#define isblank(c) __istype((c), _CTYPE_B)
#define ishexnumber(c) __istype((c), _CTYPE_X)
#define isideogram(c) __istype((c), _CTYPE_I)
@ -123,10 +144,9 @@ __END_DECLS
#define isphonogram(c) __istype((c), _CTYPE_Q)
#define isrune(c) __istype((c), 0xFFFFFF00L)
#define isspecial(c) __istype((c), _CTYPE_T)
#define toascii(c) ((c) & 0x7F)
#endif
/* See comments in <machine/_types.h> about __ct_rune_t. */
/* See comments in <sys/_types.h> about __ct_rune_t. */
__BEGIN_DECLS
unsigned long ___runetype(__ct_rune_t);
__ct_rune_t ___tolower(__ct_rune_t);

View File

@ -40,8 +40,13 @@
#ifndef _RUNE_H_
#define _RUNE_H_
#include <runetype.h>
#include <stdio.h>
#include <runetype.h>
#ifndef _RUNE_T_DECLARED
#define _RUNE_T_DECLARED
typedef __rune_t rune_t;
#endif
#define _PATH_LOCALE "/usr/share/locale"

View File

@ -43,23 +43,6 @@
#include <sys/cdefs.h>
#include <sys/_types.h>
#ifndef _RUNE_T_DECLARED
typedef __rune_t rune_t;
#define _RUNE_T_DECLARED
#endif
#ifndef _SIZE_T_DECLARED
typedef __size_t size_t;
#define _SIZE_T_DECLARED
#endif
#ifndef __cplusplus
#ifndef _WCHAR_T_DECLARED
typedef __wchar_t wchar_t;
#define _WCHAR_T_DECLARED
#endif
#endif
#define _CACHED_RUNES (1 <<8 ) /* Must be a power of 2 */
#define _CRMASK (~(_CACHED_RUNES - 1))
@ -67,9 +50,9 @@ typedef __wchar_t wchar_t;
* The lower 8 bits of runetype[] contain the digit value of the rune.
*/
typedef struct {
rune_t min; /* First rune of the range */
rune_t max; /* Last rune (inclusive) of the range */
rune_t map; /* What first maps to in maps */
__rune_t min; /* First rune of the range */
__rune_t max; /* Last rune (inclusive) of the range */
__rune_t map; /* What first maps to in maps */
unsigned long *types; /* Array of types in range */
} _RuneEntry;
@ -82,13 +65,13 @@ typedef struct {
char magic[8]; /* Magic saying what version we are */
char encoding[32]; /* ASCII name of this encoding */
rune_t (*sgetrune)(const char *, size_t, char const **);
int (*sputrune)(rune_t, char *, size_t, char **);
rune_t invalid_rune;
__rune_t (*sgetrune)(const char *, __size_t, char const **);
int (*sputrune)(__rune_t, char *, __size_t, char **);
__rune_t invalid_rune;
unsigned long runetype[_CACHED_RUNES];
rune_t maplower[_CACHED_RUNES];
rune_t mapupper[_CACHED_RUNES];
__rune_t maplower[_CACHED_RUNES];
__rune_t mapupper[_CACHED_RUNES];
/*
* The following are to deal with Runes larger than _CACHED_RUNES - 1.