10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*6793Smuffin * Common Development and Distribution License (the "License"). 6*6793Smuffin * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21*6793Smuffin 220Sstevel@tonic-gate /* 23*6793Smuffin * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #ifndef _LIBC_PORT_I18N_GETTEXT_H 280Sstevel@tonic-gate #define _LIBC_PORT_I18N_GETTEXT_H 290Sstevel@tonic-gate 300Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 310Sstevel@tonic-gate 320Sstevel@tonic-gate #include <sys/param.h> 330Sstevel@tonic-gate #include <iconv.h> 340Sstevel@tonic-gate #include <synch.h> 350Sstevel@tonic-gate 360Sstevel@tonic-gate #ifdef __cplusplus 370Sstevel@tonic-gate extern "C" { 380Sstevel@tonic-gate #endif 390Sstevel@tonic-gate 400Sstevel@tonic-gate /* Type of MO file */ 41*6793Smuffin #define T_MO_MASK 0x07 42*6793Smuffin #define T_SUN_MO 0x01 43*6793Smuffin #define T_GNU_MO 0x02 44*6793Smuffin #define T_ILL_MO 0x04 45*6793Smuffin 46*6793Smuffin #define T_GNU_MASK 0x300 47*6793Smuffin #define T_GNU_SWAPPED 0x100 48*6793Smuffin #define T_GNU_REV1 0x200 490Sstevel@tonic-gate 500Sstevel@tonic-gate #define TP_BINDING 0 510Sstevel@tonic-gate #define TP_CODESET 1 520Sstevel@tonic-gate 530Sstevel@tonic-gate /* Msg_g_node->flag */ 540Sstevel@tonic-gate #define ST_CHK 0x1 /* header has been checked? */ 550Sstevel@tonic-gate #define ST_SWP 0x2 /* reversed endian? */ 56*6793Smuffin #define ST_REV1 0x4 /* Revision 1 */ 57*6793Smuffin 58*6793Smuffin /* 59*6793Smuffin * msg_pack->status: 60*6793Smuffin * interaction between handle_lang() and handle_mo() 61*6793Smuffin */ 62*6793Smuffin #define ST_GNU_MSG_FOUND 0x1 /* valid msg found in GNU MO */ 63*6793Smuffin #define ST_GNU_MO_FOUND 0x2 /* GNU MO found */ 64*6793Smuffin #define ST_SUN_MO_FOUND 0x4 /* Sun MO found */ 650Sstevel@tonic-gate 660Sstevel@tonic-gate typedef struct domain_binding { 670Sstevel@tonic-gate char *domain; /* domain name */ 680Sstevel@tonic-gate char *binding; /* binding directory */ 690Sstevel@tonic-gate char *codeset; /* codeset */ 700Sstevel@tonic-gate struct domain_binding *next; 710Sstevel@tonic-gate } Dbinding; 720Sstevel@tonic-gate 730Sstevel@tonic-gate /* 740Sstevel@tonic-gate * this structure is used for preserving nlspath templates before 750Sstevel@tonic-gate * passing them to bindtextdomain(): 760Sstevel@tonic-gate */ 770Sstevel@tonic-gate typedef struct nlstmp { 780Sstevel@tonic-gate char pathname[MAXPATHLEN]; /* the full pathname to file */ 79*6793Smuffin size_t len; /* length of pathname */ 800Sstevel@tonic-gate struct nlstmp *next; /* link to the next entry */ 810Sstevel@tonic-gate } Nlstmp; 820Sstevel@tonic-gate 830Sstevel@tonic-gate typedef struct { 840Sstevel@tonic-gate struct msg_info *msg_file_info; /* information of msg file */ 850Sstevel@tonic-gate struct msg_struct *msg_list; /* message list */ 860Sstevel@tonic-gate char *msg_ids; /* actual message ids */ 870Sstevel@tonic-gate char *msg_strs; /* actual message strs */ 880Sstevel@tonic-gate } Msg_s_node; 890Sstevel@tonic-gate 900Sstevel@tonic-gate typedef struct expr *plural_expr_t; 910Sstevel@tonic-gate 920Sstevel@tonic-gate typedef struct { 93*6793Smuffin unsigned int len; /* length of the expanded str of macro */ 94*6793Smuffin const char *ptr; /* pointer to the expanded str of macro */ 95*6793Smuffin } gnu_d_macro_t; 96*6793Smuffin 97*6793Smuffin typedef struct { 98*6793Smuffin struct gnu_msg_info *msg_file_info; 99*6793Smuffin struct gnu_msg_rev1_info *rev1_header; 100*6793Smuffin size_t fsize; /* size of the GNU mo file */ 101*6793Smuffin uint32_t flag; /* status */ 102*6793Smuffin uint32_t num_of_str; /* number of static msgs */ 103*6793Smuffin uint32_t num_of_d_str; /* number of dynamic msgs */ 104*6793Smuffin uint32_t hash_size; /* hash table size */ 105*6793Smuffin uint32_t *hash_table; /* hash table */ 106*6793Smuffin struct gnu_msg_ent *msg_tbl[2]; /* msgid/str entries */ 107*6793Smuffin struct gnu_msg_ent *d_msg[2]; /* dynamic msgid/str entries */ 108*6793Smuffin char *mchunk; /* pointer to memory chunk of dynamic strs */ 1090Sstevel@tonic-gate char *src_encoding; /* src encoding */ 1100Sstevel@tonic-gate char *dst_encoding; /* dst encoding */ 111*6793Smuffin unsigned int nplurals; /* number of plural forms */ 112*6793Smuffin plural_expr_t plural; /* plural expression */ 113*6793Smuffin iconv_t fd; /* iconv descriptor */ 114*6793Smuffin uint32_t **conv_msgstr; /* code-converted msgstr */ 1150Sstevel@tonic-gate } Msg_g_node; 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate typedef struct msg_node { 118*6793Smuffin uint32_t hashid; /* hashed value of the domain name */ 119*6793Smuffin uint16_t type; /* T_SUN_MO, T_GNU_MO, or T_ILL_MO */ 120*6793Smuffin uint16_t trusted; /* is this a trusted source? */ 121*6793Smuffin char *path; /* name of message catalog */ 1220Sstevel@tonic-gate union { 1230Sstevel@tonic-gate Msg_s_node *sunmsg; 1240Sstevel@tonic-gate Msg_g_node *gnumsg; 1250Sstevel@tonic-gate } msg; 1260Sstevel@tonic-gate struct msg_node *next; /* link to the next */ 1270Sstevel@tonic-gate } Msg_node; 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate typedef struct nls_node { 1300Sstevel@tonic-gate char *domain; /* key: domain name */ 1310Sstevel@tonic-gate char *locale; /* key: locale name */ 1320Sstevel@tonic-gate char *nlspath; /* key: NLSPATH */ 1330Sstevel@tonic-gate char *ppaths; /* value: expanded path */ 1340Sstevel@tonic-gate struct nls_node *next; /* link to the next */ 1350Sstevel@tonic-gate } Nls_node; 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate typedef struct { 1380Sstevel@tonic-gate char *cur_domain; /* current domain */ 1390Sstevel@tonic-gate Dbinding *dbind; /* domain binding */ 140*6793Smuffin Msg_node *m_node; /* link to the Msg_node cache */ 141*6793Smuffin Nls_node *n_node; /* link to the Nls_node cache */ 1420Sstevel@tonic-gate Msg_node *c_m_node; /* link to the current Msg_node */ 1430Sstevel@tonic-gate Nls_node *c_n_node; /* link to the current Nls_node */ 1440Sstevel@tonic-gate } Gettext_t; 1450Sstevel@tonic-gate 1460Sstevel@tonic-gate struct msg_pack { 1470Sstevel@tonic-gate const char *msgid1; /* msgid1 argument */ 1480Sstevel@tonic-gate const char *msgid2; /* msgid2 argument */ 1490Sstevel@tonic-gate char *msgfile; /* msg catalog file to open */ 1500Sstevel@tonic-gate char *domain; /* textdomain name */ 1510Sstevel@tonic-gate char *binding; /* binding */ 1520Sstevel@tonic-gate char *locale; /* locale */ 1530Sstevel@tonic-gate char *language; /* LANGUAGE env */ 1540Sstevel@tonic-gate caddr_t addr; /* mmap'ed address */ 1550Sstevel@tonic-gate size_t fsz; /* file size */ 156*6793Smuffin uint32_t hash_domain; /* hash ID of domain */ 157*6793Smuffin uint32_t domain_len; /* length of domain */ 1580Sstevel@tonic-gate unsigned int n; /* n argument */ 159*6793Smuffin int category; /* category argument */ 160*6793Smuffin int plural; /* plural or not */ 161*6793Smuffin int nlsp; /* nlsp */ 162*6793Smuffin int trusted; /* trusted msg catalog or not */ 163*6793Smuffin int status; /* status */ 1640Sstevel@tonic-gate }; 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate #define DEFAULT_DOMAIN "messages" 1670Sstevel@tonic-gate #define DEFAULT_BINDING _DFLT_LOC_PATH 1680Sstevel@tonic-gate #define MSGFILESUFFIX ".mo" 1690Sstevel@tonic-gate #define MSGFILESUFFIXLEN (sizeof (MSGFILESUFFIX) - 1) 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate #define CURRENT_DOMAIN(gt) (gt)->cur_domain 1720Sstevel@tonic-gate #define FIRSTBIND(gt) (gt)->dbind 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate #define DFLTMSG(result, msgid1, msgid2, n, plural) \ 1750Sstevel@tonic-gate result = (plural ? \ 1760Sstevel@tonic-gate ((n == 1) ? (char *)msgid1 : (char *)msgid2) : \ 1770Sstevel@tonic-gate (char *)msgid1) 1780Sstevel@tonic-gate 179*6793Smuffin #define ROUND(m, s) if ((m) % (s)) (m) += ((s) - ((m) % (s))) 180*6793Smuffin 1810Sstevel@tonic-gate #define SWAP(p, ui32) \ 1820Sstevel@tonic-gate (((p)->flag & ST_SWP) ? doswap32(ui32) : (ui32)) 1830Sstevel@tonic-gate 184*6793Smuffin #define HASH_TBL(p, ui32) \ 185*6793Smuffin ((((p)->flag & (ST_REV1|ST_SWP)) == ST_SWP) ? \ 186*6793Smuffin doswap32(ui32) : (ui32)) 187*6793Smuffin 1880Sstevel@tonic-gate extern const char *defaultbind; 1890Sstevel@tonic-gate extern const char default_domain[]; 1900Sstevel@tonic-gate extern Gettext_t *global_gt; 1910Sstevel@tonic-gate 192*6793Smuffin extern char *_textdomain_u(const char *, char *); 193*6793Smuffin extern char *_real_bindtextdomain_u(const char *, const char *, int); 194*6793Smuffin extern char *_real_gettext_u(const char *, const char *, 195*6793Smuffin const char *, unsigned long int, int, int); 196*6793Smuffin extern char *handle_mo(struct msg_pack *); 1970Sstevel@tonic-gate 198*6793Smuffin extern int gnu_setmsg(Msg_node *, char *, size_t); 199*6793Smuffin extern char *handle_lang(struct msg_pack *); 200*6793Smuffin extern char *mk_msgfile(struct msg_pack *); 201*6793Smuffin extern Msg_node *check_cache(struct msg_pack *); 202*6793Smuffin extern uint32_t get_hashid(const char *, uint32_t *); 203*6793Smuffin extern uint32_t doswap32(uint32_t); 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate extern int plural_expr(plural_expr_t *, const char *); 2060Sstevel@tonic-gate extern unsigned int plural_eval(plural_expr_t, unsigned int); 2070Sstevel@tonic-gate 208*6793Smuffin extern char *gnu_key_2_text(Msg_g_node *, const char *, struct msg_pack *); 2090Sstevel@tonic-gate 210*6793Smuffin extern char *get_codeset(const char *); 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate #ifdef GETTEXT_DEBUG 213*6793Smuffin extern void gprintf(int, const char *, ...); 214*6793Smuffin extern void printgt(Gettext_t *, int); 2150Sstevel@tonic-gate extern void printmp(struct msg_pack *, int); 2160Sstevel@tonic-gate extern void printsunmsg(Msg_s_node *, int); 2170Sstevel@tonic-gate extern void printgnumsg(Msg_g_node *, int); 2180Sstevel@tonic-gate extern void printexpr(plural_expr_t, int); 2190Sstevel@tonic-gate extern void printmnp(Msg_node *, int); 2200Sstevel@tonic-gate extern void printlist(void); 221*6793Smuffin extern void print_rev1_info(Msg_g_node *); 2220Sstevel@tonic-gate #endif 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate #ifdef __cplusplus 2250Sstevel@tonic-gate } 2260Sstevel@tonic-gate #endif 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate #endif /* !_LIBC_PORT_I18N_GETTEXT_H */ 229