xref: /dflybsd-src/include/runetype.h (revision fef0a4be3c2d757f727c223fc6032f0898b816ad)
10d5acd74SJohn Marino /*-
20d5acd74SJohn Marino  * Copyright (c) 1993
30d5acd74SJohn Marino  *	The Regents of the University of California.  All rights reserved.
40d5acd74SJohn Marino  *
50d5acd74SJohn Marino  * This code is derived from software contributed to Berkeley by
60d5acd74SJohn Marino  * Paul Borman at Krystal Technologies.
70d5acd74SJohn Marino  *
80d5acd74SJohn Marino  * Redistribution and use in source and binary forms, with or without
90d5acd74SJohn Marino  * modification, are permitted provided that the following conditions
100d5acd74SJohn Marino  * are met:
110d5acd74SJohn Marino  * 1. Redistributions of source code must retain the above copyright
120d5acd74SJohn Marino  *    notice, this list of conditions and the following disclaimer.
130d5acd74SJohn Marino  * 2. Redistributions in binary form must reproduce the above copyright
140d5acd74SJohn Marino  *    notice, this list of conditions and the following disclaimer in the
150d5acd74SJohn Marino  *    documentation and/or other materials provided with the distribution.
160d5acd74SJohn Marino  * 3. Neither the name of the University nor the names of its contributors
170d5acd74SJohn Marino  *    may be used to endorse or promote products derived from this software
180d5acd74SJohn Marino  *    without specific prior written permission.
190d5acd74SJohn Marino  *
200d5acd74SJohn Marino  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
210d5acd74SJohn Marino  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
220d5acd74SJohn Marino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
230d5acd74SJohn Marino  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
240d5acd74SJohn Marino  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
250d5acd74SJohn Marino  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
260d5acd74SJohn Marino  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
270d5acd74SJohn Marino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
280d5acd74SJohn Marino  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
290d5acd74SJohn Marino  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
300d5acd74SJohn Marino  * SUCH DAMAGE.
310d5acd74SJohn Marino  *
320d5acd74SJohn Marino  *	@(#)runetype.h	8.1 (Berkeley) 6/2/93
330d5acd74SJohn Marino  * $FreeBSD: head/include/runetype.h 232620 2012-03-06 20:15:23Z dim $
340d5acd74SJohn Marino  */
350d5acd74SJohn Marino 
360d5acd74SJohn Marino #ifndef	_RUNETYPE_H_
370d5acd74SJohn Marino #define	_RUNETYPE_H_
380d5acd74SJohn Marino 
390d5acd74SJohn Marino #include <sys/cdefs.h>
409d4f17d1Szrj #include <machine/stdint.h>
410d5acd74SJohn Marino 
420d5acd74SJohn Marino #define	_CACHED_RUNES	(1 <<8 )	/* Must be a power of 2 */
430d5acd74SJohn Marino #define	_CRMASK		(~(_CACHED_RUNES - 1))
440d5acd74SJohn Marino 
456ff28e32Szrj /* See comments in <ctype.h> about __ct_rune_t. */
466ff28e32Szrj #ifndef ___CT_RUNE_T_DECLARED
476ff28e32Szrj typedef	int		__ct_rune_t;	/* Arg type for ctype funcs */
486ff28e32Szrj #define	___CT_RUNE_T_DECLARED
496ff28e32Szrj #endif
506ff28e32Szrj 
514b679595Szrj typedef __ct_rune_t	__rune_t;	/* Internal runetype.h type */
524b679595Szrj 
530d5acd74SJohn Marino /*
540d5acd74SJohn Marino  * The lower 8 bits of runetype[] contain the digit value of the rune.
550d5acd74SJohn Marino  */
560d5acd74SJohn Marino typedef struct {
570d5acd74SJohn Marino 	__rune_t	__min;		/* First rune of the range */
580d5acd74SJohn Marino 	__rune_t	__max;		/* Last rune (inclusive) of the range */
590d5acd74SJohn Marino 	__rune_t	__map;		/* What first maps to in maps */
600d5acd74SJohn Marino 	unsigned long	*__types;	/* Array of types in range */
610d5acd74SJohn Marino } _RuneEntry;
620d5acd74SJohn Marino 
630d5acd74SJohn Marino typedef struct {
640d5acd74SJohn Marino 	int		__nranges;	/* Number of ranges stored */
650d5acd74SJohn Marino 	_RuneEntry	*__ranges;	/* Pointer to the ranges */
660d5acd74SJohn Marino } _RuneRange;
670d5acd74SJohn Marino 
680d5acd74SJohn Marino typedef struct {
690d5acd74SJohn Marino 	char		__magic[8];	/* Magic saying what version we are */
700d5acd74SJohn Marino 	char		__encoding[32];	/* ASCII name of this encoding */
710d5acd74SJohn Marino 
720d5acd74SJohn Marino 	__rune_t	(*__sgetrune)(const char *, __size_t, char const **);
730d5acd74SJohn Marino 	int		(*__sputrune)(__rune_t, char *, __size_t, char **);
740d5acd74SJohn Marino 	__rune_t	__invalid_rune;
750d5acd74SJohn Marino 
760d5acd74SJohn Marino 	unsigned long	__runetype[_CACHED_RUNES];
770d5acd74SJohn Marino 	__rune_t	__maplower[_CACHED_RUNES];
780d5acd74SJohn Marino 	__rune_t	__mapupper[_CACHED_RUNES];
790d5acd74SJohn Marino 
800d5acd74SJohn Marino 	/*
810d5acd74SJohn Marino 	 * The following are to deal with Runes larger than _CACHED_RUNES - 1.
820d5acd74SJohn Marino 	 * Their data is actually contiguous with this structure so as to make
830d5acd74SJohn Marino 	 * it easier to read/write from/to disk.
840d5acd74SJohn Marino 	 */
850d5acd74SJohn Marino 	_RuneRange	__runetype_ext;
860d5acd74SJohn Marino 	_RuneRange	__maplower_ext;
870d5acd74SJohn Marino 	_RuneRange	__mapupper_ext;
880d5acd74SJohn Marino 
890d5acd74SJohn Marino 	void		*__variable;	/* Data which depends on the encoding */
900d5acd74SJohn Marino 	int		__variable_len;	/* how long that data is */
910d5acd74SJohn Marino } _RuneLocale;
920d5acd74SJohn Marino 
930d5acd74SJohn Marino #define	_RUNE_MAGIC_1	"RuneMagi"	/* Indicates version 0 of RuneLocale */
940d5acd74SJohn Marino __BEGIN_DECLS
950d5acd74SJohn Marino extern const _RuneLocale _DefaultRuneLocale;
960d5acd74SJohn Marino extern const _RuneLocale *_CurrentRuneLocale;
97*fef0a4beSSascha Wildner #if defined(__RUNETYPE_INTERNAL)
980d5acd74SJohn Marino extern const _RuneLocale *__getCurrentRuneLocale(void);
990d5acd74SJohn Marino #else
1000d5acd74SJohn Marino extern __thread const _RuneLocale *_ThreadRuneLocale;
__getCurrentRuneLocale(void)1010d5acd74SJohn Marino static __inline const _RuneLocale *__getCurrentRuneLocale(void)
1020d5acd74SJohn Marino {
1030d5acd74SJohn Marino 
1040d5acd74SJohn Marino 	if (_ThreadRuneLocale)
1050d5acd74SJohn Marino 		return _ThreadRuneLocale;
1060d5acd74SJohn Marino 	if (_CurrentRuneLocale)
1070d5acd74SJohn Marino 		return _CurrentRuneLocale;
1080d5acd74SJohn Marino 	return &_DefaultRuneLocale;
1090d5acd74SJohn Marino }
110*fef0a4beSSascha Wildner #endif /* __RUNETYPE_INTERNAL */
1110d5acd74SJohn Marino #define _CurrentRuneLocale (__getCurrentRuneLocale())
1120d5acd74SJohn Marino __END_DECLS
1130d5acd74SJohn Marino 
1140d5acd74SJohn Marino #endif	/* !_RUNETYPE_H_ */
115