runetype.c revision 2d08521bd15501c8370ba2153b9cca4f094979d0
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek/*
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * Copyright 2013 Garrett D'Amore <garrett@damore.org>
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * Copyright 2010 Nexenta Systems, Inc. All rights reserved.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * Copyright (c) 1993
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * The Regents of the University of California. All rights reserved.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek *
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * This code is derived from software contributed to Berkeley by
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * Paul Borman at Krystal Technologies.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek *
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * Redistribution and use in source and binary forms, with or without
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * modification, are permitted provided that the following conditions
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * are met:
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * 1. Redistributions of source code must retain the above copyright
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * notice, this list of conditions and the following disclaimer.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * 2. Redistributions in binary form must reproduce the above copyright
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * notice, this list of conditions and the following disclaimer in the
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * documentation and/or other materials provided with the distribution.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * 4. Neither the name of the University nor the names of its contributors
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * may be used to endorse or promote products derived from this software
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * without specific prior written permission.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek *
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2b6c28b8b605a28e1a671f5d6b484cd697e51da6batschul * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek * SUCH DAMAGE.
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek */
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek#include "lint.h"
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek#include <ctype.h>
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek#include <stdio.h>
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek#include "runetype.h"
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinekunsigned int
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek__runetype(const _RuneLocale *rl, __ct_rune_t c)
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek{
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek size_t lim;
11506c4105b984bf64636b0e2f9e88bd67fb9651gjelinek const _RuneRange *rr = &rl->__runetype_ext;
286822dd6ee35fa0959e7b55e659b92ea1c12f71 const _RuneEntry *base, *re;
0094b373ead542a342e4250eaf37854ccd3e50c0jv
0094b373ead542a342e4250eaf37854ccd3e50c0jv if (c < 0 || c == EOF)
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek return (0L);
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek /* Binary search -- see bsearch.c for explanation. */
99653d4ee642c6528e88224f12409a5f23060994eschrock base = rr->__ranges;
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek for (lim = rr->__nranges; lim != 0; lim >>= 1) {
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek re = base + (lim >> 1);
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek if (re->__min <= c && c <= re->__max) {
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek if (re->__types)
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek return (re->__types[c - re->__min]);
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek else
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek return (re->__map);
286822dd6ee35fa0959e7b55e659b92ea1c12f71 } else if (c > re->__max) {
286822dd6ee35fa0959e7b55e659b92ea1c12f71 base = re + 1;
286822dd6ee35fa0959e7b55e659b92ea1c12f71 lim--;
286822dd6ee35fa0959e7b55e659b92ea1c12f71 }
286822dd6ee35fa0959e7b55e659b92ea1c12f71 }
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek
0b5de56d26c0148ad33bb3a9201091502f24d910gjelinek return (0L);
286822dd6ee35fa0959e7b55e659b92ea1c12f71}
286822dd6ee35fa0959e7b55e659b92ea1c12f71