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
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.
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]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * Portions of this source code were derived from Berkeley 4.3 BSD
32 * under license from the Regents of the University of California.
35 #pragma ident "%Z%%M% %I% %E% SMI"
44 * TEXTDOMAIN should be defined in Makefile
45 * in case it isn't, define it here
47 #if !defined(TEXT_DOMAIN)
48 #define TEXT_DOMAIN "SYS_TEST"
52 expand_metas(char *in
) /* walk thru string interpreting \n etc. */
54 register char *out
, *cp
;
56 for (cp
= out
= in
; *in
!= NULL
; out
++, in
++) {
89 "Usage: gettext [-d domainname | --domain=domainname ] " \
90 "[domain] \"msgid\"\n" \
91 " gettext -s [-d domainname | --domain=domainname] [-e] [-n] "\
96 (void) fprintf(stderr
, gettext(ERR_USAGE
));
101 main(int argc
, char *argv
[]) /* shell script equivalent of gettext(3) */
103 char *domainpath
, *msgid
;
110 (void) setlocale(LC_ALL
, "");
111 (void) textdomain(TEXT_DOMAIN
);
122 if ((c
= *++arg
) == '\0') {
126 } else if (c
!= '-') {
132 * no spaces between -d and
144 /* not enough args */
149 /* enable escape sequence expansion */
154 /* suppress tailing newline */
171 if (*(arg
+ 1) == '\0') {
172 /* "--" found, option end */
180 if (strncmp(arg
, "domain=", 7) == 0) {
203 domainpath
= getenv("TEXTDOMAINDIR");
205 /* traditional mode */
208 * textdomain is specified by the argument.
211 } else if (!domain
) {
213 * textdomain is not specified by the argument.
214 * TEXTDOMAIN will be used.
216 domain
= getenv("TEXTDOMAIN");
219 * no domain specified
220 * Just print the argument given.
222 (void) printf("%s", expand_metas(*argv
));
227 (void) bindtextdomain(domain
, domainpath
);
229 msgid
= expand_metas(*argv
);
230 (void) fputs(dgettext(domain
, msgid
), stdout
);
231 exit(*domain
== NULL
);
235 domain
= getenv("TEXTDOMAIN");
237 if (domainpath
&& domain
) {
238 (void) bindtextdomain(domain
, domainpath
);
242 msgid
= expand_metas(*argv
++);
245 (void) fputs(domain
? dgettext(domain
, msgid
) : msgid
,
249 (void) fputc(' ', stdout
);
252 (void) fputc('\n', stdout
);
254 return ((domain
== NULL
) || (*domain
== NULL
));