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) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 #pragma ident "%Z%%M% %I% %E% SMI"
47 static char *deflt
= NULL
, *prompt
= NULL
, *error
= NULL
, *help
= NULL
;
48 static int kpid
= BADPID
;
49 static int signo
, pflags
;
51 static const char vusage
[] = "abcfglrtwxyzno";
52 static const char eusage
[] = "abcfglrtwxyznoWe";
53 static const char husage
[] = "abcfglrtwxyznoWh";
55 #define USAGE "[-[a|l][b|c|f|y][n|[o|z]]rtwx]"
57 "\t-a #absolute path\n" \
58 "\t-b #block special device\n" \
59 "\t-c #character special device\n" \
60 "\t-f #ordinary file\n" \
61 "\t-l #relative path\n" \
62 "\t-n #must not exist (new)\n" \
63 "\t-o #must exist (old)\n" \
64 "\t-r #read permission\n" \
65 "\t-t #permission to create (touch)\n" \
66 "\t-w #write permission\n" \
67 "\t-x #execute permisiion\n" \
69 "\t-z #non-zero length\n"
76 (void) fprintf(stderr
,
77 gettext("usage: %s [options] %s\n"),
79 (void) fprintf(stderr
, gettext(MYOPTS
));
80 (void) fprintf(stderr
, gettext(OPTMESG
));
81 (void) fprintf(stderr
, gettext(STDOPTS
));
85 (void) fprintf(stderr
,
86 gettext("usage: %s %s input\n"),
88 (void) fprintf(stderr
, gettext(OPTMESG
));
89 (void) fprintf(stderr
, gettext(MYOPTS
));
93 (void) fprintf(stderr
,
94 gettext("usage: %s [options] %s\n"),
96 (void) fprintf(stderr
, gettext(MYOPTS
));
97 (void) fprintf(stderr
, gettext(OPTMESG
));
98 (void) fprintf(stderr
,
99 gettext("\t-W width\n\t-h help\n"));
103 (void) fprintf(stderr
,
104 gettext("usage: %s [options] %s [input]\n"),
106 (void) fprintf(stderr
, gettext(MYOPTS
));
107 (void) fprintf(stderr
, gettext(OPTMESG
));
108 (void) fprintf(stderr
,
109 gettext("\t-W width\n\t-e error\n"));
116 * Given argv[0], return a pointer to the basename of the program.
119 prog_name(char *arg0
)
123 /* first strip trailing '/' characters (exec() allows these!) */
124 str
= arg0
+ strlen(arg0
);
125 while (str
> arg0
&& *--str
== '/')
127 if ((str
= strrchr(arg0
, '/')) != NULL
)
133 main(int argc
, char **argv
)
139 (void) setlocale(LC_ALL
, "");
141 #if !defined(TEXT_DOMAIN)
142 #define TEXT_DOMAIN "SYS_TEST"
144 (void) textdomain(TEXT_DOMAIN
);
146 prog
= prog_name(argv
[0]);
148 while ((c
= getopt(argc
, argv
, "abcfglrtwxyznod:p:e:h:k:s:QW:?"))
150 /* check for invalid option */
151 if ((*prog
== 'v') && !strchr(vusage
, c
))
153 if ((*prog
== 'e') && !strchr(eusage
, c
))
155 if ((*prog
== 'h') && !strchr(husage
, c
))
164 ckwidth
= atoi(optarg
);
166 (void) fprintf(stderr
,
167 gettext("%s: ERROR: negative display width specified\n"),
174 pflags
|= P_ABSOLUTE
;
186 case 'g': /* outdated */
191 pflags
|= P_RELATIVE
;
247 signo
= atoi(optarg
);
261 if (ckpath_stx(pflags
)) {
262 (void) fprintf(stderr
,
263 gettext("%s: ERROR: mutually exclusive options used\n"),
269 if (argc
!= (optind
+1))
270 usage(); /* too many paths listed */
271 exit(ckpath_val(argv
[optind
], pflags
));
272 } else if (*prog
== 'e') {
273 if (argc
> (optind
+1))
276 ckpath_err(pflags
, error
, argv
[optind
]);
285 ckpath_hlp(pflags
, help
);
290 len
= strlen(deflt
) + 1;
296 pathval
= (char *)malloc(len
);
298 (void) fprintf(stderr
,
299 gettext("Not enough memory\n"));
302 n
= ckpath(pathval
, pflags
, deflt
, error
, help
, prompt
);
305 (void) kill(kpid
, signo
);
308 (void) fputs(pathval
, stdout
);