diff options
author | Garrett D'Amore <garrett@nexenta.com> | 2010-08-18 14:41:42 -0700 |
---|---|---|
committer | Garrett D'Amore <garrett@nexenta.com> | 2010-08-18 14:41:42 -0700 |
commit | 163bd69b3c164dda2a59c7f08ca788e7d6ba9bea (patch) | |
tree | ee05de7a81bb03596b38c9d0fdd179c8fc4df0cf /usr/src/lib/libc | |
parent | 53274d1a13fcd0e2f2ec7b1532a47bcaf120b081 (diff) | |
download | illumos-gate-163bd69b3c164dda2a59c7f08ca788e7d6ba9bea.tar.gz |
38 need replacement for tr
Reviewed by: richlowe@richlowe.net
Approved by: garrett@nexenta.com
Diffstat (limited to 'usr/src/lib/libc')
-rw-r--r-- | usr/src/lib/libc/amd64/Makefile | 1 | ||||
-rw-r--r-- | usr/src/lib/libc/i386/Makefile.com | 1 | ||||
-rw-r--r-- | usr/src/lib/libc/port/locale/iswctype.c | 21 | ||||
-rw-r--r-- | usr/src/lib/libc/port/locale/nextwctype.c | 88 | ||||
-rw-r--r-- | usr/src/lib/libc/port/mapfile-vers | 2 | ||||
-rw-r--r-- | usr/src/lib/libc/sparc/Makefile.com | 2 | ||||
-rw-r--r-- | usr/src/lib/libc/sparcv9/Makefile.com | 2 |
7 files changed, 117 insertions, 0 deletions
diff --git a/usr/src/lib/libc/amd64/Makefile b/usr/src/lib/libc/amd64/Makefile index 3cec41db51..f714af9118 100644 --- a/usr/src/lib/libc/amd64/Makefile +++ b/usr/src/lib/libc/amd64/Makefile @@ -733,6 +733,7 @@ PORTLOCALE= \ mbstowcs.o \ mbtowc.o \ mskanji.o \ + nextwctype.o \ nl_langinfo.o \ none.o \ regcomp.o \ diff --git a/usr/src/lib/libc/i386/Makefile.com b/usr/src/lib/libc/i386/Makefile.com index 6cb439b99c..5e4250afe6 100644 --- a/usr/src/lib/libc/i386/Makefile.com +++ b/usr/src/lib/libc/i386/Makefile.com @@ -775,6 +775,7 @@ PORTLOCALE= \ mbstowcs.o \ mbtowc.o \ mskanji.o \ + nextwctype.o \ nl_langinfo.o \ none.o \ regcomp.o \ diff --git a/usr/src/lib/libc/port/locale/iswctype.c b/usr/src/lib/libc/port/locale/iswctype.c index 03d90aa86e..e6b1140562 100644 --- a/usr/src/lib/libc/port/locale/iswctype.c +++ b/usr/src/lib/libc/port/locale/iswctype.c @@ -214,3 +214,24 @@ isnumber(wint_t wc) { return (__istype(wc, _CTYPE_N)); } + +/* + * FreeBSD has iswrune() for use by external programs, and this is used by + * the "tr" program. As that program is part of our consolidation, we + * provide an _ILLUMOS_PRIVATE version of this function that we can use. + * + * No programs that are not part of the illumos stack itself should use + * this function -- programs that do reference will not be portable to + * other versions of SunOS or Solaris. + */ +int +__iswrune(wint_t wc) +{ + /* + * Note, FreeBSD ignored the low order byte, as they encode their + * ctype values differently. We can't do that (ctype is baked into + * applications), but instead can just check if *any* bit is set in + * the ctype. Any bit being set indicates its a valid rune. + */ + return (__istype(wc, 0xffffffffU)); +} diff --git a/usr/src/lib/libc/port/locale/nextwctype.c b/usr/src/lib/libc/port/locale/nextwctype.c new file mode 100644 index 0000000000..54a9d2a07b --- /dev/null +++ b/usr/src/lib/libc/port/locale/nextwctype.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2004 Tim J. Robbins. + * 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. + */ + +#include "lint.h" +#include "runetype.h" +#include <wchar.h> +#include <wctype.h> + +wint_t +__nextwctype(wint_t wc, wctype_t wct) +{ + size_t lim; + _RuneRange *rr = &_CurrentRuneLocale->__runetype_ext; + _RuneEntry *base, *re; + int noinc; + + noinc = 0; + if (wc < _CACHED_RUNES) { + wc++; + while (wc < _CACHED_RUNES) { + if (_CurrentRuneLocale->__runetype[wc] & wct) + return (wc); + wc++; + } + wc--; + } + if (rr->__ranges != NULL && wc < rr->__ranges[0].__min) { + wc = rr->__ranges[0].__min; + noinc = 1; + } + + /* Binary search -- see bsearch.c for explanation. */ + base = rr->__ranges; + for (lim = rr->__nranges; lim != 0; lim >>= 1) { + re = base + (lim >> 1); + if (re->__min <= wc && wc <= re->__max) + goto found; + else if (wc > re->__max) { + base = re + 1; + lim--; + } + } + return (-1); +found: + if (!noinc) + wc++; + if (re->__min <= wc && wc <= re->__max) { + if (re->__types != NULL) { + for (; wc <= re->__max; wc++) + if (re->__types[wc - re->__min] & wct) + return (wc); + } else if (re->__map & wct) + return (wc); + } + while (++re < rr->__ranges + rr->__nranges) { + wc = re->__min; + if (re->__types != NULL) { + for (; wc <= re->__max; wc++) + if (re->__types[wc - re->__min] & wct) + return (wc); + } else if (re->__map & wct) + return (wc); + } + return (-1); +} diff --git a/usr/src/lib/libc/port/mapfile-vers b/usr/src/lib/libc/port/mapfile-vers index b0f99cab15..2d9136f6da 100644 --- a/usr/src/lib/libc/port/mapfile-vers +++ b/usr/src/lib/libc/port/mapfile-vers @@ -2496,6 +2496,7 @@ SYMBOL_VERSION SUNWprivate_1.1 { __inf_written; __i_size; _isnanf { TYPE = FUNCTION; FILTER = libm.so.2 }; + __iswrune; __libc_threaded; _lib_version { FLAGS = NODIRECT }; _logb { TYPE = FUNCTION; FILTER = libm.so.2 }; @@ -2510,6 +2511,7 @@ SYMBOL_VERSION SUNWprivate_1.1 { _modff { TYPE = FUNCTION; FILTER = libm.so.2 }; __nan_read; __nan_written; + __nextwctype; __nis_debug_bind; __nis_debug_calls; __nis_debug_file; diff --git a/usr/src/lib/libc/sparc/Makefile.com b/usr/src/lib/libc/sparc/Makefile.com index 07c5f2e8e6..55e6678e0a 100644 --- a/usr/src/lib/libc/sparc/Makefile.com +++ b/usr/src/lib/libc/sparc/Makefile.com @@ -803,6 +803,8 @@ PORTLOCALE= \ mbstowcs.o \ mbtowc.o \ mskanji.o \ + nextwctype.o \ + nl_langinfo.o \ none.o \ regcomp.o \ regfree.o \ diff --git a/usr/src/lib/libc/sparcv9/Makefile.com b/usr/src/lib/libc/sparcv9/Makefile.com index f7674e613c..4eb9eb903b 100644 --- a/usr/src/lib/libc/sparcv9/Makefile.com +++ b/usr/src/lib/libc/sparcv9/Makefile.com @@ -754,6 +754,8 @@ PORTLOCALE= \ mbstowcs.o \ mbtowc.o \ mskanji.o \ + nextwctype.o \ + nl_langinfo.o \ none.o \ regcomp.o \ regfree.o \ |