xref: /illumos-gate/usr/src/lib/libc/port/locale/collatefile.h (revision 4c28a617e3922d92a58e813a5b955eb526b9c386)
1 /*
2  * Copyright 2015 Nexenta Systmes, Inc.  All rights reserved.
3  * Copyright 2013 Garrett D'Amore <garrett@damore.org>
4  * Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
5  *		at Electronni Visti IA, Kiev, Ukraine.
6  *			All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29 
30 #ifndef _COLLATEFILE_H_
31 #define	_COLLATEFILE_H_
32 
33 /*
34  * This file defines the format of collation data files.
35  * These are the files loaded to support LC_COLLATE category
36  * locale data.  Please note that this must define the file
37  * format in a way that allows localedef to build such files
38  * without assuming that the build system has all the same
39  * locale.h defines and structures, which means this should
40  * remain independent of things like limits.h values.
41  */
42 
43 #include <sys/types.h>
44 
45 /* NB: libc build ensure this is == COLL_WEIGHTS_MAX (from limits.h) */
46 #define	COLLATE_WEIGHTS_MAX	10
47 
48 #define	COLLATE_STR_LEN		24		/* should be 64-bit multiple */
49 #define	COLLATE_VERSION		"IllumosCollate2\n"
50 
51 #define	COLLATE_MAX_PRIORITY	(0x7fffffff)	/* max signed value */
52 #define	COLLATE_SUBST_PRIORITY	(0x40000000)	/* bit indicates subst table */
53 
54 #define	DIRECTIVE_UNDEF		0x00
55 #define	DIRECTIVE_FORWARD	0x01
56 #define	DIRECTIVE_BACKWARD	0x02
57 #define	DIRECTIVE_POSITION	0x04
58 #define	DIRECTIVE_UNDEFINED	0x08	/* special last weight for UNDEFINED */
59 
60 #define	DIRECTIVE_DIRECTION_MASK (DIRECTIVE_FORWARD | DIRECTIVE_BACKWARD)
61 
62 /*
63  * The collate file format is as follows:
64  *
65  * char		version[COLLATE_STR_LEN];	// must be COLLATE_VERSION
66  * collate_info_t	info;			// see below, includes padding
67  * collate_char_pri_t	char_data[256];		// 8 bit char values
68  * collate_subst_t	subst[*];		// 0 or more substitutions
69  * collate_chain_pri_t	chains[*];		// 0 or more chains
70  * collate_large_pri_t	large[*];		// extended char priorities
71  *
72  * Note that all structures must be 32-bit aligned, as each structure
73  * contains 32-bit member fields.  The entire file is mmap'd, so its
74  * critical that alignment be observed.  It is not generally safe to
75  * use any 64-bit values in the structures.
76  */
77 
78 typedef struct collate_info {
79 	uint8_t directive_count;
80 	uint8_t directive[COLLATE_WEIGHTS_MAX];
81 	int32_t pri_count[COLLATE_WEIGHTS_MAX];
82 	int32_t flags;
83 	int32_t chain_count;
84 	int32_t large_count;
85 	int32_t subst_count[COLLATE_WEIGHTS_MAX];
86 	int32_t undef_pri[COLLATE_WEIGHTS_MAX];
87 } collate_info_t;
88 
89 typedef struct collate_char {
90 	int32_t pri[COLLATE_WEIGHTS_MAX];
91 } collate_char_t;
92 
93 typedef struct collate_chain {
94 	wchar_t str[COLLATE_STR_LEN];
95 	int32_t pri[COLLATE_WEIGHTS_MAX];
96 } collate_chain_t;
97 
98 typedef struct collate_large {
99 	int32_t val;
100 	collate_char_t pri;
101 } collate_large_t;
102 
103 typedef struct collate_subst {
104 	int32_t key;
105 	int32_t pri[COLLATE_STR_LEN];
106 } collate_subst_t;
107 
108 #endif /* !_COLLATEFILE_H_ */
109