From edc431123ec58e73b288993dcaa279bfa6eca9f8 Mon Sep 17 00:00:00 2001 From: Ruslan Ermilov Date: Sun, 27 Feb 2005 20:31:13 +0000 Subject: [PATCH] Make the format of LC_COLLATE files architecture independent. --- Makefile.inc1 | 6 +++++- lib/libc/locale/collate.c | 15 +++++++++++++-- lib/libc/locale/collate.h | 2 +- sys/sys/param.h | 2 +- usr.bin/colldef/parse.y | 32 +++++++++++++++++++++++--------- 5 files changed, 43 insertions(+), 14 deletions(-) diff --git a/Makefile.inc1 b/Makefile.inc1 index 7099067d5708..89234b6bda98 100644 --- a/Makefile.inc1 +++ b/Makefile.inc1 @@ -775,6 +775,10 @@ _groff= gnu/usr.bin/groff/tmac _cap_mkdb= usr.bin/cap_mkdb .endif +.if ${BOOTSTRAPPING} < 600018 +_colldef= usr.bin/colldef +.endif + .if ${BOOTSTRAPPING} < 600017 _gencat= usr.bin/gencat .endif @@ -795,7 +799,7 @@ bootstrap-tools: ${_groff} \ gnu/usr.bin/texinfo \ ${_cap_mkdb} \ - usr.bin/colldef \ + ${_colldef} \ ${_gencat} \ usr.bin/lorder \ usr.bin/makewhatis \ diff --git a/lib/libc/locale/collate.c b/lib/libc/locale/collate.c index 82fe8bfd7bd0..683359800d61 100644 --- a/lib/libc/locale/collate.c +++ b/lib/libc/locale/collate.c @@ -99,7 +99,7 @@ __collate_load_tables(const char *encoding) chains = -1; if (strcmp(strbuf, COLLATE_VERSION) == 0) chains = 0; - else if (strcmp(strbuf, COLLATE_VERSION1_1) == 0) + else if (strcmp(strbuf, COLLATE_VERSION1_2) == 0) chains = 1; if (chains < 0) { (void)fclose(fp); @@ -172,10 +172,21 @@ __collate_load_tables(const char *encoding) if (__collate_char_pri_table_ptr != NULL) free(__collate_char_pri_table_ptr); __collate_char_pri_table_ptr = TMP_char_pri_table; + for (i = 0; i < UCHAR_MAX + 1; i++) { + __collate_char_pri_table[i].prim = + ntohl(__collate_char_pri_table[i].prim); + __collate_char_pri_table[i].sec = + ntohl(__collate_char_pri_table[i].sec); + } if (__collate_chain_pri_table != NULL) free(__collate_chain_pri_table); __collate_chain_pri_table = TMP_chain_pri_table; - + for (i = 0; i < chains; i++) { + __collate_chain_pri_table[i].prim = + ntohl(__collate_chain_pri_table[i].prim); + __collate_chain_pri_table[i].sec = + ntohl(__collate_chain_pri_table[i].sec); + } __collate_substitute_nontrivial = 0; for (i = 0; i < UCHAR_MAX + 1; i++) { if (__collate_substitute_table[i][0] != i || diff --git a/lib/libc/locale/collate.h b/lib/libc/locale/collate.h index ce03e748742e..2f5f5d40eff0 100644 --- a/lib/libc/locale/collate.h +++ b/lib/libc/locale/collate.h @@ -37,7 +37,7 @@ #define STR_LEN 10 #define TABLE_SIZE 100 #define COLLATE_VERSION "1.0\n" -#define COLLATE_VERSION1_1 "1.1\n" +#define COLLATE_VERSION1_2 "1.2\n" struct __collate_st_char_pri { int prim, sec; diff --git a/sys/sys/param.h b/sys/sys/param.h index 48f9d904b140..1bc28738a577 100644 --- a/sys/sys/param.h +++ b/sys/sys/param.h @@ -57,7 +57,7 @@ * is created, otherwise 1. */ #undef __FreeBSD_version -#define __FreeBSD_version 600017 /* Master, propagated to newvers */ +#define __FreeBSD_version 600018 /* Master, propagated to newvers */ #ifndef LOCORE #include diff --git a/usr.bin/colldef/parse.y b/usr.bin/colldef/parse.y index a7e312fa1ab5..584f2820e9fa 100644 --- a/usr.bin/colldef/parse.y +++ b/usr.bin/colldef/parse.y @@ -58,7 +58,7 @@ u_char __collate_substitute_table[UCHAR_MAX + 1][STR_LEN]; struct __collate_st_char_pri __collate_char_pri_table[UCHAR_MAX + 1]; struct __collate_st_chain_pri *__collate_chain_pri_table; -int chain_index; +int chain_index = 0; int prim_pri = 1, sec_pri = 1; #ifdef COLLATE_DEBUG int debug; @@ -122,11 +122,15 @@ order : ORDER order_list { sizeof(__collate_chain_pri_table[0])); chain_index++; +#ifdef COLLATE_DEBUG + if (debug) + collate_print_tables(); +#endif if ((fp = fopen(out_file, "w")) == NULL) err(EX_UNAVAILABLE, "can't open destination file %s", out_file); - strcpy(__collate_version, COLLATE_VERSION1_1); + strcpy(__collate_version, COLLATE_VERSION1_2); if (fwrite(__collate_version, sizeof(__collate_version), 1, fp) != 1) err(EX_IOERR, "IO error writting collate version to destination file %s", @@ -141,11 +145,23 @@ order : ORDER order_list { err(EX_IOERR, "IO error writting substitute table to destination file %s", out_file); + for (ch = 0; ch < UCHAR_MAX + 1; ch++) { + __collate_char_pri_table[ch].prim = + htonl(__collate_char_pri_table[ch].prim); + __collate_char_pri_table[ch].sec = + htonl(__collate_char_pri_table[ch].sec); + } if (fwrite(__collate_char_pri_table, sizeof(__collate_char_pri_table), 1, fp) != 1) err(EX_IOERR, "IO error writting char table to destination file %s", out_file); + for (ch = 0; ch < chain_index; ch++) { + __collate_chain_pri_table[ch].prim = + htonl(__collate_chain_pri_table[ch].prim); + __collate_chain_pri_table[ch].sec = + htonl(__collate_chain_pri_table[ch].sec); + } if (fwrite(__collate_chain_pri_table, sizeof(*__collate_chain_pri_table), chain_index, fp) != (size_t)chain_index) @@ -155,10 +171,6 @@ order : ORDER order_list { if (fclose(fp) != 0) err(EX_IOERR, "IO error closing destination file %s", out_file); -#ifdef COLLATE_DEBUG - if (debug) - collate_print_tables(); -#endif exit(EX_OK); } ; @@ -351,7 +363,6 @@ static void collate_print_tables(void) { int i; - struct __collate_st_chain_pri *p2; printf("Substitute table:\n"); for (i = 0; i < UCHAR_MAX + 1; i++) @@ -359,8 +370,11 @@ collate_print_tables(void) printf("\t'%c' --> \"%s\"\n", i, __collate_substitute_table[i]); printf("Chain priority table:\n"); - for (p2 = __collate_chain_pri_table; p2->str[0] != '\0'; p2++) - printf("\t\"%s\" : %d %d\n", p2->str, p2->prim, p2->sec); + for (i = 0; i < chain_index - 1; i++) + printf("\t\"%s\" : %d %d\n", + __collate_chain_pri_table[i].str, + __collate_chain_pri_table[i].prim, + __collate_chain_pri_table[i].sec); printf("Char priority table:\n"); for (i = 0; i < UCHAR_MAX + 1; i++) printf("\t'%c' : %d %d\n", i, __collate_char_pri_table[i].prim,