1*36dcc4a4SLionel Sambuc /* $NetBSD: libintl_local.h,v 1.12 2007/09/25 08:22:44 junyoung Exp $ */ 2*36dcc4a4SLionel Sambuc 3*36dcc4a4SLionel Sambuc /*- 4*36dcc4a4SLionel Sambuc * Copyright (c) 2000, 2001 Citrus Project, 5*36dcc4a4SLionel Sambuc * All rights reserved. 6*36dcc4a4SLionel Sambuc * 7*36dcc4a4SLionel Sambuc * Redistribution and use in source and binary forms, with or without 8*36dcc4a4SLionel Sambuc * modification, are permitted provided that the following conditions 9*36dcc4a4SLionel Sambuc * are met: 10*36dcc4a4SLionel Sambuc * 1. Redistributions of source code must retain the above copyright 11*36dcc4a4SLionel Sambuc * notice, this list of conditions and the following disclaimer. 12*36dcc4a4SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright 13*36dcc4a4SLionel Sambuc * notice, this list of conditions and the following disclaimer in the 14*36dcc4a4SLionel Sambuc * documentation and/or other materials provided with the distribution. 15*36dcc4a4SLionel Sambuc * 16*36dcc4a4SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17*36dcc4a4SLionel Sambuc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18*36dcc4a4SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19*36dcc4a4SLionel Sambuc * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20*36dcc4a4SLionel Sambuc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21*36dcc4a4SLionel Sambuc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22*36dcc4a4SLionel Sambuc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23*36dcc4a4SLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24*36dcc4a4SLionel Sambuc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25*36dcc4a4SLionel Sambuc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26*36dcc4a4SLionel Sambuc * SUCH DAMAGE. 27*36dcc4a4SLionel Sambuc * 28*36dcc4a4SLionel Sambuc * $Citrus: xpg4dl/FreeBSD/lib/libintl/libintl_local.h,v 1.13 2001/09/27 15:18:45 yamt Exp $ 29*36dcc4a4SLionel Sambuc */ 30*36dcc4a4SLionel Sambuc 31*36dcc4a4SLionel Sambuc #define MO_MAGIC 0x950412de 32*36dcc4a4SLionel Sambuc #define MO_MAGIC_SWAPPED 0xde120495 33*36dcc4a4SLionel Sambuc #define MO_GET_REV_MAJOR(r) (((r) >> 16) & 0xFFFF) 34*36dcc4a4SLionel Sambuc #define MO_GET_REV_MINOR(r) ((r) & 0xFFFF) 35*36dcc4a4SLionel Sambuc #define MO_MAKE_REV(maj, min) (((maj) << 16) | (min)) 36*36dcc4a4SLionel Sambuc 37*36dcc4a4SLionel Sambuc #define GETTEXT_MMAP_MAX (1024 * 1024) /*XXX*/ 38*36dcc4a4SLionel Sambuc 39*36dcc4a4SLionel Sambuc #define DEFAULT_DOMAINNAME "messages" 40*36dcc4a4SLionel Sambuc 41*36dcc4a4SLionel Sambuc /* *.mo file format */ 42*36dcc4a4SLionel Sambuc struct mo { 43*36dcc4a4SLionel Sambuc uint32_t mo_magic; /* determines endian */ 44*36dcc4a4SLionel Sambuc uint32_t mo_revision; /* file format revision: 0 */ 45*36dcc4a4SLionel Sambuc uint32_t mo_nstring; /* N: number of strings */ 46*36dcc4a4SLionel Sambuc uint32_t mo_otable; /* O: original text table offset */ 47*36dcc4a4SLionel Sambuc uint32_t mo_ttable; /* T: translated text table offset */ 48*36dcc4a4SLionel Sambuc uint32_t mo_hsize; /* S: size of hashing table */ 49*36dcc4a4SLionel Sambuc uint32_t mo_hoffset; /* H: offset of hashing table */ 50*36dcc4a4SLionel Sambuc /* rev 0.1 / 1.1 */ 51*36dcc4a4SLionel Sambuc /* system dependent string support */ 52*36dcc4a4SLionel Sambuc uint32_t mo_sysdep_nsegs; /* number of sysdep segments */ 53*36dcc4a4SLionel Sambuc uint32_t mo_sysdep_segoff; /* offset of sysdep segment table */ 54*36dcc4a4SLionel Sambuc uint32_t mo_sysdep_nstring; /* number of strings */ 55*36dcc4a4SLionel Sambuc uint32_t mo_sysdep_otable; /* offset of original text table */ 56*36dcc4a4SLionel Sambuc uint32_t mo_sysdep_ttable; /* offset of translated text table */ 57*36dcc4a4SLionel Sambuc } __packed; 58*36dcc4a4SLionel Sambuc 59*36dcc4a4SLionel Sambuc struct moentry { 60*36dcc4a4SLionel Sambuc uint32_t len; /* strlen(str), so region will be len + 1 */ 61*36dcc4a4SLionel Sambuc uint32_t off; /* offset of \0-terminated string */ 62*36dcc4a4SLionel Sambuc } __packed; 63*36dcc4a4SLionel Sambuc 64*36dcc4a4SLionel Sambuc struct mosysdepsegentry { 65*36dcc4a4SLionel Sambuc uint32_t len; /* length of this part */ 66*36dcc4a4SLionel Sambuc uint32_t ref; /* reference number of the sysdep string, 67*36dcc4a4SLionel Sambuc * concatenated just after this segment. 68*36dcc4a4SLionel Sambuc */ 69*36dcc4a4SLionel Sambuc } __packed; 70*36dcc4a4SLionel Sambuc #define MO_LASTSEG (0xFFFFFFFF) 71*36dcc4a4SLionel Sambuc 72*36dcc4a4SLionel Sambuc struct mosysdepstr { 73*36dcc4a4SLionel Sambuc uint32_t off; /* offset of seed text */ 74*36dcc4a4SLionel Sambuc struct mosysdepsegentry segs[1]; /* text segments */ 75*36dcc4a4SLionel Sambuc } __packed; 76*36dcc4a4SLionel Sambuc 77*36dcc4a4SLionel Sambuc /* libintl internal data format */ 78*36dcc4a4SLionel Sambuc struct moentry_h { 79*36dcc4a4SLionel Sambuc size_t len; /* strlen(str), so region will be len + 1 */ 80*36dcc4a4SLionel Sambuc char *off; /* offset of \0-terminated string */ 81*36dcc4a4SLionel Sambuc }; 82*36dcc4a4SLionel Sambuc 83*36dcc4a4SLionel Sambuc struct mosysdepsegs_h { 84*36dcc4a4SLionel Sambuc const char *str; 85*36dcc4a4SLionel Sambuc size_t len; 86*36dcc4a4SLionel Sambuc }; 87*36dcc4a4SLionel Sambuc 88*36dcc4a4SLionel Sambuc struct mosysdepsegentry_h { 89*36dcc4a4SLionel Sambuc uint32_t len; 90*36dcc4a4SLionel Sambuc uint32_t ref; 91*36dcc4a4SLionel Sambuc }; 92*36dcc4a4SLionel Sambuc 93*36dcc4a4SLionel Sambuc struct mosysdepstr_h { 94*36dcc4a4SLionel Sambuc const char *off; /* offset of the base string */ 95*36dcc4a4SLionel Sambuc char *expanded; /* expanded string */ 96*36dcc4a4SLionel Sambuc size_t expanded_len; /* length of expanded string */ 97*36dcc4a4SLionel Sambuc struct mosysdepsegentry_h segs[1]; /* text segments */ 98*36dcc4a4SLionel Sambuc }; 99*36dcc4a4SLionel Sambuc 100*36dcc4a4SLionel Sambuc struct gettext_plural; 101*36dcc4a4SLionel Sambuc struct mo_h { 102*36dcc4a4SLionel Sambuc uint32_t mo_magic; /* determines endian */ 103*36dcc4a4SLionel Sambuc uint32_t mo_revision; /* file format revision: 0 */ 104*36dcc4a4SLionel Sambuc uint32_t mo_nstring; /* N: number of strings */ 105*36dcc4a4SLionel Sambuc struct moentry_h *mo_otable; /* O: original text table offset */ 106*36dcc4a4SLionel Sambuc struct moentry_h *mo_ttable; /* T: translated text table offset */ 107*36dcc4a4SLionel Sambuc const char *mo_header; 108*36dcc4a4SLionel Sambuc struct gettext_plural *mo_plural; 109*36dcc4a4SLionel Sambuc unsigned long mo_nplurals; 110*36dcc4a4SLionel Sambuc char *mo_charset; 111*36dcc4a4SLionel Sambuc uint32_t mo_hsize; /* S: size of hashing table */ 112*36dcc4a4SLionel Sambuc uint32_t *mo_htable; /* H: hashing table */ 113*36dcc4a4SLionel Sambuc #define MO_HASH_SYSDEP_MASK 0x80000000 /* means sysdep entry */ 114*36dcc4a4SLionel Sambuc 115*36dcc4a4SLionel Sambuc uint32_t mo_flags; 116*36dcc4a4SLionel Sambuc #define MO_F_SYSDEP 0x00000001 /* enable sysdep string support */ 117*36dcc4a4SLionel Sambuc 118*36dcc4a4SLionel Sambuc /* system dependent string support */ 119*36dcc4a4SLionel Sambuc uint32_t mo_sysdep_nsegs; /* number of sysdep segments */ 120*36dcc4a4SLionel Sambuc uint32_t mo_sysdep_nstring; /* number of sysdep strings */ 121*36dcc4a4SLionel Sambuc struct mosysdepsegs_h *mo_sysdep_segs; /* sysdep segment table */ 122*36dcc4a4SLionel Sambuc struct mosysdepstr_h **mo_sysdep_otable; /* original text */ 123*36dcc4a4SLionel Sambuc struct mosysdepstr_h **mo_sysdep_ttable; /* translated text */ 124*36dcc4a4SLionel Sambuc }; 125*36dcc4a4SLionel Sambuc 126*36dcc4a4SLionel Sambuc 127*36dcc4a4SLionel Sambuc struct mohandle { 128*36dcc4a4SLionel Sambuc void *addr; /* mmap'ed region */ 129*36dcc4a4SLionel Sambuc size_t len; 130*36dcc4a4SLionel Sambuc struct mo_h mo; /* endian-flipped mo file header */ 131*36dcc4a4SLionel Sambuc }; 132*36dcc4a4SLionel Sambuc 133*36dcc4a4SLionel Sambuc struct domainbinding { 134*36dcc4a4SLionel Sambuc struct domainbinding *next; 135*36dcc4a4SLionel Sambuc char domainname[PATH_MAX]; 136*36dcc4a4SLionel Sambuc char path[PATH_MAX]; 137*36dcc4a4SLionel Sambuc char *codeset; 138*36dcc4a4SLionel Sambuc struct mohandle mohandle; 139*36dcc4a4SLionel Sambuc }; 140*36dcc4a4SLionel Sambuc 141*36dcc4a4SLionel Sambuc extern struct domainbinding *__bindings; 142*36dcc4a4SLionel Sambuc extern char __current_domainname[PATH_MAX]; 143*36dcc4a4SLionel Sambuc 144*36dcc4a4SLionel Sambuc __BEGIN_DECLS 145*36dcc4a4SLionel Sambuc const char *__gettext_iconv(const char *, struct domainbinding *); 146*36dcc4a4SLionel Sambuc uint32_t __intl_string_hash(const char *); 147*36dcc4a4SLionel Sambuc const char *__intl_sysdep_get_string_by_tag(const char *, size_t *); 148*36dcc4a4SLionel Sambuc __END_DECLS 149