summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2002-11-22 03:05:27 +0000
committerManuel Novoa III <mjn3@codepoet.org>2002-11-22 03:05:27 +0000
commitc386ddb4d8a1b076d94ebe8b85ca5d0dd124892b (patch)
treee30c9d77393721491f4a3a42e223980352b72ff8
parent2b8a8dc7144328f301390f13fa560d29a410e34f (diff)
Ok... here's the summary:
Hopefully locale support will build when cross compiling now. Collation is still not supported, but that's what I'm currently working on. In the next couple of days, I'll probably put up a couple of files for download that will save people the trouble of generating all the glibc locales. Added *wprintf functions, although they currently don't support floating point. That will be fixed when I rewrite _dtostr... or possibly before. Added the wcsto{inttype} functions. Added iconv() and a mini iconv utility. The require locale support and only provide for conversions involving the various unicode encodings { UCS-4*, UCS-2*, UTF-32*, UTF-16*, UTF-8 }, the 8-bit codesets built with the locale data, and the internal WCHAR_T.
-rw-r--r--Makefile6
-rw-r--r--TODO24
-rw-r--r--docs/Glibc_vs_uClibc_Differences.txt8
-rw-r--r--extra/locale/Makefile50
-rw-r--r--extra/locale/README2
-rw-r--r--extra/locale/gen_ldc.c460
-rw-r--r--extra/locale/gen_locale.c4
-rw-r--r--extra/locale/gen_mmap.c6
-rw-r--r--extra/locale/gen_wc8bit.c36
-rw-r--r--extra/locale/gen_wctype.c76
-rw-r--r--extra/locale/locale_mmap.h4
-rw-r--r--include/iconv.h54
-rw-r--r--ldso/util/Makefile2
-rw-r--r--libc/misc/locale/locale.c4
-rw-r--r--libc/misc/time/time.c7
-rw-r--r--libc/misc/wchar/Makefile15
-rw-r--r--libc/misc/wchar/wchar.c658
-rw-r--r--libc/misc/wchar/wstdio.c21
-rw-r--r--libc/stdio/Makefile10
-rw-r--r--libc/stdio/printf.c1134
-rw-r--r--libc/stdio/stdio.c58
-rw-r--r--libc/stdlib/Makefile11
-rw-r--r--libc/stdlib/stdlib.c215
-rw-r--r--libc/sysdeps/linux/common/bits/uClibc_locale.h2
-rw-r--r--libc/sysdeps/linux/common/bits/uClibc_stdio.h5
25 files changed, 2299 insertions, 573 deletions
diff --git a/Makefile b/Makefile
index 822b0192f..19dcf90ab 100644
--- a/Makefile
+++ b/Makefile
@@ -274,6 +274,11 @@ ifeq ($(strip $(HAVE_SHARED)),y)
install -m 755 ldso/util/ldconfig.target $(PREFIX)$(TARGET_PREFIX)/sbin/ldconfig; \
fi;
endif
+ifeq ($(strip $(UCLIBC_HAS_LOCALE)),y)
+ @$(MAKE) -C libc/misc/wchar iconv.target
+ install -d $(PREFIX)$(TARGET_PREFIX)/usr/bin;
+ install -m 755 libc/misc/wchar/iconv.target $(PREFIX)$(TARGET_PREFIX)/usr/bin/iconv
+endif
finished2:
@echo
@@ -339,6 +344,7 @@ clean:
$(MAKE) -C test clean
$(MAKE) -C ldso clean
$(MAKE) -C libc/misc/internals clean
+ $(MAKE) -C libc/misc/wchar clean
$(MAKE) -C libc/unistd clean
$(MAKE) -C libc/sysdeps/linux/common clean
$(MAKE) -C extra clean
diff --git a/TODO b/TODO
index e93a843c0..e6dfb79b6 100644
--- a/TODO
+++ b/TODO
@@ -18,19 +18,16 @@ Erik's TODO list for the next release:
-----------------------------------------------------------------------------
Manuel's todo:
-In the next couple of months, I plan on completing the wide char and locale
-support. Here's my current list of things to implement by early November.
+I'm currently working on completing the wide char and locale support.
+Right now i'm looking at collation. Other tasks on my list include:
1) Little things that need fixing:
----------------------------------
a) Use locale decimal point in *printf() and strto*d() -- slightly
complicated by the fact that at least one locale uses a wchar
radix that does not map to a single byte in UTF-8.
- b) Use locale digit grouping in *printf().
- c) Implement %lc (%C) and %ls (%S) handling for printf.
- d) Deal with mb format string issues in printf, scanf,
- strftime (at least).
- e) Implement wcwidth() and wcswidth() -- use Markus Kuhn's versions.
+ b) Use locale digit grouping in *printf() flosting point.
+ c) Deal with mb format string issues in scanf and strftime (at least).
2) Implement wide char numeric conversion functions -- wcsto*().
----------------------------------------------------------------
@@ -38,15 +35,6 @@ support. Here's my current list of things to implement by early November.
strto*() functions, unless locale specific alternate digit support
is desired.
- 3) Implement wide formatted output -- *wprintf():
- -------------------------------------------------
- The stream output variants should be easily created by appropriately
- modifying the char *printf() functions.
-
- The string buffer variants may take some time to implement because
- they need to store wchars in a buffer. It will be necessary to hack
- the core stdio code slightly to support this.
-
4) Reimplement scanf for narrow and wide streams.
-------------------------------------------------
The current char version of scanf() needs some cleanup. Also,
@@ -54,9 +42,6 @@ support. Here's my current list of things to implement by early November.
will require reworking the implementation of matching char sets
(enclosed in []).
- Also, as with *wprintf() above, the string buffer variants of wscanf()
- may require some additional work to the core stdio code.
-
5) Additional str{f|p}time issues.
----------------------------------
Support locale specific alternate digits.
@@ -71,6 +56,7 @@ support. Here's my current list of things to implement by early November.
b) Additional clean up of ctype and wctype.
c) Implement collation support for char and wchar -- *xfrm() and *coll().
d) transliteration of unsupported wchars in 8-bit locales (like glibc).
+ e) Support ISO/IEC 14652 draft locale extensions (LC_PAPER, etc).
Other stuff:
diff --git a/docs/Glibc_vs_uClibc_Differences.txt b/docs/Glibc_vs_uClibc_Differences.txt
index e0e1e6af4..8ebca10a9 100644
--- a/docs/Glibc_vs_uClibc_Differences.txt
+++ b/docs/Glibc_vs_uClibc_Differences.txt
@@ -100,17 +100,13 @@ wide char support
representation of wchar's is assumed to be 31 bit unicode values in
native endian representation. Also, the underlying char encoding is
assumed to match ASCII in the range 0-0x7f.
-2) In the C locale, uClibc's mb<->wc conversion functions map 0x80-CHAR_MAX
- onto their wide/narrow equivalents. glibc's conversion functions treat
- them as illegal.
locale support
--------------
1) The target for support is SUSv3 locale functionality. While nl_langinfo
has been extended, similar to glibc, it only returns values for related
locale entries.
-2) The locale code is not cross-compiler friendly. This should be fixed soon.
-3) Currently, collation support is being implemented.
+2) Currently, collation support is being implemented.
stdio
-----
@@ -136,6 +132,8 @@ stdio
8) uClibc's setvbuf is more restrictive about when it can be called than glibc's
is. The standards specify that setvbuf must occur before any other operations
take place on the stream.
+9) Right now, %m is not handled properly by printf when the format uses positional
+ args.
More to follow as I think of it...
diff --git a/extra/locale/Makefile b/extra/locale/Makefile
index bdad5cea7..3f6e7476e 100644
--- a/extra/locale/Makefile
+++ b/extra/locale/Makefile
@@ -26,13 +26,15 @@ codesets.txt:
fi;
gen_wc8bit: gen_wc8bit.c
- gcc -Os -Wall $(CFLAGS_wc8bit) gen_wc8bit.c -o gen_wc8bit
+ $(NATIVE_CC) $(NATIVE_CFLAGS) $(NATIVE_LDFLAGS) $(CFLAGS_wc8bit) $^ -o $@
+#gen_wc8bit.c -o gen_wc8bit
c8tables.h: gen_wc8bit codesets.txt
./gen_wc8bit `cat codesets.txt`
gen_wctype: gen_wctype.c
- gcc -Os -Wall gen_wctype.c -o gen_wctype
+ $(NATIVE_CC) $(NATIVE_CFLAGS) $(NATIVE_LDFLAGS) $^ -o $@
+#gen_wctype.c -o gen_wctype
# Warning! Beware tr_TR toupper/tolower exceptions!
# Warning! Ignore the width table. It will go away.
@@ -40,7 +42,8 @@ wctables.h: gen_wctype
./gen_wctype en_US
gen_locale: gen_locale.c c8tables.h
- gcc -Os -Wall gen_locale.c -o gen_locale
+ $(NATIVE_CC) $(NATIVE_CFLAGS) $(NATIVE_LDFLAGS) gen_locale.c -o $@
+#gen_locale.c -o gen_locale
# TODO: if no wide char support, we should auto-disable all UTF-8 locales
locale_tables.h: gen_locale locales.txt
@@ -64,30 +67,37 @@ locales.txt:
false; \
fi;
-ifneq ($(TARGET_ARCH),$(NATIVE_ARCH))
+# ifneq ($(TARGET_ARCH),$(NATIVE_ARCH))
-locale.mmap: gen_mmap
- echo Your locale.mmap file is either missing or out of date.
- echo The developmental code can only generate one for the
- echo target arch == native arch case. Sorry.
-else
+# locale.mmap: gen_mmap
+# echo Your locale.mmap file is either missing or out of date.
+# echo The developmental code can only generate one for the
+# echo target arch == native arch case. Sorry.
+# else
-gen_mmap: gen_mmap.c c8tables.h wctables.h locale_tables.h
- gcc $(CFLAGS_mmap) -Os -Wall -static gen_mmap.c -o gen_mmap
+# gen_mmap: gen_mmap.c c8tables.h wctables.h locale_tables.h
+# gcc $(CFLAGS_mmap) -Os -Wall -static gen_mmap.c -o gen_mmap
-locale.mmap: gen_mmap
- ./gen_mmap
+# locale.mmap: gen_mmap
+# ./gen_mmap
-endif
+# endif
+
+# lmmtolso: lmmtolso.c
+# gcc -Os -Wall lmmtolso.c -o lmmtolso
+
+# locale_data.c: lmmtolso locale.mmap
+# ./lmmtolso
-lmmtolso: lmmtolso.c
- gcc -Os -Wall lmmtolso.c -o lmmtolso
+gen_ldc: gen_ldc.c c8tables.h wctables.h locale_tables.h
+ $(NATIVE_CC) $(NATIVE_CFLAGS) $(NATIVE_LDFLAGS) $(CFLAGS_mmap) gen_ldc.c -o $@
+#gen_ldc.c -o gen_ldc
-locale_data.c: lmmtolso locale.mmap
- ./lmmtolso
+locale_data.c: gen_ldc
+ ./gen_ldc
locale_data.o: locale_data.c lt_defines.h
- $(CC) -c locale_data.c
+ $(CC) $(CFLAGS_mmap) -c locale_data.c
$(STRIPTOOL) -x -R .note -R .comment locale_data.o
uClibc_locale_data.h: c8tables.h wctables.h lt_defines.h locale_mmap.h
@@ -100,7 +110,7 @@ links-target: locale_data.o uClibc_locale_data.h
clean:
rm -f *.[oa] *~ core
- rm -f gen_wc8bit gen_wctype gen_locale
+ rm -f gen_wc8bit gen_wctype gen_locale gen_ldc
rm -f c8tables.h wctables.h locale_tables.h lt_defines.h
rm -f gen_mmap locale.mmap lmmtolso
rm -f locale_data.c locale_data.o uClibc_locale_data.h
diff --git a/extra/locale/README b/extra/locale/README
index 63723f97f..244b92538 100644
--- a/extra/locale/README
+++ b/extra/locale/README
@@ -44,7 +44,7 @@ Warning!!! Warning!!! Warning!!! Warning!!! Warning!!! Warning!!!
Warning!!! Warning!!! Warning!!! Warning!!! Warning!!! Warning!!!
-1) In the toplevel dir, 'make headers uClibc_config' .
+1) In the toplevel dir, 'make headers'.
2) Create a codesets.txt file in this dir listing the codesets you want
to support. The easiest way to do this is to edit the output of
diff --git a/extra/locale/gen_ldc.c b/extra/locale/gen_ldc.c
new file mode 100644
index 000000000..17e6c6875
--- /dev/null
+++ b/extra/locale/gen_ldc.c
@@ -0,0 +1,460 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <stdint.h>
+#include <stddef.h>
+
+#ifndef __WCHAR_ENABLED
+#warning WHOA!!! __WCHAR_ENABLED is not defined! defining it now...
+#define __WCHAR_ENABLED
+#endif
+
+#define WANT_DATA
+#include "c8tables.h"
+#ifndef __CTYPE_HAS_8_BIT_LOCALES
+#warning __CTYPE_HAS_8_BIT_LOCALES is not defined...
+/* #define __CTYPE_HAS_8_BIT_LOCALES */
+#endif
+
+/* #define Cctype_TBL_LEN 328 */
+/* #define Cuplow_TBL_LEN 400 */
+/* #define Cc2wc_TBL_LEN 1448 */
+/* #define Cwc2c_TBL_LEN 3744 */
+
+#define WANT_WCctype_data
+#define WANT_WCuplow_data
+#define WANT_WCuplow_diff_data
+/* #define WANT_WCcomb_data */
+/* #define WANT_WCwidth_data */
+#include "wctables.h"
+#undef WANT_WCctype_data
+#undef WANT_WCuplow_data
+#undef WANT_WCuplow_diff_data
+/* #undef WANT_WCcomb_data */
+/* #undef WANT_WCwidth_data */
+
+ #define WCctype_TBL_LEN (WCctype_II_LEN + WCctype_TI_LEN + WCctype_UT_LEN)
+ #define WCuplow_TBL_LEN (WCuplow_II_LEN + WCuplow_TI_LEN + WCuplow_UT_LEN)
+ #define WCuplow_diff_TBL_LEN (2 * WCuplow_diffs)
+/* #define WCcomb_TBL_LEN (WCcomb_II_LEN + WCcomb_TI_LEN + WCcomb_UT_LEN) */
+
+#include "locale_tables.h"
+
+#include "locale_mmap.h"
+
+/* #undef __PASTE2 */
+/* #define __PASTE2(A,B) A ## B */
+/* #undef __PASTE3 */
+/* #define __PASTE3(A,B,C) A ## B ## C */
+
+
+/* #define MAGIC_SIZE 64 */
+
+/* #define COMMON_MMAP(X) \ */
+/* unsigned char __PASTE3(lc_,X,_data)[__PASTE3(__lc_,X,_data_LEN)]; */
+
+/* #define COMMON_MMIDX(X) \ */
+/* unsigned char __PASTE3(lc_,X,_rows)[__PASTE3(__lc_,X,_rows_LEN)]; \ */
+/* uint16_t __PASTE3(lc_,X,_item_offsets)[__PASTE3(__lc_,X,_item_offsets_LEN)]; \ */
+/* uint16_t __PASTE3(lc_,X,_item_idx)[__PASTE3(__lc_,X,_item_idx_LEN)]; \ */
+
+/* ---------------------------------------------------------------------- */
+
+#define COMMON_OFFSETS(X) \
+ offsetof(__locale_mmap_t, __PASTE3(lc_,X,_rows)), \
+ offsetof(__locale_mmap_t, __PASTE3(lc_,X,_item_offsets)), \
+ offsetof(__locale_mmap_t, __PASTE3(lc_,X,_item_idx)), \
+ offsetof(__locale_mmap_t, __PASTE3(lc_,X,_data)) \
+
+
+static const size_t common_tbl_offsets[CATEGORIES*4] = {
+ 0, 0, 0, 0, /* ctype */
+ COMMON_OFFSETS(numeric),
+ COMMON_OFFSETS(monetary),
+ COMMON_OFFSETS(time),
+ 0, 0, 0, 0, /* collate */
+ COMMON_OFFSETS(messages),
+};
+
+
+void out_uc(FILE *f, const unsigned char *p, size_t n, char *comment)
+{
+ size_t i;
+
+ fprintf(f, "{\t/* %s */", comment);
+ for (i = 0 ; i < n ; i++) {
+ if (!(i & 7)) {
+ fprintf(f, "\n\t");
+ }
+ if (p[i]) {
+ fprintf(f, "%#04x, ", p[i]);
+ } else {
+ fprintf(f, "%#4x, ", p[i]);
+ }
+ }
+ fprintf(f, "\n},\n");
+}
+
+void out_u16(FILE *f, const uint16_t *p, size_t n, char *comment)
+{
+ size_t i;
+
+ fprintf(f, "{\t/* %s */", comment);
+ for (i = 0 ; i < n ; i++) {
+ if (!(i & 7)) {
+ fprintf(f, "\n\t");
+ }
+ if (p[i]) {
+ fprintf(f, "%#06x, ", p[i]);
+ } else {
+ fprintf(f, "%#6x, ", p[i]);
+ }
+ }
+ fprintf(f, "\n},\n");
+}
+
+void out_i16(FILE *f, const int16_t *p, size_t n, char *comment)
+{
+ size_t i;
+
+ fprintf(f, "{\t/* %s */", comment);
+ for (i = 0 ; i < n ; i++) {
+ if (!(i & 7)) {
+ fprintf(f, "\n\t");
+ }
+ fprintf(f, "%6d, ", p[i]);
+ }
+ fprintf(f, "\n},\n");
+}
+
+void out_size_t(FILE *f, const size_t *p, size_t n, char *comment)
+{
+ size_t i;
+
+ fprintf(f, "{\t/* %s */", comment);
+ for (i = 0 ; i < n ; i++) {
+ if (!(i & 3)) {
+ fprintf(f, "\n\t");
+ }
+ if (p[i]) {
+ fprintf(f, "%#010zx, ", p[i]);
+ } else {
+ fprintf(f, "%#10zx, ", p[i]);
+ }
+ }
+ fprintf(f, "\n},\n");
+}
+
+
+int main(void)
+{
+ FILE *lso; /* static object */
+ int i;
+ unsigned char magic[MAGIC_SIZE];
+
+ memset(magic, 0, MAGIC_SIZE);
+
+ if (!(lso = fopen("locale_data.c", "w"))) {
+ printf("can't open locale_data.c!\n");
+ return EXIT_FAILURE;
+ }
+
+ fprintf(lso,
+ "#include <stddef.h>\n"
+ "#include <stdint.h>\n"
+/* "#define __CTYPE_HAS_8_BIT_LOCALES\n" */
+ "#ifndef __WCHAR_ENABLED\n"
+ "#error __WCHAR_ENABLED not defined\n"
+ "#endif\n"
+ "#include \"c8tables.h\"\n"
+ "#include \"wctables.h\"\n"
+ "#include \"lt_defines.h\"\n"
+ "#include \"locale_mmap.h\"\n\n"
+ "static const __locale_mmap_t locale_mmap = {\n\n"
+ );
+ out_uc(lso, magic, MAGIC_SIZE, "magic");
+#ifdef __CTYPE_HAS_8_BIT_LOCALES
+ out_uc(lso, Cctype_data, Cctype_TBL_LEN, "tbl8ctype");
+ out_uc(lso, Cuplow_data, Cuplow_TBL_LEN, "tbl8uplow");
+#ifdef __WCHAR_ENABLED
+ out_u16(lso, Cc2wc_data, Cc2wc_TBL_LEN, "tbl8c2wc");
+ out_uc(lso, Cwc2c_data, Cwc2c_TBL_LEN, "tbl8wc2c");
+ /* translit */
+#endif /* __WCHAR_ENABLED */
+#endif /* __CTYPE_HAS_8_BIT_LOCALES */
+#ifdef __WCHAR_ENABLED
+ out_uc(lso, WCctype_data, WCctype_TBL_LEN, "tblwctype");
+ out_uc(lso, WCuplow_data, WCuplow_TBL_LEN, "tblwuplow");
+ out_i16(lso, WCuplow_diff_data, WCuplow_diff_TBL_LEN, "tblwuplow_diff");
+/* const unsigned char tblwcomb[WCcomb_TBL_LEN]; */
+ /* width?? */
+#endif /* __WCHAR_ENABLED */
+ out_uc(lso, __lc_numeric_data, __lc_numeric_data_LEN, "lc_numeric_data");
+ out_uc(lso, __lc_monetary_data, __lc_monetary_data_LEN, "lc_monetary_data");
+ out_uc(lso, __lc_time_data, __lc_time_data_LEN, "lc_time_data");
+ /* TODO -- collate*/
+ out_uc(lso, __lc_messages_data, __lc_messages_data_LEN, "lc_messages_data");
+
+#ifdef __CTYPE_HAS_8_BIT_LOCALES
+ fprintf(lso, "{ /* codeset_8_bit array */\n");
+ for (i = 0 ; i < NUM_CODESETS ; i++) {
+ fprintf(lso, "{ /* codeset_8_bit[%d] */\n", i);
+ out_uc(lso, codeset_8_bit[i].idx8ctype, Cctype_IDX_LEN, "idx8ctype");
+ out_uc(lso, codeset_8_bit[i].idx8uplow, Cuplow_IDX_LEN, "idx8uplow");
+ out_uc(lso, codeset_8_bit[i].idx8c2wc, Cc2wc_IDX_LEN, "idx8c2wc");
+ out_uc(lso, codeset_8_bit[i].idx8wc2c, Cwc2c_II_LEN, "idx8wc2c");
+ fprintf(lso, "},\n");
+ }
+ fprintf(lso, "},\n");
+#endif /* __CTYPE_HAS_8_BIT_LOCALES */
+
+ out_uc(lso, __lc_numeric_rows, __lc_numeric_rows_LEN, "lc_numeric_rows");
+ out_u16(lso, __lc_numeric_item_offsets, __lc_numeric_item_offsets_LEN, "lc_numeric_item_offsets");
+ out_u16(lso, __lc_numeric_item_idx, __lc_numeric_item_idx_LEN, "lc_numeric_item_idx");
+
+ out_uc(lso, __lc_monetary_rows, __lc_monetary_rows_LEN, "lc_monetary_rows");
+ out_u16(lso, __lc_monetary_item_offsets, __lc_monetary_item_offsets_LEN, "lc_monetary_item_offsets");
+ out_u16(lso, __lc_monetary_item_idx, __lc_monetary_item_idx_LEN, "lc_monetary_item_idx");
+
+ out_uc(lso, __lc_time_rows, __lc_time_rows_LEN, "lc_time_rows");
+ out_u16(lso, __lc_time_item_offsets, __lc_time_item_offsets_LEN, "lc_time_item_offsets");
+ out_u16(lso, __lc_time_item_idx, __lc_time_item_idx_LEN, "lc_time_item_idx");
+
+ /* TODO -- collate*/
+
+ out_uc(lso, __lc_messages_rows, __lc_messages_rows_LEN, "lc_messages_rows");
+ out_u16(lso, __lc_messages_item_offsets, __lc_messages_item_offsets_LEN, "lc_messages_item_offsets");
+ out_u16(lso, __lc_messages_item_idx, __lc_messages_item_idx_LEN, "lc_messages_item_idx");
+
+ {
+ unsigned char co_buf[CATEGORIES] = {
+ 1, __lc_numeric_item_offsets_LEN, __lc_monetary_item_offsets_LEN,
+ __lc_time_item_offsets_LEN, 0, __lc_messages_item_offsets_LEN
+ };
+ out_uc(lso, co_buf, CATEGORIES, "lc_common_item_offsets_LEN");
+ }
+
+ out_size_t(lso, common_tbl_offsets, CATEGORIES * 4, "lc_common_tbl_offsets");
+ /* offsets from start of locale_mmap_t */
+ /* rows, item_offsets, item_idx, data */
+
+#ifdef NUM_LOCALES
+ out_uc(lso, __locales, NUM_LOCALES * WIDTH_LOCALES, "locales");
+ out_uc(lso, __locale_names5, 5 * NUM_LOCALE_NAMES, "locale_names5");
+#ifdef LOCALE_AT_MODIFIERS_LENGTH
+ out_uc(lso, __locale_at_modifiers, LOCALE_AT_MODIFIERS_LENGTH, "locale_at_modifiers");
+#else
+#error LOCALE_AT_MODIFIERS_LENGTH not defined!
+#endif /* LOCALE_AT_MODIFIERS_LENGTH */
+#endif /* NUM_LOCALES */
+
+ out_uc(lso, lc_names, lc_names_LEN, "lc_names");
+#ifdef __CTYPE_HAS_8_BIT_LOCALES
+ out_uc(lso, (const unsigned char*) CODESET_LIST, sizeof(CODESET_LIST), "codeset_list");
+#endif /* __CTYPE_HAS_8_BIT_LOCALES */
+
+ fprintf(lso,
+ "\n};\n\n"
+ "const __locale_mmap_t *__locale_mmap = &locale_mmap;\n\n"
+ );
+
+ if (ferror(lso) || fclose(lso)) {
+ printf("error writing!\n");
+ return EXIT_FAILURE;
+ }
+
+ return EXIT_SUCCESS;
+}
+
+
+
+/* ---------------------------------------------------------------------- */
+
+#if 0
+#define WRITE_COMMON_MMAP(X) \
+ fseek(fp, (long) offsetof(__locale_mmap_t, __PASTE3(lc_,X,_data)), SEEK_SET); \
+ for (i=0 ; i < __PASTE3(__lc_,X,_data_LEN) ; i++) { \
+ putc(__PASTE3(__lc_,X,_data)[i], fp); \
+ }
+
+#define WRITE_COMMON_MMIDX(X) \
+ fseek(fp, (long) offsetof(__locale_mmap_t, __PASTE3(lc_,X,_rows)), SEEK_SET); \
+ for (i=0 ; i < __PASTE3(__lc_,X,_rows_LEN) ; i++) { \
+ putc(__PASTE3(__lc_,X,_rows)[i], fp); \
+ } \
+ fseek(fp, (long) offsetof(__locale_mmap_t, __PASTE3(lc_,X,_item_offsets)), SEEK_SET); \
+ for (i=0 ; i < __PASTE3(__lc_,X,_item_offsets_LEN) ; i++) { \
+ putc( ((unsigned char *) &(__PASTE3(__lc_,X,_item_offsets)[i]))[0], fp); \
+ putc( ((unsigned char *) &(__PASTE3(__lc_,X,_item_offsets)[i]))[1], fp); \
+ } \
+ fseek(fp, (long) offsetof(__locale_mmap_t, __PASTE3(lc_,X,_item_idx)), SEEK_SET); \
+ for (i=0 ; i < __PASTE3(__lc_,X,_item_idx_LEN) ; i++) { \
+ putc( ((unsigned char *) &(__PASTE3(__lc_,X,_item_idx)[i]))[0], fp); \
+ putc( ((unsigned char *) &(__PASTE3(__lc_,X,_item_idx)[i]))[1], fp); \
+ }
+
+#define WRITE_WC_DATA(X) \
+ fseek(fp, (long) offsetof(__locale_mmap_t, __PASTE2(tblw,X)), SEEK_SET); \
+ for (i=0 ; i < __PASTE3(WC,X,_TBL_LEN) ; i++) { \
+ putc(__PASTE3(WC,X,_data)[i], fp); \
+ }
+
+#define WRITE_WC_I16_DATA(X) \
+ fseek(fp, (long) offsetof(__locale_mmap_t, __PASTE2(tblw,X)), SEEK_SET); \
+ for (i=0 ; i < __PASTE3(WC,X,_TBL_LEN) ; i++) { \
+ putc( ((unsigned char *) &(__PASTE3(WC,X,_data)[i]))[0], fp); \
+ putc( ((unsigned char *) &(__PASTE3(WC,X,_data)[i]))[1], fp); \
+ }
+
+#define WRITE_C_DATA(X) \
+ fseek(fp, (long) offsetof(__locale_mmap_t, __PASTE2(tbl8,X)), SEEK_SET); \
+ for (i=0 ; i < __PASTE3(C,X,_TBL_LEN) ; i++) { \
+ putc(__PASTE3(C,X,_data)[i], fp); \
+ }
+
+#define WRITE_C_U16_DATA(X) \
+ fseek(fp, (long) offsetof(__locale_mmap_t, __PASTE2(tbl8,X)), SEEK_SET); \
+ for (i=0 ; i < __PASTE3(C,X,_TBL_LEN) ; i++) { \
+ putc( ((unsigned char *) &(__PASTE3(C,X,_data)[i]))[0], fp); \
+ putc( ((unsigned char *) &(__PASTE3(C,X,_data)[i]))[1], fp); \
+ }
+
+/**********************************************************************/
+
+#define COMMON_OFFSETS(X) \
+ offsetof(__locale_mmap_t, __PASTE3(lc_,X,_rows)), \
+ offsetof(__locale_mmap_t, __PASTE3(lc_,X,_item_offsets)), \
+ offsetof(__locale_mmap_t, __PASTE3(lc_,X,_item_idx)), \
+ offsetof(__locale_mmap_t, __PASTE3(lc_,X,_data)) \
+
+
+static const size_t common_tbl_offsets[CATEGORIES*4] = {
+ 0, 0, 0, 0, /* ctype */
+ COMMON_OFFSETS(numeric),
+ COMMON_OFFSETS(monetary),
+ COMMON_OFFSETS(time),
+ 0, 0, 0, 0, /* collate */
+ COMMON_OFFSETS(messages),
+};
+
+
+
+
+
+int main(void)
+{
+ FILE *fp;
+ size_t i;
+ unsigned char *p;
+
+ if (!(fp = fopen("locale.mmap", "w"))) {
+ printf("error - can't open locale.mmap for writing!");
+ return EXIT_FAILURE;
+ }
+
+ for (i=0 ; i < sizeof(__locale_mmap_t) ; i++) {
+ putc(0, fp); /* Zero out the file. */
+ }
+
+#ifdef __CTYPE_HAS_8_BIT_LOCALES
+ WRITE_C_DATA(ctype);
+ WRITE_C_DATA(uplow);
+#ifdef __WCHAR_ENABLED
+ WRITE_C_U16_DATA(c2wc);
+ WRITE_C_DATA(wc2c);
+ /* translit */
+#endif /* __WCHAR_ENABLED */
+#endif /* __CTYPE_HAS_8_BIT_LOCALES */
+
+#ifdef __WCHAR_ENABLED
+ WRITE_WC_DATA(ctype);
+ WRITE_WC_DATA(uplow);
+ WRITE_WC_I16_DATA(uplow_diff);
+/* WRITE_WC_DATA(comb); */
+ /* width?? */
+#endif /* __WCHAR_ENABLED */
+
+ WRITE_COMMON_MMAP(numeric);
+ WRITE_COMMON_MMAP(monetary);
+ WRITE_COMMON_MMAP(time);
+ /* TODO -- collate*/
+ WRITE_COMMON_MMAP(messages);
+
+#ifdef __CTYPE_HAS_8_BIT_LOCALES
+ fseek(fp, (long) offsetof(__locale_mmap_t, codeset_8_bit), SEEK_SET); \
+ p = (unsigned char *) codeset_8_bit;
+ for (i=0 ; i < sizeof(codeset_8_bit) ; i++) {
+ putc(p[i], fp);
+ }
+#endif /* __CTYPE_HAS_8_BIT_LOCALES */
+
+ WRITE_COMMON_MMIDX(numeric);
+ WRITE_COMMON_MMIDX(monetary);
+ WRITE_COMMON_MMIDX(time);
+ /* TODO -- collate*/
+ WRITE_COMMON_MMIDX(messages);
+
+ fseek(fp, (long) offsetof(__locale_mmap_t, lc_common_item_offsets_LEN), SEEK_SET);
+ putc(1, fp); /* ctype -- (codeset) handled specially */
+ putc(__lc_numeric_item_offsets_LEN, fp);
+ putc(__lc_monetary_item_offsets_LEN, fp);
+ putc(__lc_time_item_offsets_LEN, fp);
+ putc(0, fp); /* collate */
+ putc(__lc_messages_item_offsets_LEN, fp);
+
+ fseek(fp, (long) offsetof(__locale_mmap_t, lc_common_tbl_offsets), SEEK_SET);
+ for (i=0 ; i < sizeof(common_tbl_offsets) ; i++) {
+ putc(((unsigned char *)common_tbl_offsets)[i], fp);
+ }
+
+#ifdef NUM_LOCALES
+ fseek(fp, (long) offsetof(__locale_mmap_t, locales), SEEK_SET);
+ for (i=0 ; i < (NUM_LOCALES * WIDTH_LOCALES) ; i++) {
+ putc(__locales[i], fp);
+ }
+
+ fseek(fp, (long) offsetof(__locale_mmap_t, locale_names5), SEEK_SET);
+ for (i=0 ; i < 5 * NUM_LOCALE_NAMES ; i++) {
+ putc(__locale_names5[i], fp);
+ }
+
+#ifdef LOCALE_AT_MODIFIERS_LENGTH
+ fseek(fp, (long) offsetof(__locale_mmap_t, locale_at_modifiers), SEEK_SET);
+ for (i=0 ; i < LOCALE_AT_MODIFIERS_LENGTH ; i++) {
+ putc(__locale_at_modifiers[i], fp);
+ }
+#endif /* LOCALE_AT_MODIFIERS_LENGTH */
+#endif /* NUM_LOCALES */
+
+ fseek(fp, (long) offsetof(__locale_mmap_t, lc_names), SEEK_SET);
+ for (i=0 ; i < lc_names_LEN ; i++) {
+ putc(lc_names[i], fp);
+ }
+
+#ifdef __CTYPE_HAS_8_BIT_LOCALES
+ fseek(fp, (long) offsetof(__locale_mmap_t, codeset_list), SEEK_SET);
+ for (i=0 ; i < sizeof(CODESET_LIST) ; i++) {
+ putc((unsigned char)(CODESET_LIST[i]), fp);
+ }
+#endif /* __CTYPE_HAS_8_BIT_LOCALES */
+
+
+ if (ferror(fp) || (fclose(fp) == EOF)) {
+ printf("error - stream in error state or fclose failed!");
+ return EXIT_FAILURE;
+ }
+
+ printf("sizeof(__locale_mmap_t) = %zd\n", sizeof(__locale_mmap_t));
+
+ return EXIT_SUCCESS;
+}
+#endif
+
+/* TODO:
+ * collate data (8-bit weighted single char only)
+ * @ mappings!
+ * codeset list? yes, since we'll want to be able to inspect them...
+ * that means putting some header stuff in magic
+ * fix ctype LEN defines in gen_c8tables
+ */
diff --git a/extra/locale/gen_locale.c b/extra/locale/gen_locale.c
index 047b843dc..268c3d61b 100644
--- a/extra/locale/gen_locale.c
+++ b/extra/locale/gen_locale.c
@@ -10,7 +10,6 @@
#include <nl_types.h>
#include <stdint.h>
-#define __CTYPE_HAS_8_BIT_LOCALES
#include "c8tables.h"
@@ -101,6 +100,9 @@ static void do_locale_names(void)
fprintf(ofp, "static const unsigned char __locales[%d];\n", (3 + CATEGORIES));
fprintf(ofp, "static const unsigned char __locale_names5[5];\n");
} else {
+ if (default_utf8) {
+ fprintf(ofp, "#define __CTYPE_HAS_UTF_8_LOCALES\t\t\t1\n");
+ }
fprintf(ofp, "#define CATEGORIES\t\t\t%d\n", CATEGORIES);
fprintf(ofp, "#define WIDTH_LOCALES\t\t\t%d\n", 3+CATEGORIES);
fprintf(ofp, "#define NUM_LOCALES\t\t\t%d\n", num_locales);
diff --git a/extra/locale/gen_mmap.c b/extra/locale/gen_mmap.c
index ae5d4dff6..f9bce022c 100644
--- a/extra/locale/gen_mmap.c
+++ b/extra/locale/gen_mmap.c
@@ -16,13 +16,13 @@
#define WANT_WCctype_data
#define WANT_WCuplow_data
#define WANT_WCuplow_diff_data
-#define WANT_WCcomb_data
+/* #define WANT_WCcomb_data */
/* #define WANT_WCwidth_data */
#include "wctables.h"
#undef WANT_WCctype_data
#undef WANT_WCuplow_data
#undef WANT_WCuplow_diff_data
-#undef WANT_WCcomb_data
+/* #undef WANT_WCcomb_data */
/* #undef WANT_WCwidth_data */
/* #define WCctype_TBL_LEN (WCctype_II_LEN + WCctype_TI_LEN + WCctype_UT_LEN) */
@@ -149,7 +149,7 @@ int main(void)
WRITE_WC_DATA(ctype);
WRITE_WC_DATA(uplow);
WRITE_WC_I16_DATA(uplow_diff);
- WRITE_WC_DATA(comb);
+/* WRITE_WC_DATA(comb); */
/* width?? */
#endif /* __WCHAR_ENABLED */
diff --git a/extra/locale/gen_wc8bit.c b/extra/locale/gen_wc8bit.c
index 785c3f4c0..d76c15a51 100644
--- a/extra/locale/gen_wc8bit.c
+++ b/extra/locale/gen_wc8bit.c
@@ -7,6 +7,14 @@
#include <wctype.h>
#include <limits.h>
+#ifndef __UCLIBC__
+#ifndef _WCTYPE_H
+#define _WCTYPE_H
+#endif
+#include "../../libc/sysdeps/linux/common/bits/uClibc_ctype.h"
+#endif
+
+
/* #define CTYPE_PACKED */
#define UPLOW_IDX_SHIFT 3
/* best if 2 unpacked or 3 packed */
@@ -63,34 +71,6 @@ typedef struct {
unsigned char c2wc_idx[C2WC_IDX_LEN];
} charset_data;
-/* 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,
-};
-
int main(int argc, char **argv)
{
FILE *fp;
diff --git a/extra/locale/gen_wctype.c b/extra/locale/gen_wctype.c
index 9508a3bbf..1c8c10c43 100644
--- a/extra/locale/gen_wctype.c
+++ b/extra/locale/gen_wctype.c
@@ -10,6 +10,12 @@
#include <wchar.h>
#include <ctype.h>
+#ifndef __UCLIBC__
+#ifndef _WCTYPE_H
+#define _WCTYPE_H
+#endif
+#include "../../libc/sysdeps/linux/common/bits/uClibc_ctype.h"
+#endif
/* 0x9 : space blank */
/* 0xa : space */
@@ -61,6 +67,7 @@
#define RANGE 0xffffUL /* Restrict for 16-bit wchar_t... */
#endif
+#if 0
/* Classification codes. */
static const char *typename[] = {
@@ -81,7 +88,9 @@ static const char *typename[] = {
"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
@@ -109,21 +118,8 @@ enum {
__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)) <=