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