Skip to content

Commit b8f75a4

Browse files
committed
moved Mapping file processing into separate unit
1 parent 8b134f3 commit b8f75a4

3 files changed

Lines changed: 208 additions & 172 deletions

File tree

utilities/makelist/cfgmap.pas

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
// Copyright 2026, Jerome Shidel
2+
// The Clear BSD License
3+
// All rights reserved.
4+
5+
unit CfgMap;
6+
7+
{$mode objfpc}{$H+}
8+
9+
{$I patches.pp} // Various compiler directives to "fix" things.
10+
{$I version.def} // Version information defines
11+
12+
interface
13+
14+
uses
15+
{$IFDEF USES_CWString} cwstring, {$ENDIF}
16+
{$IFDEF UNIX}
17+
cthreads,
18+
{$ENDIF}
19+
Classes, SysUtils, IniFiles,
20+
{ you can add units after this }
21+
Version, PasExt, GloDat;
22+
23+
// Read and apply settings contained in the _Mapping.txt file.
24+
procedure ReadFileMap;
25+
26+
implementation
27+
28+
29+
function KindFromText(S : String) : TSectionKind;
30+
begin
31+
case LowerCase(Trim(S)) of
32+
'none' : Result:=skNone;
33+
'standard' : Result:=skStandard;
34+
'interrupt' : Result:=skInterrupt;
35+
'cmos' : Result:=skCMOS;
36+
'farcall' : Result:=skFarCall;
37+
'i2c' : Result:=skI2C;
38+
'memory' : Result:=skMemory;
39+
'msr' : Result:=skMSR;
40+
'port' : Result:=skPort;
41+
'glossary' : Result:=skGlossary;
42+
'table' : Result:=skTable;
43+
'smm' : Result:=skSMM;
44+
'link' : Result:=skLink;
45+
'faq' : Result:=skFAQ;
46+
else
47+
Result:=skNone;
48+
raise Exception.Create('Section Type "'+Trim(S)+'" was not recognized.');
49+
end;
50+
end;
51+
52+
procedure ReadFileMap;
53+
{ TODO 2 -cDevel Remove a lot of duplicate and similar code }
54+
var
55+
INI : TIniFile;
56+
Strs : TStringList;
57+
K, S : String;
58+
I, J : Integer;
59+
60+
procedure ReadSection(SectName : String);
61+
var
62+
X : Integer;
63+
begin
64+
INI.ReadSectionRaw(SectName, Strs);
65+
// Blanks are already removed. Remove Comments.
66+
for X := Strs.Count - 1 downto 0 do
67+
if HasLeading(Strs[X], ';', false) then
68+
Strs.Delete(X);
69+
end;
70+
71+
begin
72+
if not FileExists(DirSource + MapFile) then Exit;
73+
INI:=nil;
74+
Strs:=nil;
75+
try
76+
Strs:=TStringList.Create;
77+
INI := TIniFile.Create(DirSource + MapFile);
78+
// Replace Miscellaneous Directory when defined
79+
S:= ExcludeTrailing(INI.ReadString('MISC', 'Directory', MiscFileDir), PathDelimiter);
80+
if not DirectoryExists(DirSource + S) then begin
81+
LogMessage(vbMinimal, 'Invalid directory for miscellaneous files: ' + S);
82+
Halt(1);
83+
end else
84+
MiscFileDir:=S;
85+
// Replace INTERRUPT_1ST sections, replaces internal table
86+
ReadSection('1ST');
87+
if Strs.Count > 0 then begin
88+
SetLength(INTERRUPT_1ST, Strs.Count);
89+
for I := 0 to Strs.Count - 1 do begin
90+
S:=Strs[I];
91+
PopDelim(S, EQUAL);
92+
S:=Trim(S);
93+
INTERRUPT_1ST[I]:=Trim(S);
94+
end;
95+
end;
96+
// Replace SECTION_ORDER sections, replaces internal table
97+
ReadSection('ORDER');
98+
if Strs.Count > 0 then begin
99+
SetLength(SECTION_ORDER, Strs.Count);
100+
for I := 0 to Strs.Count - 1 do begin
101+
S:=Strs[I];
102+
PopDelim(S, EQUAL);
103+
S:=Trim(S);
104+
SECTION_ORDER[I]:=Trim(S);
105+
end;
106+
end;
107+
// Update File/Path Name mappings, updates and appends internal table
108+
ReadSection('NAMES');
109+
if Strs.Count > 0 then begin
110+
for I := 0 to Strs.Count - 1 do begin
111+
S:=Strs[I];
112+
K:=Trim(PopDelim(S, EQUAL));
113+
S:=Trim(S);
114+
if S = '' then Continue;
115+
for J := 0 to High(DOSNAMES) do
116+
if UpperCase(DOSNAMES[J].DOS) = UpperCase(K) then begin
117+
if Uppercase(K) = FILE_1ST then
118+
IntFirstDir:=S;
119+
DOSNAMES[J].Name:=S;
120+
K:='';
121+
Break;
122+
end;
123+
if K = '' then Continue;
124+
SetLength(DOSNAMES, Length(DOSNAMES) + 1);
125+
DOSNAMES[High(DOSNAMES)].DOS:=K;
126+
DOSNAMES[High(DOSNAMES)].Name:=S;
127+
DOSNAMES[High(DOSNAMES)].Kind:=skNone;
128+
end;
129+
end;
130+
// Update File/Path Name TYPE, updates and appends internal table
131+
ReadSection('TYPE');
132+
if Strs.Count > 0 then begin
133+
for I := 0 to Strs.Count - 1 do begin
134+
S:=Strs[I];
135+
K:=Trim(PopDelim(S, EQUAL));
136+
S:=Trim(S);
137+
if S = '' then Continue;
138+
for J := 0 to High(DOSNAMES) do
139+
if UpperCase(DOSNAMES[J].DOS) = UpperCase(K) then begin
140+
DOSNAMES[J].Kind:=KindFromText(S);
141+
Break;
142+
end;
143+
end;
144+
end;
145+
// Update File Description Information for FILELIST, , updates and appends
146+
// internal table
147+
ReadSection('INFO');
148+
if Strs.Count > 0 then begin
149+
for I := 0 to Strs.Count - 1 do begin
150+
S:=Strs[I];
151+
K:=Trim(PopDelim(S, EQUAL));
152+
S:=Trim(S);
153+
if S = '' then Continue;
154+
for J := 0 to High(DOSINFO) do
155+
if UpperCase(DOSINFO[J].Name) = UpperCase(K) then begin
156+
DOSINFO[J].Text:=S;
157+
K:='';
158+
Break;
159+
end;
160+
if K = '' then Continue;
161+
SetLength(DOSINFO, Length(DOSINFO) + 1);
162+
DOSINFO[High(DOSINFO)].Name:=K;
163+
DOSINFO[High(DOSINFO)].Text:=S;
164+
end;
165+
end;
166+
167+
except
168+
on E : Exception do begin
169+
LogMessage(vbCritical, 'Mapping file exception: ' + E.Message);
170+
Halt(1);
171+
end;
172+
end;
173+
if Assigned(INI) then INI.Free;
174+
if Assigned(Strs) then Strs.Free;
175+
end;
176+
177+
178+
179+
end.

