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) 1993
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * The Regents of the University of California. All rights reserved.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore *
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * This code is derived from software contributed to Berkeley by
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * Paul Borman at Krystal Technologies.
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 * 4. Neither the name of the University nor the names of its contributors
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * may be used to endorse or promote products derived from this software
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * without specific prior written permission.
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore *
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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 <stdio.h>
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore#include "runetype.h"
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
eda71b4a8fb1d0b34d0f08c47b43af49428d24c3Garrett D'Amoreunsigned int
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore__runetype(const _RuneLocale *rl, __ct_rune_t c)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore{
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore size_t lim;
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore const _RuneRange *rr = &rl->__runetype_ext;
2d08521bd15501c8370ba2153b9cca4f094979d0Garrett D'Amore const _RuneEntry *base, *re;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (c < 0 || c == EOF)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore return (0L);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore /* Binary search -- see bsearch.c for explanation. */
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore base = rr->__ranges;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore for (lim = rr->__nranges; lim != 0; lim >>= 1) {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore re = base + (lim >> 1);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (re->__min <= c && c <= re->__max) {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore if (re->__types)
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore return (re->__types[c - re->__min]);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore else
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore return (re->__map);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore } else if (c > re->__max) {
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore base = re + 1;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore lim--;
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore }
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore }
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore return (0L);
4297a3b0d0a35d80f86fff155e288e885a100e6dGarrett D'Amore}