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]
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
27 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
34 #include <sys/types.h>
38 * This file is the only one anywhere to need these functions,
39 * so we declare them here, not in libadm.h
41 extern char *__compile(char *, char *, const char *, int);
42 extern int __step(const char *, const char *);
46 #define ERRMSG0 "Input is required."
47 #define ERRMSG1 "Please enter a string containing no more than %d characters."
49 "Pattern matching has failed."
51 "Please enter a string which contains no embedded, \
52 leading or trailing spaces or tabs."
54 #define HLPMSG0 "Please enter a string"
55 #define HLPMSG1 "Please enter a string containing no more than %d characters"
56 #define HLPMSG2 "matches one of the following patterns:"
57 #define HLPMSG3 "matches the following pattern:"
58 #define HLPMSG4 "contains no embedded, leading or trailing spaces or tabs."
63 sethlp(char *msg
, char *regexp
[], int length
)
68 (void) sprintf(msg
, HLPMSG1
, length
);
70 (void) strcpy(msg
, HLPMSG0
);
72 (void) strcat(msg
, length
? " and " : " which ");
74 if (regexp
&& regexp
[0]) {
75 (void) strcat(msg
, regexp
[1] ? HLPMSG2
: HLPMSG3
);
76 for (i
= 0; regexp
[i
]; i
++) {
77 (void) strcat(msg
, "\\n\\t");
78 (void) strcat(msg
, regexp
[i
]);
81 (void) strcat(msg
, HLPMSG4
);
86 ckstr_val(char *regexp
[], int length
, char *input
)
92 if (length
&& (strlen(input
) > (size_t)length
)) {
96 if (regexp
&& regexp
[0]) {
98 for (i
= 0; !valid
&& regexp
[i
]; ++i
) {
99 if (!__compile(regexp
[i
], expbuf
, &expbuf
[ESIZE
], '\0'))
101 valid
= __step(input
, expbuf
);
105 } else if (strpbrk(input
, " \t")) {
113 ckstr_err(char *regexp
[], int length
, char *error
, char *input
)
119 if (ckstr_val(regexp
, length
, input
)) {
120 /* LINTED E_SEC_PRINTF_VAR_FMT */
121 (void) snprintf(temp
, sizeof (temp
), errstr
, length
);
122 puterror(stdout
, temp
, error
);
127 defhlp
= sethlp(temp
, regexp
, length
);
128 puterror(stdout
, defhlp
, error
);
132 ckstr_hlp(char *regexp
[], int length
, char *help
)
137 defhlp
= sethlp(hlpbuf
, regexp
, length
);
138 puthelp(stdout
, defhlp
, help
);
142 ckstr(char *strval
, char *regexp
[], int length
, char *defstr
, char *error
,
143 char *help
, char *prompt
)
147 char input
[MAX_INPUT
],
153 prompt
= "Enter an appropriate value";
156 putprmpt(stderr
, prompt
, NULL
, defstr
);
160 n
= (int)strlen(input
);
163 (void) strcpy(strval
, defstr
);
166 puterror(stderr
, ERRMSG0
, error
);
169 if (strcmp(input
, "?") == 0) {
171 defhlp
= sethlp(hlpbuf
, regexp
, length
);
172 puthelp(stderr
, defhlp
, help
);
175 if (ckquit
&& (strcmp(input
, "q") == 0)) {
176 (void) strcpy(strval
, input
);
179 if (ckstr_val(regexp
, length
, input
)) {
180 /* LINTED E_SEC_PRINTF_VAR_FMT */
181 (void) snprintf(errbuf
, sizeof (errbuf
), errstr
, length
);
182 puterror(stderr
, errbuf
, error
);
185 (void) strcpy(strval
, input
);