-
Notifications
You must be signed in to change notification settings - Fork 0
/
FILESORT.PAS
239 lines (219 loc) · 5.81 KB
/
FILESORT.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
{$I DIRECT.INC}
Unit FileSort;
{/ file sort routines /}
Interface
Uses GenTypes;
Procedure SortArea;
Implementation
Uses Dos, Crt, GenSubs, Windows, Subs1, Subs2, File0, File1, FileLock;
Procedure SortArea;
VAR A,Mark:Integer;
k:Char;
DoAll:Boolean;
Const BeenAborted : Boolean = False;
Function Aborted : Boolean;
Begin
If BeenAborted Then Begin
Aborted := True;
Exit
End;
Aborted := XPressed Or Hungupon;
If XPressed Then Begin
Beenaborted := True;
SendCr(^B'Newscan Aborted..')
End
End;
procedure filesizesort(Left,Right:integer);
label
Again;
var
Pivot:integer;
P,Q:integer;
tp1,tp2,tp3,tp4:udrec;
begin
P:=Left;
Q:=Right;
Pivot:=(Left+Right) div 2;
GoXy(44,5);
SendFull(^S+Strr(pivot)+' ');
Seek(udfile,pivot);
nRead(udfile,tp1);
While P<=Q do
begin
Seek(udfile,p);
nRead(udfile,tp2);
while tp2.filesize<tp1.filesize do begin
inc(p);
Seek(udfile,p);
nRead(udfile,tp2);
end;
Seek(udfile,q);
nRead(udfile,tp3);
while tp1.filesize<tp3.filesize do begin
dec(Q);
Seek(udfile,q);
nRead(udfile,tp3);
end;
if P>Q then goto Again;
tp4:=tp3;
tp3:=tp2;
tp2:=tp4;
Seek(udfile,p);
nWrite(udfile,tp2);
Seek(udfile,q);
nWrite(udfile,tp3);
inc(P);
dec(Q);
end;
Again:
if Left<Q then filesizesort(left,Q);
if P<Right then filesizesort(P,Right);
end;
Procedure filenamesort(Left,Right:integer);
label
Again;
var
Pivot:integer;
P,Q:integer;
tp1,tp2,tp3,tp4:udrec;
begin
P:=Left;
Q:=Right;
Pivot:=(Left+Right) div 2;
GoXy(44,5);
SendFull(^S+Strr(pivot)+' ');
Seek(udfile,pivot);
nRead(udfile,tp1);
while P<=Q do
begin
Seek(udfile,p);
nRead(udfile,tp2);
While (UpString(tp2.filename)<(UpString(tp1.filename))) Do Begin
inc(p);
Seek(udfile,p);
nRead(udfile,tp2);
end;
Seek(udfile,q);
nRead(udfile,tp3);
while (UpString(tp1.filename)<(UpString(tp3.filename))) do begin
dec(Q);
Seek(udfile,q);
nRead(udfile,tp3);
end;
if P>Q then goto Again;
tp4 := tp3;
tp3 := tp2;
tp2:=tp4;
Seek(udfile,p);
nWrite(udfile,tp2);
Seek(udfile,q);
nWrite(udfile,tp3);
inc(P);
dec(Q);
end;
Again:
if Left<Q then filenamesort(left,Q);
if P<Right then filenamesort(P,Right);
end;
procedure filedatesort(Left,Right:integer);
label
Again;
var
Pivot:integer;
P,Q:integer;
tp1,tp2,tp3,tp4:udrec;
begin
P:=Left;
Q:=Right;
Pivot:=(Left+Right) div 2;
GoXy(44,5);
SendFull(^S+Strr(pivot)+' ');
Seek(udfile,pivot);
nRead(udfile,tp1);
while P<=Q do
begin
Seek(udfile,p);
nRead(udfile,tp2);
while tp2.when<tp1.when do begin
inc(p);
Seek(udfile,p);
nRead(udfile,tp2);
end;
Seek(udfile,q);
nRead(udfile,tp3);
while tp1.when<tp3.when do Begin
dec(Q);
Seek(udfile,q);
nRead(udfile,tp3);
end;
if P>Q then goto Again;
tp4:=tp3;
tp3:=tp2;
tp2:=tp4;
Seek(udfile,p);
nWrite(udfile,tp2);
Seek(udfile,q);
nWrite(udfile,tp3);
inc(P);
dec(Q);
end;
Again:
if Left<Q then filenamesort(left,Q);
if P<Right then filenamesort(P,Right);
end;
Procedure DoSort;
Begin
Mark := NumUDS-1;
If Mark > 0 Then
Begin
GoXy(1,1);
SendCr (#27'[27C'^R^S'ÕÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͸');
SendCr (#27'[27C³ '^S'PiPELiNE File Sorter '^S'³');
SendFull(#27'[27C³ '^P'Area'^O': '^A);
Tab(Copy(area.name,1,22),22);
SendCr(^S'³');
SendFull(#27'[27C³ '^P'Sorting Method'^O': '^A);
Case K of
'F':Tab('By Name',12);
'D':Tab('By Date',12);
'S':Tab('By Size',12);
End;
SendCr(^S'³');
SendCr (#27'[27C³ '^P'Current File #'^O': '^S'³');
SendFull(#27'[27C³ '^P'Total Files'^O': '^A);
Tab(Strr(NumUds),15);
SendCr(^S'³');
SendCr (#27'[27CÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ;');
Case K of
'F':filenamesort(0,Mark);
'D':filedatesort(0,Mark);
'S':filesizesort(0,Mark);
End
End
End;
Begin
Writehdr('File Sorting...');
DoAll:=False;
WriteStr(^R'Sort All Areas? !');
DoALL := Yes;
Inpt[0] := #0;
writestr(^R'Sort By ['^S'F'^R']ilename ['^S'D'^R']ate'+
' ['^S'S'^R']ize ['^S'Q'^R']uits :*');
K := Upcase(inpt[1]);
If K=''
Then K:='Q';
If K='Q'
Then Exit;
writelog(16,6,'');
AnsiCls;
If DoALL Then
For a:=1 To numareas Do Begin
setarea(a,false);
DoSort;
If aborted Then exit
End Else DOSort;
SendCr(^M^M);
WriteHDR('Sort Complete');
End;
begin
end.