Index: lib/libc/locale/rune.h =================================================================== RCS file: /cvsroot/src/lib/libc/locale/rune.h,v retrieving revision 1.12 diff -u -r1.12 rune.h --- lib/libc/locale/rune.h 3 Sep 2007 20:31:56 -0000 1.12 +++ lib/libc/locale/rune.h 19 Sep 2007 07:05:29 -0000 @@ -62,6 +62,7 @@ #define _CTYPE_I _RUNETYPE_I #define _CTYPE_T _RUNETYPE_T #define _CTYPE_Q _RUNETYPE_Q +#define _CTYPE_W _RUNETYPE_W #define _CTYPE_SWM _RUNETYPE_SWM #define _CTYPE_SWS _RUNETYPE_SWS #define _CTYPE_SW0 _RUNETYPE_SW0 Index: lib/libc/locale/runeglue.c =================================================================== RCS file: /cvsroot/src/lib/libc/locale/runeglue.c,v retrieving revision 1.11 diff -u -r1.11 runeglue.c --- lib/libc/locale/runeglue.c 29 Nov 2005 03:11:59 -0000 1.11 +++ lib/libc/locale/runeglue.c 19 Sep 2007 07:05:29 -0000 @@ -107,7 +107,9 @@ new_toupper[0] = EOF; new_tolower[0] = EOF; for (i = 0; i < _CTYPE_NUM_CHARS; i++) { - new_ctype[i + 1]=0; + new_ctype[i + 1] = 0; + if (_CurrentRuneLocale->rl_runetype[i] & _CTYPE_W) + continue; if (_CurrentRuneLocale->rl_runetype[i] & _CTYPE_U) new_ctype[i + 1] |= _U; if (_CurrentRuneLocale->rl_runetype[i] & _CTYPE_L) Index: lib/libc/locale/runetype.h =================================================================== RCS file: /cvsroot/src/lib/libc/locale/runetype.h,v retrieving revision 1.19 diff -u -r1.19 runetype.h --- lib/libc/locale/runetype.h 29 Nov 2005 03:11:59 -0000 1.19 +++ lib/libc/locale/runetype.h 19 Sep 2007 07:05:29 -0000 @@ -72,6 +72,7 @@ #define _RUNETYPE_I UINT32_C(0x00080000) /* Ideogram */ #define _RUNETYPE_T UINT32_C(0x00100000) /* Special */ #define _RUNETYPE_Q UINT32_C(0x00200000) /* Phonogram */ +#define _RUNETYPE_W UINT32_C(0x00400000) /* Wide */ #define _RUNETYPE_SWM UINT32_C(0xc0000000)/* Mask to get screen width data */ #define _RUNETYPE_SWS 30 /* Bits to shift to get width */ #define _RUNETYPE_SW0 UINT32_C(0x00000000) /* 0 width character */ Index: usr.bin/mklocale/Makefile =================================================================== RCS file: /cvsroot/src/usr.bin/mklocale/Makefile,v retrieving revision 1.11 diff -u -r1.11 Makefile --- usr.bin/mklocale/Makefile 1 Aug 2003 17:04:04 -0000 1.11 +++ usr.bin/mklocale/Makefile 19 Sep 2007 07:05:29 -0000 @@ -2,10 +2,15 @@ .include -WARNS?= 2 +WARNS?= 2 PROG= mklocale SRCS= yacc.y lex.l CPPFLAGS+= -I. -I${.CURDIR} -I${NETBSDSRCDIR}/lib/libc YHEADER= 1 +.ifndef HOSTPROG +LDADD+= -lutil +DPADD+= ${LIBUTIL} +.endif + .include Index: usr.bin/mklocale/yacc.y =================================================================== RCS file: /cvsroot/src/usr.bin/mklocale/yacc.y,v retrieving revision 1.24 diff -u -r1.24 yacc.y --- usr.bin/mklocale/yacc.y 5 Jan 2004 23:23:36 -0000 1.24 +++ usr.bin/mklocale/yacc.y 19 Sep 2007 07:05:30 -0000 @@ -51,14 +51,21 @@ #include /* Needed by on NetBSD 1.5. */ #include /* Needed for htonl on POSIX systems. */ +#include +#include #include -#include "locale/runetype.h" #include #include #include #include +#include #include -#include +#include + +#include "citrus/citrus_module.h" +#include "citrus/citrus_ctype.h" +#include "locale/rune.h" +#include "locale/multibyte.h" #include "ldef.h" @@ -82,10 +89,10 @@ int main __P((int, char *[])); int yyerror __P((const char *s)); -void *xmalloc __P((unsigned int sz)); u_int32_t *xlalloc __P((unsigned int sz)); u_int32_t *xrelalloc __P((u_int32_t *old, unsigned int sz)); void dump_tables __P((void)); +void fixup __P((void)); int yyparse __P((void)); extern int yylex __P((void)); %} @@ -120,7 +127,7 @@ locale : /* empty */ | table - { dump_tables(); } + { fixup(); dump_tables(); } ; table : entry @@ -128,7 +135,7 @@ ; entry : ENCODING STRING - { strncpy(new_locale.rl_encoding, $2, sizeof(new_locale.rl_encoding)); } + { strlcpy(new_locale.rl_encoding, $2, sizeof(new_locale.rl_encoding)); } | VARIABLE { new_locale.rl_variable_len = strlen($1) + 1; new_locale.rl_variable = strdup($1); @@ -183,28 +190,28 @@ list : RUNE { - $$ = (rune_list *)malloc(sizeof(rune_list)); + $$ = (rune_list *)emalloc(sizeof(rune_list)); $$->min = ($1 & charsetmask) | charsetbits; $$->max = ($1 & charsetmask) | charsetbits; $$->next = 0; } | RUNE THRU RUNE { - $$ = (rune_list *)malloc(sizeof(rune_list)); + $$ = (rune_list *)emalloc(sizeof(rune_list)); $$->min = ($1 & charsetmask) | charsetbits; $$->max = ($3 & charsetmask) | charsetbits; $$->next = 0; } | list RUNE { - $$ = (rune_list *)malloc(sizeof(rune_list)); + $$ = (rune_list *)emalloc(sizeof(rune_list)); $$->min = ($2 & charsetmask) | charsetbits; $$->max = ($2 & charsetmask) | charsetbits; $$->next = $1; } | list RUNE THRU RUNE { - $$ = (rune_list *)malloc(sizeof(rune_list)); + $$ = (rune_list *)emalloc(sizeof(rune_list)); $$->min = ($2 & charsetmask) | charsetbits; $$->max = ($4 & charsetmask) | charsetbits; $$->next = $1; @@ -213,7 +220,7 @@ map : LBRK RUNE RUNE RBRK { - $$ = (rune_list *)malloc(sizeof(rune_list)); + $$ = (rune_list *)emalloc(sizeof(rune_list)); $$->min = ($2 & charsetmask) | charsetbits; $$->max = ($2 & charsetmask) | charsetbits; $$->map = $3; @@ -221,7 +228,7 @@ } | map LBRK RUNE RUNE RBRK { - $$ = (rune_list *)malloc(sizeof(rune_list)); + $$ = (rune_list *)emalloc(sizeof(rune_list)); $$->min = ($3 & charsetmask) | charsetbits; $$->max = ($3 & charsetmask) | charsetbits; $$->map = $4; @@ -229,7 +236,7 @@ } | LBRK RUNE THRU RUNE ':' RUNE RBRK { - $$ = (rune_list *)malloc(sizeof(rune_list)); + $$ = (rune_list *)emalloc(sizeof(rune_list)); $$->min = ($2 & charsetmask) | charsetbits; $$->max = ($4 & charsetmask) | charsetbits; $$->map = $6; @@ -237,7 +244,7 @@ } | map LBRK RUNE THRU RUNE ':' RUNE RBRK { - $$ = (rune_list *)malloc(sizeof(rune_list)); + $$ = (rune_list *)emalloc(sizeof(rune_list)); $$->min = ($3 & charsetmask) | charsetbits; $$->max = ($5 & charsetmask) | charsetbits; $$->map = $7; @@ -266,8 +273,7 @@ break; case 'o': locale_file = optarg; - if ((ofile = fopen(locale_file, "w")) == 0) - err(1, "unable to open output file %s", locale_file); + ofile = efopen(locale_file, "w"); break; default: usage: @@ -307,27 +313,14 @@ return 0; } -void * -xmalloc(sz) - unsigned int sz; -{ - void *r = malloc(sz); - if (!r) { - perror("xmalloc"); - abort(); - } - return(r); -} - u_int32_t * xlalloc(sz) unsigned int sz; { - u_int32_t *r = (u_int32_t *)malloc(sz * sizeof(u_int32_t)); - if (!r) { - perror("xlalloc"); - abort(); - } + u_int32_t *r; + + r = (u_int32_t *)emalloc(sz * sizeof(u_int32_t)); + return(r); } @@ -336,12 +329,10 @@ u_int32_t *old; unsigned int sz; { - u_int32_t *r = (u_int32_t *)realloc((char *)old, - sz * sizeof(u_int32_t)); - if (!r) { - perror("xrelalloc"); - abort(); - } + u_int32_t *r; + + r = (u_int32_t *)erealloc((char *)old, sz * sizeof(u_int32_t)); + return(r); } @@ -371,7 +362,7 @@ rune_list *nlist = list->next; for (i = list->min; i <= list->max; ++i) { if (list->map + (i - list->min)) { - rune_list *tmp = (rune_list *)xmalloc(sizeof(rune_list)); + rune_list *tmp = (rune_list *)emalloc(sizeof(rune_list)); tmp->min = i; tmp->max = i; add_map(map, tmp, list->map + (i - list->min)); @@ -883,3 +874,32 @@ } } } + +void +fixup() +{ + _citrus_ctype_t cd; + char *s, *t; + size_t n; + int ret, x; + wint_t ch; + + s = estrndup((const char *) + new_locale.rl_variable, new_locale.rl_variable_len); + t = strstr(s, _RUNE_CODESET); + if (t != NULL) + *t = '\0'; + n = strlen(s); + ret = _citrus_ctype_open(&cd, (const char *) + new_locale.rl_encoding, (void *)s, n, _PRIVSIZE); + if (ret != 0) + errx(1, "unable to open ctype module %s", + new_locale.rl_encoding); + free(s); + for (x = 0; x < _NB_CACHED_RUNES; ++x) { + _citrus_ctype_btowc(cd, x, &ch); + if (ch == WEOF) + types.map[x] |= _RUNETYPE_W; + } + _citrus_ctype_close(cd); +}