1131846Stjr/*- 2131846Stjr * Copyright (c) 2004 Tim J. Robbins. 3131846Stjr * All rights reserved. 4131846Stjr * 5131846Stjr * Redistribution and use in source and binary forms, with or without 6131846Stjr * modification, are permitted provided that the following conditions 7131846Stjr * are met: 8131846Stjr * 1. Redistributions of source code must retain the above copyright 9131846Stjr * notice, this list of conditions and the following disclaimer. 10131846Stjr * 2. Redistributions in binary form must reproduce the above copyright 11131846Stjr * notice, this list of conditions and the following disclaimer in the 12131846Stjr * documentation and/or other materials provided with the distribution. 13131846Stjr * 14131846Stjr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15131846Stjr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16131846Stjr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17131846Stjr * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18131846Stjr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19131846Stjr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20131846Stjr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21131846Stjr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22131846Stjr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23131846Stjr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24131846Stjr * SUCH DAMAGE. 25131846Stjr * 26131846Stjr * $FreeBSD: releng/10.2/usr.bin/tr/cset.h 200462 2009-12-13 03:14:06Z delphij $ 27131846Stjr */ 28131846Stjr 29131846Stjr#ifndef CSET_H 30131846Stjr#define CSET_H 31131846Stjr 32131846Stjr#include <stdbool.h> 33200462Sdelphij#include <wchar.h> 34131846Stjr#include <wctype.h> 35131846Stjr 36131846Stjrstruct csnode { 37131846Stjr wchar_t csn_min; 38131846Stjr wchar_t csn_max; 39131846Stjr struct csnode *csn_left; 40131846Stjr struct csnode *csn_right; 41131846Stjr}; 42131846Stjr 43131846Stjrstruct csclass { 44131846Stjr wctype_t csc_type; 45131846Stjr bool csc_invert; 46131846Stjr struct csclass *csc_next; 47131846Stjr}; 48131846Stjr 49131846Stjrstruct cset { 50131846Stjr#define CS_CACHE_SIZE 256 51131846Stjr bool cs_cache[CS_CACHE_SIZE]; 52131846Stjr bool cs_havecache; 53131846Stjr struct csclass *cs_classes; 54131846Stjr struct csnode *cs_root; 55131846Stjr bool cs_invert; 56131846Stjr}; 57131846Stjr 58131846Stjrbool cset_addclass(struct cset *, wctype_t, bool); 59131846Stjrstruct cset * cset_alloc(void); 60131846Stjrbool cset_add(struct cset *, wchar_t); 61131846Stjrvoid cset_invert(struct cset *); 62131846Stjrbool cset_in_hard(struct cset *, wchar_t); 63131846Stjrvoid cset_cache(struct cset *); 64131846Stjr 65131846Stjrstatic __inline bool 66131846Stjrcset_in(struct cset *cs, wchar_t ch) 67131846Stjr{ 68131846Stjr 69131846Stjr if (ch < CS_CACHE_SIZE && cs->cs_havecache) 70131846Stjr return (cs->cs_cache[ch]); 71131846Stjr return (cset_in_hard(cs, ch)); 72131846Stjr} 73131846Stjr 74131846Stjr#endif /* CSET_H */ 75