6416 ptime -p could support multiple processes
[unleashed.git] / usr / src / cmd / valtools / puttext.c
blob11e6e046d3efa56b2c47d7afd4885810de595018
1 /*
2 * CDDL HEADER START
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.
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]
20 * CDDL HEADER END
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <locale.h>
37 #include <libintl.h>
38 #include "libadm.h"
40 static char *prog;
41 static int nflag;
42 static int lmarg, rmarg;
44 static void
45 usage(void)
47 (void) fprintf(stderr,
48 gettext("usage: %s [-r rmarg] [-l lmarg] string\n"),
49 prog);
50 exit(1);
54 * Given argv[0], return a pointer to the basename of the program.
56 static char *
57 prog_name(char *arg0)
59 char *str;
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);
70 int
71 main(int argc, char **argv)
73 int c;
75 (void) setlocale(LC_ALL, "");
77 #if !defined(TEXT_DOMAIN)
78 #define TEXT_DOMAIN "SYS_TEST"
79 #endif
80 (void) textdomain(TEXT_DOMAIN);
82 prog = prog_name(argv[0]);
84 while ((c = getopt(argc, argv, "nr:l:?")) != EOF) {
85 switch (c) {
86 case 'n':
87 nflag++;
88 break;
90 case 'r':
91 rmarg = atoi(optarg);
92 break;
94 case 'l':
95 lmarg = atoi(optarg);
96 break;
98 default:
99 usage();
103 if ((optind + 1) != argc)
104 usage();
106 (void) puttext(stdout, argv[optind], lmarg, rmarg);
107 if (!nflag)
108 (void) fputc('\n', stdout);
109 return (0);