xref: /illumos-gate/usr/src/cmd/gettxt/gettxt.c (revision d363b1b0cb9ef6d6f3febdd8d1cba46507e97098)
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 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 #include <stdio.h>
31 #include <locale.h>
32 #include <unistd.h>
33 #include <string.h>
34 #include <stdlib.h>
35 #include <libintl.h>
36 #include <libgen.h>
37 
38 int
39 main(int argc, char **argv)
40 {
41 	char	*dfltp;
42 	char	*locp;
43 
44 	locp = setlocale(LC_ALL, "");
45 	if (locp == NULL) {
46 		(void) setlocale(LC_CTYPE, "");
47 		(void) setlocale(LC_MESSAGES, "");
48 	}
49 #if !defined(TEXT_DOMAIN)
50 #define	TEXT_DOMAIN	"SYS_TEST"
51 #endif
52 	(void) textdomain(TEXT_DOMAIN);
53 	if (argc != 2 && argc != 3) {
54 		(void) fprintf(stderr, gettext("Incorrect usage.\n"));
55 		(void) fprintf(stderr,
56 		    gettext("usage: gettxt msgid [ dflt_msg ] \n"));
57 		exit(1);
58 	}
59 
60 
61 	if (argc == 2) {
62 		(void) fputs(gettxt(argv[1], ""), stdout);
63 		exit(0);
64 	}
65 
66 	if ((dfltp = malloc(strlen(argv[2] + 1))) == (char *)NULL) {
67 		(void) fprintf(stderr, gettext("malloc failed\n"));
68 		exit(1);
69 	}
70 
71 	(void) strccpy(dfltp, argv[2]);
72 
73 	(void) fputs(gettxt(argv[1], dfltp), stdout);
74 
75 	free(dfltp);
76 
77 	return (0);
78 }
79