xref: /illumos-gate/usr/src/cmd/valtools/puttext.c (revision 88f8b78a88cbdc6d8c1af5c3e54bc49d25095c98)
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 2004 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 
31 #pragma ident	"%Z%%M%	%I%	%E% SMI"
32 
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <locale.h>
37 #include <libintl.h>
38 #include "libadm.h"
39 
40 static char	*prog;
41 static int	nflag;
42 static int	lmarg, rmarg;
43 
44 static void
45 usage(void)
46 {
47 	(void) fprintf(stderr,
48 		gettext("usage: %s [-r rmarg] [-l lmarg] string\n"),
49 		prog);
50 	exit(1);
51 }
52 
53 /*
54  * Given argv[0], return a pointer to the basename of the program.
55  */
56 static char *
57 prog_name(char *arg0)
58 {
59 	char *str;
60 
61 	/* first strip trailing '/' characters (exec() allows these!) */
62 	str = arg0 + strlen(arg0);
63 	while (str > arg0 && *--str == '/')
64 		*str = '\0';
65 	if ((str = strrchr(arg0, '/')) != NULL)
66 		return (str + 1);
67 	return (arg0);
68 }
69 
70 int
71 main(int argc, char **argv)
72 {
73 	int c;
74 
75 	(void) setlocale(LC_ALL, "");
76 
77 #if	!defined(TEXT_DOMAIN)
78 #define	TEXT_DOMAIN	"SYS_TEST"
79 #endif
80 	(void) textdomain(TEXT_DOMAIN);
81 
82 	prog = prog_name(argv[0]);
83 
84 	while ((c = getopt(argc, argv, "nr:l:?")) != EOF) {
85 		switch (c) {
86 		case 'n':
87 			nflag++;
88 			break;
89 
90 		case 'r':
91 			rmarg = atoi(optarg);
92 			break;
93 
94 		case 'l':
95 			lmarg = atoi(optarg);
96 			break;
97 
98 		default:
99 			usage();
100 		}
101 	}
102 
103 	if ((optind + 1) != argc)
104 		usage();
105 
106 	(void) puttext(stdout, argv[optind], lmarg, rmarg);
107 	if (!nflag)
108 		(void) fputc('\n', stdout);
109 	return (0);
110 }
111