dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libadm / common / ckkeywd.c
blob093562788f57d0fa77409584531f655b50a00e20
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
22 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
23 /* All Rights Reserved */
27 * Copyright (c) 1997, by Sun Microsystems, Inc.
28 * All rights reserved.
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
32 /*LINTLIBRARY*/
34 #include <stdio.h>
35 #include <string.h>
36 #include <limits.h>
37 #include <sys/types.h>
38 #include "libadm.h"
40 static int
41 match(char *strval, char *set[])
43 char *found;
44 int i, len;
46 len = (int)strlen(strval);
48 found = NULL;
49 for (i = 0; set[i]; i++) {
50 if (strncmp(set[i], strval, len) == 0) {
51 if (found)
52 return (-1); /* not unique */
53 found = set[i];
57 if (found) {
58 (void) strcpy(strval, found);
59 return (0);
61 return (1);
64 int
65 ckkeywd(char *strval, char *keyword[], char *defstr, char *error, char *help,
66 char *prompt)
68 int valid, i, n;
69 char input[MAX_INPUT];
70 char defmesg[512];
71 char *ept;
73 (void) sprintf(defmesg, "Please enter one of the following keywords: ");
74 ept = defmesg + strlen(defmesg);
75 for (i = 0; keyword[i]; ) {
76 if (i)
77 (void) strcat(ept, ", ");
78 (void) strcat(ept, keyword[i++]);
80 (void) strcat(ept, ckquit ? ", q." : ".");
82 if (!prompt)
83 prompt = "Enter appropriate value";
85 start:
86 putprmpt(stderr, prompt, keyword, defstr);
87 if (getinput(input))
88 return (1);
90 n = (int)strlen(input);
91 if (n == 0) {
92 if (defstr) {
93 (void) strcpy(strval, defstr);
94 return (0);
96 puterror(stderr, defmesg, error);
97 goto start;
99 if (strcmp(input, "?") == 0) {
100 puthelp(stderr, defmesg, help);
101 goto start;
103 if (ckquit && (strcmp(input, "q") == 0)) {
104 (void) strcpy(strval, input);
105 return (3);
108 valid = 1;
109 if (keyword)
110 valid = !match(input, keyword);
112 if (!valid) {
113 puterror(stderr, defmesg, error);
114 goto start;
116 (void) strcpy(strval, input);
117 return (0);