dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libadm / common / ckint.c
blobe7121b3b025305b1c1ac52546b267af3f000eeed
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 /*LINTLIBRARY*/
32 #pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3 */
34 #include <stdio.h>
35 #include <string.h>
36 #include <stdlib.h>
37 #include <limits.h>
38 #include <sys/types.h>
39 #include "libadm.h"
41 static void
42 setmsg(char *msg, short base)
44 if ((base == 0) || (base == 10))
45 (void) sprintf(msg, "Please enter an integer.");
46 else
47 (void) sprintf(msg, "Please enter a base %d integer.", base);
50 static void
51 setprmpt(char *prmpt, short base)
53 if ((base == 0) || (base == 10))
54 (void) sprintf(prmpt, "Enter an integer.");
55 else
56 (void) sprintf(prmpt, "Enter a base %d integer.", base);
59 int
60 ckint_val(char *value, short base)
62 char *ptr;
64 (void) strtol(value, &ptr, (int)base);
65 if (*ptr == '\0')
66 return (0);
67 return (1);
70 void
71 ckint_err(short base, char *error)
73 char defmesg[64];
75 setmsg(defmesg, base);
76 puterror(stdout, defmesg, error);
79 void
80 ckint_hlp(short base, char *help)
82 char defmesg[64];
84 setmsg(defmesg, base);
85 puthelp(stdout, defmesg, help);
88 int
89 ckint(long *intval, short base, char *defstr, char *error, char *help,
90 char *prompt)
92 long value;
93 char *ptr,
94 input[MAX_INPUT],
95 defmesg[64],
96 temp[64];
98 if (!prompt) {
99 setprmpt(temp, base);
100 prompt = temp;
102 setmsg(defmesg, base);
104 start:
105 putprmpt(stderr, prompt, NULL, defstr);
106 if (getinput(input))
107 return (1);
109 if (strlen(input) == 0) {
110 if (defstr) {
111 *intval = strtol(defstr, NULL, (int)base);
112 return (0);
114 puterror(stderr, defmesg, error);
115 goto start;
116 } else if (strcmp(input, "?") == 0) {
117 puthelp(stderr, defmesg, help);
118 goto start;
119 } else if (ckquit && (strcmp(input, "q") == 0))
120 return (3);
122 value = strtol(input, &ptr, (int)base);
123 if (*ptr != '\0') {
124 puterror(stderr, defmesg, error);
125 goto start;
127 *intval = value;
128 return (0);