runetype.h revision 102227
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.
161539Srgrimes * 3. All advertising materials mentioning features or use of this software
171539Srgrimes *    must display the following acknowledgement:
181539Srgrimes *	This product includes software developed by the University of
191539Srgrimes *	California, Berkeley and its contributors.
201539Srgrimes * 4. Neither the name of the University nor the names of its contributors
211539Srgrimes *    may be used to endorse or promote products derived from this software
221539Srgrimes *    without specific prior written permission.
231539Srgrimes *
241539Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
251539Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
261539Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
271539Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
281539Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
291539Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
301539Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
311539Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
321539Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
331539Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
341539Srgrimes * SUCH DAMAGE.
351539Srgrimes *
361539Srgrimes *	@(#)runetype.h	8.1 (Berkeley) 6/2/93
3793032Simp * $FreeBSD: head/include/runetype.h 102227 2002-08-21 16:20:02Z mike $
381539Srgrimes */
391539Srgrimes
401539Srgrimes#ifndef	_RUNETYPE_H_
411539Srgrimes#define	_RUNETYPE_H_
421539Srgrimes
4315483Sbde#include <sys/cdefs.h>
44102227Smike#include <sys/_types.h>
451539Srgrimes
46102227Smike#ifndef _RUNE_T_DECLARED
47102227Smiketypedef	__rune_t	rune_t;
48102227Smike#define	_RUNE_T_DECLARED
491539Srgrimes#endif
501539Srgrimes
51102227Smike#ifndef _SIZE_T_DECLARED
52102227Smiketypedef	__size_t	size_t;
53102227Smike#define	_SIZE_T_DECLARED
5415287Sache#endif
5515287Sache
5699640Sobrien#ifndef	__cplusplus
57102227Smike#ifndef _WCHAR_T_DECLARED
58102227Smiketypedef	__wchar_t	wchar_t;
59102227Smike#define	_WCHAR_T_DECLARED
6015483Sbde#endif
6199640Sobrien#endif
6215483Sbde
631539Srgrimes#define	_CACHED_RUNES	(1 <<8 )	/* Must be a power of 2 */
641539Srgrimes#define	_CRMASK		(~(_CACHED_RUNES - 1))
651539Srgrimes
661539Srgrimes/*
671539Srgrimes * The lower 8 bits of runetype[] contain the digit value of the rune.
681539Srgrimes */
691539Srgrimestypedef struct {
701539Srgrimes	rune_t		min;		/* First rune of the range */
711539Srgrimes	rune_t		max;		/* Last rune (inclusive) of the range */
721539Srgrimes	rune_t		map;		/* What first maps to in maps */
731539Srgrimes	unsigned long	*types;		/* Array of types in range */
741539Srgrimes} _RuneEntry;
751539Srgrimes
761539Srgrimestypedef struct {
771539Srgrimes	int		nranges;	/* Number of ranges stored */
781539Srgrimes	_RuneEntry	*ranges;	/* Pointer to the ranges */
791539Srgrimes} _RuneRange;
801539Srgrimes
811539Srgrimestypedef struct {
821539Srgrimes	char		magic[8];	/* Magic saying what version we are */
831539Srgrimes	char		encoding[32];	/* ASCII name of this encoding */
841539Srgrimes
8593189Sbde	rune_t		(*sgetrune)(const char *, size_t, char const **);
8693189Sbde	int		(*sputrune)(rune_t, char *, size_t, char **);
871539Srgrimes	rune_t		invalid_rune;
881539Srgrimes
891539Srgrimes	unsigned long	runetype[_CACHED_RUNES];
901539Srgrimes	rune_t		maplower[_CACHED_RUNES];
911539Srgrimes	rune_t		mapupper[_CACHED_RUNES];
921539Srgrimes
931539Srgrimes	/*
941539Srgrimes	 * The following are to deal with Runes larger than _CACHED_RUNES - 1.
951539Srgrimes	 * Their data is actually contiguous with this structure so as to make
961539Srgrimes	 * it easier to read/write from/to disk.
971539Srgrimes	 */
981539Srgrimes	_RuneRange	runetype_ext;
991539Srgrimes	_RuneRange	maplower_ext;
1001539Srgrimes	_RuneRange	mapupper_ext;
1011539Srgrimes
1021539Srgrimes	void		*variable;	/* Data which depends on the encoding */
1031539Srgrimes	int		variable_len;	/* how long that data is */
1041539Srgrimes} _RuneLocale;
1051539Srgrimes
1061539Srgrimes#define	_RUNE_MAGIC_1	"RuneMagi"	/* Indicates version 0 of RuneLocale */
1071539Srgrimes
1081539Srgrimesextern _RuneLocale _DefaultRuneLocale;
1091539Srgrimesextern _RuneLocale *_CurrentRuneLocale;
1101539Srgrimes
1111539Srgrimes#endif	/* !_RUNETYPE_H_ */
112