From f5dde0166d6658309344f309845075707f207509 Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Tue, 13 Oct 2015 20:43:49 +0000 Subject: [PATCH] Commit log from Dragonfly: FreeBSD extended ctypes to include numbers (e.g. isnumber()) but never actually implemented it. The isnumber() function was equivalent to the isdigit() function in every case. Now that DragonFly's ctype source files have number definitions, the number ctype can finally be implemented. It's given a new flag _CTYPE_N. The isalnum() and iswalnum() functions have been changed to use this flag rather than the _CTYPE_D digit flag. While isalnum(), isnumber(), and their wide equivalents now return different values in locale cases, the ishexnumber() and iswhexnumber() functions are unchanged. They are still aliases for isxdigit() and iswxdigit(). Also change ctype.h for isdigit and isxdigit to use sbistype like the other functions. Obtained from: dragonfly --- include/_ctype.h | 1 + include/ctype.h | 8 ++++---- include/wctype.h | 10 +++++----- include/xlocale/_ctype.h | 4 ++-- lib/libc/locale/isctype.c | 4 ++-- lib/libc/locale/iswctype.c | 8 ++++---- lib/libc/locale/table.c | 20 ++++++++++---------- lib/libc/locale/wctype.c | 4 +++- usr.bin/localedef/ctype.c | 7 ++++++- 9 files changed, 37 insertions(+), 29 deletions(-) diff --git a/include/_ctype.h b/include/_ctype.h index 2bef5870d905..8a43409e0aa0 100644 --- a/include/_ctype.h +++ b/include/_ctype.h @@ -59,6 +59,7 @@ #define _CTYPE_I 0x00080000L /* Ideogram */ #define _CTYPE_T 0x00100000L /* Special */ #define _CTYPE_Q 0x00200000L /* Phonogram */ +#define _CTYPE_N 0x00400000L /* Number (superset of digit) */ #define _CTYPE_SW0 0x20000000L /* 0 width character */ #define _CTYPE_SW1 0x40000000L /* 1 width character */ #define _CTYPE_SW2 0x80000000L /* 2 width character */ diff --git a/include/ctype.h b/include/ctype.h index 299b5028ed27..0ca422c26337 100644 --- a/include/ctype.h +++ b/include/ctype.h @@ -85,17 +85,17 @@ int isspecial(int); __END_DECLS #ifndef __cplusplus -#define isalnum(c) __sbistype((c), _CTYPE_A|_CTYPE_D) +#define isalnum(c) __sbistype((c), _CTYPE_A|_CTYPE_D|_CTYPE_N) #define isalpha(c) __sbistype((c), _CTYPE_A) #define iscntrl(c) __sbistype((c), _CTYPE_C) -#define isdigit(c) __isctype((c), _CTYPE_D) /* ANSI -- locale independent */ +#define isdigit(c) __sbistype((c), _CTYPE_D) #define isgraph(c) __sbistype((c), _CTYPE_G) #define islower(c) __sbistype((c), _CTYPE_L) #define isprint(c) __sbistype((c), _CTYPE_R) #define ispunct(c) __sbistype((c), _CTYPE_P) #define isspace(c) __sbistype((c), _CTYPE_S) #define isupper(c) __sbistype((c), _CTYPE_U) -#define isxdigit(c) __isctype((c), _CTYPE_X) /* ANSI -- locale independent */ +#define isxdigit(c) __sbistype((c), _CTYPE_X) #define tolower(c) __sbtolower(c) #define toupper(c) __sbtoupper(c) #endif /* !__cplusplus */ @@ -126,7 +126,7 @@ __END_DECLS #define digittoint(c) __sbmaskrune((c), 0xFF) #define ishexnumber(c) __sbistype((c), _CTYPE_X) #define isideogram(c) __sbistype((c), _CTYPE_I) -#define isnumber(c) __sbistype((c), _CTYPE_D) +#define isnumber(c) __sbistype((c), _CTYPE_D|_CTYPE_N) #define isphonogram(c) __sbistype((c), _CTYPE_Q) #define isrune(c) __sbistype((c), 0xFFFFFF00L) #define isspecial(c) __sbistype((c), _CTYPE_T) diff --git a/include/wctype.h b/include/wctype.h index 2a2abd9c460d..f176739e101f 100644 --- a/include/wctype.h +++ b/include/wctype.h @@ -95,27 +95,27 @@ wint_t nextwctype(wint_t, wctype_t); __END_DECLS #ifndef __cplusplus -#define iswalnum(wc) __istype((wc), _CTYPE_A|_CTYPE_D) +#define iswalnum(wc) __istype((wc), _CTYPE_A|_CTYPE_D|_CTYPE_N) #define iswalpha(wc) __istype((wc), _CTYPE_A) #define iswblank(wc) __istype((wc), _CTYPE_B) #define iswcntrl(wc) __istype((wc), _CTYPE_C) #define iswctype(wc, charclass) __istype((wc), (charclass)) -#define iswdigit(wc) __isctype((wc), _CTYPE_D) +#define iswdigit(wc) __istype((wc), _CTYPE_D) #define iswgraph(wc) __istype((wc), _CTYPE_G) #define iswlower(wc) __istype((wc), _CTYPE_L) #define iswprint(wc) __istype((wc), _CTYPE_R) #define iswpunct(wc) __istype((wc), _CTYPE_P) #define iswspace(wc) __istype((wc), _CTYPE_S) #define iswupper(wc) __istype((wc), _CTYPE_U) -#define iswxdigit(wc) __isctype((wc), _CTYPE_X) +#define iswxdigit(wc) __istype((wc), _CTYPE_X) #define towlower(wc) __tolower(wc) #define towupper(wc) __toupper(wc) #if __BSD_VISIBLE #define iswascii(wc) (((wc) & ~0x7F) == 0) -#define iswhexnumber(wc) __istype((wc), _CTYPE_X) +#define iswhexnumber(wc) __istype((wc), _CTYPE_X) /* alias of iswxdigit */ #define iswideogram(wc) __istype((wc), _CTYPE_I) -#define iswnumber(wc) __istype((wc), _CTYPE_D) +#define iswnumber(wc) __istype((wc), _CTYPE_D|_CTYPE_N) #define iswphonogram(wc) __istype((wc), _CTYPE_Q) #define iswrune(wc) __istype((wc), 0xFFFFFF00L) #define iswspecial(wc) __istype((wc), _CTYPE_T) diff --git a/include/xlocale/_ctype.h b/include/xlocale/_ctype.h index b048c55bbb03..25a9c723c964 100644 --- a/include/xlocale/_ctype.h +++ b/include/xlocale/_ctype.h @@ -119,7 +119,7 @@ __sbistype_l(__ct_rune_t __c, unsigned long __f, locale_t __loc) { return __sbistype_l(__c, __cat, __l); } #endif -XLOCALE_ISCTYPE(alnum, _CTYPE_A|_CTYPE_D) +XLOCALE_ISCTYPE(alnum, _CTYPE_A|_CTYPE_D|_CTYPE_N) XLOCALE_ISCTYPE(alpha, _CTYPE_A) XLOCALE_ISCTYPE(blank, _CTYPE_B) XLOCALE_ISCTYPE(cntrl, _CTYPE_C) @@ -128,7 +128,7 @@ XLOCALE_ISCTYPE(graph, _CTYPE_G) XLOCALE_ISCTYPE(hexnumber, _CTYPE_X) XLOCALE_ISCTYPE(ideogram, _CTYPE_I) XLOCALE_ISCTYPE(lower, _CTYPE_L) -XLOCALE_ISCTYPE(number, _CTYPE_D) +XLOCALE_ISCTYPE(number, _CTYPE_D|_CTYPE_N) XLOCALE_ISCTYPE(phonogram, _CTYPE_Q) XLOCALE_ISCTYPE(print, _CTYPE_R) XLOCALE_ISCTYPE(punct, _CTYPE_P) diff --git a/lib/libc/locale/isctype.c b/lib/libc/locale/isctype.c index 25505343d41a..8f93f1919bfb 100644 --- a/lib/libc/locale/isctype.c +++ b/lib/libc/locale/isctype.c @@ -54,7 +54,7 @@ digittoint(int c) int isalnum(int c) { - return (__sbistype(c, _CTYPE_A|_CTYPE_D)); + return (__sbistype(c, _CTYPE_A|_CTYPE_N)); } #undef isalpha @@ -124,7 +124,7 @@ islower(int c) int isnumber(int c) { - return (__sbistype(c, _CTYPE_D)); + return (__sbistype(c, _CTYPE_N)); } #undef isphonogram diff --git a/lib/libc/locale/iswctype.c b/lib/libc/locale/iswctype.c index 59d432c90ce0..dad0621bebd5 100644 --- a/lib/libc/locale/iswctype.c +++ b/lib/libc/locale/iswctype.c @@ -44,7 +44,7 @@ __FBSDID("$FreeBSD$"); int iswalnum(wint_t wc) { - return (__istype(wc, _CTYPE_A|_CTYPE_D)); + return (__istype(wc, _CTYPE_A|_CTYPE_N)); } #undef iswalpha @@ -79,7 +79,7 @@ iswcntrl(wint_t wc) int iswdigit(wint_t wc) { - return (__isctype(wc, _CTYPE_D)); + return (__istype(wc, _CTYPE_D)); } #undef iswgraph @@ -114,7 +114,7 @@ iswlower(wint_t wc) int iswnumber(wint_t wc) { - return (__istype(wc, _CTYPE_D)); + return (__istype(wc, _CTYPE_N)); } #undef iswphonogram @@ -170,7 +170,7 @@ iswupper(wint_t wc) int iswxdigit(wint_t wc) { - return (__isctype(wc, _CTYPE_X)); + return (__istype(wc, _CTYPE_X)); } #undef towlower diff --git a/lib/libc/locale/table.c b/lib/libc/locale/table.c index e89d4799b394..80b19f5ced5e 100644 --- a/lib/libc/locale/table.c +++ b/lib/libc/locale/table.c @@ -101,16 +101,16 @@ const _RuneLocale _Default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E_R|_CTYPE_G, _CTYPE_P|_CTYPE_R|_CTYPE_G, diff --git a/lib/libc/locale/wctype.c b/lib/libc/locale/wctype.c index de880b4d92e6..e20712175154 100644 --- a/lib/libc/locale/wctype.c +++ b/lib/libc/locale/wctype.c @@ -73,9 +73,10 @@ wctype_l(const char *property, locale_t locale) "ideogram\0" /* BSD extension */ "special\0" /* BSD extension */ "phonogram\0" /* BSD extension */ + "number\0" /* BSD extension */ "rune\0"; /* BSD extension */ static const wctype_t propmasks[] = { - _CTYPE_A|_CTYPE_D, + _CTYPE_A|_CTYPE_N, _CTYPE_A, _CTYPE_B, _CTYPE_C, @@ -90,6 +91,7 @@ wctype_l(const char *property, locale_t locale) _CTYPE_I, _CTYPE_T, _CTYPE_Q, + _CTYPE_N, 0xFFFFFF00L }; size_t len1, len2; diff --git a/usr.bin/localedef/ctype.c b/usr.bin/localedef/ctype.c index 3081f800e70a..22f4d8b75284 100644 --- a/usr.bin/localedef/ctype.c +++ b/usr.bin/localedef/ctype.c @@ -51,6 +51,11 @@ __FBSDID("$FreeBSD$"); #include "runefile.h" +/* Needed for bootstrapping, _CTYPE_N */ +#ifndef _CTYPE_N +#define _CTYPE_N 0x00400000L +#endif + #define _ISUPPER _CTYPE_U #define _ISLOWER _CTYPE_L #define _ISDIGIT _CTYPE_D @@ -65,7 +70,7 @@ __FBSDID("$FreeBSD$"); #define _E1 _CTYPE_Q #define _E2 _CTYPE_I #define _E3 0 -#define _E4 0 +#define _E4 _CTYPE_N #define _E5 _CTYPE_T static wchar_t last_ctype;