14297a3b0SGarrett D'Amore /* 24297a3b0SGarrett D'Amore * Copyright (c) 1989, 1993 34297a3b0SGarrett D'Amore * The Regents of the University of California. All rights reserved. 44297a3b0SGarrett D'Amore * (c) UNIX System Laboratories, Inc. 54297a3b0SGarrett D'Amore * All or some portions of this file are derived from material licensed 64297a3b0SGarrett D'Amore * to the University of California by American Telephone and Telegraph 74297a3b0SGarrett D'Amore * Co. or Unix System Laboratories, Inc. and are reproduced herein with 84297a3b0SGarrett D'Amore * the permission of UNIX System Laboratories, Inc. 94297a3b0SGarrett D'Amore * 104297a3b0SGarrett D'Amore * This code is derived from software contributed to Berkeley by 114297a3b0SGarrett D'Amore * Paul Borman at Krystal Technologies. 124297a3b0SGarrett D'Amore * 134297a3b0SGarrett D'Amore * Redistribution and use in source and binary forms, with or without 144297a3b0SGarrett D'Amore * modification, are permitted provided that the following conditions 154297a3b0SGarrett D'Amore * are met: 164297a3b0SGarrett D'Amore * 1. Redistributions of source code must retain the above copyright 174297a3b0SGarrett D'Amore * notice, this list of conditions and the following disclaimer. 184297a3b0SGarrett D'Amore * 2. Redistributions in binary form must reproduce the above copyright 194297a3b0SGarrett D'Amore * notice, this list of conditions and the following disclaimer in the 204297a3b0SGarrett D'Amore * documentation and/or other materials provided with the distribution. 214297a3b0SGarrett D'Amore * 4. Neither the name of the University nor the names of its contributors 224297a3b0SGarrett D'Amore * may be used to endorse or promote products derived from this software 234297a3b0SGarrett D'Amore * without specific prior written permission. 244297a3b0SGarrett D'Amore * 254297a3b0SGarrett D'Amore * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 264297a3b0SGarrett D'Amore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 274297a3b0SGarrett D'Amore * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 284297a3b0SGarrett D'Amore * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 294297a3b0SGarrett D'Amore * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 304297a3b0SGarrett D'Amore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 314297a3b0SGarrett D'Amore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 324297a3b0SGarrett D'Amore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 334297a3b0SGarrett D'Amore * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 344297a3b0SGarrett D'Amore * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 354297a3b0SGarrett D'Amore * SUCH DAMAGE. 364297a3b0SGarrett D'Amore */ 374297a3b0SGarrett D'Amore 384297a3b0SGarrett D'Amore /* 394297a3b0SGarrett D'Amore * Copyright 2010 Nexenta Systems, Inc. All rights reserved. 404297a3b0SGarrett D'Amore * Use is subject to license terms. 414297a3b0SGarrett D'Amore */ 424297a3b0SGarrett D'Amore 434297a3b0SGarrett D'Amore #include "lint.h" 444297a3b0SGarrett D'Amore #include <wctype.h> 454297a3b0SGarrett D'Amore #include "runefile.h" 464297a3b0SGarrett D'Amore #include "runetype.h" 474297a3b0SGarrett D'Amore #include "_ctype.h" 484297a3b0SGarrett D'Amore 494297a3b0SGarrett D'Amore /* 504297a3b0SGarrett D'Amore * We removed: iswascii, iswrune, iswhexnumber, and iswnumber, as 514297a3b0SGarrett D'Amore * these are not present on Solaris. Note that the standard requires 524297a3b0SGarrett D'Amore * iswascii to be a macro, so it is defined in our headers. 534297a3b0SGarrett D'Amore * 544297a3b0SGarrett D'Amore * We renamed (per Solaris) iswideogram, iswspecial, iswspecial to the 554297a3b0SGarrett D'Amore * equivalent values without "w". We added a new isnumber, that looks 564297a3b0SGarrett D'Amore * for non-ASCII numbers. 574297a3b0SGarrett D'Amore */ 584297a3b0SGarrett D'Amore 594297a3b0SGarrett D'Amore static int 60eda71b4aSGarrett D'Amore __istype(wint_t c, unsigned int f) 614297a3b0SGarrett D'Amore { 62eda71b4aSGarrett D'Amore unsigned int rt; 634297a3b0SGarrett D'Amore 644297a3b0SGarrett D'Amore /* Fast path for single byte locales */ 654297a3b0SGarrett D'Amore if (c < 0 || c >= _CACHED_RUNES) 664297a3b0SGarrett D'Amore rt = ___runetype(c); 674297a3b0SGarrett D'Amore else 684297a3b0SGarrett D'Amore rt = _CurrentRuneLocale->__runetype[c]; 695ffb5900SGarrett D'Amore return (rt & f); 704297a3b0SGarrett D'Amore } 714297a3b0SGarrett D'Amore 724297a3b0SGarrett D'Amore static int 73eda71b4aSGarrett D'Amore __isctype(wint_t c, unsigned int f) 744297a3b0SGarrett D'Amore { 75eda71b4aSGarrett D'Amore unsigned int rt; 764297a3b0SGarrett D'Amore 774297a3b0SGarrett D'Amore /* Fast path for single byte locales */ 784297a3b0SGarrett D'Amore if (c < 0 || c >= _CACHED_RUNES) 794297a3b0SGarrett D'Amore return (0); 804297a3b0SGarrett D'Amore else 814297a3b0SGarrett D'Amore rt = _CurrentRuneLocale->__runetype[c]; 825ffb5900SGarrett D'Amore return (rt & f); 834297a3b0SGarrett D'Amore } 844297a3b0SGarrett D'Amore 854297a3b0SGarrett D'Amore #undef iswctype 864297a3b0SGarrett D'Amore int 874297a3b0SGarrett D'Amore iswctype(wint_t wc, wctype_t class) 884297a3b0SGarrett D'Amore { 89eda71b4aSGarrett D'Amore return (__istype(wc, class)); 904297a3b0SGarrett D'Amore } 914297a3b0SGarrett D'Amore 924297a3b0SGarrett D'Amore #undef _iswctype 934297a3b0SGarrett D'Amore unsigned 944297a3b0SGarrett D'Amore _iswctype(wchar_t wc, int class) 954297a3b0SGarrett D'Amore { 96eda71b4aSGarrett D'Amore return (__istype((wint_t)wc, (unsigned int)class)); 974297a3b0SGarrett D'Amore } 984297a3b0SGarrett D'Amore 994297a3b0SGarrett D'Amore #undef iswalnum 1004297a3b0SGarrett D'Amore int 1014297a3b0SGarrett D'Amore iswalnum(wint_t wc) 1024297a3b0SGarrett D'Amore { 1034297a3b0SGarrett D'Amore return (__istype(wc, _CTYPE_A|_CTYPE_D)); 1044297a3b0SGarrett D'Amore } 1054297a3b0SGarrett D'Amore 1064297a3b0SGarrett D'Amore #undef iswalpha 1074297a3b0SGarrett D'Amore int 1084297a3b0SGarrett D'Amore iswalpha(wint_t wc) 1094297a3b0SGarrett D'Amore { 1104297a3b0SGarrett D'Amore return (__istype(wc, _CTYPE_A)); 1114297a3b0SGarrett D'Amore } 1124297a3b0SGarrett D'Amore 1134297a3b0SGarrett D'Amore #undef iswblank 1144297a3b0SGarrett D'Amore int 1154297a3b0SGarrett D'Amore iswblank(wint_t wc) 1164297a3b0SGarrett D'Amore { 1174297a3b0SGarrett D'Amore return (__istype(wc, _CTYPE_B)); 1184297a3b0SGarrett D'Amore } 1194297a3b0SGarrett D'Amore 1204297a3b0SGarrett D'Amore #undef iswcntrl 1214297a3b0SGarrett D'Amore int 1224297a3b0SGarrett D'Amore iswcntrl(wint_t wc) 1234297a3b0SGarrett D'Amore { 1244297a3b0SGarrett D'Amore return (__istype(wc, _CTYPE_C)); 1254297a3b0SGarrett D'Amore } 1264297a3b0SGarrett D'Amore 1274297a3b0SGarrett D'Amore #undef iswdigit 1284297a3b0SGarrett D'Amore int 1294297a3b0SGarrett D'Amore iswdigit(wint_t wc) 1304297a3b0SGarrett D'Amore { 1314297a3b0SGarrett D'Amore return (__isctype(wc, _CTYPE_D)); 1324297a3b0SGarrett D'Amore } 1334297a3b0SGarrett D'Amore 1344297a3b0SGarrett D'Amore #undef iswgraph 1354297a3b0SGarrett D'Amore int 1364297a3b0SGarrett D'Amore iswgraph(wint_t wc) 1374297a3b0SGarrett D'Amore { 1384297a3b0SGarrett D'Amore return (__istype(wc, _CTYPE_G)); 1394297a3b0SGarrett D'Amore } 1404297a3b0SGarrett D'Amore 1414297a3b0SGarrett D'Amore #undef isideogram 1424297a3b0SGarrett D'Amore int 1434297a3b0SGarrett D'Amore isideogram(wint_t wc) 1444297a3b0SGarrett D'Amore { 1454297a3b0SGarrett D'Amore return (__istype(wc, _CTYPE_I)); 1464297a3b0SGarrett D'Amore } 1474297a3b0SGarrett D'Amore 1484297a3b0SGarrett D'Amore #undef iswlower 1494297a3b0SGarrett D'Amore int 1504297a3b0SGarrett D'Amore iswlower(wint_t wc) 1514297a3b0SGarrett D'Amore { 1524297a3b0SGarrett D'Amore return (__istype(wc, _CTYPE_L)); 1534297a3b0SGarrett D'Amore } 1544297a3b0SGarrett D'Amore 1554297a3b0SGarrett D'Amore #undef isphonogram 1564297a3b0SGarrett D'Amore int 1574297a3b0SGarrett D'Amore isphonogram(wint_t wc) 1584297a3b0SGarrett D'Amore { 1594297a3b0SGarrett D'Amore return (__istype(wc, _CTYPE_Q)); 1604297a3b0SGarrett D'Amore } 1614297a3b0SGarrett D'Amore 1624297a3b0SGarrett D'Amore #undef iswprint 1634297a3b0SGarrett D'Amore int 1644297a3b0SGarrett D'Amore iswprint(wint_t wc) 1654297a3b0SGarrett D'Amore { 1664297a3b0SGarrett D'Amore return (__istype(wc, _CTYPE_R)); 1674297a3b0SGarrett D'Amore } 1684297a3b0SGarrett D'Amore 1694297a3b0SGarrett D'Amore #undef iswpunct 1704297a3b0SGarrett D'Amore int 1714297a3b0SGarrett D'Amore iswpunct(wint_t wc) 1724297a3b0SGarrett D'Amore { 1734297a3b0SGarrett D'Amore return (__istype(wc, _CTYPE_P)); 1744297a3b0SGarrett D'Amore } 1754297a3b0SGarrett D'Amore 1764297a3b0SGarrett D'Amore #undef iswspace 1774297a3b0SGarrett D'Amore int 1784297a3b0SGarrett D'Amore iswspace(wint_t wc) 1794297a3b0SGarrett D'Amore { 1804297a3b0SGarrett D'Amore return (__istype(wc, _CTYPE_S)); 1814297a3b0SGarrett D'Amore } 1824297a3b0SGarrett D'Amore 1834297a3b0SGarrett D'Amore #undef iswupper 1844297a3b0SGarrett D'Amore int 1854297a3b0SGarrett D'Amore iswupper(wint_t wc) 1864297a3b0SGarrett D'Amore { 1874297a3b0SGarrett D'Amore return (__istype(wc, _CTYPE_U)); 1884297a3b0SGarrett D'Amore } 1894297a3b0SGarrett D'Amore 1904297a3b0SGarrett D'Amore #undef iswxdigit 1914297a3b0SGarrett D'Amore int 1924297a3b0SGarrett D'Amore iswxdigit(wint_t wc) 1934297a3b0SGarrett D'Amore { 1944297a3b0SGarrett D'Amore return (__isctype(wc, _CTYPE_X)); 1954297a3b0SGarrett D'Amore } 1964297a3b0SGarrett D'Amore 1974297a3b0SGarrett D'Amore #undef isenglish 1984297a3b0SGarrett D'Amore int 1994297a3b0SGarrett D'Amore isenglish(wint_t wc) 2004297a3b0SGarrett D'Amore { 2014297a3b0SGarrett D'Amore return (__istype(wc, _CTYPE_E)); 2024297a3b0SGarrett D'Amore } 2034297a3b0SGarrett D'Amore 2044297a3b0SGarrett D'Amore #undef isspecial 2054297a3b0SGarrett D'Amore int 2064297a3b0SGarrett D'Amore isspecial(wint_t wc) 2074297a3b0SGarrett D'Amore { 2084297a3b0SGarrett D'Amore return (__istype(wc, _CTYPE_T)); 2094297a3b0SGarrett D'Amore } 2104297a3b0SGarrett D'Amore 2114297a3b0SGarrett D'Amore #undef isnumber 2124297a3b0SGarrett D'Amore int 2134297a3b0SGarrett D'Amore isnumber(wint_t wc) 2144297a3b0SGarrett D'Amore { 2154297a3b0SGarrett D'Amore return (__istype(wc, _CTYPE_N)); 2164297a3b0SGarrett D'Amore } 217*163bd69bSGarrett D'Amore 218*163bd69bSGarrett D'Amore /* 219*163bd69bSGarrett D'Amore * FreeBSD has iswrune() for use by external programs, and this is used by 220*163bd69bSGarrett D'Amore * the "tr" program. As that program is part of our consolidation, we 221*163bd69bSGarrett D'Amore * provide an _ILLUMOS_PRIVATE version of this function that we can use. 222*163bd69bSGarrett D'Amore * 223*163bd69bSGarrett D'Amore * No programs that are not part of the illumos stack itself should use 224*163bd69bSGarrett D'Amore * this function -- programs that do reference will not be portable to 225*163bd69bSGarrett D'Amore * other versions of SunOS or Solaris. 226*163bd69bSGarrett D'Amore */ 227*163bd69bSGarrett D'Amore int 228*163bd69bSGarrett D'Amore __iswrune(wint_t wc) 229*163bd69bSGarrett D'Amore { 230*163bd69bSGarrett D'Amore /* 231*163bd69bSGarrett D'Amore * Note, FreeBSD ignored the low order byte, as they encode their 232*163bd69bSGarrett D'Amore * ctype values differently. We can't do that (ctype is baked into 233*163bd69bSGarrett D'Amore * applications), but instead can just check if *any* bit is set in 234*163bd69bSGarrett D'Amore * the ctype. Any bit being set indicates its a valid rune. 235*163bd69bSGarrett D'Amore */ 236*163bd69bSGarrett D'Amore return (__istype(wc, 0xffffffffU)); 237*163bd69bSGarrett D'Amore } 238