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
, length
;
51 static const char vusage
[] = "rl";
52 static const char husage
[] = "rlWh";
53 static const char eusage
[] = "rlWe";
55 #define USAGE "[-l length] [[-r regexp] [...]]"
62 (void) fprintf(stderr
,
63 gettext("usage: %s [options] %s\n"),
65 (void) fprintf(stderr
, gettext(OPTMESG
));
66 (void) fprintf(stderr
, gettext(STDOPTS
));
70 (void) fprintf(stderr
,
71 gettext("usage: %s %s input\n"), prog
, USAGE
);
75 (void) fprintf(stderr
,
76 gettext("usage: %s [options] %s\n"),
78 (void) fprintf(stderr
, gettext(OPTMESG
));
79 (void) fprintf(stderr
,
80 gettext("\t-W width\n\t-h help\n"));
84 (void) fprintf(stderr
,
85 gettext("usage: %s [options] %s\n"),
87 (void) fprintf(stderr
, gettext(OPTMESG
));
88 (void) fprintf(stderr
,
89 gettext("\t-W width\n\t-e error\n"));
96 * Given argv[0], return a pointer to the basename of the program.
103 /* first strip trailing '/' characters (exec() allows these!) */
104 str
= arg0
+ strlen(arg0
);
105 while (str
> arg0
&& *--str
== '/')
107 if ((str
= strrchr(arg0
, '/')) != NULL
)
113 main(int argc
, char **argv
)
119 size_t maxregexp
= MAXREGEXP
;
122 (void) setlocale(LC_ALL
, "");
124 #if !defined(TEXT_DOMAIN)
125 #define TEXT_DOMAIN "SYS_TEST"
127 (void) textdomain(TEXT_DOMAIN
);
129 prog
= prog_name(argv
[0]);
131 regexp
= (char **)calloc(maxregexp
, sizeof (char *));
133 (void) fprintf(stderr
,
134 gettext("Not enough memory\n"));
137 while ((c
= getopt(argc
, argv
, "r:l:d:p:e:h:k:s:QW:?")) != EOF
) {
138 /* check for invalid option */
139 if ((*prog
== 'v') && !strchr(vusage
, c
))
141 if ((*prog
== 'e') && !strchr(eusage
, c
))
143 if ((*prog
== 'h') && !strchr(husage
, c
))
152 ckwidth
= atoi(optarg
);
154 (void) fprintf(stderr
,
155 gettext("%s: ERROR: negative display width specified\n"),
162 regexp
[nregexp
++] = optarg
;
163 if (nregexp
== maxregexp
) {
164 maxregexp
+= MAXREGEXP
;
165 regexp
= (char **)realloc(regexp
,
166 maxregexp
* sizeof (char *));
168 (void) fprintf(stderr
,
169 gettext("Not enough memory\n"));
172 (void) memset(regexp
+ nregexp
, 0,
173 (maxregexp
- nregexp
) *
179 length
= atoi(optarg
);
180 if ((length
<= 0) || (length
> 128)) {
181 (void) fprintf(stderr
,
182 gettext("%s: ERROR: length must be between 1 and 128\n"),
209 signo
= atoi(optarg
);
224 if (argc
!= (optind
+1))
226 if (ckstr_val(regexp
, length
, argv
[optind
]))
232 if (argc
> (optind
+1))
233 usage(); /* too many args */
235 ckstr_err(regexp
, length
, error
, argv
[optind
]);
244 ckstr_hlp(regexp
, length
, help
);
248 regexp
[nregexp
] = NULL
;
251 len
= strlen(deflt
) + 1;
257 strval
= (char *)malloc(len
);
259 (void) fprintf(stderr
,
260 gettext("Not enough memory\n"));
263 n
= ckstr(strval
, regexp
, length
, deflt
, error
, help
, prompt
);
266 (void) kill(kpid
, signo
);
269 (void) fputs(strval
, stdout
);