2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 /* @(#)io.c 1.19 98/10/10 Copyright 1988 J. Schilling */
15 * Copyright (c) 1988 J. Schilling
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License version 2
20 * as published by the Free Software Foundation.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License along with
28 * this program; see the file COPYING. If not, write to the Free Software
29 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
46 static char *skipwhite(const char *);
47 static void prt_std(char *, long, long, long, struct disk *);
48 BOOL cvt_std(char *, long *, long, long, struct disk *);
49 extern BOOL getvalue(char *, long *, long, long,
50 void (*)(char *, long, long, long, struct disk *),
51 BOOL (*)(char *, long *, long, long, struct disk *),
53 extern BOOL getlong(char *, long *, long, long);
54 extern BOOL getint(char *, int *, int, int);
55 extern BOOL yes(char *, ...);
58 char *skipwhite(const char *s)
60 register const Uchar *p = (const Uchar *)s;
73 cvt_std(char *linep, long *lp, long mini, long maxi, struct disk *dp)
77 /* printf("cvt_std(\"%s\", %d, %d, %d);\n", linep, *lp, mini, maxi);*/
79 if (linep[0] == '?') {
80 printf("Enter a number in the range from %ld to %ld\n",
82 printf("The default radix is 10\n");
83 printf("Precede number with '0x' for hexadecimal or with '0' for octal\n");
84 printf("Shorthands are:\n");
85 printf("\t'^' for minimum value (%ld)\n", mini);
86 printf("\t'$' for maximum value (%ld)\n", maxi);
87 printf("\t'+' for incrementing value to %ld\n", *lp + 1);
88 printf("\t'-' for decrementing value to %ld\n", *lp - 1);
91 if (linep[0] == '^' && *skipwhite(&linep[1]) == '\0') {
93 } else if (linep[0] == '$' && *skipwhite(&linep[1]) == '\0') {
95 } else if (linep[0] == '+' && *skipwhite(&linep[1]) == '\0') {
98 } else if (linep[0] == '-' && *skipwhite(&linep[1]) == '\0') {
101 } else if (*astol(linep, &l)) {
102 printf("Not a number: '%s'.\n", linep);
105 if (l < mini || l > maxi) {
106 printf("'%s' is out of range.\n", linep);
115 prt_std(char *s, long l, long mini, long maxi, struct disk *dp)
117 printf("%s %ld (%ld - %ld)/<cr>:", s, l, mini, maxi);
121 BOOL getvalue(char *s, long *lp, long mini, long maxi,
122 void (*prt)(char *, long, long, long, struct disk *),
123 BOOL (*cvt)(char *, long *, long, long, struct disk *),
130 (*prt)(s, *lp, mini, maxi, dp);
133 if (rols_getline(line, 80) == EOF)
136 linep = skipwhite(line);
138 * Nicht initialisierte Variablen
139 * duerfen nicht uebernommen werden
141 if (linep[0] == '\0' && *lp != -1L)
144 if (strlen(linep) == 0) {
147 } else if ((*cvt)(linep, lp, mini, maxi, dp))
154 BOOL getlong(char *s, long *lp, long mini, long maxi)
156 return (getvalue(s, lp, mini, maxi, prt_std, cvt_std, (void *)0));
160 BOOL getint(char *s, int *ip, int mini, int maxi)
165 ret = getlong(s, &l, (long)mini, (long)maxi);
171 BOOL yes(char *form, ...)
177 va_start(args, form);
181 if (rols_getline(okbuf, sizeof(okbuf)) == EOF)
183 if (okbuf[0] == '?') {
184 printf("Enter 'y', 'Y', 'yes' or 'YES' if you agree with the previous asked question.\n");
185 printf("All other input will be handled as if the question has beed answered with 'no'.\n");
188 if(streql(okbuf, "y") || streql(okbuf, "yes") ||
189 streql(okbuf, "Y") || streql(okbuf, "YES"))