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