4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore/*
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore * Copyright 2013 Garrett D'Amore <garrett@damore.org>
6b5e5868e7ebf1aff3a5abd7d0c4ef0e5fbf3648Garrett D'Amore * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * Copyright (c) 2002 Tim J. Robbins.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * All rights reserved.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore *
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * Redistribution and use in source and binary forms, with or without
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * modification, are permitted provided that the following conditions
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * are met:
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * 1. Redistributions of source code must retain the above copyright
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * notice, this list of conditions and the following disclaimer.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * 2. Redistributions in binary form must reproduce the above copyright
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * notice, this list of conditions and the following disclaimer in the
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * documentation and/or other materials provided with the distribution.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore *
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * SUCH DAMAGE.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore#include "lint.h"
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore#include <ctype.h>
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore#include <string.h>
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore#include <wctype.h>
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore#include <note.h>
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore#include <locale.h>
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore#include "_ctype.h"
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore/*
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore * For now, we don't support locale specific character classes. This is
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore * a capability that needs to be added (locales should be able to define
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore * their own character classes.)
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amorewctype_t
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amorewctype_l(const char *property, locale_t loc)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore{
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore static const struct {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore const char *name;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore wctype_t mask;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore } props[] = {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore { "alnum", _CTYPE_A|_CTYPE_D },
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore { "alpha", _CTYPE_A },
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore { "blank", _CTYPE_B },
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore { "cntrl", _CTYPE_C },
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore { "digit", _CTYPE_D },
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore { "graph", _CTYPE_G },
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore { "lower", _CTYPE_L },
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore { "print", _CTYPE_R },
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore { "punct", _CTYPE_P },
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore { "space", _CTYPE_S },
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore { "upper", _CTYPE_U },
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore { "xdigit", _CTYPE_X },
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore { "ideogram", _CTYPE_I }, /* BSD extension */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore { "special", _CTYPE_T }, /* BSD extension */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore { "phonogram", _CTYPE_Q }, /* BSD extension */
04a6f8c58c26d076f7f02ff5dd23f3532e252101Garrett D'Amore { "rune", -1 }, /* BSD extension */
04a6f8c58c26d076f7f02ff5dd23f3532e252101Garrett D'Amore { NULL, 0 }, /* Default */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore };
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore int i;
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore _NOTE(ARGUNUSED(loc));
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore i = 0;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore while (props[i].name != NULL && strcmp(props[i].name, property) != 0)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore i++;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore return (props[i].mask);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore}
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amorewctype_t
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amorewctype(const char *property)
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore{
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore return (wctype_l(property, uselocale(NULL)));
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore}