2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: merge.c /main/4 1995/12/08 09:44:13 rswiston $ */
27 Merge international messages back into CDE files.
30 merge [-bs][-lang language][-dfile Default.tmsg] Primary.tmsg\
33 -bs : The backslash+n is left alone and not interpreted.
34 -lang language : Language of messages. (If not specified, the value
35 of LANG environment variable is used.)
36 -dfile Default.tmsg : Default message file.
38 Primary.tmsg : Primary message file.
39 File.nls : Template file.
43 June 93 Hatim Amro -Updated this tool to have support for a default .tmsg
44 file in case the primery one is not found or missing
45 a message whose number is in the .nls file. I, also,
46 rewrote the option stripping and handling code for
47 better flexibility. I find the Syntax above very
48 confusing, I provide a simpler one below, which,
49 includes the new -dfile option.
51 merge [-lang Ja_JP][-dfile Default.tmsg] Primary.tmsg < File.nls > File
53 July 93 Hatim Amro -In order to comply with request from Ann Barnette, the
54 backslash n is left alone and not interpreted if the
55 new -bs option is specified in the parameter list.
56 (this option will not be published)
59 merge [-bs][-lang Ja_JP][-dfile Default.tmsg]\
60 Primary.tmsg < File.nls > File
62 8/2/93 Masato Suzuki - -lang option is generalized. (This options doesn't
63 necessarily need to be specified for single-byte
64 languages.) Error messages are enhanced. And bug
67 12/13/93 Masato Suzuki -Modified so that the format of message file(*.tmsg)
68 is compliant to XPG message catalog file. (But it's
71 Format of message file.
72 $set n [comment] ... n must be 1.
74 m message-text ... Message text may contain following spcial characters
79 \ (at end of line) continue on same line
81 Following XPG format and escape sequences are not supported.
83 \v, \b, \r, \f, \ddd, \xdddd
86 * Following pattern in proforma will be replaced by the matched message in
87 * catalogue. This pattern must be in one line.
89 * %|nls-???-###| : ??? must be numerics.
90 * ### is comment, can be nothing.
100 nl_catd catfile[2] = {NULL, NULL}; /* [0] for primary, [1] for default */
107 int crt_line[3] = {0, 0, 1}; /* current line [0]: Primary message file */
108 /* [1]: Default message file */
109 /* [2]: Template file */
111 void process_message ();
115 int find_msg_in_file ();
121 void main (argc, argv)
127 get_option(&argc, argv);
130 fatal("Usage: merge [-lang language][-dfile Default.tmsg] Primary.tmsg < File.nls > File \n", 0, 9);
133 setlocale(LC_ALL, lang);
134 /* LC_CTYPE need to be set to make "gencat" command work correctly */
135 sprintf( envvar, "LC_CTYPE=%s", lang );
138 setlocale(LC_ALL, "");
148 for (s = s0 = "|nls-"; *s != 0; s++)
149 if (c = get_char (), c != *s)
152 /* if the string matchs "%|nls-", go to process_message(). */
170 catclose(catfile[0]);
173 catclose(catfile[1]);
175 unlink("./.dt_pfile.cat");
176 unlink("./.dt_dfile.cat");
182 * If the pattern "%|nls-???-###|" is found in the template file, replace it
185 void process_message ()
190 while (c = get_char (), c != '-')
193 case EOF: fatal ("Unterminated NLS sequence.\n", crt_line[2]-1, 2);
194 case '\n': fatal ("Unterminated NLS sequence.\n", crt_line[2]-1, 2);
195 default: fatal ("Bad character in NLS sequence.\n", crt_line[2], 2);
196 case '0': m = m * 10 + 0; break;
197 case '1': m = m * 10 + 1; break;
198 case '2': m = m * 10 + 2; break;
199 case '3': m = m * 10 + 3; break;
200 case '4': m = m * 10 + 4; break;
201 case '5': m = m * 10 + 5; break;
202 case '6': m = m * 10 + 6; break;
203 case '7': m = m * 10 + 7; break;
204 case '8': m = m * 10 + 8; break;
205 case '9': m = m * 10 + 9; break;
208 while (c = get_char (), c != '|')
209 if (c == '\n' || c == EOF)
210 fatal ("Unterminated NLS sequence.\n", crt_line[2]-1, 2);
213 printf ("%s", big_buff);
215 printf ("....Missing message #%d", m);
216 fprintf (stderr, "*** Error: Missing message #%d\n", m);
221 * Get a character from template. Incriment line count if new line is found.
240 unlink("./.dt_pfile.cat");
241 unlink("./.dt_dfile.cat");
245 sprintf(line,"/usr/bin/gencat ./.dt_pfile.cat %s",pfile);
246 if ( system(line) != 0 )
248 fatal("primary .tmsg file would not gencat\n",0,9);
252 catfile[0] = catopen("./.dt_pfile.cat",0);
256 sprintf(line,"/usr/bin/gencat ./.dt_dfile.cat %s",dfile);
257 if ( system(line) != 0 )
259 fatal("default .tmsg file would not gencat\n",0,9);
264 catfile[1] = catopen("./.dt_dfile.cat",0);
267 if(catfile[0] == NULL && catfile[1] == NULL)
268 fatal("Can't open message files.\n", 0, 9);
273 * Search a message by specified number. If found, returns 1 and the message
274 * will be set in big_buff. If not found, returns 0.
276 int find_message (msg)
277 int msg; /* message number to be searched */
281 if(catfile[0] != NULL)
282 ret = find_msg_in_file(msg, 0);
283 if(ret == 0 && catfile[1] != NULL)
284 ret = find_msg_in_file(msg, 1);
289 * Search a line starts with the message number in specified file. If found,
290 * the line will be passed to get_message() and returns 1.
291 * If not found, returns 0.
293 int find_msg_in_file (msg, file)
294 int msg; /* message number to be searched */
295 int file; /* 0: Primary message file, 1: Default message file */
297 big_buff = catgets(catfile[file],1,msg,"MSG_NOT_FOUND");
298 if ( strcmp(big_buff,"MSG_NOT_FOUND") )
305 * Display error message and exit program.
307 * file == file in which the error found 0: Primary message file
308 * 1: Default message file
312 void fatal (char *m, int line, int file)
313 /* file in which the error found 0: Primary message file */
314 /* 1: Default message file */
315 /* 2: Template file */
318 fprintf (stderr, "*** Fatal: ");
319 fprintf (stderr, "%s", m);
323 fprintf(stderr, " [Line %d in Primary message file]\n", line);
326 fprintf(stderr, " [Line %d in Default message file]\n", line);
329 fprintf(stderr, " [Line %d in Template file]\n", line);
335 * Parse command line options.
337 void get_option (argc, argv)
343 for(i = 1; i < *argc; i++) {
344 if(strcmp(argv[i], "-bs") == 0) {
347 else if(strcmp(argv[i], "-lang") == 0) {
348 if(argv[i+1] != NULL && strlen(argv[i+1]) > 0) {
349 lang = (char *)malloc(sizeof(char) * (strlen(argv[i+1]) + 1));
350 strcpy(lang, argv[i+1]);
354 else if(strcmp(argv[i], "-dfile") == 0) {
355 if(argv[i+1] != NULL && strlen(argv[i+1]) > 0) {
356 dfile = (char *)malloc(sizeof(char) * (strlen(argv[i+1]) + 1));
357 strcpy(dfile, argv[i+1]);
362 if(strlen(argv[i]) > 0) {
363 pfile = (char *)malloc(sizeof(char) * (strlen(argv[i]) + 1));
364 strcpy(pfile, argv[i]);