home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Frostbyte's 1980s DOS Shareware Collection
/
floppyshareware.zip
/
floppyshareware
/
USCX
/
TURBO-06.ZIP
/
TOOLKIT.INC
< prev
next >
Wrap
Text File
|
1985-02-23
|
5KB
|
173 lines
{
TOOLKIT Pascal functions and procedures for interactive programs
Copyright (c) 1983 by Ronald Florence
RDREAL: reads a real number in decimal notation
RDINT: reads an integer between low and high limits
RDCHAR: reads a char in a declared set
YES: reads a y/n response
NOMORE: prompts "More?" and reads a response
PAUSE: waits until any key is pressed to continue
The functions are used to speed up interactive input and to prevent
"Data error in file USER" crashes. In a "repeat...until" loop, RDINT
and RDREAL repeat a prompt line and sound a bell until a suitable
response is entered. For example:
repeat
write ('Enter a number between 1 and 10: ');
until rdint (number, 1, 10);
RDCHAR, YES, NOMORE and PAUSE are "inkey" functions which do not
require the return key.
For compact code store each function as a separate file to be called
with a $INCLUDE metacommand. Remember to include CHARSET: SET of CHAR
as a type declaration in any program which uses RDCHAR.
}
function RDREAL (var r: real): boolean;
const
bell = chr (7);
var
decimal, left, right: real;
neg: boolean;
begin
left:= 0;
decimal:= 1;
right:= 0;
neg:= false;
while not eoln and not (input^ in [chr(33)..chr(255)]) do get (input);
neg:= input^ = chr(45);
if neg then get (input);
rdreal:= input^ in ['0'..'9'];
while input^ in ['0'..'9'] do begin;
left:= left * 10 + ord (input^) - ord ('0');
get (input);
end;
if input^ = chr(46) then begin
get (input);
while input^ in ['0'..'9'] do begin
right:= right + decimal * (ord (input^) - ord ('0')) / 10;
decimal:= decimal / 10;
get (input);
end;
end;
r:= left + right;
if neg then r:= - r;
if input^ in [chr(33)..chr(44), chr(47), chr(58)..chr(255)] then begin
rdreal:= false;
write (bell);
end;
readln;
end;
function RDINT (var i:integer; low,high:integer): boolean;
const
bell = chr (7);
var
neg: boolean;
begin
i:= 0;
neg:= false;
while not eoln and not (input^ in [chr(33)..chr(255)]) do get (input);
neg:= input^ = chr(45);
if neg then get (input);
while input^ in ['0'..'9'] do begin
i:= i * 10 + ord (input^) - ord ('0');
get (input);
end;
if neg then i:= - i;
if (input^ in [chr(33)..chr(44), chr(46), chr(47), chr(58)..chr(255)]) or
(eoln and ((i < low) or (i > high))) then begin
rdint:= false;
write (bell);
end
else rdint:= (i >= low) and (i <= high);
readln;
end;
function RDCHAR (okchars: charset): char;
var f, g: file of char;
c: char;
function inkey: char;
begin
repeat get (f) until f^ <> chr (0);
inkey:= f^;
end;
begin
assign (f, 'user');
reset (f);
assign (g, 'user');
rewrite (g);
repeat
c:= inkey;
if not (c in okchars) then if c in ['A'..'Z'] then
c:= chr (ord(c) - ord('A') + ord('a'))
else if c in ['a'..'z'] then c:= chr (ord(c) - ord('a') + ord('A'));
until c in okchars;
write (g, c);
writeln;
rdchar:= c;
end;
function YES: boolean;
var f, g: file of char;
c: char;
function inkey: char;
begin
repeat get (f) until f^ <> chr (0);
inkey:= f^;
end;
begin
assign (f, 'user');
reset (f);
assign (g, 'user');
rewrite (g);
repeat c:= inkey until c in ['y','Y','n','N'];
write (g,c);
writeln;
yes:= c in ['y', 'Y'];
end;
function NOMORE: boolean;
var f, g: file of char;
c: char;
function inkey: char;
begin
repeat get (f) until f^ <> chr (0);
inkey:= f^;
end;
begin
write ('More? ');
assign (f, 'user');
reset (f);
assign (g, 'user');
rewrite (g);
repeat c:= inkey until c in ['y','Y','n','N'];
write (g, c);
writeln;
nomore:= c in ['n', 'N']
end;
procedure PAUSE;
var f: file of char;
begin
assign (f, 'user');
reset (f);
write ('Press any key to continue...');
repeat get (f) until f^ <> chr (0);
writeln;
end;