runetype.h revision 1539
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
371539Srgrimes */
381539Srgrimes
391539Srgrimes#ifndef	_RUNETYPE_H_
401539Srgrimes#define	_RUNETYPE_H_
411539Srgrimes
421539Srgrimes#include <machine/ansi.h>
431539Srgrimes#include <sys/cdefs.h>
441539Srgrimes
451539Srgrimes#ifdef  _BSD_WCHAR_T_
461539Srgrimestypedef _BSD_WCHAR_T_	rune_t;
471539Srgrimestypedef _BSD_WCHAR_T_	wchar_t;
481539Srgrimes#undef  _BSD_WCHAR_T_
491539Srgrimes#endif
501539Srgrimes
511539Srgrimes#define	_CACHED_RUNES	(1 <<8 )	/* Must be a power of 2 */
521539Srgrimes#define	_CRMASK		(~(_CACHED_RUNES - 1))
531539Srgrimes
541539Srgrimes/*
551539Srgrimes * The lower 8 bits of runetype[] contain the digit value of the rune.
561539Srgrimes */
571539Srgrimestypedef struct {
581539Srgrimes	rune_t		min;		/* First rune of the range */
591539Srgrimes	rune_t		max;		/* Last rune (inclusive) of the range */
601539Srgrimes	rune_t		map;		/* What first maps to in maps */
611539Srgrimes	unsigned long	*types;		/* Array of types in range */
621539Srgrimes} _RuneEntry;
631539Srgrimes
641539Srgrimestypedef struct {
651539Srgrimes	int		nranges;	/* Number of ranges stored */
661539Srgrimes	_RuneEntry	*ranges;	/* Pointer to the ranges */
671539Srgrimes} _RuneRange;
681539Srgrimes
691539Srgrimestypedef struct {
701539Srgrimes	char		magic[8];	/* Magic saying what version we are */
711539Srgrimes	char		encoding[32];	/* ASCII name of this encoding */
721539Srgrimes
731539Srgrimes	rune_t		(*sgetrune)
741539Srgrimes	    __P((const char *, unsigned int, char const **));
751539Srgrimes	int		(*sputrune)
761539Srgrimes	    __P((rune_t, char *, unsigned int, char **));
771539Srgrimes	rune_t		invalid_rune;
781539Srgrimes
791539Srgrimes	unsigned long	runetype[_CACHED_RUNES];
801539Srgrimes	rune_t		maplower[_CACHED_RUNES];
811539Srgrimes	rune_t		mapupper[_CACHED_RUNES];
821539Srgrimes
831539Srgrimes	/*
841539Srgrimes	 * The following are to deal with Runes larger than _CACHED_RUNES - 1.
851539Srgrimes	 * Their data is actually contiguous with this structure so as to make
861539Srgrimes	 * it easier to read/write from/to disk.
871539Srgrimes	 */
881539Srgrimes	_RuneRange	runetype_ext;
891539Srgrimes	_RuneRange	maplower_ext;
901539Srgrimes	_RuneRange	mapupper_ext;
911539Srgrimes
921539Srgrimes	void		*variable;	/* Data which depends on the encoding */
931539Srgrimes	int		variable_len;	/* how long that data is */
941539Srgrimes} _RuneLocale;
951539Srgrimes
961539Srgrimes#define	_RUNE_MAGIC_1	"RuneMagi"	/* Indicates version 0 of RuneLocale */
971539Srgrimes
981539Srgrimesextern _RuneLocale _DefaultRuneLocale;
991539Srgrimesextern _RuneLocale *_CurrentRuneLocale;
1001539Srgrimes
1011539Srgrimes#endif	/* !_RUNETYPE_H_ */
102