14297a3b0SGarrett D'Amore /*
22d08521bSGarrett D'Amore * Copyright 2013 Garrett D'Amore <garrett@damore.org>
36b5e5868SGarrett D'Amore * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
44297a3b0SGarrett D'Amore * Copyright (c) 2002 Tim J. Robbins.
54297a3b0SGarrett D'Amore * All rights reserved.
64297a3b0SGarrett D'Amore *
74297a3b0SGarrett D'Amore * Redistribution and use in source and binary forms, with or without
84297a3b0SGarrett D'Amore * modification, are permitted provided that the following conditions
94297a3b0SGarrett D'Amore * are met:
104297a3b0SGarrett D'Amore * 1. Redistributions of source code must retain the above copyright
114297a3b0SGarrett D'Amore * notice, this list of conditions and the following disclaimer.
124297a3b0SGarrett D'Amore * 2. Redistributions in binary form must reproduce the above copyright
134297a3b0SGarrett D'Amore * notice, this list of conditions and the following disclaimer in the
144297a3b0SGarrett D'Amore * documentation and/or other materials provided with the distribution.
154297a3b0SGarrett D'Amore *
164297a3b0SGarrett D'Amore * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
174297a3b0SGarrett D'Amore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
184297a3b0SGarrett D'Amore * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
194297a3b0SGarrett D'Amore * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
204297a3b0SGarrett D'Amore * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
214297a3b0SGarrett D'Amore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
224297a3b0SGarrett D'Amore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
234297a3b0SGarrett D'Amore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
244297a3b0SGarrett D'Amore * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
254297a3b0SGarrett D'Amore * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
264297a3b0SGarrett D'Amore * SUCH DAMAGE.
274297a3b0SGarrett D'Amore */
284297a3b0SGarrett D'Amore
294297a3b0SGarrett D'Amore #include "lint.h"
304297a3b0SGarrett D'Amore #include <ctype.h>
314297a3b0SGarrett D'Amore #include <string.h>
324297a3b0SGarrett D'Amore #include <wctype.h>
332d08521bSGarrett D'Amore #include <locale.h>
344297a3b0SGarrett D'Amore #include "_ctype.h"
354297a3b0SGarrett D'Amore
362d08521bSGarrett D'Amore /*
372d08521bSGarrett D'Amore * For now, we don't support locale specific character classes. This is
382d08521bSGarrett D'Amore * a capability that needs to be added (locales should be able to define
392d08521bSGarrett D'Amore * their own character classes.)
402d08521bSGarrett D'Amore */
414297a3b0SGarrett D'Amore wctype_t
wctype_l(const char * property,locale_t loc __unused)42*4a38094cSToomas Soome wctype_l(const char *property, locale_t loc __unused)
434297a3b0SGarrett D'Amore {
444297a3b0SGarrett D'Amore static const struct {
454297a3b0SGarrett D'Amore const char *name;
464297a3b0SGarrett D'Amore wctype_t mask;
474297a3b0SGarrett D'Amore } props[] = {
484297a3b0SGarrett D'Amore { "alnum", _CTYPE_A|_CTYPE_D },
494297a3b0SGarrett D'Amore { "alpha", _CTYPE_A },
504297a3b0SGarrett D'Amore { "blank", _CTYPE_B },
514297a3b0SGarrett D'Amore { "cntrl", _CTYPE_C },
524297a3b0SGarrett D'Amore { "digit", _CTYPE_D },
534297a3b0SGarrett D'Amore { "graph", _CTYPE_G },
544297a3b0SGarrett D'Amore { "lower", _CTYPE_L },
554297a3b0SGarrett D'Amore { "print", _CTYPE_R },
564297a3b0SGarrett D'Amore { "punct", _CTYPE_P },
574297a3b0SGarrett D'Amore { "space", _CTYPE_S },
584297a3b0SGarrett D'Amore { "upper", _CTYPE_U },
594297a3b0SGarrett D'Amore { "xdigit", _CTYPE_X },
604297a3b0SGarrett D'Amore { "ideogram", _CTYPE_I }, /* BSD extension */
614297a3b0SGarrett D'Amore { "special", _CTYPE_T }, /* BSD extension */
624297a3b0SGarrett D'Amore { "phonogram", _CTYPE_Q }, /* BSD extension */
6304a6f8c5SGarrett D'Amore { "rune", -1 }, /* BSD extension */
6404a6f8c5SGarrett D'Amore { NULL, 0 }, /* Default */
654297a3b0SGarrett D'Amore };
664297a3b0SGarrett D'Amore int i;
674297a3b0SGarrett D'Amore
684297a3b0SGarrett D'Amore i = 0;
694297a3b0SGarrett D'Amore while (props[i].name != NULL && strcmp(props[i].name, property) != 0)
704297a3b0SGarrett D'Amore i++;
714297a3b0SGarrett D'Amore
724297a3b0SGarrett D'Amore return (props[i].mask);
734297a3b0SGarrett D'Amore }
742d08521bSGarrett D'Amore
752d08521bSGarrett D'Amore wctype_t
wctype(const char * property)762d08521bSGarrett D'Amore wctype(const char *property)
772d08521bSGarrett D'Amore {
782d08521bSGarrett D'Amore return (wctype_l(property, uselocale(NULL)));
792d08521bSGarrett D'Amore }
80