Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor - rename ARRLRec to TDXCCRec; ARRLDX to gDXCCList. #93

Merged
merged 1 commit into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions ARRL.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
interface

uses
SysUtils, Classes, Contnrs, PerlRegEx, pcre;
Classes;

type
TARRLRec= class
TDXCCRec= class
public
prefixReg: string;
Entity: string;
Expand All @@ -16,49 +16,49 @@ TARRLRec= class
function GetString: string;
end;

TARRL= class
TDXCC= class
private
ARRLList: TList;
procedure LoadARRL;
DXCCList: TList;
procedure LoadDxCCList;
procedure Delimit(var AStringList: TStringList; const AText: string);
function SearchPrefix(out index : integer; const ACallPrefix : string) : Boolean;
public
constructor Create;
function FindRec(out dxrec : TARRLRec; const ACallsign : string) : Boolean;
function FindRec(out dxrec : TDXCCRec; const ACallsign : string) : Boolean;
function GetStationInfo(const ACallsign: string): string;
function Search(ACallsign: string): string;
end;

var
ARRLDX: TARRL;
gDXCCList: TDXCC;

implementation

uses
log;
SysUtils, Contnrs, log, PerlRegEx, pcre;

procedure TARRL.LoadARRL;
procedure TDXCC.LoadDxCCList;
var
slst, tl: TStringList;
i: integer;
AR: TARRLRec;
AR: TDXCCRec;
begin
slst:= TStringList.Create;
tl:= TStringList.Create;
try
ARRLList:= TList.Create;
DXCCList:= TList.Create;
slst.LoadFromFile(ParamStr(1) + 'ARRL.LIST');
slst.Sort;
for i:= 0 to slst.Count-1 do begin
self.Delimit(tl, slst.Strings[i]);
if (tl.Count = 7) then begin
AR:= TARRLRec.Create;
AR:= TDXCCRec.Create;
AR.prefixReg:= tl.Strings[1];
AR.Entity:= tl.Strings[2];
AR.Continent:= tl.Strings[3];
AR.ITU:= tl.Strings[4];
AR.CQ:= tl.Strings[5];
ARRLList.Add(AR);
DXCCList.Add(AR);
end;
end;
finally
Expand All @@ -67,14 +67,14 @@ procedure TARRL.LoadARRL;
end;
end;

constructor TARRL.Create;
constructor TDXCC.Create;
begin
inherited Create;
LoadARRL;
LoadDxCCList;
end;

// search ARRL prefix records for given callsign prefix.
function TARRL.SearchPrefix(out index : integer; const ACallPrefix : string) : Boolean;
// search ARRL DXCC prefix records for given callsign prefix.
function TDXCC.SearchPrefix(out index : integer; const ACallPrefix : string) : Boolean;
var
reg: TPerlRegEx;
s: string;
Expand All @@ -84,8 +84,8 @@ function TARRL.SearchPrefix(out index : integer; const ACallPrefix : string) : B
try
Result:= False;
reg.Subject := UTF8Encode(ACallPrefix);
for i:= ARRLList.Count - 1 downto 0 do begin
s:= '^(' + TARRLRec(ARRLList.Items[i]).prefixReg + ')';
for i:= DXCCList.Count - 1 downto 0 do begin
s:= '^(' + TDXCCRec(DXCCList.Items[i]).prefixReg + ')';
reg.RegEx:= UTF8Encode(s);
if Reg.Match then begin
index:= i;
Expand All @@ -98,7 +98,7 @@ function TARRL.SearchPrefix(out index : integer; const ACallPrefix : string) : B
end;
end;

function TARRL.FindRec(out dxrec : TARRLRec; const ACallsign : string) : Boolean;
function TDXCC.FindRec(out dxrec : TDXCCRec; const ACallsign : string) : Boolean;
var
sC, sP: string;
index : integer;
Expand All @@ -108,11 +108,11 @@ function TARRL.FindRec(out dxrec : TARRLRec; const ACallsign : string) : Boolean
sP:= ExtractPrefix(sC);
Result:= SearchPrefix(index, sP);
if Result then
dxrec:= TARRLRec(ARRLList.Items[index]);
dxrec:= TDXCCRec(DXCCList.Items[index]);
end;

// return status bar information string.
function TARRL.GetStationInfo(const ACallsign: string): string;
function TDXCC.GetStationInfo(const ACallsign: string): string;
var
i : integer;
sC, sP: string;
Expand All @@ -121,10 +121,10 @@ function TARRL.GetStationInfo(const ACallsign: string): string;
sC:= ExtractCallsign(ACallsign);
sP:= ExtractPrefix(sC);
if SearchPrefix(i, sP) then
Result:= sC + ' ' + TARRLRec(ARRLList[i]).GetString;
Result:= sC + ' ' + TDXCCRec(DXCCList[i]).GetString;
end;

