1genmsg(1)                        User Commands                       genmsg(1)
2
3
4

NAME

6       genmsg  -  generate  a  message source file by extracting messages from
7       source files
8

SYNOPSIS

10       genmsg [-abdfrntx] [-c message-tag] [-g project-file]
11            [-l project-file] [-m prefix] [-M suffix]
12            [-o message-file] [-p preprocessor] [-s set-tags]  file...
13
14

DESCRIPTION

16       The genmsg utility extracts message strings with calls  to  catgets(3C)
17       from  source  files  and  writes them in a format suitable for input to
18       gencat(1).
19
20   Invocation
21       genmsg reads one or more input files and, by default, generates a  mes‐
22       sage  source  file  whose name is composed of the first input file name
23       with .msg. If the -o option is specified, genmsg uses the option  argu‐
24       ment for its output file.
25
26
27
28
29       ┌─────────────────────────────────────┬─────────────────────┐
30CommandOutput File
31       ├─────────────────────────────────────┼─────────────────────┤
32genmsg prog.c                        │ prog.c.msg          │
33gensmg main.c util.c tool.c          │ main.c.msg          │
34genmsg -o prog.msg mail.c util.c     │ prog.msg            │
35       └─────────────────────────────────────┴─────────────────────┘
36
37
38       genmsg  also allows you to invoke a preprocessor to solve the dependen‐
39       cies of macros and define statements for the catgets(3C) calls.
40
41   Auto Message Numbering
42       genmsg replaces message numbers with the calculated numbers based  upon
43       the project file if the message numbers are -1, and it generates copies
44       of the input files with the new message  numbers  and  a  copy  of  the
45       project file with the new maximum message numbers.
46
47
48       A  project  file  is  a database that stores a list of set numbers with
49       their maximum message numbers. Each line in a project file is  composed
50       of a set number and its maximum message number:
51
52       Set_number    Maximum_message_number
53
54
55
56       In  a project file, a line beginning with a number sign (#) or an ASCII
57       space is considered as a comment and ignored.
58
59
60       genmsg also has the reverse operation to replace  all  message  numbers
61       with -1.
62
63   Comment Extraction
64       genmsg  allows  you to comment about messages and set numbers to inform
65       the translator how the messages should be translated. It  extracts  the
66       comment,  which  is  surrounded with the comment indicators and has the
67       specified tag inside the comment, from the input  file  and  writes  it
68       with  a dollar ($) prefix in the output file. genmsg supports the C and
69       C++ comment indicators, '/*', '*/', and '//'.
70
71   Testing
72       genmsg generates two kinds of messages for testing,  prefixed  messages
73       and  long messages. Prefixed messages allow you to check that your pro‐
74       gram is retrieving the messages from the message catalog. Long messages
75       allow you to check the appearance of your window program's initial size
76       and position.
77

OPTIONS

79       The following options are supported:
80
81       -a                 Append the output into the message file message-file
82                          that is specified by the -o option. If two different
83                          messages that have the same set and  message  number
84                          are found, the message in the specified message file
85                          is kept and the other message in the input  file  is
86                          discarded.
87
88
89       -b                 Place  the extracted comment after the corresponding
90                          message in the output file. This option changes  the
91                          placement behavior of the -s or -c option.
92
93
94       -c message-tag     Extract  message  comments having message-tag inside
95                          them from the input files and write them with a  '$'
96                          prefix as a comment in the output file.
97
98
99       -d                 Include  an  original text of a message as a comment
100                          to be preserved along with  its  translations.  With
101                          this  option,  the  translator  can see the original
102                          messages even after they  are  replaced  with  their
103                          translations.
104
105
106       -f                 Overwrite  the input files and the project file when
107                          used with the -l or -r option. With the  -r  option,
108                          genmsg overwrites only the input files.
109
110
111       -g project-file    Generate project-file that has a list of set numbers
112                          and their  maximum  message  numbers  in  the  input
113                          files.
114
115
116       -l project-file    Replace  message numbers with the calculated numbers
117                          based upon project-file if the message  numbers  are
118                          -1  in  the input files, and then generate copies of
119                          the input files with the new message numbers  and  a
120                          copy  of  project-file  with the new maximum message
121                          numbers. If project-file is not found,  genmsg  uses
122                          the  maximum  message  number in the input file as a
123                          base number and generates project-file.
124
125
126       -m prefix          Fill in the message with prefix. This option is use‐
127                          ful for testing.
128
129
130       -M suffix          Fill in the message with suffix. This option is use‐
131                          ful for testing.
132
133
134       -n                 Add comment lines to the output file indicating  the
135                          file  name  and line number in the input files where
136                          each extracted string is encountered.
137
138
139       -o message-file    Write the output to message-file.
140
141
142       -p preprocessor    Invoke preprocessor to preprocess macros and  define
143                          statements  for  the catgets(3C) calls. genmsg first
144                          invokes the option argument as  a  preprocesser  and
145                          then  starts  the  normal process against the output
146                          from the preprocessor. genmsg initiates this process
147                          for all the input files.
148
149
150       -r                 Replace message numbers with -1. This is the reverse
151                          operation of the -l option.
152
153
154       -s set-tag         Extract set number comments  having  set-tag  inside
155                          them  from the input files and write them with a '$'
156                          prefix as a comment in the output file. If  multiple
157                          comments are specified for one set number, the first
158                          one is extracted and the rest of them are discarded.
159
160
161       -t                 Generate a message that is three times  as  long  as
162                          the  original  message.  This  option  is useful for
163                          testing.
164
165
166       -x                 Suppress warning messages about message and set num‐
167                          ber range checks and conflicts.
168
169

OPERANDS

171       file    An input source file.
172
173

EXAMPLES

175       Example 1 Assigning Message Numbers and Generating New Files
176
177
178       Suppose that you have the following source and project files:
179
180
181         example% cat test.c
182         printf(catgets(catfd, 1, -1, "line too long\n"));
183         printf(catgets(catfd, 2, -1, "invalid code\n"));
184
185         example% cat proj
186         1   10
187         2   20
188
189
190
191
192       The command
193
194
195         example% genmsg -l proj test.c
196
197
198
199
200       would  assign the calculated message numbers based upon proj and gener‐
201       ate the following files:
202
203
204       test.c.msg    Message file
205
206
207       proj.new      Updated project file
208
209
210       test.c.new    New source file
211
212
213         example% cat test.c.msg
214         $quote "
215         $set    1
216         11      "line too long\n"
217         $set    2
218         21      "invalid code\n"
219
220         example% cat proj.new
221         1   11
222         2   21
223
224         example% cat test.c.new
225         printf(catgets(catfd, 1, 11, "line too long\n"));
226         printf(catgets(catfd, 2, 21, "invalid code\n"));
227
228
229
230       Example 2 Extracting Comments Into a File
231
232
233       The command
234
235
236         example% genmsg -s SET -c MSG test.c
237         example% cat test.c
238         /* SET: tar messages */
239         /* MSG: don't translate "tar". */
240         catgets(catfd, 1, 1, "tar: tape write error");
241         // MSG: don't translate "tar" and "-I".
242         catgets(catfd, 1, 2, "tar: missing argument for -I flag");
243
244
245
246
247       would extract the comments and write them in the following output file:
248
249
250         example% cat test.c.msg
251         $ /* SET: tar messages */
252         $set    1
253         $ /* MSG: don't translate "tar". */
254         1       "tar: tape write error"
255         $ // MSG: don't translate "tar" and "-I".
256         2       "tar: missing argument for -I flag"
257
258
259
260       Example 3 Generating Test Messages
261
262
263       The following command:
264
265
266         example% genmsg -m PRE: -M :FIX test.c
267
268
269
270
271       might generate the following messages for testing:
272
273
274         example% cat test.c.msg
275         1       "PRE:OK:FIX"
276         2       "PRE:Cancel:FIX"
277
278
279
280       Example 4 Parsing a Macro and Writing the Extracted Messages
281
282
283       Given the following input:
284
285
286         example% cat example.c
287         #include <nl_types.h>
288         #define MSG1    "message1"
289         #define MSG2    "message2"
290         #define MSG3    "message3"
291         #define MSG(n)  catgets(catd, 1, n, MSG ## n)
292         void
293         main(int argc, char **argv)
294         {
295         nl_catd catd = catopen(argv[0], NL_CAT_LOCALE);
296         (void) printf("%s0\n, MSG(1));
297         (void) printf("%s0\n, MSG(2));
298         (void) printf("%s0\n, MSG(3));
299         (void) catclose(catd);
300         }
301
302
303
304
305       The following command:
306
307
308         example% genmsg -p "cc -E" -o example.msg example.c
309
310
311
312
313       would parse the MSG macros and write the extracted messages  in   exam‐
314       ple.msg.
315
316
317       Example 5 Assigning Calculated Message Numbers
318
319
320       Suppose that you have the following header, source, and project files:
321
322
323         example% cat ../inc/msg.h
324         #define WARN_SET                     1
325         #define ERR_SET                      2
326         #define WARN_MSG(id, msg) catgets(catd, WARN_SET, (id), (msg))
327         #define ERR_MSG(id, msg)  catgets(catd, ERR_SET, (id), (msg))
328         example% example.c
329         #include "msg.h"
330         printf("%s, WARN_MSG(-1, "Warning error"));
331         printf("%s, ERR_MSG(-1, "Fatal error"));
332         example % proj
333         1     10
334         2     10
335
336
337
338
339       The command
340
341
342         example% genmsg -f -p "cc -E -I../inc" -l proj \
343            -o example.msg example.c
344
345
346
347
348       would  assign  each of the -1 message numbers a calculated number based
349       upon  proj and would overwrite the results to example.c and proj. Also,
350       this command writes the extracted messages in example.msg.
351
352

ENVIRONMENT VARIABLES

354       See  environ(5) for descriptions of the following environment variables
355       that affect the execution of genmsg: LC_MESSAGES and NLSPATH.
356

EXIT STATUS

358       The following exit values are returned:
359
360       0     Successful completion.
361
362
363       >0    An error occurred.
364
365

ATTRIBUTES

367       See attributes(5) for descriptions of the following attributes:
368
369
370
371
372       ┌─────────────────────────────┬─────────────────────────────┐
373       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
374       ├─────────────────────────────┼─────────────────────────────┤
375       │Availability                 │SUNWloc                      │
376       └─────────────────────────────┴─────────────────────────────┘
377

SEE ALSO

379       gencat(1), catgets(3C), catopen(3C), attributes(5), environ(5)
380

NOTES

382       genmsg does not handle pointers or variables in the  catgets(3C)  call.
383       For example:
384
385
386         const int set_num = 1;
387         extern int msg_num(const char *);
388         const char *msg = "Hello";
389         catgets(catd, set_num, msg_num(msg), msg);
390
391
392
393
394       When  the  auto  message numbering is turned on with a preprocessor, if
395       there are multiple -1's in the catgets(3C) line, genmsg replaces all of
396       the  -1's  in the line with a calculated number. For example, given the
397       input:
398
399         #define MSG(id, msg) catgets(catd, 1, (id), (msg))
400         if (ret == -1) printf("%s, MSG(-1, "Failed"));
401
402
403
404
405       the command
406
407         genmsg -l proj -p "cc -E"
408
409
410
411
412       would produce:
413
414            #define MSG(id, msg) catgets(catd, 1, (id), (msg))
415            if (ret == 1) printf("%s, MSG(1, "Failed"));
416
417
418
419
420       The workaround would be to split it into two lines as follows:
421
422            if (ret == -1)
423                  printf("%s, MSG(-1, "Failed"));
424
425
426
427
428
429SunOS 5.11                        14 May 2004                        genmsg(1)
Impressum