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 (c) 1997, by Sun Microsystems, Inc.
28 * All rights reserved.
31 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3 */
38 #include <sys/types.h>
42 #define PROMPT10 "Enter an integer between %ld and %ld"
43 #define PROMPT "Enter a base %d integer between %ld and %ld"
44 #define MESG10 "Please enter an integer between %ld and %ld."
45 #define MESG "Please enter a base %d integer between %ld and %ld."
48 setmsg(char *msg
, long lower
, long upper
, int base
)
50 if ((base
== 10) || (base
== 0))
51 (void) sprintf(msg
, MESG10
, lower
, upper
);
53 (void) sprintf(msg
, MESG
, base
, lower
, upper
);
57 ckrange_err(long lower
, long upper
, int base
, char *error
)
61 setmsg(defmesg
, lower
, upper
, base
);
62 puterror(stdout
, defmesg
, error
);
66 ckrange_hlp(long lower
, long upper
, int base
, char *help
)
70 setmsg(defmesg
, lower
, upper
, base
);
71 puthelp(stdout
, defmesg
, help
);
75 ckrange_val(long lower
, long upper
, int base
, char *input
)
80 value
= strtol(input
, &ptr
, base
);
81 if ((*ptr
!= '\0') || (value
< lower
) || (value
> upper
))
87 ckrange(long *rngval
, long lower
, long upper
, short base
, char *defstr
,
88 char *error
, char *help
, char *prompt
)
93 char input
[MAX_INPUT
];
102 (void) sprintf(buffer
, "%ld-%ld", lower
, upper
);
109 (void) sprintf(defpmpt
, PROMPT10
, lower
, upper
);
111 (void) sprintf(defpmpt
, PROMPT
, base
, lower
, upper
);
115 setmsg(defmesg
, lower
, upper
, base
);
120 putprmpt(stderr
, prompt
, choices
, defstr
);
124 n
= (int)strlen(input
);
127 *rngval
= strtol(defstr
, NULL
, base
);
130 puterror(stderr
, defmesg
, error
);
133 if (strcmp(input
, "?") == 0) {
134 puthelp(stderr
, defmesg
, help
);
137 if (ckquit
&& (strcmp(input
, "q") == 0))
140 value
= strtol(input
, &ptr
, base
);
142 valid
= ((value
>= lower
) && (value
<= upper
));
146 puterror(stderr
, defmesg
, error
);