11539Srgrimes/*-
21539Srgrimes * Copyright (c) 1993
31539Srgrimes *	The Regents of the University of California.  All rights reserved.
41539Srgrimes *
51539Srgrimes * This code is derived from software contributed to Berkeley by
61539Srgrimes * Paul Borman at Krystal Technologies.
71539Srgrimes *
81539Srgrimes * Redistribution and use in source and binary forms, with or without
91539Srgrimes * modification, are permitted provided that the following conditions
101539Srgrimes * are met:
111539Srgrimes * 1. Redistributions of source code must retain the above copyright
121539Srgrimes *    notice, this list of conditions and the following disclaimer.
131539Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
141539Srgrimes *    notice, this list of conditions and the following disclaimer in the
151539Srgrimes *    documentation and/or other materials provided with the distribution.
16203964Simp * 3. Neither the name of the University nor the names of its contributors
171539Srgrimes *    may be used to endorse or promote products derived from this software
181539Srgrimes *    without specific prior written permission.
191539Srgrimes *
201539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
211539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
221539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
231539Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
241539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
251539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
261539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
271539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
281539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
291539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
301539Srgrimes * SUCH DAMAGE.
311539Srgrimes *
321539Srgrimes *	@(#)runetype.h	8.1 (Berkeley) 6/2/93
3393032Simp * $FreeBSD$
341539Srgrimes */
351539Srgrimes
361539Srgrimes#ifndef	_RUNETYPE_H_
371539Srgrimes#define	_RUNETYPE_H_
381539Srgrimes
3915483Sbde#include <sys/cdefs.h>
40102227Smike#include <sys/_types.h>
411539Srgrimes
421539Srgrimes#define	_CACHED_RUNES	(1 <<8 )	/* Must be a power of 2 */
431539Srgrimes#define	_CRMASK		(~(_CACHED_RUNES - 1))
441539Srgrimes
451539Srgrimes/*
461539Srgrimes * The lower 8 bits of runetype[] contain the digit value of the rune.
471539Srgrimes */
481539Srgrimestypedef struct {
49130961Stjr	__rune_t	__min;		/* First rune of the range */
50130961Stjr	__rune_t	__max;		/* Last rune (inclusive) of the range */
51130961Stjr	__rune_t	__map;		/* What first maps to in maps */
52130961Stjr	unsigned long	*__types;	/* Array of types in range */
531539Srgrimes} _RuneEntry;
541539Srgrimes
551539Srgrimestypedef struct {
56130961Stjr	int		__nranges;	/* Number of ranges stored */
57130961Stjr	_RuneEntry	*__ranges;	/* Pointer to the ranges */
581539Srgrimes} _RuneRange;
591539Srgrimes
601539Srgrimestypedef struct {
61130961Stjr	char		__magic[8];	/* Magic saying what version we are */
62130961Stjr	char		__encoding[32];	/* ASCII name of this encoding */
631539Srgrimes
64130961Stjr	__rune_t	(*__sgetrune)(const char *, __size_t, char const **);
65130961Stjr	int		(*__sputrune)(__rune_t, char *, __size_t, char **);
66130961Stjr	__rune_t	__invalid_rune;
671539Srgrimes
68130961Stjr	unsigned long	__runetype[_CACHED_RUNES];
69130961Stjr	__rune_t	__maplower[_CACHED_RUNES];
70130961Stjr	__rune_t	__mapupper[_CACHED_RUNES];
711539Srgrimes
721539Srgrimes	/*
731539Srgrimes	 * The following are to deal with Runes larger than _CACHED_RUNES - 1.
741539Srgrimes	 * Their data is actually contiguous with this structure so as to make
751539Srgrimes	 * it easier to read/write from/to disk.
761539Srgrimes	 */
77130961Stjr	_RuneRange	__runetype_ext;
78130961Stjr	_RuneRange	__maplower_ext;
79130961Stjr	_RuneRange	__mapupper_ext;
801539Srgrimes
81130961Stjr	void		*__variable;	/* Data which depends on the encoding */
82130961Stjr	int		__variable_len;	/* how long that data is */
831539Srgrimes} _RuneLocale;
841539Srgrimes
851539Srgrimes#define	_RUNE_MAGIC_1	"RuneMagi"	/* Indicates version 0 of RuneLocale */
86227753Stheraven__BEGIN_DECLS
87227753Stheravenextern const _RuneLocale _DefaultRuneLocale;
88232498Stheravenextern const _RuneLocale *_CurrentRuneLocale;
89232498Stheraven#if defined(__NO_TLS) || defined(__RUNETYPE_INTERNAL)
90232498Stheravenextern const _RuneLocale *__getCurrentRuneLocale(void);
91232498Stheraven#else
92232498Stheravenextern _Thread_local const _RuneLocale *_ThreadRuneLocale;
93232620Sdimstatic __inline const _RuneLocale *__getCurrentRuneLocale(void)
94232498Stheraven{
95232498Stheraven
96232498Stheraven	if (_ThreadRuneLocale)
97232498Stheraven		return _ThreadRuneLocale;
98232498Stheraven	if (_CurrentRuneLocale)
99232498Stheraven		return _CurrentRuneLocale;
100232498Stheraven	return &_DefaultRuneLocale;
101232498Stheraven}
102232498Stheraven#endif /* __NO_TLS || __RUNETYPE_INTERNAL */
103227753Stheraven#define _CurrentRuneLocale (__getCurrentRuneLocale())
104227753Stheraven__END_DECLS
1051539Srgrimes
1061539Srgrimes#endif	/* !_RUNETYPE_H_ */
107