forked from jr8ppg/MorseRunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calls.pas
129 lines (105 loc) · 2.5 KB
/
Calls.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
unit Calls;
interface
uses
SysUtils, Windows, Classes,
Generics.Collections, Generics.Defaults;
type
TCall = class(TObject)
Callsign: string;
Number: string;
public
constructor Create();
end;
TCallList = class(TObjectList<TCall>)
public
constructor Create(OwnsObjects: Boolean = True);
procedure LoadFromFile(filename: string);
procedure LoadFromMaster();
end;
implementation
constructor TCall.Create();
begin
Callsign := '';
Number := '';
end;
constructor TCallList.Create(OwnsObjects: Boolean);
begin
Inherited Create(OwnsObjects);
end;
procedure TCallList.LoadFromFile(filename: string);
var
i: Integer;
slFile: TStringList;
slLine: TStringList;
O: TCall;
begin
slFile := TStringList.Create();
slLine := TStringList.Create();
slLine.Delimiter := #09;
slLine.StrictDelimiter := True;
try
Clear();
filename := ExtractFilePath(ParamStr(0)) + filename;
slFile.LoadFromFile(filename);
slFile.Sort();
for i := 0 to slFile.Count - 1 do begin
slLine.DelimitedText := slFile[i];
O := TCall.Create();
O.Callsign := slLine[0];
O.Number := slLine[1];
Add(O);
end;
finally
slFile.Free();
slLIne.Free();
end;
end;
procedure TCallList.LoadFromMaster();
const
Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/';
CHRCOUNT = Length(Chars);
INDEXSIZE = Sqr(CHRCOUNT) + 1;
INDEXBYTES = INDEXSIZE * SizeOf(Integer);
var
i: integer;
FileName: string;
FFileSize: integer;
FIndex: array[0..INDEXSIZE-1] of integer;
Data: AnsiString;
CL: TStringList;
S: string;
O: TCall;
begin
Clear;
FileName := ExtractFilePath(ParamStr(0)) + 'Master.dta';
if not FileExists(FileName) then Exit;
with TFileStream.Create(FileName, fmOpenRead) do
try
FFileSize := Size;
if FFileSize < INDEXBYTES then Exit;
ReadBuffer(FIndex, INDEXBYTES);
if (FIndex[0] <> INDEXBYTES) or (FIndex[INDEXSIZE-1] <> FFileSize)
then Exit;
SetLength(Data, Size - Position);
ReadBuffer(Data[1], Length(Data));
finally
Free;
end;
S := StringReplace(string(Data), #00, #09, [rfReplaceAll]);
CL := TStringList.Create();
try
CL.Delimiter := #09;
CL.StrictDelimiter := True;
CL.DelimitedText := S;
CL.Sort();
for i := 0 to CL.Count - 1 do begin
S := CL[i];
O := TCall.Create();
O.Callsign := S;
Add(O);
end;
finally
CL.Free();
end;
end;
end.