Module Name: src Committed By: joerg Date: Tue Apr 16 11:39:13 UTC 2013
Modified Files: src/include: wctype.h src/lib/libc/include: namespace.h src/lib/libc/locale: iswctype_mb.c Log Message: Add wcwidth_l, wcswidth_l and the wctype.h family of *_l functions. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/include/wctype.h cvs rdiff -u -r1.156 -r1.157 src/lib/libc/include/namespace.h cvs rdiff -u -r1.11 -r1.12 src/lib/libc/locale/iswctype_mb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/include/wctype.h diff -u src/include/wctype.h:1.7 src/include/wctype.h:1.8 --- src/include/wctype.h:1.7 Sat Mar 27 22:14:09 2010 +++ src/include/wctype.h Tue Apr 16 11:39:13 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: wctype.h,v 1.7 2010/03/27 22:14:09 tnozaki Exp $ */ +/* $NetBSD: wctype.h,v 1.8 2013/04/16 11:39:13 joerg Exp $ */ /*- * Copyright (c)1999 Citrus Project, @@ -72,6 +72,31 @@ wint_t towlower(wint_t); wint_t towupper(wint_t); wctrans_t wctrans(const char *); wctype_t wctype(const char *); + +#if (_POSIX_C_SOURCE - 0) >= 200809L || defined(_NETBSD_SOURCE) +# ifndef __LOCALE_T_DECLARED +typedef struct _locale *locale_t; +# define __LOCALE_T_DECLARED +# endif +int iswalnum_l(wint_t, locale_t); +int iswalpha_l(wint_t, locale_t); +int iswblank_l(wint_t, locale_t); +int iswcntrl_l(wint_t, locale_t); +int iswdigit_l(wint_t, locale_t); +int iswgraph_l(wint_t, locale_t); +int iswlower_l(wint_t, locale_t); +int iswprint_l(wint_t, locale_t); +int iswpunct_l(wint_t, locale_t); +int iswspace_l(wint_t, locale_t); +int iswupper_l(wint_t, locale_t); +int iswxdigit_l(wint_t, locale_t); +int iswctype_l(wint_t, wctype_t, locale_t); +wint_t towctrans_l(wint_t, wctrans_t, locale_t); +wint_t towlower_l(wint_t, locale_t); +wint_t towupper_l(wint_t, locale_t); +wctrans_t wctrans_l(const char *, locale_t); +wctype_t wctype_l(const char *, locale_t); +#endif __END_DECLS #endif /* _WCTYPE_H_ */ Index: src/lib/libc/include/namespace.h diff -u src/lib/libc/include/namespace.h:1.156 src/lib/libc/include/namespace.h:1.157 --- src/lib/libc/include/namespace.h:1.156 Mon Aug 20 21:38:10 2012 +++ src/lib/libc/include/namespace.h Tue Apr 16 11:39:13 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: namespace.h,v 1.156 2012/08/20 21:38:10 dsl Exp $ */ +/* $NetBSD: namespace.h,v 1.157 2013/04/16 11:39:13 joerg Exp $ */ /*- * Copyright (c) 1997-2004 The NetBSD Foundation, Inc. @@ -703,6 +703,7 @@ #define wcstod _wcstod #define wcstold _wcstold #define wcwidth _wcwidth +#define wcwidth_l _wcwidth_l #define xdr_accepted_reply _xdr_accepted_reply #define xdr_array _xdr_array #define xdr_authunix_parms _xdr_authunix_parms Index: src/lib/libc/locale/iswctype_mb.c diff -u src/lib/libc/locale/iswctype_mb.c:1.11 src/lib/libc/locale/iswctype_mb.c:1.12 --- src/lib/libc/locale/iswctype_mb.c:1.11 Sun Jun 13 04:14:57 2010 +++ src/lib/libc/locale/iswctype_mb.c Tue Apr 16 11:39:13 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: iswctype_mb.c,v 1.11 2010/06/13 04:14:57 tnozaki Exp $ */ +/* $NetBSD: iswctype_mb.c,v 1.12 2013/04/16 11:39:13 joerg Exp $ */ /*- * Copyright (c)2008 Citrus Project, @@ -28,7 +28,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: iswctype_mb.c,v 1.11 2010/06/13 04:14:57 tnozaki Exp $"); +__RCSID("$NetBSD: iswctype_mb.c,v 1.12 2013/04/16 11:39:13 joerg Exp $"); #endif /* LIBC_SCCS and not lint */ #include "namespace.h" @@ -47,20 +47,29 @@ __RCSID("$NetBSD: iswctype_mb.c,v 1.11 2 #include "_wctype_local.h" #include "_wctrans_local.h" -#define _RUNE_LOCALE() ((_RuneLocale const *) \ - (*_current_locale())->part_impl[(size_t)LC_CTYPE]) +#define _RUNE_LOCALE(loc) ((_RuneLocale const *) \ + (loc)->part_impl[(size_t)LC_CTYPE]) #define _ISWCTYPE_FUNC(name, index) \ int \ -isw##name(wint_t wc) \ +isw##name##_l(wint_t wc, locale_t loc) \ { \ _RuneLocale const *rl; \ _WCTypeEntry const *te; \ \ - rl = _RUNE_LOCALE(); \ + if (loc == NULL) \ + loc = _C_locale; \ + \ + rl = _RUNE_LOCALE(loc); \ te = &rl->rl_wctype[index]; \ return _iswctype_priv(rl, wc, te); \ +} \ +int \ +isw##name(wint_t wc) \ +{ \ + return isw##name##_l(wc, *_current_locale()); \ } + _ISWCTYPE_FUNC(alnum, _WCTYPE_INDEX_ALNUM) _ISWCTYPE_FUNC(alpha, _WCTYPE_INDEX_ALPHA) _ISWCTYPE_FUNC(blank, _WCTYPE_INDEX_BLANK) @@ -76,25 +85,36 @@ _ISWCTYPE_FUNC(xdigit, _WCTYPE_INDEX_XDI #define _TOWCTRANS_FUNC(name, index) \ wint_t \ -tow##name(wint_t wc) \ +tow##name##_l(wint_t wc, locale_t loc) \ { \ _RuneLocale const *rl; \ _WCTransEntry const *te; \ \ - rl = _RUNE_LOCALE(); \ + if (loc == NULL) \ + loc = _C_locale; \ + \ + rl = _RUNE_LOCALE(loc); \ te = &rl->rl_wctrans[index]; \ return _towctrans_priv(wc, te); \ +} \ +wint_t \ +tow##name(wint_t wc) \ +{ \ + return tow##name##_l(wc, *_current_locale()); \ } _TOWCTRANS_FUNC(upper, _WCTRANS_INDEX_UPPER) _TOWCTRANS_FUNC(lower, _WCTRANS_INDEX_LOWER) wctype_t -wctype(const char *charclass) +wctype_l(const char *charclass, locale_t loc) { _RuneLocale const *rl; size_t i; - rl = _RUNE_LOCALE(); + if (loc == NULL) + loc = _C_locale; + + rl = _RUNE_LOCALE(loc); for (i = 0; i < _WCTYPE_NINDEXES; ++i) { if (!strcmp(rl->rl_wctype[i].te_name, charclass)) return (wctype_t)__UNCONST(&rl->rl_wctype[i]); @@ -102,13 +122,22 @@ wctype(const char *charclass) return (wctype_t)NULL; } +wctype_t +wctype(const char *charclass) +{ + return wctype_l(charclass, *_current_locale()); +} + wctrans_t -wctrans(const char *charmap) +wctrans_l(const char *charmap, locale_t loc) { _RuneLocale const *rl; size_t i; - rl = _RUNE_LOCALE(); + if (loc == NULL) + loc = _C_locale; + + rl = _RUNE_LOCALE(loc); for (i = 0; i < _WCTRANS_NINDEXES; ++i) { _DIAGASSERT(rl->rl_wctrans[i].te_name != NULL); if (!strcmp(rl->rl_wctrans[i].te_name, charmap)) @@ -117,8 +146,14 @@ wctrans(const char *charmap) return (wctrans_t)NULL; } +wctrans_t +wctrans(const char *charmap) +{ + return wctrans_l(charmap, *_current_locale()); +} + int -iswctype(wint_t wc, wctype_t charclass) +iswctype_l(wint_t wc, wctype_t charclass, locale_t loc) { _RuneLocale const *rl; _WCTypeEntry const *te; @@ -127,11 +162,21 @@ iswctype(wint_t wc, wctype_t charclass) errno = EINVAL; return 0; } - rl = _RUNE_LOCALE(); + + if (loc == NULL) + loc = _C_locale; + + rl = _RUNE_LOCALE(loc); te = (_WCTypeEntry const *)(void *)charclass; return _iswctype_priv(rl, wc, te); } +int +iswctype(wint_t wc, wctype_t charclass) +{ + return iswctype_l(wc, charclass, *_current_locale()); +} + wint_t towctrans(wint_t wc, wctrans_t charmap) { @@ -145,17 +190,29 @@ towctrans(wint_t wc, wctrans_t charmap) return _towctrans_priv(wc, te); } +/* ARGSUSED */ +wint_t +towctrans_l(wint_t wc, wctrans_t charmap, locale_t loc) +{ + return towctrans(wc, charmap); +} + __weak_alias(wcwidth,_wcwidth) +__weak_alias(wcwidth_l,_wcwidth_l) int -wcwidth(wchar_t wc) +wcwidth_l(wchar_t wc, locale_t loc) { _RuneLocale const *rl; _RuneType x; if (wc == L'\0') return 0; - rl = _RUNE_LOCALE(); + + if (loc == NULL) + loc = _C_locale; + + rl = _RUNE_LOCALE(loc); x = _runetype_priv(rl, wc); if (x & _RUNETYPE_R) return ((unsigned)x & _RUNETYPE_SWM) >> _RUNETYPE_SWS; @@ -163,7 +220,13 @@ wcwidth(wchar_t wc) } int -wcswidth(const wchar_t * __restrict ws, size_t wn) +wcwidth(wchar_t wc) +{ + return wcwidth_l(wc, *_current_locale()); +} + +int +wcswidth_l(const wchar_t * __restrict ws, size_t wn, locale_t loc) { _RuneLocale const *rl; _RuneType x; @@ -171,7 +234,10 @@ wcswidth(const wchar_t * __restrict ws, _DIAGASSERT(ws != NULL); - rl = _RUNE_LOCALE(); + if (loc == NULL) + loc = _C_locale; + + rl = _RUNE_LOCALE(loc); width = 0; while (wn > 0 && *ws != L'\0') { x = _runetype_priv(rl, *ws); @@ -182,3 +248,9 @@ wcswidth(const wchar_t * __restrict ws, } return width; } + +int +wcswidth(const wchar_t * __restrict ws, size_t wn) +{ + return wcswidth_l(ws, wn, *_current_locale()); +}