xref: /illumos-gate/usr/src/cmd/tr/cset.h (revision 163bd69b3c164dda2a59c7f08ca788e7d6ba9bea)
1*163bd69bSGarrett D'Amore /*
2*163bd69bSGarrett D'Amore  * Copyright (c) 2004 Tim J. Robbins.
3*163bd69bSGarrett D'Amore  * All rights reserved.
4*163bd69bSGarrett D'Amore  *
5*163bd69bSGarrett D'Amore  * Redistribution and use in source and binary forms, with or without
6*163bd69bSGarrett D'Amore  * modification, are permitted provided that the following conditions
7*163bd69bSGarrett D'Amore  * are met:
8*163bd69bSGarrett D'Amore  * 1. Redistributions of source code must retain the above copyright
9*163bd69bSGarrett D'Amore  *    notice, this list of conditions and the following disclaimer.
10*163bd69bSGarrett D'Amore  * 2. Redistributions in binary form must reproduce the above copyright
11*163bd69bSGarrett D'Amore  *    notice, this list of conditions and the following disclaimer in the
12*163bd69bSGarrett D'Amore  *    documentation and/or other materials provided with the distribution.
13*163bd69bSGarrett D'Amore  *
14*163bd69bSGarrett D'Amore  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15*163bd69bSGarrett D'Amore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16*163bd69bSGarrett D'Amore  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17*163bd69bSGarrett D'Amore  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18*163bd69bSGarrett D'Amore  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19*163bd69bSGarrett D'Amore  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20*163bd69bSGarrett D'Amore  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21*163bd69bSGarrett D'Amore  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22*163bd69bSGarrett D'Amore  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23*163bd69bSGarrett D'Amore  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24*163bd69bSGarrett D'Amore  * SUCH DAMAGE.
25*163bd69bSGarrett D'Amore  */
26*163bd69bSGarrett D'Amore 
27*163bd69bSGarrett D'Amore #ifndef CSET_H
28*163bd69bSGarrett D'Amore #define	CSET_H
29*163bd69bSGarrett D'Amore 
30*163bd69bSGarrett D'Amore #include <stdbool.h>
31*163bd69bSGarrett D'Amore #include <wchar.h>
32*163bd69bSGarrett D'Amore #include <wctype.h>
33*163bd69bSGarrett D'Amore 
34*163bd69bSGarrett D'Amore struct csnode {
35*163bd69bSGarrett D'Amore 	wchar_t		csn_min;
36*163bd69bSGarrett D'Amore 	wchar_t		csn_max;
37*163bd69bSGarrett D'Amore 	struct csnode	*csn_left;
38*163bd69bSGarrett D'Amore 	struct csnode	*csn_right;
39*163bd69bSGarrett D'Amore };
40*163bd69bSGarrett D'Amore 
41*163bd69bSGarrett D'Amore struct csclass {
42*163bd69bSGarrett D'Amore 	wctype_t	csc_type;
43*163bd69bSGarrett D'Amore 	bool		csc_invert;
44*163bd69bSGarrett D'Amore 	struct csclass	*csc_next;
45*163bd69bSGarrett D'Amore };
46*163bd69bSGarrett D'Amore 
47*163bd69bSGarrett D'Amore struct cset {
48*163bd69bSGarrett D'Amore #define	CS_CACHE_SIZE	256
49*163bd69bSGarrett D'Amore 	bool		cs_cache[CS_CACHE_SIZE];
50*163bd69bSGarrett D'Amore 	bool		cs_havecache;
51*163bd69bSGarrett D'Amore 	struct csclass	*cs_classes;
52*163bd69bSGarrett D'Amore 	struct csnode	*cs_root;
53*163bd69bSGarrett D'Amore 	bool		cs_invert;
54*163bd69bSGarrett D'Amore };
55*163bd69bSGarrett D'Amore 
56*163bd69bSGarrett D'Amore bool			cset_addclass(struct cset *, wctype_t, bool);
57*163bd69bSGarrett D'Amore struct cset 		*cset_alloc(void);
58*163bd69bSGarrett D'Amore bool 			cset_add(struct cset *, wchar_t);
59*163bd69bSGarrett D'Amore void			cset_invert(struct cset *);
60*163bd69bSGarrett D'Amore bool			cset_in_hard(struct cset *, wchar_t);
61*163bd69bSGarrett D'Amore void			cset_cache(struct cset *);
62*163bd69bSGarrett D'Amore 
63*163bd69bSGarrett D'Amore #endif	/* CSET_H */
64