14297a3b0SGarrett D'Amore /*
22d08521bSGarrett D'Amore  * Copyright 2013 Garrett D'Amore <garrett@damore.org>
36b5e5868SGarrett D'Amore  * Copyright 2010 Nexenta Systems, Inc.  All rights reserved.
44297a3b0SGarrett D'Amore  * Copyright (c) 1993
54297a3b0SGarrett D'Amore  *	The Regents of the University of California.  All rights reserved.
64297a3b0SGarrett D'Amore  *
74297a3b0SGarrett D'Amore  * This code is derived from software contributed to Berkeley by
84297a3b0SGarrett D'Amore  * Paul Borman at Krystal Technologies.
94297a3b0SGarrett D'Amore  *
104297a3b0SGarrett D'Amore  * Redistribution and use in source and binary forms, with or without
114297a3b0SGarrett D'Amore  * modification, are permitted provided that the following conditions
124297a3b0SGarrett D'Amore  * are met:
134297a3b0SGarrett D'Amore  * 1. Redistributions of source code must retain the above copyright
144297a3b0SGarrett D'Amore  *    notice, this list of conditions and the following disclaimer.
154297a3b0SGarrett D'Amore  * 2. Redistributions in binary form must reproduce the above copyright
164297a3b0SGarrett D'Amore  *    notice, this list of conditions and the following disclaimer in the
174297a3b0SGarrett D'Amore  *    documentation and/or other materials provided with the distribution.
184297a3b0SGarrett D'Amore  * 3. Neither the name of the University nor the names of its contributors
194297a3b0SGarrett D'Amore  *    may be used to endorse or promote products derived from this software
204297a3b0SGarrett D'Amore  *    without specific prior written permission.
214297a3b0SGarrett D'Amore  *
224297a3b0SGarrett D'Amore  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
234297a3b0SGarrett D'Amore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
244297a3b0SGarrett D'Amore  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
254297a3b0SGarrett D'Amore  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
264297a3b0SGarrett D'Amore  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
274297a3b0SGarrett D'Amore  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
284297a3b0SGarrett D'Amore  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
294297a3b0SGarrett D'Amore  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
304297a3b0SGarrett D'Amore  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
314297a3b0SGarrett D'Amore  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
324297a3b0SGarrett D'Amore  * SUCH DAMAGE.
334297a3b0SGarrett D'Amore  */
344297a3b0SGarrett D'Amore /*
354297a3b0SGarrett D'Amore  * Because we borrowed the __rune_t defintions from _types.h, we need
364297a3b0SGarrett D'Amore  * this copyright notice as well:
374297a3b0SGarrett D'Amore  *
384297a3b0SGarrett D'Amore  * Copyright (c) 2002 Mike Barcroft <mike@FreeBSD.org>
394297a3b0SGarrett D'Amore  * All rights reserved.
404297a3b0SGarrett D'Amore  *
414297a3b0SGarrett D'Amore  * Redistribution and use in source and binary forms, with or without
424297a3b0SGarrett D'Amore  * modification, are permitted provided that the following conditions
434297a3b0SGarrett D'Amore  * are met:
444297a3b0SGarrett D'Amore  * 1. Redistributions of source code must retain the above copyright
454297a3b0SGarrett D'Amore  *    notice, this list of conditions and the following disclaimer.
464297a3b0SGarrett D'Amore  * 2. Redistributions in binary form must reproduce the above copyright
474297a3b0SGarrett D'Amore  *    notice, this list of conditions and the following disclaimer in the
484297a3b0SGarrett D'Amore  *    documentation and/or other materials provided with the distribution.
494297a3b0SGarrett D'Amore  *
504297a3b0SGarrett D'Amore  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
514297a3b0SGarrett D'Amore  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
524297a3b0SGarrett D'Amore  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
534297a3b0SGarrett D'Amore  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
544297a3b0SGarrett D'Amore  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
554297a3b0SGarrett D'Amore  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
564297a3b0SGarrett D'Amore  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
574297a3b0SGarrett D'Amore  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
584297a3b0SGarrett D'Amore  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
594297a3b0SGarrett D'Amore  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
604297a3b0SGarrett D'Amore  * SUCH DAMAGE.
614297a3b0SGarrett D'Amore  */
624297a3b0SGarrett D'Amore 
634297a3b0SGarrett D'Amore #ifndef	_RUNETYPE_H_
644297a3b0SGarrett D'Amore #define	_RUNETYPE_H_
654297a3b0SGarrett D'Amore 
664297a3b0SGarrett D'Amore #define	_CACHED_RUNES	(1 << 8)		/* Must be a power of 2 */
674297a3b0SGarrett D'Amore #define	_CRMASK		(~(_CACHED_RUNES - 1))
684297a3b0SGarrett D'Amore 
694297a3b0SGarrett D'Amore /*
704297a3b0SGarrett D'Amore  * rune_t is declared to be an ``int'' instead of the more natural
714297a3b0SGarrett D'Amore  * ``unsigned long'' or ``long''.  Two things are happening here.  It is not
724297a3b0SGarrett D'Amore  * unsigned so that EOF (-1) can be naturally assigned to it and used.  Also,
734297a3b0SGarrett D'Amore  * it looks like 10646 will be a 31 bit standard.  This means that if your
744297a3b0SGarrett D'Amore  * ints cannot hold 32 bits, you will be in trouble.  The reason an int was
754297a3b0SGarrett D'Amore  * chosen over a long is that the is*() and to*() routines take ints (says
764297a3b0SGarrett D'Amore  * ANSI C), but they use __ct_rune_t instead of int.
774297a3b0SGarrett D'Amore  *
784297a3b0SGarrett D'Amore  * NOTE: rune_t is not covered by ANSI nor other standards, and should not
794297a3b0SGarrett D'Amore  * be instantiated outside of lib/libc/locale.  Use wchar_t.  wchar_t and
804297a3b0SGarrett D'Amore  * rune_t must be the same type.  Also, wint_t must be no narrower than
814297a3b0SGarrett D'Amore  * wchar_t, and should be able to hold all members of the largest
824297a3b0SGarrett D'Amore  * character set plus one extra value (WEOF), and must be at least 16 bits.
834297a3b0SGarrett D'Amore  *
844297a3b0SGarrett D'Amore  * For compatibility with Solaris, we want to use long in ILP32, and int in
854297a3b0SGarrett D'Amore  * LP64.  This is due to historical Solaris legacy.  (See <wchar.h> for
864297a3b0SGarrett D'Amore  * the definition.)
874297a3b0SGarrett D'Amore  */
884297a3b0SGarrett D'Amore 
894297a3b0SGarrett D'Amore #if	defined(_LP64)
904297a3b0SGarrett D'Amore typedef int		__ct_rune_t;	/* arg type for ctype funcs */
914297a3b0SGarrett D'Amore #else
924297a3b0SGarrett D'Amore typedef	int		__ct_rune_t;
934297a3b0SGarrett D'Amore #endif
944297a3b0SGarrett D'Amore 
954297a3b0SGarrett D'Amore typedef	int		__rune_t;	/* rune_t (see above) */
964297a3b0SGarrett D'Amore 
974297a3b0SGarrett D'Amore /*
984297a3b0SGarrett D'Amore  * The lower 8 bits of runetype[] contain the digit value of the rune.
994297a3b0SGarrett D'Amore  */
100*bc09504fSGordon Ross typedef struct _RuneEntry {
1014297a3b0SGarrett D'Amore 	__rune_t	__min;		/* First rune of the range */
1024297a3b0SGarrett D'Amore 	__rune_t	__max;		/* Last rune (inclusive) of the range */
1034297a3b0SGarrett D'Amore 	__rune_t	__map;		/* What first maps to in maps */
104eda71b4aSGarrett D'Amore 	unsigned	*__types;	/* Array of types in range */
1054297a3b0SGarrett D'Amore } _RuneEntry;
1064297a3b0SGarrett D'Amore 
107*bc09504fSGordon Ross typedef struct _RuneRange {
1084297a3b0SGarrett D'Amore 	int		__nranges;	/* Number of ranges stored */
1094297a3b0SGarrett D'Amore 	_RuneEntry	*__ranges;	/* Pointer to the ranges */
1104297a3b0SGarrett D'Amore } _RuneRange;
1114297a3b0SGarrett D'Amore 
112*bc09504fSGordon Ross typedef struct _RuneLocale {
1134297a3b0SGarrett D'Amore 	char		__magic[8];	/* Magic saying what version we are */
1142d08521bSGarrett D'Amore 	char		__encoding[32];	/* ASCII name of encoding */
1154297a3b0SGarrett D'Amore 
1164297a3b0SGarrett D'Amore 	unsigned int	__runetype[_CACHED_RUNES];
1174297a3b0SGarrett D'Amore 	__rune_t	__maplower[_CACHED_RUNES];
1184297a3b0SGarrett D'Amore 	__rune_t	__mapupper[_CACHED_RUNES];
1194297a3b0SGarrett D'Amore 
1204297a3b0SGarrett D'Amore 	/*
1214297a3b0SGarrett D'Amore 	 * The following are to deal with Runes larger than _CACHED_RUNES - 1.
1224297a3b0SGarrett D'Amore 	 * Their data is actually contiguous with this structure so as to make
1234297a3b0SGarrett D'Amore 	 * it easier to read/write from/to disk.
1244297a3b0SGarrett D'Amore 	 */
1254297a3b0SGarrett D'Amore 	_RuneRange	__runetype_ext;
1264297a3b0SGarrett D'Amore 	_RuneRange	__maplower_ext;
1274297a3b0SGarrett D'Amore 	_RuneRange	__mapupper_ext;
1284297a3b0SGarrett D'Amore 
1294297a3b0SGarrett D'Amore 	void		*__variable;	/* Data which depends on the encoding */
1304297a3b0SGarrett D'Amore 	int		__variable_len;	/* how long that data is */
1314297a3b0SGarrett D'Amore } _RuneLocale;
1324297a3b0SGarrett D'Amore 
1334297a3b0SGarrett D'Amore #define	_RUNE_MAGIC_1	"RuneMagi"	/* Indicates version 0 of RuneLocale */
1344297a3b0SGarrett D'Amore 
1354297a3b0SGarrett D'Amore extern _RuneLocale _DefaultRuneLocale;
1362d08521bSGarrett D'Amore 
1372d08521bSGarrett D'Amore unsigned int __runetype(const _RuneLocale *, int);
1384297a3b0SGarrett D'Amore 
1394297a3b0SGarrett D'Amore #endif	/* !_RUNETYPE_H_ */
140