xref: /illumos-gate/usr/src/lib/libc/inc/msgfmt.h (revision 1da57d551424de5a9d469760be7c4b4d4f10a755)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _MSGFMT_H
27 #define	_MSGFMT_H
28 
29 #include <stdint.h>
30 #include <stddef.h>
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 /*
37  *	Sun MO file format
38  */
39 
40 /*
41  *
42  *		+-------------------------------+
43  *		| (int) middle message id       |
44  *		+-------------------------------+
45  *		| (int) total # of messages     |
46  *		+-------------------------------+
47  *		| (int) total msgid length      |
48  *		+-------------------------------+
49  *		| (int) total msgstr length     |
50  *		+-------------------------------+
51  *		| (int) size of msg_struct size	|
52  *		+-------------------------------+
53  *		+-------------------------------+
54  *		| (int) less                    |
55  *		+-------------------------------+
56  *		| (int) more                    |
57  *		+-------------------------------+
58  *		| (int) msgid offset            |
59  *		+-------------------------------+
60  *		| (int) msgstr offset           |
61  *		+-------------------------------+
62  *			................
63  *		+-------------------------------+
64  *		| (variable str) msgid          |
65  *		+-------------------------------+
66  *		| (variable str) msgid          |
67  *		+-------------------------------+
68  *			................
69  *		+-------------------------------+
70  *		| (variable str) msgid          |
71  *		+-------------------------------+
72  *		+-------------------------------+
73  *		| (variable str) msgstr         |
74  *		+-------------------------------+
75  *		| (variable str) msgstr         |
76  *		+-------------------------------+
77  *			................
78  *		+-------------------------------+
79  *		| (variable str) msgstr         |
80  *		+-------------------------------+
81  */
82 
83 struct msg_info {
84 	int	msg_mid;			/* middle message id */
85 	int	msg_count;			/* total # of messages */
86 	int	str_count_msgid;	/* total msgid length */
87 	int	str_count_msgstr;	/* total msgstr length */
88 	int	msg_struct_size;	/* size of msg_struct_size */
89 };
90 
91 struct msg_struct {
92 	int	less;				/* index of left leaf */
93 	int	more;				/* index of right leaf */
94 	int	msgid_offset;		/* msgid offset */
95 	int msgstr_offset;		/* msgstr offset */
96 };
97 
98 #define	MSG_STRUCT_SIZE		(sizeof (struct msg_struct))
99 
100 /*
101  * The following is the size of the old msg_struct used be defined
102  * in usr/src/cmd/msgfmt/msgfmt.c.
103  * Old msg_struct contained:
104  * struct msg_struct {
105  *		char	*msgid;
106  *		char	*msgstr;
107  *		int	msgid_offset;
108  *		int	msgstr_offset;
109  *		struct msg_struct	*next;
110  * };
111  */
112 #define	OLD_MSG_STRUCT_SIZE	20
113 
114 #define	LEAFINDICATOR		-99
115 
116 /*
117  *	GNU MO file format
118  */
119 
120 /*
121  *
122  *             +-----------------------------------------+
123  *           0 | (uint32_t) magic number                 |
124  *             +-----------------------------------------+
125  *           4 | (uint32_t) format revision              |
126  *             +-----------------------------------------+
127  *           8 | (uint32_t) number of strings            | == N
128  *             +-----------------------------------------+
129  *          12 | (uint32_t) offset of msgid table        | == O
130  *             +-----------------------------------------+
131  *          16 | (uint32_t) offset of msgstr table       | == T
132  *             +-----------------------------------------+
133  *          20 | (uint32_t) size of hashing table        | == S
134  *             +-----------------------------------------+
135  *          24 | (uint32_t) offset of hashing table      | == H
136  *             +-----------------------------------------+
137  *             +-----------------------------------------+
138  *           O | (uint32_t) length of 0th msgid          |
139  *             +-----------------------------------------+
140  *         O+4 | (uint32_t) offset of 0th msgid          | == M(0)
141  *             +-----------------------------------------+
142  *             ...............................
143  *             +-----------------------------------------+
144  * O+((N-1)*8) | (uint32_t) length of (N-1)th msgid      |
145  *             +-----------------------------------------+
146  * O+((N-1)*8) | (uint32_t) offset of (N-1)th msgid      | == M(N-1)
147  *       +4    +-----------------------------------------+
148  *             +-----------------------------------------+
149  *           T | (uint32_t) length of 0th msgstr         |
150  *             +-----------------------------------------+
151  *         T+4 | (uint32_t) offset of 0th msgstr         | == Q(0)
152  *             +-----------------------------------------+
153  *             ...............................
154  *             +-----------------------------------------+
155  * T+((N-1)*8) | (uint32_t) length of (N-1)th msgstr     |
156  *             +-----------------------------------------+
157  * T+((N-1)*8) | (uint32_t) offset of (N-1)th msgstr     | == Q(N-1)
158  *       +4    +-----------------------------------------+
159  *             +-----------------------------------------+
160  *           H | (uint32_t) start hashing table          |
161  *             +-----------------------------------------+
162  *             ...............................
163  *             +-----------------------------------------+
164  *   H + S * 4 | (uint32_t) end hashing table            |
165  *             +-----------------------------------------+
166  *             +-----------------------------------------+
167  *        M(0) | NULL terminated 0th msgid string        |
168  *             +-----------------------------------------+
169  *        M(1) | NULL terminated 1st msgid string        |
170  *             +-----------------------------------------+
171  *             ...............................
172  *             +-----------------------------------------+
173  *      M(N-1) | NULL terminated (N-1)th msgid string    |
174  *             +-----------------------------------------+
175  *             +-----------------------------------------+
176  *        Q(0) | NULL terminated 0th msgstr string       |
177  *             +-----------------------------------------+
178  *        Q(1) | NULL terminated 1st msgstr string       |
179  *             +-----------------------------------------+
180  *             ...............................
181  *             +-----------------------------------------+
182  *      Q(N-1) | NULL terminated (N-1)th msgstr string   |
183  *             +-----------------------------------------+
184  */
185 
186 /*
187  *	GNU MO file format (Revision 1)
188  */
189 /*
190  *
191  *             +-----------------------------------------------+
192  *           0 | (uint32_t) magic number                       |
193  *             +-----------------------------------------------+
194  *           4 | (uint32_t) format revision                    |
195  *             +-----------------------------------------------+
196  *           8 | (uint32_t) number of strings                  | == N
197  *             +-----------------------------------------------+
198  *          12 | (uint32_t) offset of msgid table              | == O
199  *             +-----------------------------------------------+
200  *          16 | (uint32_t) offset of msgstr table             | == T
201  *             +-----------------------------------------------+
202  *          20 | (uint32_t) size of hashing table              | == S
203  *             +-----------------------------------------------+
204  *          24 | (uint32_t) offset of hashing table            | == H
205  *             +-----------------------------------------------+
206  *          32 | (uint32_t) number of dynamic macros           | == M
207  *             +-----------------------------------------------+
208  *          36 | (uint32_t) offset of dynamic macros           | == P
209  *             +-----------------------------------------------+
210  *          40 | (uint32_t) number of dynamic strings          | == D
211  *             +-----------------------------------------------+
212  *          44 | (uint32_t) offset of dynamic msgid tbl        | == A
213  *             +-----------------------------------------------+
214  *          48 | (uint32_t) offset of dynamic msgstr tbl       | == B
215  *             +-----------------------------------------------+
216  *             +-----------------------------------------------+
217  *           O | (uint32_t) length of 0th msgid                |
218  *             +-----------------------------------------------+
219  *         O+4 | (uint32_t) offset of 0th msgid                | == M(0)
220  *             +-----------------------------------------------+
221  *             ...............................
222  *             +-----------------------------------------------+
223  * O+((N-1)*8) | (uint32_t) length of (N-1)th msgid            |
224  *             +-----------------------------------------------+
225  * O+((N-1)*8) | (uint32_t) offset of (N-1)th msgid            | == M(N-1)
226  *       +4    +-----------------------------------------------+
227  *             +-----------------------------------------------+
228  *           T | (uint32_t) length of 0th msgstr               |
229  *             +-----------------------------------------------+
230  *         T+4 | (uint32_t) offset of 0th msgstr               | == Q(0)
231  *             +-----------------------------------------------+
232  *             ...............................
233  *             +-----------------------------------------------+
234  * T+((N-1)*8) | (uint32_t) length of (N-1)th msgstr           |
235  *             +-----------------------------------------------+
236  * T+((N-1)*8) | (uint32_t) offset of (N-1)th msgstr           | == Q(N-1)
237  *       +4    +-----------------------------------------------+
238  *             +-----------------------------------------------+
239  *           H | (uint32_t) start hashing table                |
240  *             +-----------------------------------------------+
241  *             ...............................
242  *             +-----------------------------------------------+
243  *   H + S * 4 | (uint32_t) end hashing table                  |
244  *             +-----------------------------------------------+
245  *             +-----------------------------------------------+
246  *           P | (uint32_t) length of 0th macro                |
247  *             +-----------------------------------------------+
248  *         P+4 | (uint32_t) offset of 0th macro                | == C(0)
249  *             +-----------------------------------------------+
250  *             ...............................
251  *             +-----------------------------------------------+
252  * P+((M-1)*8) | (uint32_t) length of (M-1)th macro            |
253  *             +-----------------------------------------------+
254  * P+((M-1)*8) | (uint32_t) offset of (M-1)th macro            | == C(M-1)
255  *       +4    +-----------------------------------------------+
256  *             +-----------------------------------------------+
257  *           A | (uint32_t) offset of 0th d_msgid              | == L(0)
258  *             +-----------------------------------------------+
259  *             ...............................
260  *             +-----------------------------------------------+
261  * A+((D-1)*4) | (uint32_t) offset of (D-1)th d_msgid          | == L(D-1)
262  *             +-----------------------------------------------+
263  *             +-----------------------------------------------+
264  *           B | (uint32_t) offset of 0th d_msgstr             | == E(0)
265  *             +-----------------------------------------------+
266  *             ...............................
267  *             +-----------------------------------------------+
268  * B+((D-1)*4) | (uint32_t) offset of (D-1)th d_msgstr         | == E(D-1)
269  *             +-----------------------------------------------+
270  *             +-----------------------------------------------+
271  *        L(0) | (uint32_t) offset of 0th d_msgid message      | == F(0)
272  *             +-----------------------------------------------+
273  *      L(0)+4 | (uint32_t) length of 0th fixed substring      |
274  *             +-----------------------------------------------+
275  *      L(0)+8 | (uint32_t) index to a dynamic macro           |
276  *             +-----------------------------------------------+
277  *             ...............................
278  *             +-----------------------------------------------+
279  *     L(0)+4+ | (uint32_t) length of (m-1)th fixed substring  |
280  *   ((m-1)*8) +-----------------------------------------------+
281  *     L(0)+8+ | (uint32_t) NOMORE_DYNAMIC_STR                 |
282  *   ((m-1)*8) +-----------------------------------------------+
283  *             +-----------------------------------------------+
284  *      L(D-1) | (uint32_t) offset of 0th d_msgid message      | == F(D-1)
285  *             +-----------------------------------------------+
286  *    L(D-1)+4 | (uint32_t) length of 0th fixed substring      |
287  *             +-----------------------------------------------+
288  *    L(D-1)+8 | (uint32_t) index to a dynamic macro           |
289  *             +-----------------------------------------------+
290  *             ...............................
291  *             +-----------------------------------------------+
292  *    L(D-1)+4 | (uint32_t) length of (m-1)th fixed substring  |
293  *   ((m-1)*8) +-----------------------------------------------+
294  *    L(D-1)+8 | (uint32_t) NOMORE_DYNAMIC_STR                 |
295  *   ((m-1)*8) +-----------------------------------------------+
296  *             +-----------------------------------------------+
297  *        E(0) | (uint32_t) offset of 0th d_msgstr message     | == G(0)
298  *             +-----------------------------------------------+
299  *      E(0)+4 | (uint32_t) length of 0th fixed substring      |
300  *             +-----------------------------------------------+
301  *      E(0)+8 | (uint32_t) index to a dynamic macro           |
302  *             +-----------------------------------------------+
303  *             ...............................
304  *             +-----------------------------------------------+
305  *     E(0)+4+ | (uint32_t) length of (m-1)th fixed substring  |
306  *   ((m-1)*8) +-----------------------------------------------+
307  *     E(0)+8+ | (uint32_t) NOMORE_DYNAMIC_STR                 |
308  *   ((m-1)*8) +-----------------------------------------------+
309  *             +-----------------------------------------------+
310  *      E(D-1) | (uint32_t) offset of 0th d_msgstr message     | == G(D-1)
311  *             +-----------------------------------------------+
312  *    E(D-1)+4 | (uint32_t) length of 0th fixed substring      |
313  *             +-----------------------------------------------+
314  *    E(D-1)+8 | (uint32_t) index to a dynamic macro           |
315  *             +-----------------------------------------------+
316  *             ...............................
317  *             +-----------------------------------------------+
318  *    E(D-1)+4 | (uint32_t) length of (m-1)th fixed substring  |
319  *   ((m-1)*8) +-----------------------------------------------+
320  *    E(D-1)+8 | (uint32_t) NOMORE_DYNAMIC_STR                 |
321  *   ((m-1)*8) +-----------------------------------------------+
322  *             +-----------------------------------------------+
323  *        M(0) | NULL terminated 0th msgid string              |
324  *             +-----------------------------------------------+
325  *        M(1) | NULL terminated 1st msgid string              |
326  *             +-----------------------------------------------+
327  *             ...............................
328  *             +-----------------------------------------------+
329  *      M(N-1) | NULL terminated (N-1)th msgid string          |
330  *             +-----------------------------------------------+
331  *        Q(0) | NULL terminated 0th msgstr string             |
332  *             +-----------------------------------------------+
333  *        Q(1) | NULL terminated 1st msgstr string             |
334  *             +-----------------------------------------------+
335  *             ...............................
336  *             +-----------------------------------------------+
337  *      Q(N-1) | NULL terminated (N-1)th msgstr string         |
338  *             +-----------------------------------------------+
339  *             +-----------------------------------------------+
340  *        C(0) | NULL terminated 0th macro                     |
341  *             +-----------------------------------------------+
342  *             ...............................
343  *             +-----------------------------------------------+
344  *      C(M-1) | NULL terminated (M-1)th macro                 |
345  *             +-----------------------------------------------+
346  *             +-----------------------------------------------+
347  *        F(0) | NULL terminated 0th dynamic msgid string      |
348  *             +-----------------------------------------------+
349  *             ...............................
350  *             +-----------------------------------------------+
351  *      F(D-1) | NULL terminated (D-1)th dynamic msgid string  |
352  *             +-----------------------------------------------+
353  *             +-----------------------------------------------+
354  *        G(0) | NULL terminated 0th dynamic msgstr string     |
355  *             +-----------------------------------------------+
356  *             ...............................
357  *             +-----------------------------------------------+
358  *      G(D-1) | NULL terminated (D-1)th dynamic msgstr string |
359  *             +-----------------------------------------------+
360  */
361 
362 #define	GNU_MAGIC			0x950412de
363 #define	GNU_MAGIC_SWAPPED		0xde120495
364 #define	GNU_REVISION			0
365 #define	GNU_REVISION_0_0		0
366 #define	GNU_REVISION_0_0_SWAPPED	0
367 #define	GNU_REVISION_0_1		0x00000001
368 #define	GNU_REVISION_0_1_SWAPPED	0x01000000
369 #define	GNU_REVISION_1_1		0x00010001
370 #define	GNU_REVISION_1_1_SWAPPED	0x01000100
371 #define	NOMORE_DYNAMIC_MACRO		0xffffffff
372 
373 enum gnu_msgidstr {
374 	MSGID = 0,
375 	MSGSTR = 1
376 };
377 
378 struct gnu_msg_info {
379 	uint32_t	magic;
380 	uint32_t	revision;
381 	uint32_t	num_of_str;
382 	uint32_t	off_msgid_tbl;
383 	uint32_t	off_msgstr_tbl;
384 	uint32_t	sz_hashtbl;
385 	uint32_t	off_hashtbl;
386 };
387 
388 struct gnu_msg_rev1_info {
389 	uint32_t	num_of_dynamic_macro;
390 	uint32_t	off_dynamic_macro;
391 	uint32_t	num_of_dynamic_str;
392 	uint32_t	off_dynamic_msgid_tbl;
393 	uint32_t	off_dynamic_msgstr_tbl;
394 };
395 
396 struct gnu_msg_ent {
397 	uint32_t	len;
398 	uint32_t	offset;
399 };
400 
401 struct gnu_dynamic_ent {
402 	uint32_t	len;
403 	uint32_t	idx;
404 };
405 
406 struct gnu_dynamic_tbl {
407 	uint32_t	offset;
408 	struct gnu_dynamic_ent	entry[1];
409 };
410 
411 #ifdef	__cplusplus
412 }
413 #endif
414 
415 #endif /* _MSGFMT_H */
416