utilities/makelist/makelist.lpr

Lines changed: 2 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
Version, // Program version information, generated by version.sh
2020
PasExt, BinTree, // A couple basic MPLA units.
2121
GloDat, // Global types, variables, data, etc.
22-
CfgOpts; // Command Line option processing.
23-
22+
CfgOpts, // Command Line option processing.
23+
CfgMap; // Reading and processing of _Mapping.txt file.
2424

2525
// Saves Filename of an Entry with a problem, error, etc to a file when the
2626
// "IssueFileName" file name is set.
@@ -889,156 +889,6 @@ procedure Build;
889889
SectionTree.Free;
890890
end;
891891

892-
{ ---------------------------------------------------------------------------- }
893-
894-
function KindFromText(S : String) : TSectionKind;
895-
begin
896-
case LowerCase(Trim(S)) of
897-
'none' : Result:=skNone;
898-
'standard' : Result:=skStandard;
899-
'interrupt' : Result:=skInterrupt;
900-
'cmos' : Result:=skCMOS;
901-
'farcall' : Result:=skFarCall;
902-
'i2c' : Result:=skI2C;
903-
'memory' : Result:=skMemory;
904-
'msr' : Result:=skMSR;
905-
'port' : Result:=skPort;
906-
'glossary' : Result:=skGlossary;
907-
'table' : Result:=skTable;
908-
'smm' : Result:=skSMM;
909-
'link' : Result:=skLink;
910-
'faq' : Result:=skFAQ;
911-
else
912-
Result:=skNone;
913-
raise Exception.Create('Section Type "'+Trim(S)+'" was not recognized.');
914-
end;
915-
end;
916-
917-
procedure ReadFileMap;
918-
{ TODO 2 -cDevel Remove a lot of duplicate and similar code }
919-
var
920-
INI : TIniFile;
921-
Strs : TStringList;
922-
K, S : String;
923-
I, J : Integer;
924-
925-
procedure ReadSection(SectName : String);
926-
var
927-
X : Integer;
928-
begin
929-
INI.ReadSectionRaw(SectName, Strs);
930-
// Blanks are already removed. Remove Comments.
931-
for X := Strs.Count - 1 downto 0 do
932-
if HasLeading(Strs[X], ';', false) then
933-
Strs.Delete(X);
934-
end;
935-
936-
begin
937-
if not FileExists(DirSource + MapFile) then Exit;
938-
INI:=nil;
939-
Strs:=nil;
940-
try
941-
Strs:=TStringList.Create;
942-
INI := TIniFile.Create(DirSource + MapFile);
943-
// Replace Miscellaneous Directory when defined
944-
S:= ExcludeTrailing(INI.ReadString('MISC', 'Directory', MiscFileDir), PathDelimiter);
945-
if not DirectoryExists(DirSource + S) then begin
946-
LogMessage(vbMinimal, 'Invalid directory for miscellaneous files: ' + S);
947-
Halt(1);
948-
end else
949-
MiscFileDir:=S;
950-
// Replace INTERRUPT_1ST sections, replaces internal table
951-
ReadSection('1ST');
952-
if Strs.Count > 0 then begin
953-
SetLength(INTERRUPT_1ST, Strs.Count);
954-
for I := 0 to Strs.Count - 1 do begin
955-
S:=Strs[I];
956-
PopDelim(S, EQUAL);
957-
S:=Trim(S);
958-
INTERRUPT_1ST[I]:=Trim(S);
959-
end;
960-
end;
961-
// Replace SECTION_ORDER sections, replaces internal table
962-
ReadSection('ORDER');
963-
if Strs.Count > 0 then begin
964-
SetLength(SECTION_ORDER, Strs.Count);
965-
for I := 0 to Strs.Count - 1 do begin
966-
S:=Strs[I];
967-
PopDelim(S, EQUAL);
968-
S:=Trim(S);
969-
SECTION_ORDER[I]:=Trim(S);
970-
end;
971-
end;
972-
// Update File/Path Name mappings, updates and appends internal table
973-
ReadSection('NAMES');
974-
if Strs.Count > 0 then begin
975-
for I := 0 to Strs.Count - 1 do begin
976-
S:=Strs[I];
977-
K:=Trim(PopDelim(S, EQUAL));
978-
S:=Trim(S);
979-
if S = '' then Continue;
980-
for J := 0 to High(DOSNAMES) do
981-
if UpperCase(DOSNAMES[J].DOS) = UpperCase(K) then begin
982-
if Uppercase(K) = FILE_1ST then
983-
IntFirstDir:=S;
984-
DOSNAMES[J].Name:=S;
985-
K:='';
986-
Break;
987-
end;
988-
if K = '' then Continue;
989-
SetLength(DOSNAMES, Length(DOSNAMES) + 1);
990-
DOSNAMES[High(DOSNAMES)].DOS:=K;
991-
DOSNAMES[High(DOSNAMES)].Name:=S;
992-
DOSNAMES[High(DOSNAMES)].Kind:=skNone;
993-
end;
994-
end;
995-
// Update File/Path Name TYPE, updates and appends internal table
996-
ReadSection('TYPE');
997-
if Strs.Count > 0 then begin
998-
for I := 0 to Strs.Count - 1 do begin
999-
S:=Strs[I];
1000-
K:=Trim(PopDelim(S, EQUAL));
1001-
S:=Trim(S);
1002-
if S = '' then Continue;
1003-
for J := 0 to High(DOSNAMES) do
1004-
if UpperCase(DOSNAMES[J].DOS) = UpperCase(K) then begin
1005-
DOSNAMES[J].Kind:=KindFromText(S);
1006-
Break;
1007-
end;
1008-
end;
1009-
end;
1010-
// Update File Description Information for FILELIST, , updates and appends
1011-
// internal table
1012-
ReadSection('INFO');
1013-
if Strs.Count > 0 then begin
1014-
for I := 0 to Strs.Count - 1 do begin
1015-
S:=Strs[I];
1016-
K:=Trim(PopDelim(S, EQUAL));
1017-
S:=Trim(S);
1018-
if S = '' then Continue;
1019-
for J := 0 to High(DOSINFO) do
1020-
if UpperCase(DOSINFO[J].Name) = UpperCase(K) then begin
1021-
DOSINFO[J].Text:=S;
1022-
K:='';
1023-
Break;
1024-
end;
1025-
if K = '' then Continue;
1026-
SetLength(DOSINFO, Length(DOSINFO) + 1);
1027-
DOSINFO[High(DOSINFO)].Name:=K;
1028-
DOSINFO[High(DOSINFO)].Text:=S;
1029-
end;
1030-
end;
1031-
1032-
except
1033-
on E : Exception do begin
1034-
LogMessage(vbCritical, 'Mapping file exception: ' + E.Message);
1035-
Halt(1);
1036-
end;
1037-
end;
1038-
if Assigned(INI) then INI.Free;
1039-
if Assigned(Strs) then Strs.Free;
1040-
end;
1041-
1042892
// We do not really need to include the Lazarus Resourse in the executable.
1043893
// But, Lazarus keeps sticking it back in here. So, whatever, its only a couple
1044894
// of bytes.

0 commit comments

Comments
 (0)