runetype.h revision 93032
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 93032 2002-03-23 17:24:55Z imp $
381539Srgrimes */
391539Srgrimes
401539Srgrimes#ifndef	_RUNETYPE_H_
411539Srgrimes#define	_RUNETYPE_H_
421539Srgrimes
4315483Sbde#include <sys/cdefs.h>
441539Srgrimes#include <machine/ansi.h>
451539Srgrimes
4615483Sbde#ifdef	_BSD_RUNE_T_
4715483Sbdetypedef	_BSD_RUNE_T_	rune_t;
4815483Sbde#undef	_BSD_RUNE_T_
491539Srgrimes#endif
501539Srgrimes
5115287Sache#ifdef	_BSD_SIZE_T_
5215287Sachetypedef	_BSD_SIZE_T_	size_t;
5315287Sache#undef	_BSD_SIZE_T_
5415287Sache#endif
5515287Sache
5615483Sbde#ifdef	_BSD_WCHAR_T_
5715483Sbdetypedef	_BSD_WCHAR_T_	wchar_t;
5815483Sbde#undef	_BSD_WCHAR_T_
5915483Sbde#endif
6015483Sbde
611539Srgrimes#define	_CACHED_RUNES	(1 <<8 )	/* Must be a power of 2 */
621539Srgrimes#define	_CRMASK		(~(_CACHED_RUNES - 1))
631539Srgrimes
641539Srgrimes/*
651539Srgrimes * The lower 8 bits of runetype[] contain the digit value of the rune.
661539Srgrimes */
671539Srgrimestypedef struct {
681539Srgrimes	rune_t		min;		/* First rune of the range */
691539Srgrimes	rune_t		max;		/* Last rune (inclusive) of the range */
701539Srgrimes	rune_t		map;		/* What first maps to in maps */
711539Srgrimes	unsigned long	*types;		/* Array of types in range */
721539Srgrimes} _RuneEntry;
731539Srgrimes
741539Srgrimestypedef struct {
751539Srgrimes	int		nranges;	/* Number of ranges stored */
761539Srgrimes	_RuneEntry	*ranges;	/* Pointer to the ranges */
771539Srgrimes} _RuneRange;
781539Srgrimes
791539Srgrimestypedef struct {
801539Srgrimes	char		magic[8];	/* Magic saying what version we are */
811539Srgrimes	char		encoding[32];	/* ASCII name of this encoding */
821539Srgrimes
831539Srgrimes	rune_t		(*sgetrune)
8493032Simp(const char *, size_t, char const **);
851539Srgrimes	int		(*sputrune)
8693032Simp(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