summaryrefslogtreecommitdiff
path: root/extra/locale/gen_ldc.c
diff options
context:
space:
mode:
authorManuel Novoa III <mjn3@codepoet.org>2002-12-20 19:26:35 +0000
committerManuel Novoa III <mjn3@codepoet.org>2002-12-20 19:26:35 +0000
commitc9d66e44af5c93a1ea5487fd9bff78274be65850 (patch)
tree975bb662b51ac91f8d1434553b936784b175a802 /extra/locale/gen_ldc.c
parentbd6e7b0208c9652717bec30abff2d8dc12eaaca7 (diff)
The big thing is locale dependent collation support.
Also added outdigit support and (legacy) YESSTR/NOSTR support.
Diffstat (limited to 'extra/locale/gen_ldc.c')
-rw-r--r--extra/locale/gen_ldc.c205
1 files changed, 18 insertions, 187 deletions
diff --git a/extra/locale/gen_ldc.c b/extra/locale/gen_ldc.c
index 17e6c6875..399587d96 100644
--- a/extra/locale/gen_ldc.c
+++ b/extra/locale/gen_ldc.c
@@ -39,6 +39,7 @@
#define WCuplow_diff_TBL_LEN (2 * WCuplow_diffs)
/* #define WCcomb_TBL_LEN (WCcomb_II_LEN + WCcomb_TI_LEN + WCcomb_UT_LEN) */
+#include "locale_collate.h"
#include "locale_tables.h"
#include "locale_mmap.h"
@@ -69,7 +70,7 @@
static const size_t common_tbl_offsets[CATEGORIES*4] = {
- 0, 0, 0, 0, /* ctype */
+ COMMON_OFFSETS(ctype),
COMMON_OFFSETS(numeric),
COMMON_OFFSETS(monetary),
COMMON_OFFSETS(time),
@@ -190,6 +191,7 @@ int main(void)
/* const unsigned char tblwcomb[WCcomb_TBL_LEN]; */
/* width?? */
#endif /* __WCHAR_ENABLED */
+ out_uc(lso, __lc_ctype_data, __lc_ctype_data_LEN, "lc_ctype_data");
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");
@@ -209,6 +211,10 @@ int main(void)
fprintf(lso, "},\n");
#endif /* __CTYPE_HAS_8_BIT_LOCALES */
+ out_uc(lso, __lc_ctype_rows, __lc_ctype_rows_LEN, "lc_ctype_rows");
+ out_u16(lso, __lc_ctype_item_offsets, __lc_ctype_item_offsets_LEN, "lc_ctype_item_offsets");
+ out_u16(lso, __lc_ctype_item_idx, __lc_ctype_item_idx_LEN, "lc_ctype_item_idx");
+
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");
@@ -221,16 +227,23 @@ int main(void)
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");
+ /* collate should be last*/
+ assert(sizeof(__locale_collate_tbl)/sizeof(__locale_collate_tbl[0]) == __lc_collate_data_LEN) ;
+ out_u16(lso, __locale_collate_tbl, __lc_collate_data_LEN, "collate_data");
+
+
{
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
+ __lc_ctype_item_offsets_LEN,
+ __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");
}
@@ -267,190 +280,8 @@ int main(void)
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!