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
418
419
420
421
422
423
424
425
426
|
.\" Copyright 2005 Sun Microsystems, Inc. All rights reserved.
.\" Use is subject to license terms.
.\"
.\" CDDL HEADER START
.\"
.\" The contents of this file are subject to the terms of the
.\" Common Development and Distribution License, Version 1.0 only
.\" (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
.\"
.if n .tr \--
.TH sgsmsg 1ONBLD "Jun 2, 1999"
.SH NAME
sgsmsg \- generate message strings for SGS subsystem.
.SH SYNOPSIS
.B sgsmsg
[
.B \-cl
] [
.BI \-d\0 "data"
] [
.BI \-h\0 "defs"
] [
.BI \-i\0 "ident"
]
.if n .ti +5n
[
.BI \-m\0 "messages"
] [
.BI \-n\0 "name"
]
.I file \.\.\.
.SH AVAILABILITY
SUNWonld
.SH DESCRIPTION
\f3sgsmsg\f1 generates several message files from an input string definition
\f2file\f1. \f3sgsmsg\f1 provides a flexible, centralized, mechanism
of collecting character strings within a code group such as an executable or
shared object. All character strings are captured into a single data array
within the \f2data\f1 file.
The data array is similar to that produced by
.BR xstr (1)),
and helps reduce the relocation overhead incurred by string pointers.
.LP
Indexes into the data array are generated as
definitions within the \f2defs\f1 file. The code group can reference each
character string via predefined macros.
.LP
The character strings may also be translated into an internationalized
format and captured in the
\f2messages\f1 file. By default these message strings are suitable for
.BR gettext (3I)
manipulation. The \f3\-c\f1 option provides for these message strings to be
translated into a form suitable for
.BR catgets (3C)
manipulation.
.SH OPERANDS
One of more input \f2file\f1s contains a definition for each character
string used by a particular code group. The interpretation of a
definition is determined by the first character of each line within
the input \f2file\f1:
.LP
.PD 0
.RS +4
.IP \(bu 3
Entries that begin with a \f3#\fI, \f3$\f1 or a newline are treated as
comments and are copied (as is) to the \f2messages\f1 file.
.IP \(bu 3
Entries that begin with a \f3@\f1 are translated and will be written to
one or more of the output files. Two translations are possible dependent upon
whether one or more tokens follow the \f3@\f1 character.
.RE
.PD
.sp
.LP
An \f4@\f1 character followed by a single token is interpreted as one of
two reserved message output
\f2indicators\f1, or a message \f2identifier\f1. The reserved output
indicator \f4_START_\f1 enables output to the \f2messages\f1 file (note that
the occurrence of any \f4@\f1 token will also enable message output).
The reserved output indicator \f4_END_\f1 disables output to the
\f2messages\f1 file. These two indicators provides a means of isolating
only those character strings that require translation into the \f2messages\f1
file.
.LP
Besides the reserved output indicators, an \f4@\f1 character followed by a
single token is taken to be a
message \f2identifier\f1. This identifier will be translated into a
\f2domain\f1 name for
.BR gettext (3I)
output, or a \f2setid\f1 for
.BR catgets (3C)
output. This translated value is determine by substituting the message
\f2identifier\f1 token
for the associated definition from in the \f2ident\f1 file. Note that
a message \f2identifier\f1 is required for
.BR catgets (3C)
use but is optional for
.BR gettext (3I).
.LP
An \f4@\f1 character followed by multiple tokens is taken to be a
string \f2definition\f1 followed by a quoted character string. Character
strings can be continued over multiple lines by ending the preceding
line with a backslash - all initial whitespace on the continuation line will
is ignored. Character strings can contain the escape sequences
.B \en
for newline,
.B \et
for tab,
.B \ev
for vertical tab,
.B \eb
for backspace,
.B \er
for carriage return,
.B \ef
for formfeed,
.B \e\e
for backslash, and
\e"
for double quote.
.LP
The character string is copied to the \f2data\f1 array
and an index into this array is generated as the \f2definition\f1 within
the string
\f2defs\f1 file. The character string is also translated to the appropriate
message format and written to the \f2messages\f1 file.
.SH OPTIONS
.TP 12
.B \-c
By default, strings generated in the \f2messages\f1 file are suitable for
.BR msgfmt (1)
processing, which provides for message extraction via
.BR gettext (3I).
This option causes the formatting of the message strings to be suitable for
.BR gencat (1)
processing, which provides for message extraction via
.BR catgets (3C).
.TP
.BI \-d\0 data
Specify a \f2data\f1 file is to be created.
This file contains a single data array, by default named (\f2__name\f1[]),
containing all the strings
defined in the string definition \f2file\f1.
.TP
.BI \-h\0 defs
Specify a \f2defs\f1 file is to be created.
This file contains definitions for each character string contained in
the data array within the \f2data\f1 file. These definitions represent
offsets in the data array for each string. Reference to individual strings
should use one of the two defined macros \f4MSG_INTL\f1 (which specifies
a user defined message extraction function), or \f4MSG_ORIG\f1
(which specifies a direct access to the \f2__name\f1[] array).
.TP
.BI \-i\0 ident
Specify an \f2ident\f1 file from which to interpret a message identifier
token.
.TP
.B \-l
Indicate that the \f2data\f1 array be defined local (\f2static\f1). This
is useful for establishing individual string arrays on a per-object basis.
.TP
.BI \-m\0 messages
Specify a \f2messages\f1 file is to be created. This
contain message strings suitable for delivery to a localization group.
.TP
.BI \-n\0 name
Specify an alternative interface \f2name\f1. This name is used to label
the message data array (\f2__name\f1[]) and the user defined message
extraction function (const char * \f2_name\f1(int)) which will interface
with this array.
.SH EXAMPLES
The following examples provide a simplified guide to using the \f3sgsmsg\fP
command, including sample input files and generated output files.
.LP
The following \f2ident\f1 file provides message \f2identifiers\f1 for
the link-editor utilities
.BR ld (1),
.BR libld.so.2 ,
and
.BR liblddbg.so.3 .
These identifiers are referenced from the input string definition files
of the respective code groups:
.if n .ta 1.8i 2.2i
.if t .ta 1.6i 2.2i
.RS
.nf
.ft 3
% cat sgs.ident
.ft 1
.if t .sp 0.35
.if n .sp
# mesgid setid domain
.if t .sp 0.35
.if n .sp
MSG_ID_LD 1 SUNW_OST_SGS
MSG_ID_LIBLD 2 SUNW_OST_SGS
MSG_ID_LIBLDDBG 3 SUNW_OST_SGS
.fi
.RE
.if t .bp
.LP
The following string definition \f2file\f1 defines a small number of
strings used by
.BR libld.so.2 :
.ta 2.2i
.RS
.nf
.ft 3
% cat libld.msg
.ft 1
.if t .sp 0.35
.if n .sp
@ _START_
.if t .sp 0.35
.if n .sp
# Message file for cmd/sgs/libld.
.if t .sp 0.35
.if n .sp
@ MSG_ID_LIBLD
# System call messages
.if t .sp 0.35
.if n .sp
@ MSG_SYS_OPEN "file %s: cannot open file: %s"
@ MSG_SYS_MMAP "file %s: cannot mmap file: %s"
# Symbol processing errors
.if t .sp 0.35
.if n .sp
@ MSG_SYM_DIFFTYPE "symbol `%s' has differing types:"
@ MSG_SYM_DIFFATTR "symbol `%s' has differing %s:\\n\\
\ \\t(file %s value=0x%x; file %s value=0x%x);"
.if t .sp 0.35
.if n .sp
@ _END_
# The following strings represent reserved names. Reference to
# these strings is via the MSG_ORIG() macro, and thus no
# translations are required.
.if t .sp 0.35
.if n .sp
@ MSG_STR_EMPTY ""
@ MSG_PTH_DEVZERO "/dev/zero"
@ MSG_SUNW_OST_SGS "SUNW_OST_SGS"
.fi
.RE
.LP
Using the above input files, the following string and message data files can be
generated:
.if t .ta 0.5i 2.2i
.if n .ta 0.5i 0.8i 3.0i
.RS
.nf
.ft 3
% sgsmsg\ \ \-i sgs.ident\ \ \-m\ messages\ \ \-d\ msg.c\ \ \-h\ msg.h \\
\ \ \ \ \-n\ libld_msg\ \ libld.msg
% cat msg.c
.ft 1
.if t .sp 0.35
.if n .sp
const char __libld_msg[] = { 0x00,
0x66, 0x69, 0x6c, 0x65, 0x20, 0x25, 0x73, 0x3a, \.\.\.\.
0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x20, 0x6f, 0x70, \.\.\.\.
\.\.\.\.
0x00
};
.if t .bp
.ft 3
% cat msg.h
.ft 1
.if t .sp 0.35
.if n .sp
extern const char __libld_msg[];
.if t .sp 0.35
.if n .sp
#define MSG_ORIG(x) &__libld_msg[x]
.if t .sp 0.35
.if n .sp
extern const char * _libld_msg(int);
.if t .sp 0.35
.if n .sp
#define MSG_INTL(x) _libld_msg(x)
.if t .sp 0.35
.if n .sp
#define MSG_SYS_OPEN 1
#define MSG_SYS_MMAP 31
#define MSG_SYM_DIFFTYPE 61
#define MSG_SYM_DIFFATTR 94
#define MSG_STR_EMPTY 167
#define MSG_PTH_DEVZERO 168
#define MSG_SUNW_OST_SGS 178
.ft 3
% cat messages
.ft 1
.if t .sp 0.35
.if n .sp
# Message file for cmd/sgs/libld.
.if t .sp 0.35
.if n .sp
domain "SUNW_OST_SGS"
.if t .sp 0.35
.if n .sp
# System call messages
.if t .sp 0.35
.if n .sp
msgid "file %s: cannot open file: %s"
msgstr ""
msgid "file %s: cannot mmap file: %s"
msgstr ""
.if t .sp 0.35
.if n .sp
# Symbol processing errors
.if t .sp 0.35
.if n .sp
msgid "symbol `%s' has differing types:"
msgstr ""
msgid "symbol `%s' has differing %s:\\n\\t(file %s value=0x%x; file %s value=0x%x);"
msgstr ""
.fi
.RE
.LP
References to the string data from the code group
should use one of the two defined macros
depending upon whether an original or localized string is required.
For example, the simple
.BR open (2)
of a file would use the original string, however its associated
error message should be localized:
.if n .ta 0.75i
.if t .ta 0.5i 2.2i
.RS
.nf
.ft 3
const char * file = MSG_ORIG(MSG_PTH_DEVZERO);
.if t .sp 0.35
.if n .sp
if ((fd = open(file, O_RDWR, 0)) == -1) {
int err = errno;
(void) fprintf(stderr, MSG_INTL(MSG_SYS_OPEN), file,
strerror(err));
return (1);
}
.fi
.RE
.if t .bp
.LP
The \f3MSG_INTL\f1 definition provides for a user defined message
extraction function
that allows the greatest flexibility in providing an objects localization.
Normally this interface is quite simple. For a code group that resides
in a shared object the following interface can be provided by the user:
.RS
.nf
.ft 3
extern char * _dgettext(const char *, const char *);
.if t .sp 0.35
.if n .sp
const char *
_libld_msg(int mid)
{
return (_dgettext(MSG_ORIG(MSG_SUNW_OST_SGS),
MSG_ORIG(mid)));
}
.fi
.RE
.LP
For a code group that resides in an executable the following interface,
and initialization can be provided by the user:
.RS
.nf
.ft 3
#include <locale.h>
int
main(int argc, char ** argv)
{
\&\.\.\.\.\.\.
(void) setlocale(LC_MESSAGES, MSG_ORIG(MSG_STR_EMPTY));
(void) textdomain(MSG_ORIG(MSG_SUNW_OST_SGS));
\&\.\.\.\.\.\.
}
const char *
_ld_msg(int mid)
{
return (gettext(MSG_ORIG(mid)));
}
.RE
.sp
.SH "EXIT STATUS"
A non-zero error return indicates a processing error.
.PD
.SH "SEE ALSO"
.BR gencat (1),
.BR ld (1),
.BR msgfmt (1),
.BR catgets (3C),
.BR gettext (3C).
.if n .tr \-\-
|