diff options
-rw-r--r-- | lib/libc/citrus/citrus_ctype.h | 36 | ||||
-rw-r--r-- | lib/libc/citrus/citrus_ctype_local.h | 36 | ||||
-rw-r--r-- | lib/libc/locale/___runetype_mb.c | 70 | ||||
-rw-r--r-- | lib/libc/locale/_wctrans.c | 115 | ||||
-rw-r--r-- | lib/libc/locale/_wctrans_local.h | 58 | ||||
-rw-r--r-- | lib/libc/locale/iswctype.c | 226 | ||||
-rw-r--r-- | lib/libc/locale/rune.c | 319 | ||||
-rw-r--r-- | lib/libc/locale/rune.h | 81 | ||||
-rw-r--r-- | lib/libc/locale/rune_local.h | 46 | ||||
-rw-r--r-- | lib/libc/locale/runeglue.c | 127 | ||||
-rw-r--r-- | lib/libc/locale/runetable.c | 405 | ||||
-rw-r--r-- | lib/libc/locale/setrunelocale.c | 206 |
12 files changed, 1725 insertions, 0 deletions
diff --git a/lib/libc/citrus/citrus_ctype.h b/lib/libc/citrus/citrus_ctype.h new file mode 100644 index 00000000000..28356ab079f --- /dev/null +++ b/lib/libc/citrus/citrus_ctype.h @@ -0,0 +1,36 @@ +/* $OpenBSD: citrus_ctype.h,v 1.1 2005/08/07 10:16:23 espie Exp $ */ +/* $NetBSD: citrus_ctype.h,v 1.2 2003/03/05 20:18:15 tshiozak Exp $ */ + +/*- + * Copyright (c)2002 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#ifndef _CITRUS_CTYPE_H_ +#define _CITRUS_CTYPE_H_ + +#include "citrus_ctype_local.h" + +#endif diff --git a/lib/libc/citrus/citrus_ctype_local.h b/lib/libc/citrus/citrus_ctype_local.h new file mode 100644 index 00000000000..e3bcd923be2 --- /dev/null +++ b/lib/libc/citrus/citrus_ctype_local.h @@ -0,0 +1,36 @@ +#ifndef _CITRUS_CTYPE_LOCAL_H_ +#define _CITRUS_CTYPE_LOCAL_H_ +/* $OpenBSD: citrus_ctype_local.h,v 1.1 2005/08/07 10:16:23 espie Exp $ */ +/* $NetBSD: citrus_ctype_local.h,v 1.2 2003/03/05 20:18:15 tshiozak Exp $ */ + +/*- + * Copyright (c)2002 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + */ + +#define _CITRUS_DEFAULT_CTYPE_NAME "NONE" + +#endif + diff --git a/lib/libc/locale/___runetype_mb.c b/lib/libc/locale/___runetype_mb.c new file mode 100644 index 00000000000..c2eddf6cbe3 --- /dev/null +++ b/lib/libc/locale/___runetype_mb.c @@ -0,0 +1,70 @@ +/* $OpenBSD: ___runetype_mb.c,v 1.1 2005/08/07 10:16:23 espie Exp $ */ +/* $NetBSD: ___runetype_mb.c,v 1.10 2005/02/10 19:19:57 tnozaki Exp $ */ + +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> + +#include <wctype.h> +#include "rune.h" +#include "rune_local.h" + +_RuneType +___runetype_mb(wint_t c) +{ + rune_t c0; + uint32_t x; + _RuneRange *rr; + _RuneEntry *base, *re; + + if (c == WEOF) + return (0U); + + c0 = (rune_t)c; /* XXX assumes wint_t = int */ + rr = &_CurrentRuneLocale->rl_runetype_ext; + base = rr->rr_rune_ranges; + for (x = rr->rr_nranges; x; x >>= 1) { + re = base + (x >> 1); + if (re->re_min <= c0 && re->re_max >= c0) { + if (re->re_rune_types) + return (re->re_rune_types[c0 - re->re_min]); + else + return (re->re_map); + } else if (c0 > re->re_max) { + base = re + 1; + x--; + } + } + + return (0U); +} diff --git a/lib/libc/locale/_wctrans.c b/lib/libc/locale/_wctrans.c new file mode 100644 index 00000000000..3960ac216a4 --- /dev/null +++ b/lib/libc/locale/_wctrans.c @@ -0,0 +1,115 @@ +/* $OpenBSD: _wctrans.c,v 1.1 2005/08/07 10:16:23 espie Exp $ */ +/* $NetBSD: _wctrans.c,v 1.6 2005/02/10 19:19:57 tnozaki Exp $ */ + +/*- + * Copyright (c)2003 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> + +#include <wctype.h> +#include <stdlib.h> +#include <string.h> +#include "rune.h" +#include "rune_local.h" +#include "_wctrans_local.h" + +/* + * _wctrans_init: + */ + +void +_wctrans_init(_RuneLocale *rl) +{ + rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_name = "tolower"; + rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_cached = rl->rl_maplower; + rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_extmap = &rl->rl_maplower_ext; + rl->rl_wctrans[_WCTRANS_INDEX_UPPER].te_name = "toupper"; + rl->rl_wctrans[_WCTRANS_INDEX_UPPER].te_cached = rl->rl_mapupper; + rl->rl_wctrans[_WCTRANS_INDEX_UPPER].te_extmap = &rl->rl_mapupper_ext; +} + +/* + * _wctrans_ext: + * translate a character (extended part) + */ +wint_t +_towctrans_ext(wint_t c, struct _WCTransEntry *te) +{ + rune_t c0; + uint32_t x; + _RuneRange *rr; + _RuneEntry *base, *re; + + if (c == WEOF) + return (c); + + c0 = (rune_t)c; /* XXX assumes wchar_t = int */ + rr = te->te_extmap; + base = rr->rr_rune_ranges; + for (x = rr->rr_nranges; x != 0; x >>= 1) { + re = base + (x >> 1); + if (re->re_min <= c0 && re->re_max >= c0) + return (re->re_map + c0 - re->re_min); + else if (c0 >= re->re_max) { + base = re + 1; + x--; + } + } + + return (c); +} diff --git a/lib/libc/locale/_wctrans_local.h b/lib/libc/locale/_wctrans_local.h new file mode 100644 index 00000000000..4487f729369 --- /dev/null +++ b/lib/libc/locale/_wctrans_local.h @@ -0,0 +1,58 @@ +/* $NetBSD: _wctrans_local.h,v 1.2 2003/04/06 18:33:23 tshiozak Exp $ */ + +/*- + * Copyright (c)2003 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _WCTRANS_LOCAL_H_ +#define _WCTRANS_LOCAL_H_ + +extern wint_t _towctrans_ext(wint_t, _WCTransEntry *); +extern void _wctrans_init(_RuneLocale *); + +static __inline wint_t +_towctrans(wint_t c, _WCTransEntry *te) +{ + return (_RUNE_ISCACHED(c) ? + te->te_cached[(rune_t)c]:_towctrans_ext(c, te)); +} + +static __inline struct _WCTransEntry * +_wctrans_lower(_RuneLocale *rl) +{ + if (rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_name==NULL) + _wctrans_init(rl); + return (&rl->rl_wctrans[_WCTRANS_INDEX_LOWER]); +} + +static __inline struct _WCTransEntry * +_wctrans_upper(_RuneLocale *rl) +{ + if (rl->rl_wctrans[_WCTRANS_INDEX_UPPER].te_name==NULL) + _wctrans_init(rl); + return (&rl->rl_wctrans[_WCTRANS_INDEX_UPPER]); +} + +#endif diff --git a/lib/libc/locale/iswctype.c b/lib/libc/locale/iswctype.c new file mode 100644 index 00000000000..0f2aa34729a --- /dev/null +++ b/lib/libc/locale/iswctype.c @@ -0,0 +1,226 @@ +/* $OpenBSD: iswctype.c,v 1.1 2005/08/07 10:16:23 espie Exp $ */ +/* $NetBSD: iswctype.c,v 1.15 2005/02/09 21:35:46 kleink Exp $ */ + +/* + * Copyright (c) 1989 The Regents of the University of California. + * All rights reserved. + * (c) UNIX System Laboratories, Inc. + * All or some portions of this file are derived from material licensed + * to the University of California by American Telephone and Telegraph + * Co. or Unix System Laboratories, Inc. and are reproduced herein with + * the permission of UNIX System Laboratories, Inc. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> + +#include <wchar.h> +#include <wctype.h> +#include <ctype.h> +#include <errno.h> +#include <string.h> +#include "rune.h" +#include "runetype.h" +#include "rune_local.h" +#include "_wctrans_local.h" + +#ifdef lint +#define __inline +#endif + +static __inline _RuneType __runetype_w(wint_t); +static __inline int __isctype_w(wint_t, _RuneType); +static __inline wint_t __toupper_w(wint_t); +static __inline wint_t __tolower_w(wint_t); + +static __inline _RuneType +__runetype_w(wint_t c) +{ + _RuneLocale *rl = _CurrentRuneLocale; + + return (_RUNE_ISCACHED(c) ? + rl->rl_runetype[c] : ___runetype_mb(c)); +} + +static __inline int +__isctype_w(wint_t c, _RuneType f) +{ + return (!!(__runetype_w(c) & f)); +} + +static __inline wint_t +__toupper_w(wint_t c) +{ + return (_towctrans(c, _wctrans_upper(_CurrentRuneLocale))); +} + +static __inline wint_t +__tolower_w(wint_t c) +{ + return (_towctrans(c, _wctrans_lower(_CurrentRuneLocale))); +} + +int +iswalnum(wint_t c) +{ + return (__isctype_w((c), _CTYPE_A|_CTYPE_D)); +} + +int +iswalpha(wint_t c) +{ + return (__isctype_w((c), _CTYPE_A)); +} + +int +iswblank(wint_t c) +{ + return (__isctype_w((c), _CTYPE_B)); +} + +int +iswcntrl(wint_t c) +{ + return (__isctype_w((c), _CTYPE_C)); +} + +int +iswdigit(wint_t c) +{ + return (__isctype_w((c), _CTYPE_D)); +} + +int +iswgraph(wint_t c) +{ + return (__isctype_w((c), _CTYPE_G)); +} + +int +iswlower(wint_t c) +{ + return (__isctype_w((c), _CTYPE_L)); +} + +int +iswprint(wint_t c) +{ + return (__isctype_w((c), _CTYPE_R)); +} + +int +iswpunct(wint_t c) +{ + return (__isctype_w((c), _CTYPE_P)); +} + +int +iswspace(wint_t c) +{ + return (__isctype_w((c), _CTYPE_S)); +} + +int +iswupper(wint_t c) +{ + return (__isctype_w((c), _CTYPE_U)); +} + +int +iswxdigit(wint_t c) +{ + return (__isctype_w((c), _CTYPE_X)); +} + +wint_t +towupper(wint_t c) +{ + return (__toupper_w(c)); +} + +wint_t +towlower(wint_t c) +{ + return (__tolower_w(c)); +} + +int +wcwidth(wchar_t c) +{ + return (((unsigned)__runetype_w(c) & _CTYPE_SWM) >> _CTYPE_SWS); +} + +wctrans_t +wctrans(const char *charclass) +{ + int i; + _RuneLocale *rl = _CurrentRuneLocale; + + if (rl->rl_wctrans[_WCTRANS_INDEX_LOWER].te_name==NULL) + _wctrans_init(rl); + + for (i=0; i<_WCTRANS_NINDEXES; i++) + if (!strcmp(rl->rl_wctrans[i].te_name, charclass)) + return ((wctrans_t)&rl->rl_wctrans[i]); + + return ((wctrans_t)NULL); +} + +wint_t +towctrans(wint_t c, wctrans_t desc) +{ + if (desc==NULL) { + errno = EINVAL; + return (c); + } + return (_towctrans(c, (_WCTransEntry *)desc)); +} + +wctype_t +wctype(const char *property) +{ + int i; + _RuneLocale *rl = _CurrentRuneLocale; + + for (i=0; i<_WCTYPE_NINDEXES; i++) + if (!strcmp(rl->rl_wctype[i].te_name, property)) + return ((wctype_t)&rl->rl_wctype[i]); + return ((wctype_t)NULL); +} + +int +iswctype(wint_t c, wctype_t charclass) +{ + + /* + * SUSv3: If charclass is 0, iswctype() shall return 0. + */ + if (charclass == (wctype_t)0) { + return 0; + } + + return (__isctype_w(c, ((_WCTypeEntry *)charclass)->te_mask)); +} diff --git a/lib/libc/locale/rune.c b/lib/libc/locale/rune.c new file mode 100644 index 00000000000..cb0805e08b8 --- /dev/null +++ b/lib/libc/locale/rune.c @@ -0,0 +1,319 @@ +/* $OpenBSD: rune.c,v 1.1 2005/08/07 10:16:23 espie Exp $ */ +/* $NetBSD: rune.c,v 1.26 2004/05/09 11:26:33 kleink Exp $ */ + +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> + +#include <assert.h> +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <errno.h> +#include <wchar.h> +#include <sys/types.h> +#include <sys/stat.h> +#include "rune.h" +#include "rune_local.h" + +static int readrange(_RuneLocale *, _RuneRange *, _FileRuneRange *, void *, FILE *); +static void _freeentry(_RuneRange *); +static void _wctype_init(_RuneLocale *rl); + +static int +readrange(_RuneLocale *rl, _RuneRange *rr, _FileRuneRange *frr, void *lastp, + FILE *fp) +{ + uint32_t i; + _RuneEntry *re; + _FileRuneEntry fre; + + re = (_RuneEntry *)rl->rl_variable; + + rr->rr_nranges = ntohl(frr->frr_nranges); + if (rr->rr_nranges == 0) { + rr->rr_rune_ranges = NULL; + return 0; + } + + rr->rr_rune_ranges = re; + for (i = 0; i < rr->rr_nranges; i++) { + if (fread(&fre, sizeof(fre), 1, fp) != 1) + return -1; + + re->re_min = ntohl((u_int32_t)fre.fre_min); + re->re_max = ntohl((u_int32_t)fre.fre_max); + re->re_map = ntohl((u_int32_t)fre.fre_map); + re++; + + if ((void *)re > lastp) + return -1; + } + rl->rl_variable = re; + return 0; +} + +static int +readentry(_RuneRange *rr, FILE *fp) +{ + _RuneEntry *re; + size_t l, i, j; + int error; + + re = rr->rr_rune_ranges; + for (i = 0; i < rr->rr_nranges; i++) { + if (re[i].re_map != 0) { + re[i].re_rune_types = NULL; + continue; + } + + l = re[i].re_max - re[i].re_min + 1; + re[i].re_rune_types = malloc(l * sizeof(_RuneType)); + if (!re[i].re_rune_types) { + error = ENOMEM; + goto fail; + } + memset(re[i].re_rune_types, 0, l * sizeof(_RuneType)); + + if (fread(re[i].re_rune_types, sizeof(_RuneType), l, fp) != l) + goto fail2; + + for (j = 0; j < l; j++) + re[i].re_rune_types[j] = ntohl(re[i].re_rune_types[j]); + } + return 0; + +fail: + for (j = 0; j < i; j++) { + free(re[j].re_rune_types); + re[j].re_rune_types = NULL; + } + return error; +fail2: + for (j = 0; j <= i; j++) { + free(re[j].re_rune_types); + re[j].re_rune_types = NULL; + } + return errno; +} + +/* XXX: temporary implementation */ +static void +find_codeset(_RuneLocale *rl) +{ + char *top, *codeset, *tail, *ep; + + /* end of rl_variable region */ + ep = (char *)rl->rl_variable; + ep += rl->rl_variable_len; + rl->rl_codeset = NULL; + if (!(top = strstr(rl->rl_variable, _RUNE_CODESET))) + return; + tail = strpbrk(top, " \t"); + codeset = top + sizeof(_RUNE_CODESET) - 1; + if (tail) { + *top = *tail; + *tail = '\0'; + rl->rl_codeset = strdup(codeset); + strlcpy(top + 1, tail + 1, (unsigned)(ep - (top + 1))); + } else { + *top = '\0'; + rl->rl_codeset = strdup(codeset); + } +} + +void +_freeentry(_RuneRange *rr) +{ + _RuneEntry *re; + uint32_t i; + + re = rr->rr_rune_ranges; + for (i = 0; i < rr->rr_nranges; i++) { + if (re[i].re_rune_types) + free(re[i].re_rune_types); + re[i].re_rune_types = NULL; + } +} + +void +_wctype_init(_RuneLocale *rl) +{ + memcpy(&rl->rl_wctype, &_DefaultRuneLocale.rl_wctype, + sizeof(rl->rl_wctype)); +} + + +_RuneLocale * +_Read_RuneMagi(FILE *fp) +{ + /* file */ + _FileRuneLocale frl; + /* host data */ + char *hostdata; + size_t hostdatalen; + void *lastp; + _RuneLocale *rl; + struct stat sb; + int x; + + if (fstat(fileno(fp), &sb) < 0) + return NULL; + + if (sb.st_size < sizeof(_FileRuneLocale)) + return NULL; + /* XXX more validation? */ + + /* Someone might have read the magic number once already */ + rewind(fp); + + if (fread(&frl, sizeof(frl), 1, fp) != 1) + return NULL; + if (memcmp(frl.frl_magic, _RUNE_MAGIC_1, sizeof(frl.frl_magic))) + return NULL; + + hostdatalen = sizeof(*rl) + ntohl((u_int32_t)frl.frl_variable_len) + + ntohl(frl.frl_runetype_ext.frr_nranges) * sizeof(_RuneEntry) + + ntohl(frl.frl_maplower_ext.frr_nranges) * sizeof(_RuneEntry) + + ntohl(frl.frl_mapupper_ext.frr_nranges) * sizeof(_RuneEntry); + + if ((hostdata = malloc(hostdatalen)) == NULL) + return NULL; + memset(hostdata, 0, hostdatalen); + lastp = hostdata + hostdatalen; + + rl = (_RuneLocale *)hostdata; + rl->rl_variable = rl + 1; + + memcpy(rl->rl_magic, frl.frl_magic, sizeof(rl->rl_magic)); + memcpy(rl->rl_encoding, frl.frl_encoding, sizeof(rl->rl_encoding)); + + rl->rl_invalid_rune = ntohl((u_int32_t)frl.frl_invalid_rune); + rl->rl_variable_len = ntohl((u_int32_t)frl.frl_variable_len); + + for (x = 0; x < _CACHED_RUNES; ++x) { + rl->rl_runetype[x] = ntohl(frl.frl_runetype[x]); + + /* XXX assumes rune_t = u_int32_t */ + rl->rl_maplower[x] = ntohl((u_int32_t)frl.frl_maplower[x]); + rl->rl_mapupper[x] = ntohl((u_int32_t)frl.frl_mapupper[x]); + } + + if (readrange(rl, &rl->rl_runetype_ext, &frl.frl_runetype_ext, lastp, fp)) + { + free(hostdata); + return NULL; + } + if (readrange(rl, &rl->rl_maplower_ext, &frl.frl_maplower_ext, lastp, fp)) + { + free(hostdata); + return NULL; + } + if (readrange(rl, &rl->rl_mapupper_ext, &frl.frl_mapupper_ext, lastp, fp)) + { + free(hostdata); + return NULL; + } + + if (readentry(&rl->rl_runetype_ext, fp) != 0) { + free(hostdata); + return NULL; + } + + if ((u_int8_t *)rl->rl_variable + rl->rl_variable_len > + (u_int8_t *)lastp) { + _freeentry(&rl->rl_runetype_ext); + free(hostdata); + return NULL; + } + if (rl->rl_variable_len == 0) + rl->rl_variable = NULL; + else if (fread(rl->rl_variable, rl->rl_variable_len, 1, fp) != 1) { + _freeentry(&rl->rl_runetype_ext); + free(hostdata); + return NULL; + } + find_codeset(rl); + _wctype_init(rl); + + /* + * error if we have junk at the tail, + * or if we can't allocate memory. + */ + if (ftell(fp) != sb.st_size || __make_ctype_tabs(rl) == -1) { + _freeentry(&rl->rl_runetype_ext); + free(hostdata); + return NULL; + } + + return(rl); +} + +void +_NukeRune(_RuneLocale *rl) +{ + + if (rl != &_DefaultRuneLocale) { + _freeentry(&rl->rl_runetype_ext); + free(rl->rl_tabs); + free(rl->rl_codeset); + free(rl); + } +} + diff --git a/lib/libc/locale/rune.h b/lib/libc/locale/rune.h new file mode 100644 index 00000000000..849c99f1345 --- /dev/null +++ b/lib/libc/locale/rune.h @@ -0,0 +1,81 @@ +/* $OpenBSD: rune.h,v 1.1 2005/08/07 10:16:23 espie Exp $ */ +/* $NetBSD: rune.h,v 1.9 2003/08/07 16:43:04 agc Exp $ */ + +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)rune.h 8.1 (Berkeley) 6/27/93 + */ + +#ifndef _RUNE_H_ +#define _RUNE_H_ + +#include <stdio.h> +#include <wchar.h> +#include "runetype.h" + +/* + * map _RTYPE_x to _CTYPE_x + * + * XXX: these should be defined in ctype.h and used in isxxx macros. + * (note: current isxxx macros use "old" NetBSD masks and + * _CTYPE_x are not public.) + */ +#define _CTYPE_A _RUNETYPE_A +#define _CTYPE_C _RUNETYPE_C +#define _CTYPE_D _RUNETYPE_D +#define _CTYPE_G _RUNETYPE_G +#define _CTYPE_L _RUNETYPE_L +#define _CTYPE_P _RUNETYPE_P +#define _CTYPE_S _RUNETYPE_S +#define _CTYPE_U _RUNETYPE_U +#define _CTYPE_X _RUNETYPE_X +#define _CTYPE_B _RUNETYPE_B +#define _CTYPE_R _RUNETYPE_R +#define _CTYPE_I _RUNETYPE_I +#define _CTYPE_T _RUNETYPE_T +#define _CTYPE_Q _RUNETYPE_Q +#define _CTYPE_SWM _RUNETYPE_SWM +#define _CTYPE_SWS _RUNETYPE_SWS +#define _CTYPE_SW0 _RUNETYPE_SW0 +#define _CTYPE_SW1 _RUNETYPE_SW1 +#define _CTYPE_SW2 _RUNETYPE_SW2 +#define _CTYPE_SW3 _RUNETYPE_SW3 + +/* + * global variables + */ +extern size_t __mb_len_max_runtime; +extern _RuneLocale _DefaultRuneLocale; +extern _RuneLocale *_CurrentRuneLocale; +extern char *_PathLocale; + +#endif /*! _RUNE_H_ */ diff --git a/lib/libc/locale/rune_local.h b/lib/libc/locale/rune_local.h new file mode 100644 index 00000000000..c482d5e53b1 --- /dev/null +++ b/lib/libc/locale/rune_local.h @@ -0,0 +1,46 @@ +/* $OpenBSD: rune_local.h,v 1.1 2005/08/07 10:16:24 espie Exp $ */ +/* $NetBSD: rune_local.h,v 1.7 2003/03/02 22:18:15 tshiozak Exp $ */ + +/*- + * Copyright (c) 2000 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifndef _RUNE_LOCAL_H_ +#define _RUNE_LOCAL_H_ + +/* rune.c */ +extern _RuneLocale *_Read_RuneMagi(FILE *fp); +extern void _NukeRune(_RuneLocale *); + +/* setrunelocale.c */ +extern int _xpg4_setrunelocale(const char *); +extern _RuneLocale *_findrunelocale(const char *); +extern int _newrunelocale(const char *); + +/* runeglue.c */ +extern int __make_ctype_tabs(_RuneLocale *); +extern void __install_currentrunelocale_ctype(); + +#endif diff --git a/lib/libc/locale/runeglue.c b/lib/libc/locale/runeglue.c new file mode 100644 index 00000000000..48c9ea79bef --- /dev/null +++ b/lib/libc/locale/runeglue.c @@ -0,0 +1,127 @@ +/* $OpenBSD: runeglue.c,v 1.1 2005/08/07 10:16:24 espie Exp $ */ +/* $NetBSD: runeglue.c,v 1.10 2003/03/10 21:18:49 tshiozak Exp $ */ + +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Id: runeglue.c,v 1.7 2000/12/22 22:52:29 itojun Exp + */ + +/* + * Glue code to hide "rune" facility from user programs. + * This is important to keep backward/future compatibility. + */ + +#include <sys/cdefs.h> + +#include <assert.h> +#include <limits.h> +#include <stdio.h> +#include <sys/types.h> +#include <ctype.h> +#include <stdlib.h> +#include <string.h> +#include <wchar.h> +#include "rune.h" +#include "rune_local.h" +#include "ctype_private.h" + +#if EOF != -1 +#error "EOF != -1" +#endif +#if _CACHED_RUNES != 256 +#error "_CACHED_RUNES != 256" +#endif + +int +__make_ctype_tabs(_RuneLocale *rl) +{ + int i; + struct old_tabs *p; + + p = malloc(sizeof *p); + if (!p) + return -1; + + rl->rl_tabs = p; + p->ctype_tab[0] = 0; + p->toupper_tab[0] = EOF; + p->tolower_tab[0] = EOF; + for (i = 0; i < CTYPE_NUM_CHARS; i++) { + p->ctype_tab[i + 1]=0; + if (rl->rl_runetype[i] & _CTYPE_U) + p->ctype_tab[i + 1] |= _U; + if (rl->rl_runetype[i] & _CTYPE_L) + p->ctype_tab[i + 1] |= _L; + if (rl->rl_runetype[i] & _CTYPE_D) + p->ctype_tab[i + 1] |= _N; + if (rl->rl_runetype[i] & _CTYPE_S) + p->ctype_tab[i + 1] |= _S; + if (rl->rl_runetype[i] & _CTYPE_P) + p->ctype_tab[i + 1] |= _P; + if (rl->rl_runetype[i] & _CTYPE_C) + p->ctype_tab[i + 1] |= _C; + if (rl->rl_runetype[i] & _CTYPE_X) + p->ctype_tab[i + 1] |= _X; + /* + * TWEAK! _B has been used incorrectly (or with older + * declaration) in ctype.h isprint() macro. + * _B does not mean isblank, it means "isprint && !isgraph". + * the following is okay since isblank() was hardcoded in + * function (i.e. isblank() is inherently locale unfriendly). + */ +#if 1 + if ((rl->rl_runetype[i] & (_CTYPE_R | _CTYPE_G)) + == _CTYPE_R) + p->ctype_tab[i + 1] |= _B; +#else + if (rl->rl_runetype[i] & _CTYPE_B) + p->ctype_tab[i + 1] |= _B; +#endif + p->toupper_tab[i + 1] = (short)rl->rl_mapupper[i]; + p->tolower_tab[i + 1] = (short)rl->rl_maplower[i]; + } + return 0; +} + +void +__install_currentrunelocale_ctype() +{ + if (_CurrentRuneLocale->rl_tabs != NULL) { + /* LINTED const cast */ + _ctype_ = (const unsigned char *) + &(_CurrentRuneLocale->rl_tabs->ctype_tab); + /* LINTED const cast */ + _toupper_tab_ = (const short *) + &(_CurrentRuneLocale->rl_tabs->toupper_tab); + /* LINTED const cast */ + _tolower_tab_ = (const short *) + &(_CurrentRuneLocale->rl_tabs->tolower_tab); + } else { + _ctype_ = _C_ctype_; + _toupper_tab_ = _C_toupper_; + _tolower_tab_ = _C_tolower_; + } +} diff --git a/lib/libc/locale/runetable.c b/lib/libc/locale/runetable.c new file mode 100644 index 00000000000..3324d1baa22 --- /dev/null +++ b/lib/libc/locale/runetable.c @@ -0,0 +1,405 @@ +/* $NetBSD: runetable.c,v 1.12 2003/08/07 16:43:04 agc Exp $ */ + +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/lib/libc/locale/table.c,v 1.13 2000/02/08 07:43:25 obrien Exp $ + */ + +#include <sys/cdefs.h> + +#include <stdlib.h> +#include <ctype.h> +#include <locale.h> +#include <assert.h> +#include <wchar.h> +#include "rune.h" +#include "rune_local.h" +#include <stdlib.h> + +_RuneLocale _DefaultRuneLocale = { + _RUNE_MAGIC_1, + "NONE", + _DEFAULT_INVALID_RUNE, + + { /*00*/ _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + /*08*/ _CTYPE_C, + _CTYPE_C|_CTYPE_S|_CTYPE_B, + _CTYPE_C|_CTYPE_S, + _CTYPE_C|_CTYPE_S, + _CTYPE_C|_CTYPE_S, + _CTYPE_C|_CTYPE_S, + _CTYPE_C, + _CTYPE_C, + /*10*/ _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + /*18*/ _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + _CTYPE_C, + /*20*/ _CTYPE_S|_CTYPE_B|_CTYPE_R|_CTYPE_SW1, + _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, + _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, + _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, + _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, + _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, + _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, + _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, + /*28*/ _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, + _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, + _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, + _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, + _CTYPE_P|_CTYPE_R|_CTYPE_G|_CTYPE_SW1, + _CTYPE_P|_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x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 'a', 'b', 'c', 'd', 'e', 'f', 'g', + 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', + 'x', 'y', 'z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 'a', 'b', 'c', 'd', 'e', 'f', 'g', + 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', + 'x', 'y', 'z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, + 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, + 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, + }, + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 'A', 'B', 'C', 'D', 'E', 'F', 'G', + 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + 'X', 'Y', 'Z', 0x5b, 0x5c, 0x5d, 0x5e, 0x5f, + 0x60, 'A', 'B', 'C', 'D', 'E', 'F', 'G', + 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + 'X', 'Y', 'Z', 0x7b, 0x7c, 0x7d, 0x7e, 0x7f, + 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f, + 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, + 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f, + 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, + 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf, + 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, + 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf, + 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, + 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf, + 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, + 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf, + 0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, + 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, + 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, + 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, + }, + { 0, NULL }, + { 0, NULL }, + { 0, NULL }, + NULL, 0, + "646", + 0, + { + { NULL, NULL, NULL }, + { NULL, NULL, NULL }, + }, + { + { "alnum", _CTYPE_A|_CTYPE_D }, + { "alpha", _CTYPE_A }, + { "blank", _CTYPE_B }, + { "cntrl", _CTYPE_C }, + { "digit", _CTYPE_D }, + { "graph", _CTYPE_G }, + { "lower", _CTYPE_L }, + { "print", _CTYPE_R }, + { "punct", _CTYPE_P }, + { "space", _CTYPE_S }, + { "upper", _CTYPE_U }, + { "xdigit", _CTYPE_X }, + }, + NULL +}; + +_RuneLocale *_CurrentRuneLocale = &_DefaultRuneLocale; + +char *_PathLocale; diff --git a/lib/libc/locale/setrunelocale.c b/lib/libc/locale/setrunelocale.c new file mode 100644 index 00000000000..6e8d2fa17f4 --- /dev/null +++ b/lib/libc/locale/setrunelocale.c @@ -0,0 +1,206 @@ +/* $OpenBSD: setrunelocale.c,v 1.1 2005/08/07 10:16:24 espie Exp $ */ +/* $NetBSD: setrunelocale.c,v 1.14 2003/08/07 16:43:07 agc Exp $ */ + +/*- + * Copyright (c)1999 Citrus Project, + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1998 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Paul Kranenburg. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/*- + * Copyright (c) 1993 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Paul Borman at Krystal Technologies. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/cdefs.h> + +#include "rune.h" +#include <assert.h> +#include <errno.h> +#include <limits.h> +#include <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <stddef.h> +#include <unistd.h> +#include <locale.h> +#include <citrus/citrus_ctype.h> +#include "rune_local.h" + +struct localetable { + char path[PATH_MAX]; + _RuneLocale *runelocale; + struct localetable *next; +}; +static struct localetable *localetable_head; + +_RuneLocale * +_findrunelocale(const char *path) +{ + struct localetable *lt; + + /* ones which we have seen already */ + for (lt = localetable_head; lt; lt = lt->next) + if (strcmp(path, lt->path) == 0) + return lt->runelocale; + + return NULL; +} + +int +_newrunelocale(const char *path) +{ + struct localetable *lt; + FILE *fp; + _RuneLocale *rl; + + /* path may be NULL (actually, it's checked below) */ + + if (!path || strlen(path) + 1 > sizeof(lt->path)) + return EFAULT; + + rl = _findrunelocale(path); + if (rl) + return 0; + + if ((fp = fopen(path, "r")) == NULL) + return ENOENT; + + if ((rl = _Read_RuneMagi(fp)) != NULL) + goto found; + + fclose(fp); + return EFTYPE; + +found: + fclose(fp); + + rl->rl_citrus_ctype = NULL; + + if (strcmp(rl->rl_encoding, _CITRUS_DEFAULT_CTYPE_NAME) != 0) { + _NukeRune(rl); + return EINVAL; + } + /* register it */ + lt = malloc(sizeof(struct localetable)); + if (lt == NULL) { + _NukeRune(rl); + return ENOMEM; + } + strlcpy(lt->path, path, sizeof(lt->path)); + lt->runelocale = rl; + lt->next = localetable_head; + localetable_head = lt; + + return 0; +} + +int +_xpg4_setrunelocale(const char *encoding) +{ + char path[PATH_MAX]; + _RuneLocale *rl; + int error; + + if (!strcmp(encoding, "C") || !strcmp(encoding, "POSIX")) { + rl = &_DefaultRuneLocale; + goto found; + } + + snprintf(path, sizeof(path), "%s/%s/LC_CTYPE", _PathLocale, encoding); + + error = _newrunelocale(path); + if (error) + return error; + rl = _findrunelocale(path); + if (!rl) + return ENOENT; + +found: + _CurrentRuneLocale = rl; + + return 0; +} |