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