xref: /illumos-gate/usr/src/cmd/msgfmt/gnu_msgfmt.c (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright (c) 2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #include "gnu_msgfmt.h"
28 
29 static char	*cmd;
30 int	fuzzy_flag = 0;
31 int	verbose_flag = 0;
32 int	strict_flag = 0;
33 int	po_error = 0;
34 char	*inputdir = NULL;
35 char	*outfile = NULL;
36 char	**po_names;
37 
38 static void
usage(void)39 usage(void)
40 {
41 	(void) fprintf(stderr,
42 		gettext(ERR_USAGE), cmd);
43 	exit(1);
44 }
45 
46 int
main(int argc,char ** argv)47 main(int argc, char **argv)
48 {
49 	int	i, ret;
50 	static struct flags	flag;
51 
52 	(void) setlocale(LC_ALL, "");
53 #if	!defined(TEXT_DOMAIN)
54 #define	TEXT_DOMAIN	"SYS_TEST"
55 #endif
56 	(void) textdomain(TEXT_DOMAIN);
57 
58 	if (cmd = strrchr(argv[0], '/'))
59 		++cmd;
60 	else
61 		cmd = argv[0];
62 
63 	ret = parse_option(&argc, &argv, &flag);
64 	if (ret == -1) {
65 		usage();
66 		/* NOTREACHED */
67 	}
68 	if (flag.idir) {
69 		inputdir = flag.idir;
70 	}
71 	if (flag.ofile) {
72 		outfile = flag.ofile;
73 		catalog_init(outfile);
74 	}
75 	if (flag.fuzzy) {
76 		fuzzy_flag = 1;
77 	}
78 	if (flag.sun_p) {
79 		error(gettext(ERR_SUN_ON_GNU), cmd);
80 		/* NOTREACHED */
81 	}
82 	if (flag.verbose) {
83 		verbose_flag = 1;
84 	}
85 	if (flag.strict) {
86 		strict_flag = 1;
87 	}
88 
89 	po_names = (char **)Xmalloc(argc * sizeof (char *));
90 	while (argc-- > 0) {
91 		if (verbose_flag) {
92 			diag(gettext(DIAG_START_PROC), *argv);
93 		}
94 		po_init(*argv);
95 		(void) yyparse();
96 		po_fini();
97 		argv++;
98 	}
99 	for (i = 0; i < cur_po_index; i++) {
100 		free(po_names[i]);
101 	}
102 	free(po_names);
103 	if (po_error) {
104 		/* error found */
105 		error(gettext(ERR_ERROR_FOUND), po_error);
106 		/* NOTREACHED */
107 	}
108 	output_all_gnu_mo_files();
109 
110 	return (0);
111 }
112