17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*f13ac639Smuffin * Common Development and Distribution License (the "License"). 6*f13ac639Smuffin * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21*f13ac639Smuffin 227c478bd9Sstevel@tonic-gate /* 23*f13ac639Smuffin * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _LIBC_PORT_I18N_GETTEXT_H 287c478bd9Sstevel@tonic-gate #define _LIBC_PORT_I18N_GETTEXT_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <sys/param.h> 337c478bd9Sstevel@tonic-gate #include <iconv.h> 347c478bd9Sstevel@tonic-gate #include <synch.h> 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #ifdef __cplusplus 377c478bd9Sstevel@tonic-gate extern "C" { 387c478bd9Sstevel@tonic-gate #endif 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* Type of MO file */ 41*f13ac639Smuffin #define T_MO_MASK 0x07 42*f13ac639Smuffin #define T_SUN_MO 0x01 43*f13ac639Smuffin #define T_GNU_MO 0x02 44*f13ac639Smuffin #define T_ILL_MO 0x04 45*f13ac639Smuffin 46*f13ac639Smuffin #define T_GNU_MASK 0x300 47*f13ac639Smuffin #define T_GNU_SWAPPED 0x100 48*f13ac639Smuffin #define T_GNU_REV1 0x200 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate #define TP_BINDING 0 517c478bd9Sstevel@tonic-gate #define TP_CODESET 1 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate /* Msg_g_node->flag */ 547c478bd9Sstevel@tonic-gate #define ST_CHK 0x1 /* header has been checked? */ 557c478bd9Sstevel@tonic-gate #define ST_SWP 0x2 /* reversed endian? */ 56*f13ac639Smuffin #define ST_REV1 0x4 /* Revision 1 */ 57*f13ac639Smuffin 58*f13ac639Smuffin /* 59*f13ac639Smuffin * msg_pack->status: 60*f13ac639Smuffin * interaction between handle_lang() and handle_mo() 61*f13ac639Smuffin */ 62*f13ac639Smuffin #define ST_GNU_MSG_FOUND 0x1 /* valid msg found in GNU MO */ 63*f13ac639Smuffin #define ST_GNU_MO_FOUND 0x2 /* GNU MO found */ 64*f13ac639Smuffin #define ST_SUN_MO_FOUND 0x4 /* Sun MO found */ 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate typedef struct domain_binding { 677c478bd9Sstevel@tonic-gate char *domain; /* domain name */ 687c478bd9Sstevel@tonic-gate char *binding; /* binding directory */ 697c478bd9Sstevel@tonic-gate char *codeset; /* codeset */ 707c478bd9Sstevel@tonic-gate struct domain_binding *next; 717c478bd9Sstevel@tonic-gate } Dbinding; 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate /* 747c478bd9Sstevel@tonic-gate * this structure is used for preserving nlspath templates before 757c478bd9Sstevel@tonic-gate * passing them to bindtextdomain(): 767c478bd9Sstevel@tonic-gate */ 777c478bd9Sstevel@tonic-gate typedef struct nlstmp { 787c478bd9Sstevel@tonic-gate char pathname[MAXPATHLEN]; /* the full pathname to file */ 79*f13ac639Smuffin size_t len; /* length of pathname */ 807c478bd9Sstevel@tonic-gate struct nlstmp *next; /* link to the next entry */ 817c478bd9Sstevel@tonic-gate } Nlstmp; 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate typedef struct { 847c478bd9Sstevel@tonic-gate struct msg_info *msg_file_info; /* information of msg file */ 857c478bd9Sstevel@tonic-gate struct msg_struct *msg_list; /* message list */ 867c478bd9Sstevel@tonic-gate char *msg_ids; /* actual message ids */ 877c478bd9Sstevel@tonic-gate char *msg_strs; /* actual message strs */ 887c478bd9Sstevel@tonic-gate } Msg_s_node; 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate typedef struct expr *plural_expr_t; 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate typedef struct { 93*f13ac639Smuffin unsigned int len; /* length of the expanded str of macro */ 94*f13ac639Smuffin const char *ptr; /* pointer to the expanded str of macro */ 95*f13ac639Smuffin } gnu_d_macro_t; 96*f13ac639Smuffin 97*f13ac639Smuffin typedef struct { 98*f13ac639Smuffin struct gnu_msg_info *msg_file_info; 99*f13ac639Smuffin struct gnu_msg_rev1_info *rev1_header; 100*f13ac639Smuffin size_t fsize; /* size of the GNU mo file */ 101*f13ac639Smuffin uint32_t flag; /* status */ 102*f13ac639Smuffin uint32_t num_of_str; /* number of static msgs */ 103*f13ac639Smuffin uint32_t num_of_d_str; /* number of dynamic msgs */ 104*f13ac639Smuffin uint32_t hash_size; /* hash table size */ 105*f13ac639Smuffin uint32_t *hash_table; /* hash table */ 106*f13ac639Smuffin struct gnu_msg_ent *msg_tbl[2]; /* msgid/str entries */ 107*f13ac639Smuffin struct gnu_msg_ent *d_msg[2]; /* dynamic msgid/str entries */ 108*f13ac639Smuffin char *mchunk; /* pointer to memory chunk of dynamic strs */ 1097c478bd9Sstevel@tonic-gate char *src_encoding; /* src encoding */ 1107c478bd9Sstevel@tonic-gate char *dst_encoding; /* dst encoding */ 111*f13ac639Smuffin unsigned int nplurals; /* number of plural forms */ 1127c478bd9Sstevel@tonic-gate plural_expr_t plural; /* plural expression */ 1137c478bd9Sstevel@tonic-gate iconv_t fd; /* iconv descriptor */ 114*f13ac639Smuffin uint32_t **conv_msgstr; /* code-converted msgstr */ 1157c478bd9Sstevel@tonic-gate } Msg_g_node; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate typedef struct msg_node { 118*f13ac639Smuffin uint32_t hashid; /* hashed value of the domain name */ 119*f13ac639Smuffin uint16_t type; /* T_SUN_MO, T_GNU_MO, or T_ILL_MO */ 120*f13ac639Smuffin uint16_t trusted; /* is this a trusted source? */ 1217c478bd9Sstevel@tonic-gate char *path; /* name of message catalog */ 1227c478bd9Sstevel@tonic-gate union { 1237c478bd9Sstevel@tonic-gate Msg_s_node *sunmsg; 1247c478bd9Sstevel@tonic-gate Msg_g_node *gnumsg; 1257c478bd9Sstevel@tonic-gate } msg; 1267c478bd9Sstevel@tonic-gate struct msg_node *next; /* link to the next */ 1277c478bd9Sstevel@tonic-gate } Msg_node; 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate typedef struct nls_node { 1307c478bd9Sstevel@tonic-gate char *domain; /* key: domain name */ 1317c478bd9Sstevel@tonic-gate char *locale; /* key: locale name */ 1327c478bd9Sstevel@tonic-gate char *nlspath; /* key: NLSPATH */ 1337c478bd9Sstevel@tonic-gate char *ppaths; /* value: expanded path */ 1347c478bd9Sstevel@tonic-gate struct nls_node *next; /* link to the next */ 1357c478bd9Sstevel@tonic-gate } Nls_node; 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate typedef struct { 1387c478bd9Sstevel@tonic-gate char *cur_domain; /* current domain */ 1397c478bd9Sstevel@tonic-gate Dbinding *dbind; /* domain binding */ 140*f13ac639Smuffin Msg_node *m_node; /* link to the Msg_node cache */ 141*f13ac639Smuffin Nls_node *n_node; /* link to the Nls_node cache */ 1427c478bd9Sstevel@tonic-gate Msg_node *c_m_node; /* link to the current Msg_node */ 1437c478bd9Sstevel@tonic-gate Nls_node *c_n_node; /* link to the current Nls_node */ 1447c478bd9Sstevel@tonic-gate } Gettext_t; 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate struct msg_pack { 1477c478bd9Sstevel@tonic-gate const char *msgid1; /* msgid1 argument */ 1487c478bd9Sstevel@tonic-gate const char *msgid2; /* msgid2 argument */ 1497c478bd9Sstevel@tonic-gate char *msgfile; /* msg catalog file to open */ 1507c478bd9Sstevel@tonic-gate char *domain; /* textdomain name */ 1517c478bd9Sstevel@tonic-gate char *binding; /* binding */ 1527c478bd9Sstevel@tonic-gate char *locale; /* locale */ 1537c478bd9Sstevel@tonic-gate char *language; /* LANGUAGE env */ 1547c478bd9Sstevel@tonic-gate caddr_t addr; /* mmap'ed address */ 1557c478bd9Sstevel@tonic-gate size_t fsz; /* file size */ 156*f13ac639Smuffin uint32_t hash_domain; /* hash ID of domain */ 157*f13ac639Smuffin uint32_t domain_len; /* length of domain */ 1587c478bd9Sstevel@tonic-gate unsigned int n; /* n argument */ 1597c478bd9Sstevel@tonic-gate int category; /* category argument */ 1607c478bd9Sstevel@tonic-gate int plural; /* plural or not */ 1617c478bd9Sstevel@tonic-gate int nlsp; /* nlsp */ 1627c478bd9Sstevel@tonic-gate int trusted; /* trusted msg catalog or not */ 163*f13ac639Smuffin int status; /* status */ 1647c478bd9Sstevel@tonic-gate }; 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate #define DEFAULT_DOMAIN "messages" 1677c478bd9Sstevel@tonic-gate #define DEFAULT_BINDING _DFLT_LOC_PATH 1687c478bd9Sstevel@tonic-gate #define MSGFILESUFFIX ".mo" 1697c478bd9Sstevel@tonic-gate #define MSGFILESUFFIXLEN (sizeof (MSGFILESUFFIX) - 1) 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate #define CURRENT_DOMAIN(gt) (gt)->cur_domain 1727c478bd9Sstevel@tonic-gate #define FIRSTBIND(gt) (gt)->dbind 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate #define DFLTMSG(result, msgid1, msgid2, n, plural) \ 1757c478bd9Sstevel@tonic-gate result = (plural ? \ 1767c478bd9Sstevel@tonic-gate ((n == 1) ? (char *)msgid1 : (char *)msgid2) : \ 1777c478bd9Sstevel@tonic-gate (char *)msgid1) 1787c478bd9Sstevel@tonic-gate 179*f13ac639Smuffin #define ROUND(m, s) if ((m) % (s)) (m) += ((s) - ((m) % (s))) 180*f13ac639Smuffin 1817c478bd9Sstevel@tonic-gate #define SWAP(p, ui32) \ 1827c478bd9Sstevel@tonic-gate (((p)->flag & ST_SWP) ? doswap32(ui32) : (ui32)) 1837c478bd9Sstevel@tonic-gate 184*f13ac639Smuffin #define HASH_TBL(p, ui32) \ 185*f13ac639Smuffin ((((p)->flag & (ST_REV1|ST_SWP)) == ST_SWP) ? \ 186*f13ac639Smuffin doswap32(ui32) : (ui32)) 187*f13ac639Smuffin 1887c478bd9Sstevel@tonic-gate extern const char *defaultbind; 1897c478bd9Sstevel@tonic-gate extern const char default_domain[]; 1907c478bd9Sstevel@tonic-gate extern Gettext_t *global_gt; 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate extern char *_textdomain_u(const char *, char *); 1937c478bd9Sstevel@tonic-gate extern char *_real_bindtextdomain_u(const char *, const char *, int); 1947c478bd9Sstevel@tonic-gate extern char *_real_gettext_u(const char *, const char *, 1957c478bd9Sstevel@tonic-gate const char *, unsigned long int, int, int); 196*f13ac639Smuffin extern char *handle_mo(struct msg_pack *); 1977c478bd9Sstevel@tonic-gate 198*f13ac639Smuffin extern int gnu_setmsg(Msg_node *, char *, size_t); 199*f13ac639Smuffin extern char *handle_lang(struct msg_pack *); 2007c478bd9Sstevel@tonic-gate extern char *mk_msgfile(struct msg_pack *); 201*f13ac639Smuffin extern Msg_node *check_cache(struct msg_pack *); 202*f13ac639Smuffin extern uint32_t get_hashid(const char *, uint32_t *); 203*f13ac639Smuffin extern uint32_t doswap32(uint32_t); 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate extern int plural_expr(plural_expr_t *, const char *); 2067c478bd9Sstevel@tonic-gate extern unsigned int plural_eval(plural_expr_t, unsigned int); 2077c478bd9Sstevel@tonic-gate 208*f13ac639Smuffin extern char *gnu_key_2_text(Msg_g_node *, const char *, struct msg_pack *); 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate extern char *get_codeset(const char *); 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate #ifdef GETTEXT_DEBUG 213*f13ac639Smuffin extern void gprintf(int, const char *, ...); 214*f13ac639Smuffin extern void printgt(Gettext_t *, int); 2157c478bd9Sstevel@tonic-gate extern void printmp(struct msg_pack *, int); 2167c478bd9Sstevel@tonic-gate extern void printsunmsg(Msg_s_node *, int); 2177c478bd9Sstevel@tonic-gate extern void printgnumsg(Msg_g_node *, int); 2187c478bd9Sstevel@tonic-gate extern void printexpr(plural_expr_t, int); 2197c478bd9Sstevel@tonic-gate extern void printmnp(Msg_node *, int); 2207c478bd9Sstevel@tonic-gate extern void printlist(void); 221*f13ac639Smuffin extern void print_rev1_info(Msg_g_node *); 2227c478bd9Sstevel@tonic-gate #endif 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2257c478bd9Sstevel@tonic-gate } 2267c478bd9Sstevel@tonic-gate #endif 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate #endif /* !_LIBC_PORT_I18N_GETTEXT_H */ 229