1/*-
2 * Copyright (c) 1995 Alex Tatmanjants <alex@elvisti.kiev.ua>
3 *		at Electronni Visti IA, Kiev, Ukraine.
4 *			All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 * $FreeBSD: src/lib/libc/locale/collate.h,v 1.14 2002/08/30 20:26:02 ache Exp $
28 */
29
30#ifndef _COLLATE_H_
31#define	_COLLATE_H_
32
33#include <sys/cdefs.h>
34#ifndef __LIBC__
35#include <sys/types.h>
36#endif /* !__LIBC__ */
37#include <limits.h>
38
39#define STR_LEN 10
40#define TABLE_SIZE 100
41#define COLLATE_VERSION    "1.0\n"
42#define COLLATE_VERSION1_1 "1.1\n"
43#define COLLATE_VERSION1_1A "1.1A\n"
44/* see discussion in string/FreeBSD/strxfrm for this value */
45#define COLLATE_MAX_PRIORITY ((1 << 24) - 1)
46
47#define DIRECTIVE_UNDEF 0x00
48#define DIRECTIVE_FORWARD 0x01
49#define DIRECTIVE_BACKWARD 0x02
50#define DIRECTIVE_POSITION 0x04
51
52#define DIRECTIVE_DIRECTION_MASK (DIRECTIVE_FORWARD | DIRECTIVE_BACKWARD)
53
54#define COLLATE_SUBST_DUP 0x0001
55
56#define IGNORE_EQUIV_CLASS 1
57
58struct __collate_st_info {
59	__uint8_t directive[COLL_WEIGHTS_MAX];
60	__uint8_t flags;
61#if __DARWIN_BYTE_ORDER == __DARWIN_LITTLE_ENDIAN
62	__uint8_t directive_count:4;
63	__uint8_t chain_max_len:4;
64#else
65	__uint8_t chain_max_len:4;
66	__uint8_t directive_count:4;
67#endif
68	__int32_t undef_pri[COLL_WEIGHTS_MAX];
69	__int32_t subst_count[COLL_WEIGHTS_MAX];
70	__int32_t chain_count;
71	__int32_t large_pri_count;
72};
73
74struct __collate_st_char_pri {
75	__int32_t pri[COLL_WEIGHTS_MAX];
76};
77struct __collate_st_chain_pri {
78	__darwin_wchar_t str[STR_LEN];
79	__int32_t pri[COLL_WEIGHTS_MAX];
80};
81struct __collate_st_large_char_pri {
82	__int32_t val;
83	struct __collate_st_char_pri pri;
84};
85struct __collate_st_subst {
86	__int32_t val;
87	__darwin_wchar_t str[STR_LEN];
88};
89
90#ifndef __LIBC__
91extern int __collate_load_error;
92extern int __collate_substitute_nontrivial;
93#define __collate_char_pri_table (*__collate_char_pri_table_ptr)
94extern struct __collate_st_char_pri __collate_char_pri_table[UCHAR_MAX + 1];
95extern struct __collate_st_chain_pri *__collate_chain_pri_table;
96extern __int32_t *__collate_chain_equiv_table;
97extern struct __collate_st_info __collate_info;
98#endif /* !__LIBC__ */
99
100__BEGIN_DECLS
101#ifdef __LIBC__
102__darwin_wchar_t	*__collate_mbstowcs(const char *, locale_t);
103__darwin_wchar_t	*__collate_wcsdup(const __darwin_wchar_t *);
104__darwin_wchar_t	*__collate_substitute(const __darwin_wchar_t *, int, locale_t);
105int	__collate_load_tables(const char *, locale_t);
106void	__collate_lookup_l(const __darwin_wchar_t *, int *, int *, int *, locale_t);
107void	__collate_lookup_which(const __darwin_wchar_t *, int *, int *, int, locale_t);
108void	__collate_xfrm(const __darwin_wchar_t *, __darwin_wchar_t **, locale_t);
109int	__collate_range_cmp(__darwin_wchar_t, __darwin_wchar_t, locale_t);
110size_t	__collate_collating_symbol(__darwin_wchar_t *, size_t, const char *, size_t, __darwin_mbstate_t *, locale_t);
111int	__collate_equiv_class(const char *, size_t, __darwin_mbstate_t *, locale_t);
112size_t	__collate_equiv_match(int, __darwin_wchar_t *, size_t, __darwin_wchar_t, const char *, size_t, __darwin_mbstate_t *, size_t *, locale_t);
113#else /* !__LIBC__ */
114void	__collate_lookup(const unsigned char *, int *, int *, int *);
115#endif /* __LIBC__ */
116#ifdef COLLATE_DEBUG
117void	__collate_print_tables(void);
118#endif
119__END_DECLS
120
121#endif /* !_COLLATE_H_ */
122