function TARRL.Search(ACallsign: string): string;
function TDXCC.Search(ACallsign: string): string;
var
reg: TPerlRegEx;
i: integer;
Expand All @@ -136,11 +136,11 @@ function TARRL.Search(ACallsign: string): string;
sC:= ExtractCallsign(ACallsign);
sP:= ExtractPrefix(sC);
reg.Subject := UTF8Encode(sP);
for i:= ARRLList.Count - 1 downto 0 do begin
s:= '^(' + TARRLRec(ARRLList.Items[i]).prefixReg + ')';
for i:= DXCCList.Count - 1 downto 0 do begin
s:= '^(' + TDXCCRec(DXCCList.Items[i]).prefixReg + ')';
reg.RegEx:= UTF8Encode(s);
if Reg.Match then begin
Result:= sC + ' ' + TARRLRec(ARRLList[i]).GetString;
Result:= sC + ' ' + TDXCCRec(DXCCList[i]).GetString;
Break;
end;
end;
Expand All @@ -149,7 +149,7 @@ function TARRL.Search(ACallsign: string): string;
end;
end;

procedure TARRL.Delimit(var AStringList: TStringList; const AText: string);
procedure TDXCC.Delimit(var AStringList: TStringList; const AText: string);
const
DelimitChar: char= ';';
var
Expand All @@ -171,7 +171,7 @@ procedure TARRL.Delimit(var AStringList: TStringList; const AText: string);

{ TARRLRec }

function TARRLRec.GetString: string;
function TDXCCRec.GetString: string;
begin
Result:= Format('%s/%s; ITU Zone:%s; CQ Zone:%s', [Entity, Continent, ITU, CQ]);
end;
Expand Down
4 changes: 2 additions & 2 deletions ArrlFd.pas
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ function TArrlFieldDay.FindCallRec(out fdrec: TFdCallRec; const ACall: string):
function TArrlFieldDay.GetStationInfo(const ACallsign: string) : string;
var
fdrec : TFdCallRec;
dxrec : TARRLRec;
dxrec : TDXCCRec;
userText : string;
dxEntity : string;
begin
Expand All @@ -169,7 +169,7 @@ function TArrlFieldDay.GetStationInfo(const ACallsign: string) : string;

// if caller is DX station, include its Continent/Entity
if (fdrec.Section = 'DX') and
ARRLDX.FindRec(dxrec, ACallsign) then
gDXCCList.FindRec(dxrec, ACallsign) then
dxEntity:= dxRec.Continent + '/' + dxRec.Entity;
end;

Expand Down
4 changes: 2 additions & 2 deletions CqWW.pas
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ function TCqWw.FindCallRec(out fdrec: TCqWwCallRec; const ACall: string): Boolea
function TCqWw.GetStationInfo(const ACallsign: string) : string;
var
fdrec : TCqWwCallRec;
dxrec : TARRLRec;
dxrec : TDXCCRec;
userText : string;
dxEntity : string;
begin
Expand All @@ -156,7 +156,7 @@ function TCqWw.GetStationInfo(const ACallsign: string) : string;
userText:= fdrec.UserText;

// find caller's Continent/Entity
if ARRLDX.FindRec(dxrec, ACallsign) then
if gDXCCList.FindRec(dxrec, ACallsign) then
dxEntity:= dxRec.Continent + '/' + dxRec.Entity;
end;

Expand Down
2 changes: 1 addition & 1 deletion Log.pas
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ procedure UpdateSbar(const ACallsign: string);
scNaQp:
s := gNAQP.GetStationInfo(ACallsign);
else
s := ARRLDX.Search(ACallsign);
s := gDXCCList.Search(ACallsign);
end;

// '&' are suppressed in this control; replace with '&&'
Expand Down
5 changes: 2 additions & 3 deletions Main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ procedure TMainForm.FormCreate(Sender: TObject);

// Adding a contest: implement a new contest-specific call history .pas file.
// Adding a contest: load call history file (be sure to delete it below).
ARRLDX:= TARRL.Create;
gDXCCList := TDXCC.Create;
gARRLFD := TArrlFieldDay.Create;
gNAQP := TNcjNaQp.Create;
gCQWW := TCqWW.Create;
Expand All @@ -466,7 +466,7 @@ procedure TMainForm.FormCreate(Sender: TObject);
procedure TMainForm.FormDestroy(Sender: TObject);
begin
ToIni;
ARRLDX.Free;
gDXCCList.Free;
gARRLFD.Free;
gNAQP.Free;
gCQWW.Free;
Expand Down Expand Up @@ -952,7 +952,6 @@ procedure TMainForm.SetMyExchange(const AExchange: string);

procedure TMainForm.UpdateTitleBar;
begin
// Adding a contest: consider application's title bar.
if (SimContest = scHst) and not HamName.IsEmpty then // for HST, add operator name
Caption := Format('Morse Runner - Community Edition: %s', [HamName])
else // Default is: Morse Runner - Community Edition
Expand Down
4 changes: 2 additions & 2 deletions NaQp.pas
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function TNcjNaQp.FindCallRec(out recOut: TNaQpCallRec; const ACall: string): Bo
function TNcjNaQp.GetStationInfo(const ACallsign: string) : string;
var
rec : TNaQpCallRec;
dxrec : TARRLRec;
dxrec : TDXCCRec;
userText : string;
dxEntity : string;
begin
Expand All @@ -148,7 +148,7 @@ function TNcjNaQp.GetStationInfo(const ACallsign: string) : string;

// if caller is DX station, include its Continent/Entity
if (rec.State = 'DX') and
ARRLDX.FindRec(dxrec, ACallsign) then
gDXCCList.FindRec(dxrec, ACallsign) then
dxEntity:= dxRec.Continent + '/' + dxRec.Entity;
end;

Expand Down