From: guenther Date: Mon, 25 Jul 2022 21:38:24 +0000 (+0000) Subject: Simplify wctype() and wctype_l(): we have one set of classification X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=703df344475716be7a0c10a8d70b7df7e0e1feb2;p=openbsd Simplify wctype() and wctype_l(): we have one set of classification types used by all (== both) locales; put their implementation in one file and make the mapping static there. The rl_wctype member of _RuneLocale and its initialization go away at the same time. ok schwarze@ --- diff --git a/lib/libc/hidden/wctype.h b/lib/libc/hidden/wctype.h index 87ce1611e02..c3d9331b550 100644 --- a/lib/libc/hidden/wctype.h +++ b/lib/libc/hidden/wctype.h @@ -1,4 +1,4 @@ -/* $OpenBSD: wctype.h,v 1.2 2017/09/05 03:16:13 schwarze Exp $ */ +/* $OpenBSD: wctype.h,v 1.3 2022/07/25 21:38:24 guenther Exp $ */ /* * Copyright (c) 2015 Philip Guenther * @@ -54,7 +54,7 @@ PROTO_STD_DEPRECATED(towupper); PROTO_DEPRECATED(towupper_l); PROTO_STD_DEPRECATED(wctrans); PROTO_DEPRECATED(wctrans_l); -PROTO_STD_DEPRECATED(wctype); +PROTO_NORMAL(wctype); PROTO_DEPRECATED(wctype_l); #endif /* !_LIBC_WCTYPE_H_ */ diff --git a/lib/libc/locale/Makefile.inc b/lib/libc/locale/Makefile.inc index 2f13ffcdcee..89cb470966b 100644 --- a/lib/libc/locale/Makefile.inc +++ b/lib/libc/locale/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.24 2018/04/04 14:53:02 schwarze Exp $ +# $OpenBSD: Makefile.inc,v 1.25 2022/07/25 21:38:24 guenther Exp $ # locale sources .PATH: ${LIBCSRCDIR}/locale @@ -7,7 +7,7 @@ SRCS+= btowc.c _def_messages.c _def_monetary.c _def_numeric.c _def_time.c \ localeconv.c nl_langinfo.c nl_langinfo_l.c setlocale.c \ duplocale.c freelocale.c newlocale.c uselocale.c \ __mb_cur_max.c _CurrentRuneLocale.c _get_locname.c \ - isctype_l.c iswctype.c iswctype_l.c \ + isctype_l.c iswctype.c iswctype_l.c wctype.c \ mblen.c mbrlen.c mbstowcs.c mbtowc.c multibyte_citrus.c wcscoll.c \ wcscoll_l.c \ wcstombs.c wctob.c wctomb.c wcstof.c wcstod.c wcstold.c wcstol.c \ diff --git a/lib/libc/locale/iswctype.c b/lib/libc/locale/iswctype.c index b7b4e7da3ea..ea7cd3149b2 100644 --- a/lib/libc/locale/iswctype.c +++ b/lib/libc/locale/iswctype.c @@ -1,4 +1,4 @@ -/* $OpenBSD: iswctype.c,v 1.7 2017/09/05 03:16:13 schwarze Exp $ */ +/* $OpenBSD: iswctype.c,v 1.8 2022/07/25 21:38:24 guenther Exp $ */ /* $NetBSD: iswctype.c,v 1.15 2005/02/09 21:35:46 kleink Exp $ */ /* @@ -200,18 +200,6 @@ towctrans(wint_t c, wctrans_t desc) } DEF_STRONG(towctrans); -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) { diff --git a/lib/libc/locale/iswctype_l.c b/lib/libc/locale/iswctype_l.c index 8da0e792835..2fc9d7de414 100644 --- a/lib/libc/locale/iswctype_l.c +++ b/lib/libc/locale/iswctype_l.c @@ -1,4 +1,4 @@ -/* $OpenBSD: iswctype_l.c,v 1.1 2017/09/05 03:16:13 schwarze Exp $ */ +/* $OpenBSD: iswctype_l.c,v 1.2 2022/07/25 21:38:24 guenther Exp $ */ /* $NetBSD: iswctype.c,v 1.15 2005/02/09 21:35:46 kleink Exp $ */ /* @@ -194,19 +194,6 @@ towctrans_l(wint_t c, wctrans_t desc, return towctrans(c, desc); } -wctype_t -wctype_l(const char *property, locale_t locale) -{ - _RuneLocale *rl; - int i; - - rl = __runelocale(locale); - for (i = 0; i < _WCTYPE_NINDEXES; i++) - if (strcmp(rl->rl_wctype[i].te_name, property) == 0) - return &rl->rl_wctype[i]; - return NULL; -} - int iswctype_l(wint_t c, wctype_t charclass, locale_t locale) { diff --git a/lib/libc/locale/rune.c b/lib/libc/locale/rune.c index 97566656ec0..a017b31740b 100644 --- a/lib/libc/locale/rune.c +++ b/lib/libc/locale/rune.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rune.c,v 1.8 2019/06/28 13:32:41 deraadt Exp $ */ +/* $OpenBSD: rune.c,v 1.9 2022/07/25 21:38:24 guenther Exp $ */ /* $NetBSD: rune.c,v 1.26 2004/05/09 11:26:33 kleink Exp $ */ /*- @@ -80,7 +80,6 @@ do { \ static int readrange(_RuneLocale *, _RuneRange *, uint32_t, void *, FILE *); static void _freeentry(_RuneRange *); -static void _wctype_init(_RuneLocale *rl); static int readrange(_RuneLocale *rl, _RuneRange *rr, uint32_t nranges, void *lastp, @@ -205,13 +204,6 @@ _freeentry(_RuneRange *rr) } } -void -_wctype_init(_RuneLocale *rl) -{ - memcpy(&rl->rl_wctype, &_DefaultRuneLocale.rl_wctype, - sizeof(rl->rl_wctype)); -} - _RuneLocale * _Read_RuneMagi(FILE *fp) @@ -303,7 +295,6 @@ _Read_RuneMagi(FILE *fp) goto rune_err; if (find_codeset(rl)) goto rune_err; - _wctype_init(rl); /* * error if we have junk at the tail, diff --git a/lib/libc/locale/runetable.c b/lib/libc/locale/runetable.c index 89cd04d47b2..6adc16350be 100644 --- a/lib/libc/locale/runetable.c +++ b/lib/libc/locale/runetable.c @@ -252,19 +252,5 @@ _RuneLocale _DefaultRuneLocale = { { 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 }; diff --git a/lib/libc/locale/runetype.h b/lib/libc/locale/runetype.h index e12ed1f0818..8532dfef493 100644 --- a/lib/libc/locale/runetype.h +++ b/lib/libc/locale/runetype.h @@ -1,7 +1,7 @@ #ifndef _NB_RUNETYPE_H_ #define _NB_RUNETYPE_H_ -/* $OpenBSD: runetype.h,v 1.8 2016/09/05 09:47:03 schwarze Exp $ */ +/* $OpenBSD: runetype.h,v 1.9 2022/07/25 21:38:24 guenther Exp $ */ /* $NetBSD: runetype.h,v 1.18 2003/08/07 16:43:04 agc Exp $ */ /*- * Copyright (c) 1993 @@ -150,7 +150,7 @@ typedef struct _WCTransEntry { * wctype stuffs. */ typedef struct _WCTypeEntry { - char *te_name; + char te_name[8]; _RuneType te_mask; } _WCTypeEntry; #define _WCTYPE_INDEX_ALNUM 0 @@ -200,7 +200,6 @@ typedef struct { */ char *rl_codeset; _WCTransEntry rl_wctrans[_WCTRANS_NINDEXES]; - _WCTypeEntry rl_wctype[_WCTYPE_NINDEXES]; struct old_tabs * rl_tabs; diff --git a/lib/libc/locale/wctype.c b/lib/libc/locale/wctype.c new file mode 100644 index 00000000000..b6c432cb23d --- /dev/null +++ b/lib/libc/locale/wctype.c @@ -0,0 +1,76 @@ +/* $OpenBSD: wctype.c,v 1.1 2022/07/25 21:38:24 guenther 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 +#include +#include +#include "rune.h" +#include "runetype.h" + +static struct _WCTypeEntry wctype_entries[_WCTYPE_NINDEXES] = +{ + { "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 }, +}; + +wctype_t +wctype(const char *property) +{ + int i; + + for (i = 0; i < _WCTYPE_NINDEXES; i++) + if (strcmp(wctype_entries[i].te_name, property) == 0) + return &wctype_entries[i]; + return NULL; +} +DEF_STRONG(wctype); + +wctype_t +wctype_l(const char *property, locale_t locale __attribute__((__unused__))) +{ + return wctype(property); +}