xref: /freebsd/include/runetype.h (revision 5a1d1441)
159deaec5SRodney W. Grimes /*-
22321c474SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
32321c474SPedro F. Giffuni  *
459deaec5SRodney W. Grimes  * Copyright (c) 1993
559deaec5SRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
659deaec5SRodney W. Grimes  *
759deaec5SRodney W. Grimes  * This code is derived from software contributed to Berkeley by
859deaec5SRodney W. Grimes  * Paul Borman at Krystal Technologies.
959deaec5SRodney W. Grimes  *
1059deaec5SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
1159deaec5SRodney W. Grimes  * modification, are permitted provided that the following conditions
1259deaec5SRodney W. Grimes  * are met:
1359deaec5SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
1459deaec5SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
1559deaec5SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
1659deaec5SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
1759deaec5SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
18f2556687SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
1959deaec5SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
2059deaec5SRodney W. Grimes  *    without specific prior written permission.
2159deaec5SRodney W. Grimes  *
2259deaec5SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2359deaec5SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2459deaec5SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2559deaec5SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2659deaec5SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2759deaec5SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2859deaec5SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2959deaec5SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3059deaec5SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3159deaec5SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3259deaec5SRodney W. Grimes  * SUCH DAMAGE.
3359deaec5SRodney W. Grimes  */
3459deaec5SRodney W. Grimes 
3559deaec5SRodney W. Grimes #ifndef	_RUNETYPE_H_
3659deaec5SRodney W. Grimes #define	_RUNETYPE_H_
3759deaec5SRodney W. Grimes 
3859deaec5SRodney W. Grimes #include <sys/cdefs.h>
39abbd8902SMike Barcroft #include <sys/_types.h>
4059deaec5SRodney W. Grimes 
4159deaec5SRodney W. Grimes #define	_CACHED_RUNES	(1 <<8 )	/* Must be a power of 2 */
4259deaec5SRodney W. Grimes #define	_CRMASK		(~(_CACHED_RUNES - 1))
4359deaec5SRodney W. Grimes 
4459deaec5SRodney W. Grimes /*
4559deaec5SRodney W. Grimes  * The lower 8 bits of runetype[] contain the digit value of the rune.
4659deaec5SRodney W. Grimes  */
4759deaec5SRodney W. Grimes typedef struct {
48ddc1ededSTim J. Robbins 	__rune_t	__min;		/* First rune of the range */
49ddc1ededSTim J. Robbins 	__rune_t	__max;		/* Last rune (inclusive) of the range */
50ddc1ededSTim J. Robbins 	__rune_t	__map;		/* What first maps to in maps */
51ddc1ededSTim J. Robbins 	unsigned long	*__types;	/* Array of types in range */
5259deaec5SRodney W. Grimes } _RuneEntry;
5359deaec5SRodney W. Grimes 
5459deaec5SRodney W. Grimes typedef struct {
55ddc1ededSTim J. Robbins 	int		__nranges;	/* Number of ranges stored */
56ddc1ededSTim J. Robbins 	_RuneEntry	*__ranges;	/* Pointer to the ranges */
5759deaec5SRodney W. Grimes } _RuneRange;
5859deaec5SRodney W. Grimes 
5959deaec5SRodney W. Grimes typedef struct {
60ddc1ededSTim J. Robbins 	char		__magic[8];	/* Magic saying what version we are */
61ddc1ededSTim J. Robbins 	char		__encoding[32];	/* ASCII name of this encoding */
6259deaec5SRodney W. Grimes 
63ddc1ededSTim J. Robbins 	__rune_t	(*__sgetrune)(const char *, __size_t, char const **);
64ddc1ededSTim J. Robbins 	int		(*__sputrune)(__rune_t, char *, __size_t, char **);
65ddc1ededSTim J. Robbins 	__rune_t	__invalid_rune;
6659deaec5SRodney W. Grimes 
67ddc1ededSTim J. Robbins 	unsigned long	__runetype[_CACHED_RUNES];
68ddc1ededSTim J. Robbins 	__rune_t	__maplower[_CACHED_RUNES];
69ddc1ededSTim J. Robbins 	__rune_t	__mapupper[_CACHED_RUNES];
7059deaec5SRodney W. Grimes 
7159deaec5SRodney W. Grimes 	/*
7259deaec5SRodney W. Grimes 	 * The following are to deal with Runes larger than _CACHED_RUNES - 1.
7359deaec5SRodney W. Grimes 	 * Their data is actually contiguous with this structure so as to make
7459deaec5SRodney W. Grimes 	 * it easier to read/write from/to disk.
7559deaec5SRodney W. Grimes 	 */
76ddc1ededSTim J. Robbins 	_RuneRange	__runetype_ext;
77ddc1ededSTim J. Robbins 	_RuneRange	__maplower_ext;
78ddc1ededSTim J. Robbins 	_RuneRange	__mapupper_ext;
7959deaec5SRodney W. Grimes 
80ddc1ededSTim J. Robbins 	void		*__variable;	/* Data which depends on the encoding */
81ddc1ededSTim J. Robbins 	int		__variable_len;	/* how long that data is */
8259deaec5SRodney W. Grimes } _RuneLocale;
8359deaec5SRodney W. Grimes 
8459deaec5SRodney W. Grimes #define	_RUNE_MAGIC_1	"RuneMagi"	/* Indicates version 0 of RuneLocale */
853c87aa1dSDavid Chisnall __BEGIN_DECLS
863c87aa1dSDavid Chisnall extern const _RuneLocale _DefaultRuneLocale;
87a8ed63bbSDavid Chisnall extern const _RuneLocale *_CurrentRuneLocale;
883ae8d83dSKonstantin Belousov #ifdef __RUNETYPE_INTERNAL
89a8ed63bbSDavid Chisnall extern const _RuneLocale *__getCurrentRuneLocale(void);
90a8ed63bbSDavid Chisnall #else
91a8ed63bbSDavid Chisnall extern _Thread_local const _RuneLocale *_ThreadRuneLocale;
__getCurrentRuneLocale(void)92b1e45245SDimitry Andric static __inline const _RuneLocale *__getCurrentRuneLocale(void)
93a8ed63bbSDavid Chisnall {
94a8ed63bbSDavid Chisnall 
95a8ed63bbSDavid Chisnall 	if (_ThreadRuneLocale)
96a8ed63bbSDavid Chisnall 		return _ThreadRuneLocale;
97a8ed63bbSDavid Chisnall 	return _CurrentRuneLocale;
98a8ed63bbSDavid Chisnall }
993ae8d83dSKonstantin Belousov #endif /*__RUNETYPE_INTERNAL */
1003c87aa1dSDavid Chisnall #define _CurrentRuneLocale (__getCurrentRuneLocale())
1013c87aa1dSDavid Chisnall __END_DECLS
10259deaec5SRodney W. Grimes 
10359deaec5SRodney W. Grimes #endif	/* !_RUNETYPE_H_ */
104