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