sd: remove 'ssd' driver support
[unleashed/tickless.git] / usr / src / lib / libadm / common / ckyorn.c
blob942e0ebaf028d2d0063db66fbd1d02a4b8c45db7
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 2004 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */
32 /*LINTLIBRARY*/
34 #include <stdio.h>
35 #include <ctype.h>
36 #include <string.h>
37 #include <limits.h>
38 #include <sys/types.h>
39 #include "libadm.h"
41 static char *choices[] = { "y", "n", NULL };
42 static char *vchoices[] = { "y", "n", "yes", "no", NULL };
44 #define TMPSIZ 7
45 #define REQMSG "Input is required."
46 #define ERRMSG "Please enter yes or no."
47 #define HLPMSG \
48 "To respond in the affirmative, enter y, yes, Y, or YES. \
49 To respond in the negative, enter n, no, N, or NO."
51 int
52 ckyorn_val(char *str)
54 int i;
55 char *pt,
56 temp[TMPSIZ+1];
58 for (pt = temp, i = 0; *str && i < TMPSIZ; i++) {
59 *pt++ = tolower((unsigned char)*str++);
61 *pt = '\0';
62 for (i = 0; vchoices[i]; ) {
63 if (strcmp(temp, vchoices[i++]) == 0)
64 return (0);
66 return (-1);
69 void
70 ckyorn_err(char *error)
72 puterror(stdout, ERRMSG, error);
75 void
76 ckyorn_hlp(char *help)
78 puthelp(stdout, HLPMSG, help);
81 int
82 ckyorn(char *yorn, char *defstr, char *error, char *help, char *prompt)
84 int n;
85 char input[MAX_INPUT];
87 if (!prompt)
88 prompt = "Yes or No";
89 start:
90 putprmpt(stderr, prompt, choices, defstr);
91 if (getinput(input))
92 return (1);
94 n = (int)strlen(input);
95 if (n == 0) {
96 if (defstr) {
97 (void) strcpy(yorn, defstr);
98 return (0);
100 puterror(stderr, REQMSG, error);
101 goto start;
103 if (strcmp(input, "?") == 0) {
104 puthelp(stderr, HLPMSG, help);
105 goto start;
107 if (ckquit && (strcmp(input, "q") == 0))
108 return (3);
110 if (ckyorn_val(input)) {
111 puterror(stderr, ERRMSG, error);
112 goto start;
114 (void) strcpy(yorn, input);
115 return (0);