4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _LIBC_PORT_I18N_GETTEXT_H
28 #define _LIBC_PORT_I18N_GETTEXT_H
30 #include <sys/param.h>
39 #define T_MO_MASK 0x07
44 #define T_GNU_MASK 0x300
45 #define T_GNU_SWAPPED 0x100
46 #define T_GNU_REV1 0x200
51 /* Msg_g_node->flag */
52 #define ST_CHK 0x1 /* header has been checked? */
53 #define ST_SWP 0x2 /* reversed endian? */
54 #define ST_REV1 0x4 /* Revision 1 */
58 * interaction between handle_lang() and handle_mo()
60 #define ST_GNU_MSG_FOUND 0x1 /* valid msg found in GNU MO */
61 #define ST_GNU_MO_FOUND 0x2 /* GNU MO found */
62 #define ST_SUN_MO_FOUND 0x4 /* Sun MO found */
64 typedef struct domain_binding
{
65 char *domain
; /* domain name */
66 char *binding
; /* binding directory */
67 char *codeset
; /* codeset */
68 struct domain_binding
*next
;
72 * this structure is used for preserving nlspath templates before
73 * passing them to bindtextdomain():
75 typedef struct nlstmp
{
76 char pathname
[MAXPATHLEN
]; /* the full pathname to file */
77 size_t len
; /* length of pathname */
78 struct nlstmp
*next
; /* link to the next entry */
82 struct msg_info
*msg_file_info
; /* information of msg file */
83 struct msg_struct
*msg_list
; /* message list */
84 char *msg_ids
; /* actual message ids */
85 char *msg_strs
; /* actual message strs */
88 typedef struct expr
*plural_expr_t
;
91 unsigned int len
; /* length of the expanded str of macro */
92 const char *ptr
; /* pointer to the expanded str of macro */
96 struct gnu_msg_info
*msg_file_info
;
97 struct gnu_msg_rev1_info
*rev1_header
;
98 size_t fsize
; /* size of the GNU mo file */
99 uint32_t flag
; /* status */
100 uint32_t num_of_str
; /* number of static msgs */
101 uint32_t num_of_d_str
; /* number of dynamic msgs */
102 uint32_t hash_size
; /* hash table size */
103 uint32_t *hash_table
; /* hash table */
104 struct gnu_msg_ent
*msg_tbl
[2]; /* msgid/str entries */
105 struct gnu_msg_ent
*d_msg
[2]; /* dynamic msgid/str entries */
106 char *mchunk
; /* pointer to memory chunk of dynamic strs */
107 char *src_encoding
; /* src encoding */
108 char *dst_encoding
; /* dst encoding */
109 unsigned int nplurals
; /* number of plural forms */
110 plural_expr_t plural
; /* plural expression */
111 iconv_t fd
; /* iconv descriptor */
112 uint32_t **conv_msgstr
; /* code-converted msgstr */
115 typedef struct msg_node
{
116 uint32_t hashid
; /* hashed value of the domain name */
117 uint16_t type
; /* T_SUN_MO, T_GNU_MO, or T_ILL_MO */
118 uint16_t trusted
; /* is this a trusted source? */
119 char *path
; /* name of message catalog */
124 struct msg_node
*next
; /* link to the next */
127 typedef struct nls_node
{
128 char *domain
; /* key: domain name */
129 char *locale
; /* key: locale name */
130 char *nlspath
; /* key: NLSPATH */
131 char *ppaths
; /* value: expanded path */
132 struct nls_node
*next
; /* link to the next */
136 char *cur_domain
; /* current domain */
137 Dbinding
*dbind
; /* domain binding */
138 Msg_node
*m_node
; /* link to the Msg_node cache */
139 Nls_node
*n_node
; /* link to the Nls_node cache */
140 Msg_node
*c_m_node
; /* link to the current Msg_node */
141 Nls_node
*c_n_node
; /* link to the current Nls_node */
145 const char *msgid1
; /* msgid1 argument */
146 const char *msgid2
; /* msgid2 argument */
147 char *msgfile
; /* msg catalog file to open */
148 char *domain
; /* textdomain name */
149 char *binding
; /* binding */
150 const char *locale
; /* locale */
151 char *language
; /* LANGUAGE env */
152 caddr_t addr
; /* mmap'ed address */
153 size_t fsz
; /* file size */
154 uint32_t hash_domain
; /* hash ID of domain */
155 uint32_t domain_len
; /* length of domain */
156 unsigned int n
; /* n argument */
157 int category
; /* category argument */
158 int plural
; /* plural or not */
160 int trusted
; /* trusted msg catalog or not */
161 int status
; /* status */
164 #define DEFAULT_DOMAIN "messages"
165 #define DEFAULT_BINDING _DFLT_LOC_PATH
166 #define MSGFILESUFFIX ".mo"
167 #define MSGFILESUFFIXLEN (sizeof (MSGFILESUFFIX) - 1)
169 #define CURRENT_DOMAIN(gt) (gt)->cur_domain
170 #define FIRSTBIND(gt) (gt)->dbind
172 #define DFLTMSG(result, msgid1, msgid2, n, plural) \
174 ((n == 1) ? (char *)msgid1 : (char *)msgid2) : \
177 #define ROUND(m, s) if ((m) % (s)) (m) += ((s) - ((m) % (s)))
179 #define SWAP(p, ui32) \
180 (((p)->flag & ST_SWP) ? doswap32(ui32) : (ui32))
182 #define HASH_TBL(p, ui32) \
183 ((((p)->flag & (ST_REV1|ST_SWP)) == ST_SWP) ? \
184 doswap32(ui32) : (ui32))
186 extern const char *defaultbind
;
187 extern const char default_domain
[];
188 extern Gettext_t
*global_gt
;
190 extern char *_textdomain_u(const char *, char *);
191 extern char *_real_bindtextdomain_u(const char *, const char *, int);
192 extern char *_real_gettext_u(const char *, const char *,
193 const char *, unsigned long int, int, int, locale_t
);
194 extern char *handle_mo(struct msg_pack
*);
196 extern int gnu_setmsg(Msg_node
*, char *, size_t);
197 extern char *handle_lang(struct msg_pack
*);
198 extern char *mk_msgfile(struct msg_pack
*);
199 extern Msg_node
*check_cache(struct msg_pack
*);
200 extern uint32_t get_hashid(const char *, uint32_t *);
201 extern uint32_t doswap32(uint32_t);
203 extern int plural_expr(plural_expr_t
*, const char *);
204 extern unsigned int plural_eval(plural_expr_t
, unsigned int);
206 extern char *gnu_key_2_text(Msg_g_node
*, const char *, struct msg_pack
*);
208 extern char *get_codeset(const char *);
211 extern void gprintf(int, const char *, ...);
212 extern void printgt(Gettext_t
*, int);
213 extern void printmp(struct msg_pack
*, int);
214 extern void printsunmsg(Msg_s_node
*, int);
215 extern void printgnumsg(Msg_g_node
*, int);
216 extern void printexpr(plural_expr_t
, int);
217 extern void printmnp(Msg_node
*, int);
218 extern void printlist(void);
219 extern void print_rev1_info(Msg_g_node
*);
226 #endif /* !_LIBC_PORT_I18N_GETTEXT_H */