This repository was archived by the owner on Oct 11, 2022. It is now read-only.
forked from nickelsworth/swag
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0074.pas
More file actions
73 lines (67 loc) · 1.56 KB
/
Copy path0074.pas
File metadata and controls
73 lines (67 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
{
Here is a routine I used. It forces entry of a proper filename,
not quite what you're looking for, but close:
}
uses
Crt;
const
OKFNameChars = ['A'..'Z','a'..'z','0'..'9','$','%','''',
'-','@','{','}','~','`','!','#','(',')','&'];
procedure Backspace;
begin
gotoxy(wherex-1,1);write(' ');gotoxy(wherex-1,1);
end;
function GetFileName(Prompt : string) : string;
var
OKCharSet : set of char;
ch : char;
Done : boolean;
Name : string;
len : byte absolute Name;
begin
OKCharSet := OKFNameChars + ['.',#8,#13,#27];
write(Prompt);
Done := false;
Name := '';
repeat
repeat
ch := upcase(readkey);
until (ch in OKCharSet);
case ch of
#8 : if len > 0 then begin
Backspace;
dec(len);
end;
#13 : Done := true;
#27 : begin
while len > 0 do begin
Backspace;
dec(len);
end;
Done := true;
end;
'.' : if (len > 0)
and (pos('.',Name) = 0) then begin
write('.');
Name := Name + '.';
end;
else if ((pos('.',Name) = 0) and (len < 8))
or (len - pos('.',Name) < 3) then begin
Name := Name + ch;
write(ch);
end;
end; { case }
until Done;
writeln;
GetFileName := Name;
end;
{ test follows }
var
fname : string;
begin
clrscr;
repeat
fname := GetFileName('Enter file name: ');
until fname = '';
end.