home *** CD-ROM | disk | FTP | other *** search
- {
- procedure and functions in this library
-
- WriteStr write message out at (Col,Line)
- Error writes message out at (1,1), waits for character
- GetChar prompt user for one of a set of characters
- Yes asks user questions, waits for a Y/N answer
- GetInteger prompt user for an integer value in the range Min..Max
- GrabInt function version of GetInteger; used for subrange vars
- WriteReal write real value w/adjustable format
- GetReal prompt user for a real value in the range Min..Max
- GetString prompt user for a string
- IOCheck checks for I/O error; prints message if necessary
-
- }
-
- type
- msgstr = string[80];
- charset = set of char;
-
- var
- ioerr : boolean;
- iocode : integer;
-
- procedure writestr(col,line : integer; tstr : msgstr);
- {
- purpose writes message out at spot indicated
- last update 23 Jun 85
- }
- begin
- gotoxy(col,line); clreol;
- write(tstr)
- end; { of proc WriteStr }
-
- procedure error(msg : msgstr);
- {
- purpose writes error message out at (1,1); waits for character
- last update 05 Jul 85
- }
- const
- bell = ^g;
- var
- ch : char;
- begin
- writestr(1,1,msg+bell+' (hit any key) ');
- read(kbd,ch)
- end; { of proc Error }
-
- procedure getchar(var ch : char; prompt : msgstr; okset : charset);
- {
- purpose let user enter command
- last update 23 Jun 85
- }
- begin
- writestr(1,1,prompt);
- repeat
- read(kbd,ch);
- ch := upcase(ch)
- until ch in okset;
- writeln(ch)
- end; { of proc GetChar }
-
- function yes(question : msgstr) : boolean;
- {
- purpose asks user Y/N question
- last update 03 Jul 85
- }
- var
- ch : char;
- begin
- getchar(ch,question+' (Y/N) ',['Y','N']);
- yes := (ch = 'Y')
- end; { of func Yes }
-
- function grabint(prompt : msgstr; min,max : integer) : integer;
- {
- purpose prompts user for value in range Min..Max
- note you may not be able to pass subrange variables to
- GetInteger because of the difference in size. In
- such cases, you can use GrabInt and directly assign
- the returned value to the subrange variable.
- last update 05 Jul 85
- }
- var
- val : integer;
- begin
- {$I-}
- if min > max then begin
- val := min;
- min := max;
- max := val
- end;
- repeat
- writestr(1,1,prompt);
- write(' [',min,'..',max,']: ');
- readln(val)
- until (ioresult = 0) and (min <= val) and (val <= max);
- grabint := val
- {$I+}
- end; { of proc GetInteger }
-
- procedure getinteger(var val : integer; prompt : msgstr; min,max : integer);
- {
- purpose prompts user for value in range Min..Max
- last update 22 June 1985
- }
- begin
- val := grabint(prompt,min,max)
- end; { of proc GetInteger }
-
- procedure writereal(rval : real; width,digits : byte);
- {
- purpose decide which format to use based on magnitude
- last update 10 Jul 85
- }
- const
- ln10 = 2.302585093;
- var
- tval : real;
- limit,log : integer;
-
- procedure condition(min : byte; var val :byte; max : byte);
- begin
- if val < min
- then val := min
- else if val > max
- then val := max
- end; { of local proc Condition }
-
- begin
- condition(8,width,80);
- condition(0,digits,width-3);
- tval := abs(rval);
- limit := (width-digits) - 1;
- if rval < 0.0
- then limit:= limit - 1;
- if tval = 0.0
- then log := 0
- else log := round(ln(tval)/ln10);
- if (log < -digits) or (log >= limit)
- then write(rval:width)
- else write(rval:width:digits)
- end; { of proc WriteReal }
-
- procedure getreal(var val : real; prompt : msgstr; min,max : real);
- {
- purpose prompts user for value in range Min..Max
- last update 23 June 85
- }
- begin
- {$I-}
- repeat
- writestr(1,1,prompt+' [');
- writereal(min,8,4); write('..'); writereal(max,8,4);
- write(']: '); readln(val);
- until (ioresult = 0) and (min <= val) and (val <= max)
- {$I+}
- end; { of proc GetReal }
-
- procedure getstring(var nstr : msgstr; prompt : msgstr; maxlen : integer;
- okset : charset);
- {
- purpose get string from user
- last update 09 Jul 85
- }
- const
- bs = ^h;
- cr = ^m;
- conset : charset = [bs,cr];
- var
- tstr : msgstr;
- tlen,x : integer;
- ch : char;
- begin
- {$I-} { turn off I/O checking }
- tstr := '';
- tlen := 0;
- writestr(1,1,prompt);
- x := 1 + length(prompt);
- okset := okset + conset;
- repeat
- gotoxy(x,1);
- repeat
- read(kbd,ch)
- until ch in okset;
- if ch = bs then begin
- if tlen > 0 then begin
- tlen := tlen - 1;
- x := x - 1;
- gotoxy(x,1); write(' ');
- end
- end
- else if (ch <> cr) and (tlen < maxlen) then begin
- write(ch);
- tlen := tlen + 1;
- tstr[tlen] := ch;
- x := x + 1;
- end
- until ch = cr;
- if tlen > 0 then begin
- tstr[0] := chr(tlen);
- nstr := tstr
- end
- else write(nstr)
- {$I+}
- end; { of proc GetString }
-
- procedure iocheck;
- {
- purpose check for IO error; print message if needed
- last update 08 Jul 85
- }
- var
- tstr : string[4];
- begin
- iocode := ioresult;
- ioerr := (iocode <> 0);
- if ioerr then case iocode of
- $01 : error('IOERROR> File does not exist');
- $02 : error('IOERROR> File not open for input');
- $03 : error('IOERROR> File not open for output');
- $04 : error('IOERROR> File not open');
- $10 : error('IOERROR> Error in numeric format');
- $20 : error('IOERROR> Operation not allowed on logical device');
- $21 : error('IOERROR> Not allowed in direct mode');
- $22 : error('IOERROR> Assign to standard files not allowed');
- $90 : error('IOERROR> Record length mismatch');
- $91 : error('IOERROR> Seek beyond end of file');
- $99 : error('IOERROR> Unexpected end of file');
- $f0 : error('IOERROR> Disk write error');
- $f1 : error('IOERROR> Directory is full');
- $f2 : error('IOERROR> File size overflow');
- $ff : error('IOERROR> File disappeared')
- else str(iocode:3,tstr);
- error('IOERROR> Unknown I/O error: '+tstr)
- end
- end; { of proc IOCheck }
-