-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDISKOP.PAS
280 lines (248 loc) · 5.44 KB
/
DISKOP.PAS
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
Unit diskop;
{$X+}{$a+}
INTERFACE
uses dos,tmaths,ttypes;
const
maxbuff=20000;
type
fragtype=(D,P,N,E);
bufferedblock=object
f:file;
fsize:longint;
blockpos,blocksize,blockmax:word;
buffer,bufferpos:^byte;
eof:boolean;
function open(filename:string):boolean;
function fpos:longint;
procedure fseek(pos:longint);
procedure fskip(pos:longint);
procedure blockread(buf:byteptr;count:word);
function get:byte;
procedure close;
end;
Function cd(path:string):string;
Function fragname(path:string;frag:fragtype):string;
Function gtdir:string;
Function numoffiles(path,filter:string;attrfilter:word):integer;
Function NumOfDrives:byte;
Function CurrentDrive:byte;
Function Truncatepath(path:string):string;
Function fexist(path:string):boolean;
Function Pexist(path:string):boolean;
Function instring(name:string;testchar:char):boolean;
{Function readkey:char;
Function keypressed:boolean;}
IMPLEMENTATION
Function CurrentDrive:byte;assembler;
asm
mov ah,19h
int 21h
end;
function NumOfDrives:byte;assembler;
asm
mov ah,19h {get current disk handle}
int 21
mov dl,ah {load this into next function}
mov ah,0Eh
int 21h {call interrupt}
end;
function bufferedblock.open(filename:string):boolean;
var maxavailable:longint;
var recsize:word;
begin
if (not fexist(filename)) then begin open:=false;exit;end;
recsize:=1;
assign(f,filename);
reset(f,recsize);
fsize:=filesize(f);
maxavailable:=maxavail;
{keep within 16bit range}
if maxavailable>maxbuff then maxavailable:=maxbuff;
{if filesize is smaller, fine}
blocksize:=smaller(maxavailable,fsize);
getmem(buffer,blocksize);
bufferpos:=buffer;
blockmax:=blocksize;
blockpos:=blockmax;
eof:=false;
open:=true;
end;
function bufferedblock.get;
var recsize:word;
begin
recsize:=1;
{if end of block and not end of file....}
if (fsize>1)and(not eof) then begin
if blockpos=blockmax then begin
blockmax:=smaller(fsize,blocksize);
system.blockread(f,buffer^,blockmax,recsize);
blockpos:=1;
bufferpos:=buffer;
end else begin
inc(blockpos);
inc(bufferpos);
end;
dec(fsize);
get:=bufferpos^;
end else begin
{end of file, set flag and exit}
get:=0;
eof:=true;
end;
{writeln(eof);}
end;
procedure bufferedblock.close;
begin
freemem(buffer,blocksize);
system.close(f);
end;
function bufferedblock.fpos:longint;
begin
fpos:=filepos(f)+blockpos-blockmax-1;
end;
procedure bufferedblock.blockread(buf:byteptr;count:word);
var lop:word;
begin
for lop:=1 to count do begin
buf^:=get;
inc(buf)
end;
end;
procedure bufferedblock.fseek(pos:longint);
var lop:longint;
recsize:word;
begin
recsize:=1;
Seek(f,pos);
fsize:=filesize(f)-pos;
blockmax:=smaller(fsize,blocksize);
blockpos:=blockmax;
bufferpos:=buffer;
eof:=false;
end;
procedure bufferedblock.fskip(pos:longint);
begin
fseek(filepos(f)+blockpos-blockmax-1+pos);
end;
{Function readkey:char;
var out:char;
Begin
asm
mov ah,0
int 16h
mov out,al
cmp al,0
jnz @end
mov out,ah
@end:
end;
readkey:=out;
end;
Function keypressed:boolean;
Begin
keypressed:=port[$60]<>0;
end;}
Function fexist(path:string):boolean;
var f:file;
Begin
(*{$I-}
Assign(f,path);
reset(f);
close(f);
{$I+}
FExist := (IOResult = 0);*)
Fexist:=(fsearch(path,'')<>'');
end;
Function Pexist(path:string):boolean;
var dirinfo:searchrec;
Begin
{$I-}
FindFirst(path+'*.*', anyfile, DirInfo);
{$I+}
PExist := (IOResult = 0) and (path <> '');
end;
Function cd(path:string):string;
Begin
if (copy(path,length(path),1)='\') and (length(path)<>3) then
path:=copy(path,1,length(path)-1);
{$I-};
chdir(path);
{$I+};
if ioresult=0 then path:=gtdir
else path:='nil';
cd:=path;
end;
Function gtdir:string;
var temp:string;
Begin
getdir(0,temp);
if temp[length(temp)]<>'\' then
temp:=temp+'\';
gtdir:=temp;
end;
Function Truncatepath(path:string):string;
Var lop:byte;
Temp:string;
Begin
lop:=Length(path);
Path:=copy(path,1,length(path)-1);
While (path[lop]<>'\') and (lop>0) do
dec(lop);
truncatepath:=copy(path,1,lop);
End;
Function fragname(path:string;frag:fragtype):string;
Var Dir: DirStr;Name: NameStr;Ext: ExtStr;
Begin
fsplit(path,dir,name,ext);
case frag of
d:fragname:=copy(dir,1,3);
p:fragname:=dir;
n:fragname:=name;
e:fragname:=ext
end;
end;
Function instring(name:string;testchar:char):boolean;
var lop:byte;out:boolean;
Begin
out:=false;lop:=1;
while (lop<=length(name))and(out=false) do begin
out:=name[lop]=testchar;
inc(lop);
end;
instring:=out;
end;
Function numoffiles(path,filter:string;attrfilter:word):integer;
var count:word;dirinfo:searchrec;
Begin
count:=0;
FindFirst(path+filter, attrfilter, DirInfo);
while DosError=0 do
begin
if (dirinfo.attr=attrfilter)or((attrfilter=anyfile)and(dirinfo.attr
<>directory){and(DirInfo.Name<>'.')and(DirInfo.Name<>'..')}) then
inc(count);
FindNext(DirInfo);
end;
numoffiles:=count;
end;
{Procedure inputdrives(var disks:menutype);
Var lop,count:byte;
Begin
count:=0;
For lop:=0 to 25 do
if disksize(lop)<>-1 then inc(count);
with disks do
Begin
maxopts:=count;maxylen:=4;
getmem(attrib,1+maxopts);getmem(info,(1+maxopts)*21);
count:=0;
For lop:=0 to 25 do
if disksize(lop)<>-1 then
Begin
disks.info^[count]:='Drive '+chr(65+count);
disks.attrib^[count]:=0;
inc(count);
end;
end;
end;}
End.