Hi Bernhard,
Please review the following patch.
It contains the following simplifications:
* UCLIBC_CTYPE_HEADER define is removed, as it always
equal to "include/bits/uClibc_ctype.h".
* __CTYPE_unclassified and other similar __CTYPE_xxxx
constants are moved to separate include file,
bits/uClibc_charclass.h
* After that, we are removing duplicate declaration
of these constants in libc/misc/wctype/_wctype.c
* Ugly re-inclusion trick in extra/locale/gen_wctype.c
can be deleted now.
* Remove large ifdefed-out chunk in extra/locale/gen_wctype.c
* Move __CTYPE_isalnum() etc macros from uClibc_ctype.h
to their single user, extra/locale/gen_wctype.c
(can be simplified further)
* Delete "#warning TODO: Fix the __CTYPE_* codes!",
I believe that's what this patch does.
Please review, I might have missed something...
--
vda
diff -d -urpN uClibc.7/extra/locale/gen_wc8bit.c
uClibc.8/extra/locale/gen_wc8bit.c
--- uClibc.7/extra/locale/gen_wc8bit.c 2008-12-20 15:38:10.000000000 +0100
+++ uClibc.8/extra/locale/gen_wc8bit.c 2008-12-22 05:17:40.000000000 +0100
@@ -18,7 +18,7 @@
#ifndef _WCTYPE_H
#define _WCTYPE_H
#endif
-#include UCLIBC_CTYPE_HEADER
+#include "include/bits/uClibc_ctype.h"
/* #define CTYPE_PACKED */
diff -d -urpN uClibc.7/extra/locale/gen_wctype.c
uClibc.8/extra/locale/gen_wctype.c
--- uClibc.7/extra/locale/gen_wctype.c 2008-12-20 15:38:10.000000000 +0100
+++ uClibc.8/extra/locale/gen_wctype.c 2008-12-22 05:17:40.000000000 +0100
@@ -14,13 +14,7 @@
#include <wchar.h>
#include <ctype.h>
-#ifndef _CTYPE_H
-#define _CTYPE_H
-#endif
-#ifndef _WCTYPE_H
-#define _WCTYPE_H
-#endif
-#include UCLIBC_CTYPE_HEADER
+#include "include/bits/uClibc_charclass.h"
/* 0x9 : space blank */
/* 0xa : space */
@@ -62,7 +56,6 @@
/* typecount[15] = 0 empty_slot */
-
/* Set to #if 0 to restrict wchars to 16 bits. */
#if 1
#define RANGE 0x2ffffUL
@@ -72,59 +65,22 @@
#define RANGE 0xffffUL /* Restrict for 16-bit wchar_t... */
#endif
-#if 0
-/* Classification codes. */
-
-static const char *typename[] = {
- "C_unclassified",
- "C_alpha_nonupper_nonlower",
- "C_alpha_lower",
- "C_alpha_upper_lower",
- "C_alpha_upper",
- "C_digit",
- "C_punct",
- "C_graph",
- "C_print_space_nonblank",
- "C_print_space_blank",
- "C_space_nonblank_noncntrl",
- "C_space_blank_noncntrl",
- "C_cntrl_space_nonblank",
- "C_cntrl_space_blank",
- "C_cntrl_nonspace",
- "empty_slot"
-};
-#endif
-
-#if 0
-/* Taking advantage of the C99 mutual-exclusion guarantees for the various
- * (w)ctype classes, including the descriptions of printing and control
- * (w)chars, we can place each in one of the following mutually-exlusive
- * subsets. Since there are less than 16, we can store the data for
- * each (w)chars in a nibble. In contrast, glibc uses an unsigned int
- * per (w)char, with one bit flag for each is* type. While this allows
- * a simple '&' operation to determine the type vs. a range test and a
- * little special handling for the "blank" and "xdigit" types in my
- * approach, it also uses 8 times the space for the tables on the typical
- * 32-bit archs we supported.*/
-enum {
- __CTYPE_unclassified = 0,
- __CTYPE_alpha_nonupper_nonlower,
- __CTYPE_alpha_lower,
- __CTYPE_alpha_upper_lower,
- __CTYPE_alpha_upper,
- __CTYPE_digit,
- __CTYPE_punct,
- __CTYPE_graph,
- __CTYPE_print_space_nonblank,
- __CTYPE_print_space_blank,
- __CTYPE_space_nonblank_noncntrl,
- __CTYPE_space_blank_noncntrl,
- __CTYPE_cntrl_space_nonblank,
- __CTYPE_cntrl_space_blank,
- __CTYPE_cntrl_nonspace,
-};
-#endif
-
+/* Some macros that test for various (w)ctype classes when passed one of the
+ * designator values enumerated above. */
+#define __CTYPE_isalnum(D) ((unsigned int)(D-1) <=
(__CTYPE_digit-1))
+#define __CTYPE_isalpha(D) ((unsigned int)(D-1) <=
(__CTYPE_alpha_upper-1))
+#define __CTYPE_isblank(D) \
+ ((((unsigned int)(D - __CTYPE_print_space_nonblank)) <= 5) && (D & 1))
+#define __CTYPE_iscntrl(D) (((unsigned int)(D -
__CTYPE_cntrl_space_nonblank)) <= 2)
+#define __CTYPE_isdigit(D) (D == __CTYPE_digit)
+#define __CTYPE_isgraph(D) ((unsigned int)(D-1) <=
(__CTYPE_graph-1))
+#define __CTYPE_islower(D) (((unsigned int)(D -
__CTYPE_alpha_lower)) <= 1)
+#define __CTYPE_isprint(D) ((unsigned int)(D-1) <=
(__CTYPE_print_space_blank-1))
+#define __CTYPE_ispunct(D) (D == __CTYPE_punct)
+#define __CTYPE_isspace(D) (((unsigned int)(D -
__CTYPE_print_space_nonblank)) <= 5)
+#define __CTYPE_isupper(D) (((unsigned int)(D -
__CTYPE_alpha_upper_lower)) <= 1)
+/* #define __CTYPE_isxdigit(D) -- isxdigit is untestable this way.
+ * But that's ok as isxdigit() (and isdigit() too) are locale-invariant. */
#define __CTYPE_isxdigit(D,X) \
(__CTYPE_isdigit(D) || (((unsigned int)(((X)|0x20) - 'a')) <= 5))
diff -d -urpN uClibc.7/extra/locale/Makefile.in
uClibc.8/extra/locale/Makefile.in
--- uClibc.7/extra/locale/Makefile.in 2008-12-20 15:38:10.000000000 +0100
+++ uClibc.8/extra/locale/Makefile.in 2008-12-22 05:17:40.000000000 +0100
@@ -15,8 +15,7 @@ LOCALE_DATA_FILENAME := uClibc-locale-20
BUILD_CFLAGS-locale-common := \
-D__UCLIBC_GEN_LOCALE \
- -I$(top_builddir) \
- -DUCLIBC_CTYPE_HEADER='"include/bits/uClibc_ctype.h"'
+ -I$(top_builddir)
BUILD_CFLAGS-gen_wc8bit := $(BUILD_CFLAGS-locale-common) -DCTYPE_PACKED=1
BUILD_CFLAGS-gen_wctype := $(BUILD_CFLAGS-locale-common)
diff -d -urpN uClibc.7/libc/misc/wctype/_wctype.c
uClibc.8/libc/misc/wctype/_wctype.c
--- uClibc.7/libc/misc/wctype/_wctype.c 2008-12-21 15:06:14.000000000 +0100
+++ uClibc.8/libc/misc/wctype/_wctype.c 2008-12-22 05:21:49.000000000 +0100
@@ -70,43 +70,9 @@
* towctrans function. */
/* #define SMALL_UPLOW */
-/**********************************************************************/
-#ifdef __UCLIBC_MJN3_ONLY__
-#ifdef L_iswspace
-/* generates one warning */
-#warning TODO: Fix the __CTYPE_* codes!
-#endif
-#endif /* __UCLIBC_MJN3_ONLY__ */
-#if 1
-/* Taking advantage of the C99 mutual-exclusion guarantees for the various
- * (w)ctype classes, including the descriptions of printing and control
- * (w)chars, we can place each in one of the following mutually-exlusive
- * subsets. Since there are less than 16, we can store the data for
- * each (w)chars in a nibble. In contrast, glibc uses an unsigned int
- * per (w)char, with one bit flag for each is* type. While this allows
- * a simple '&' operation to determine the type vs. a range test and a
- * little special handling for the "blank" and "xdigit" types in my
- * approach, it also uses 8 times the space for the tables on the typical
- * 32-bit archs we supported.*/
-enum {
- __CTYPE_unclassified = 0,
- __CTYPE_alpha_nonupper_nonlower,
- __CTYPE_alpha_lower,
- __CTYPE_alpha_upper_lower,
- __CTYPE_alpha_upper,
- __CTYPE_digit,
- __CTYPE_punct,
- __CTYPE_graph,
- __CTYPE_print_space_nonblank,
- __CTYPE_print_space_blank,
- __CTYPE_space_nonblank_noncntrl,
- __CTYPE_space_blank_noncntrl,
- __CTYPE_cntrl_space_nonblank,
- __CTYPE_cntrl_space_blank,
- __CTYPE_cntrl_nonspace
-};
-#endif
+/* Pull in __CTYPE_xxx constants */
+#include <bits/uClibc_charclass.h>
/* The following is used to implement wctype(), but it is defined
diff -d -urpN uClibc.7/libc/sysdeps/linux/common/bits/uClibc_charclass.h
uClibc.8/libc/sysdeps/linux/common/bits/uClibc_charclass.h
--- uClibc.7/libc/sysdeps/linux/common/bits/uClibc_charclass.h 1970-01-01
01:00:00.000000000 +0100
+++ uClibc.8/libc/sysdeps/linux/common/bits/uClibc_charclass.h 2008-12-22
05:17:40.000000000 +0100
@@ -0,0 +1,40 @@
+/* Copyright (C) 2008 Denys Vlasenko <[email protected]>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ */
+
+#ifndef _BITS_UCLIBC_CHARCLASS_H
+#define _BITS_UCLIBC_CHARCLASS_H
+
+/* Taking advantage of the C99 mutual-exclusion guarantees for the various
+ * (w)ctype classes, including the descriptions of printing and control
+ * (w)chars, we can place each in one of the following mutually-exlusive
+ * subsets. Since there are less than 16, we can store the data for
+ * each (w)chars in a nibble. In contrast, glibc uses an unsigned int
+ * per (w)char, with one bit flag for each is* type. While this allows
+ * a simple '&' operation to determine the type vs. a range test and a
+ * little special handling for the "blank" and "xdigit" types in my
+ * approach, it also uses 8 times the space for the tables on the typical
+ * 32-bit archs we supported.*/
+enum {
+ __CTYPE_unclassified = 0,
+ __CTYPE_alpha_nonupper_nonlower,
+ __CTYPE_alpha_lower,
+ __CTYPE_alpha_upper_lower,
+ __CTYPE_alpha_upper,
+ __CTYPE_digit,
+ __CTYPE_punct,
+ __CTYPE_graph,
+ __CTYPE_print_space_nonblank,
+ __CTYPE_print_space_blank,
+ __CTYPE_space_nonblank_noncntrl,
+ __CTYPE_space_blank_noncntrl,
+ __CTYPE_cntrl_space_nonblank,
+ __CTYPE_cntrl_space_blank,
+ __CTYPE_cntrl_nonspace
+};
+
+#endif
diff -d -urpN uClibc.7/libc/sysdeps/linux/common/bits/uClibc_ctype.h
uClibc.8/libc/sysdeps/linux/common/bits/uClibc_ctype.h
--- uClibc.7/libc/sysdeps/linux/common/bits/uClibc_ctype.h 2008-12-22
05:20:31.000000000 +0100
+++ uClibc.8/libc/sysdeps/linux/common/bits/uClibc_ctype.h 2008-12-22
05:17:40.000000000 +0100
@@ -31,57 +31,15 @@
#error Always include <{w}ctype.h> rather than <bits/uClibc_ctype.h>
#endif
-#ifndef _BITS_CTYPE_H
-#define _BITS_CTYPE_H
+#ifndef _BITS_UCLIBC_CTYPE_H
+#define _BITS_UCLIBC_CTYPE_H
#ifdef __UCLIBC_GEN_LOCALE
+/* We are in extra/locale/gen_XXX tools build */
-/* Taking advantage of the C99 mutual-exclusion guarantees for the various
- * (w)ctype classes, including the descriptions of printing and control
- * (w)chars, we can place each in one of the following mutually-exlusive
- * subsets. Since there are less than 16, we can store the data for
- * each (w)chars in a nibble. In contrast, glibc uses an unsigned int
- * per (w)char, with one bit flag for each is* type. While this allows
- * a simple '&' operation to determine the type vs. a range test and a
- * little special handling for the "blank" and "xdigit" types in my
- * approach, it also uses 8 times the space for the tables on the typical
- * 32-bit archs we supported.*/
-enum {
- __CTYPE_unclassified = 0,
- __CTYPE_alpha_nonupper_nonlower,
- __CTYPE_alpha_lower,
- __CTYPE_alpha_upper_lower,
- __CTYPE_alpha_upper,
- __CTYPE_digit,
- __CTYPE_punct,
- __CTYPE_graph,
- __CTYPE_print_space_nonblank,
- __CTYPE_print_space_blank,
- __CTYPE_space_nonblank_noncntrl,
- __CTYPE_space_blank_noncntrl,
- __CTYPE_cntrl_space_nonblank,
- __CTYPE_cntrl_space_blank,
- __CTYPE_cntrl_nonspace
-};
-
-/* Some macros that test for various (w)ctype classes when passed one of the
- * designator values enumerated above. */
-#define __CTYPE_isalnum(D) ((unsigned int)(D-1) <=
(__CTYPE_digit-1))
-#define __CTYPE_isalpha(D) ((unsigned int)(D-1) <=
(__CTYPE_alpha_upper-1))
-#define __CTYPE_isblank(D) \
- ((((unsigned int)(D - __CTYPE_print_space_nonblank)) <= 5) && (D & 1))
-#define __CTYPE_iscntrl(D) (((unsigned int)(D -
__CTYPE_cntrl_space_nonblank)) <= 2)
-#define __CTYPE_isdigit(D) (D == __CTYPE_digit)
-#define __CTYPE_isgraph(D) ((unsigned int)(D-1) <=
(__CTYPE_graph-1))
-#define __CTYPE_islower(D) (((unsigned int)(D -
__CTYPE_alpha_lower)) <= 1)
-#define __CTYPE_isprint(D) ((unsigned int)(D-1) <=
(__CTYPE_print_space_blank-1))
-#define __CTYPE_ispunct(D) (D == __CTYPE_punct)
-#define __CTYPE_isspace(D) (((unsigned int)(D -
__CTYPE_print_space_nonblank)) <= 5)
-#define __CTYPE_isupper(D) (((unsigned int)(D -
__CTYPE_alpha_upper_lower)) <= 1)
-/* #define __CTYPE_isxdigit(D) -- isxdigit is untestable this way.
- * But that's ok as isxdigit() (and isdigit() too) are locale-invariant. */
+#include "uClibc_charclass.h"
-#else /* __UCLIBC_GEN_LOCALE *****************************************/
+#else /* !__UCLIBC_GEN_LOCALE */
/* Define some ctype macros valid for the C/POSIX locale. */
@@ -238,15 +196,13 @@ __END_DECLS
#define tolower(c) __tolower(c)
#define toupper(c) __toupper(c)
-
#endif
-#else /* _GNUC__ ***************************************************/
+#else /* !_GNUC__ */
#if !defined __NO_CTYPE && !defined __cplusplus
/* These macros should be safe from side effects. */
-
#define isdigit(c) __C_isdigit(c)
#define isalpha(c) __C_isalpha(c)
#define isprint(c) __C_isprint(c)
@@ -261,4 +217,4 @@ __END_DECLS
#endif /* __UCLIBC_GEN_LOCALE */
-#endif /* _BITS_CTYPE_H */
+#endif /* _BITS_UCLIBC_CTYPE_H */
_______________________________________________
uClibc mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/uclibc