Skip to content

Commit 7874b9d

Browse files
committed
one-off fixflags, complete.
1 parent 6af44af commit 7874b9d

3 files changed

Lines changed: 328 additions & 5 deletions

File tree

.timestamps

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11162,11 +11162,11 @@
1116211162
1775168885 7d90943f6f0d41d75f9ec12df08c6c7cd0becfac5056efeac8397c947c4565330e3e39d81f8ede4b466dc524508899a4ecf4131c6a34f9509bb0e2ad69722c9d utilities/one-off/fix-flags/LICENSE
1116311163
1775721907 dde88acaec75c1493c9a72f1c93660b630e31140edab0eb396ce8758c84398dbc5c9739d3a5490c991adcc3e168ddb5b494781a9f13e2979fbac918c0c998d6f utilities/one-off/fix-flags/build.sh
1116411164
1775720857 65c41a770ccfaf73347b159282a94f6684e0a3453ac349f5ae8ecf65f836f9ef76712bdc3b0d4260938fd33cf948f0f84d97a69f3ffb4bf69f9e2f56e458c86d utilities/one-off/fix-flags/fixflags.lpi
11165-
1775721981 400c1cf01eaa5cbae4e3d98c4cc0c0d4ebd9db35a17f68c7a3fd8f467b3447fff2ac43dd2fdf549ac259c2f74e61202a07ea03af37001b84d44fce6badb8223d utilities/one-off/fix-flags/fixflags.lpr
11166-
1775720857 8de4de5da23c6eda8b4031613b6d3d463676fc6b5961ac3229244867451317e1f5d76d40d5c440e6bb5b56199f5a4796d78df6f61a1b5beff647d2947dcc84bd utilities/one-off/fix-flags/fixflags.lps
11165+
1775731634 9128b1fcf390829161585ccc9e2abd5319fd07bd1e796839ef903128e0d132364c120b131e65719cccc2303781c1f3c0a4e74b9b734609b6bb6b0c0ccf9ac13d utilities/one-off/fix-flags/fixflags.lpr
11166+
1775731635 58c1e0bac87348ab811c4be2ad59edff173e2b04e1e4afccaf19552e0483b1ff3adaaa84de84466569df722c82f453c80e7bc659015780962038b797f1352842 utilities/one-off/fix-flags/fixflags.lps
1116711167
1775346672 3b7b7e6edaaf6c9728d260d3ca2bfd3ef4b08615e1f5caa1ca18e44439c85c5b53a445fb2decbf81874f761f4f818e2750e9e2291adc6497f052a7807328aee1 utilities/one-off/fix-flags/pasext.pp
1116811168
1775168827 6693f98642328f20ac92c57358eb532107f81b00e506b939ffd65dedf03d5baf2b825588128fe00bda86530b130809a7075384df429b9fd86f0ef9ea2db88cb6 utilities/one-off/fix-flags/patches.pp
1116911169
1775722009 f665bed2ca046bc0e1e47440db1d46a1fce6a2296151fc398f996b9aa164d28176b3846df23c6c4d2b0da7f7044afc3189d8296e7739af6da528f4d25094c3aa utilities/one-off/fix-flags/version.def
1117011170
1775722009 c113f3cc415ff2809a68f88ff16fc9ba549366afa1a4827378f67966f4297859a033a2ba86f97cb4337d9149874dbb4a3d7f900dc2483e815ec3b03b84aa695d utilities/one-off/fix-flags/version.pp
1117111171
1775434032 6df374e7a87c22059bf39cd9ed1614e1af6d785e20c2ec6b386b164b31816462027d0ebfe11ae4ecaa1f6d5bca15d3ab5ad9ff7d14df9ec47bfd13e3d4e0a6d3 utilities/one-off/fix-flags/version.sh
11172-
1771024215 51046ff1f0af1128137740ff54b6a6e06bfdcddea713f8b2731226bc5017304f2d368a4ba96ab11da3195dd85e25b423c579017496d553685fa0d96c2ccea930 utilities/parse_results.log
11172+
1771024215 51046ff1f0af1128137740ff54b6a6e06bfdcddea713f8b2731226bc5017304f2d368a4ba96ab11da3195dd85e25b423c579017496d553685fa0d96c2ccea930 utilities/one-off/parse_results.log

utilities/one-off/fix-flags/fixflags.lpr

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,224 @@
1717
{ you can add units after this },
1818
PasExt;
1919

20+
const
21+
SRCDIR='../../../source/';
22+
23+
var
24+
BAR : String;
25+
GROUP : String;
26+
COUNT: integer;
27+
28+
const
29+
Flags : array of record
30+
Flag : String;
31+
Text : String;
32+
end = (
33+
(Flag:'U'; Text:'undocumented'),
34+
(Flag:'u'; Text:'partially documented'),
35+
(Flag:'P'; Text:'available only in protected mode'),
36+
(Flag:'R'; Text:'available only in real or V86 mode '),
37+
(Flag:'C'; Text:'callout or callback (usually hooked rather than called)'),
38+
(Flag:'O'; Text:'obsolete (no longer present in current versions)')
39+
);
40+
41+
42+
type
43+
THeadField = record
44+
Key, Value, Text : String;
45+
end;
46+
THeadFields = array of THeadField;
47+
48+
function CompressWhitespace(S : RawByteString) : RawByteString;
49+
begin
50+
Result:=Trim(StringReplace(S, TAB, SPACE, [rfReplaceAll]));
51+
repeat
52+
S:=Result;
53+
Result:=StringReplace(S, SPACE+SPACE, SPACE, [rfReplaceAll]);
54+
until Result=S;
55+
end;
56+
57+
function GetFlag(Flag : String) : String;
58+
var
59+
I : Integer;
60+
begin
61+
Result:='';
62+
for I := 0 to High(Flags) do
63+
if Flag=Flags[I].Flag then begin
64+
Result:=Flags[I].Text;
65+
Break;
66+
end;
67+
end;
68+
69+
procedure ProcessFile(FileName : String);
70+
var
71+
Orig, Work, Dest, Title, S, K, V : RawByteString;
72+
Head : THeadFields;
73+
A, B : TArrayOfRawByteString;
74+
Needed : Boolean;
75+
I : Integer;
76+
DT : TDateTime;
77+
2078
begin
79+
if FileLoad(Filename, Orig) <> 0 then begin
80+
WriteLn('Error loading file: ' + FileName);
81+
Halt(1);
82+
end;
83+
if not FileAge(FileName, DT) then DT:=-1;
84+
Orig:=NormalizeLineEndings(Orig, CRLF);
85+
Work:=Orig;
86+
// Search to start of header. "Should be" the first line, but just in case...
87+
repeat
88+
S := PopDelim(Work, CRLF);
89+
if Copy(S, 1, 75) = Copy(BAR, 1, 75) then Break;
90+
if Work = '' then begin
91+
// File has no header.
92+
Exit;
93+
end;
94+
until false;
95+
Head:=[];
96+
// Parse current header
97+
repeat
98+
S := PopDelim(Work, CRLF);
99+
if Copy(S, 1, 75) = Copy(BAR, 1, 75) then Break;
100+
if Work = '' then begin
101+
WriteLn('File header not terminated: ' + Filename);
102+
Exit;
103+
end;
104+
S:=CompressWhitespace(S);
105+
if S = '' then Continue;
106+
K:= PopDelim(S, COLON);
107+
S:=Trim(S);
108+
V:= PopDelim(S, SPACE);
109+
S:=Trim(S);
110+
Case Lowercase(K) of
111+
'unique id' : begin
112+
SetLength(Head, Length(Head)+1);
113+
Head[High(Head)].Key:='Unique ID';
114+
Head[High(Head)].Value:=V;
115+
Head[High(Head)].Text:=S;
116+
end;
117+
'category' : begin
118+
SetLength(Head, Length(Head)+1);
119+
Head[High(Head)].Key:='Category';
120+
Head[High(Head)].Value:=V;
121+
Head[High(Head)].Text:=S;
122+
end;
123+
'flag' : begin
124+
// Ignore old flags
125+
(*
126+
SetLength(Head, Length(Head)+1);
127+
Head[High(Head)].Key:=K;
128+
Head[High(Head)].Value:=V;
129+
Head[High(Head)].Text:=S;
130+
*)
131+
end;
132+
else
133+
WriteLn('Unknown header field "' + K + '" in: ' + Filename);
134+
Exit;
135+
end;
136+
until false;
137+
// Get Entry Title
138+
repeat
139+
S := Trim(PopDelim(Work, CRLF));
140+
until (S <> '') or (Work = '');
141+
if S = '' then begin
142+
WriteLn('Entry Title not found: ' + FileName);
143+
Exit;
144+
end;
145+
Title:=S;
146+
// File roughly validated as an entry, display Group Once
147+
if GROUP <> '' then begin
148+
WriteLn(GROUP);
149+
GROUP:='';
150+
end;
151+
// Parse the Title Flags
152+
S:=CompressWhiteSpace(S);
153+
S:=PopDelim(S, '-');
154+
V:=Trim(CutDelim(S, SPACE, 3));
155+
if Length(V) = 0 then begin
156+
SetLength(Head, Length(Head)+1);
157+
Head[High(Head)].Key:='Flag';
158+
Head[High(Head)].Value:='n/a';
159+
Head[High(Head)].Text:='';
160+
end else begin
161+
for I := 1 to Length(V) do begin
162+
SetLength(Head, Length(Head)+1);
163+
Head[High(Head)].Key:='Flag';
164+
Head[High(Head)].Value:=V[I];
165+
S:=GetFlag(V[I]);
166+
if S = '' then begin
167+
WriteLn('Unknown flag "' + V[I] + '" in file: ' + FileName);
168+
Exit;
169+
end;
170+
Head[High(Head)].Text:=S;
171+
end;
172+
end;
173+
174+
// Create entry with updated header
175+
Dest:=BAR + CRLF;
176+
for I := 0 to High(Head) do
177+
Cat(Dest, TrimRight(
178+
LeftPad(Head[I].Key, 10) + ':' + SPACE +
179+
RightPad(Head[I].Value, 3) + SPACE +
180+
Head[I].Text ) +
181+
CRLF);
182+
Cat(Dest, BAR + CRLF + CRLF + Title + CRLF + Work); // Copy body into Dest
183+
21184

185+
// If no change, we are done.
186+
if Dest = Orig then Exit;
187+
// Test for significant changes
188+
A:=Explode(Orig, CRLF);
189+
B:=Explode(Dest, CRLF);
190+
if High(A) = High(B) then begin
191+
Needed:=False;
192+
for I := 0 to High(A) do
193+
if CompressWhiteSpace(A[I]) <> CompressWhiteSpace(B[I]) then begin
194+
Needed:=True;
195+
Break;
196+
end;
197+
if not Needed then Exit;
198+
end;
199+
WriteLn(TAB + FileName);
200+
Inc(COUNT);
201+
// exit;
202+
if FileLoad(Filename, Dest) <> 0 then begin
203+
WriteLn('Error saving file: ' + FileName);
204+
Halt(1);
205+
end;
206+
if DT <> -1 then FileSetDate(Filename, DateTimeToFileDate(DT));
207+
end;
208+
209+
procedure ProcessGroup(G : String);
210+
var
211+
I : Integer;
212+
L : TStringList;
213+
begin
214+
L := TStringList.Create;
215+
GROUP:='Working: ' + G;
216+
DirScan(SRCDIR + G + PathDelimiter + WildCard, L, [dsFiles, dsRecursive]);
217+
for I := 0 to L.Count - 1 do
218+
if (not HasLeading(L[I], UNDERSCORE)) and (HasTrailing(L[I], '.txt', false)) then
219+
ProcessFile(SRCDIR + G + PathDelimiter + L[I]);
220+
L.Free;
221+
end;
222+
223+
procedure ProcessAll;
224+
var
225+
I : Integer;
226+
G : TArrayOfString;
227+
begin
228+
COUNT:=0;
229+
DirScan(SRCDIR + Wildcard, G, [dsDirectories]);
230+
for I := 0 to High(G) do
231+
if LowerCase(G[I]) <> 'miscellaneous' then
232+
ProcessGroup(G[I]);
233+
WriteLn(COUNT, ' files updated');
234+
end;
235+
236+
begin
237+
BAR:=StringOf('-', 80);
238+
ProcessAll;
22239
end.
23240

utilities/one-off/fix-flags/fixflags.lps

Lines changed: 108 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,118 @@
88
<Filename Value="fixflags.lpr"/>
99
<IsPartOfProject Value="True"/>
1010
<IsVisibleTab Value="True"/>
11-
<CursorPos Y="10"/>
11+
<TopLine Value="174"/>
12+
<CursorPos X="6" Y="201"/>
1213
<UsageCount Value="20"/>
1314
<Loaded Value="True"/>
1415
</Unit>
16+
<Unit>
17+
<Filename Value="pasext.pp"/>
18+
<UnitName Value="PasExt"/>
19+
<EditorIndex Value="1"/>
20+
<TopLine Value="4267"/>
21+
<CursorPos X="53" Y="4287"/>
22+
<UsageCount Value="10"/>
23+
<Loaded Value="True"/>
24+
</Unit>
1525
</Units>
16-
<JumpHistory HistoryIndex="-1"/>
26+
<JumpHistory HistoryIndex="23">
27+
<Position>
28+
<Filename Value="fixflags.lpr"/>
29+
<Caret Line="27" Column="21"/>
30+
</Position>
31+
<Position>
32+
<Filename Value="fixflags.lpr"/>
33+
<Caret Line="29" Column="65"/>
34+
</Position>
35+
<Position>
36+
<Filename Value="fixflags.lpr"/>
37+
<Caret Line="32" TopLine="5"/>
38+
</Position>
39+
<Position>
40+
<Filename Value="fixflags.lpr"/>
41+
<Caret Line="33" Column="13" TopLine="9"/>
42+
</Position>
43+
<Position>
44+
<Filename Value="fixflags.lpr"/>
45+
<Caret Line="47" Column="18" TopLine="20"/>
46+
</Position>
47+
<Position>
48+
<Filename Value="fixflags.lpr"/>
49+
<Caret Line="65" TopLine="19"/>
50+
</Position>
51+
<Position>
52+
<Filename Value="fixflags.lpr"/>
53+
<Caret Line="76" Column="12" TopLine="32"/>
54+
</Position>
55+
<Position>
56+
<Filename Value="fixflags.lpr"/>
57+
<Caret Line="70" Column="21" TopLine="45"/>
58+
</Position>
59+
<Position>
60+
<Filename Value="fixflags.lpr"/>
61+
<Caret Line="64" Column="9" TopLine="50"/>
62+
</Position>
63+
<Position>
64+
<Filename Value="fixflags.lpr"/>
65+
<Caret Line="75" Column="16" TopLine="33"/>
66+
</Position>
67+
<Position>
68+
<Filename Value="fixflags.lpr"/>
69+
<Caret Line="55" Column="4" TopLine="28"/>
70+
</Position>
71+
<Position>
72+
<Filename Value="fixflags.lpr"/>
73+
<Caret Line="77" Column="11" TopLine="43"/>
74+
</Position>
75+
<Position>
76+
<Filename Value="fixflags.lpr"/>
77+
<Caret Line="111" Column="19" TopLine="73"/>
78+
</Position>
79+
<Position>
80+
<Filename Value="fixflags.lpr"/>
81+
<Caret Line="116" Column="42" TopLine="66"/>
82+
</Position>
83+
<Position>
84+
<Filename Value="fixflags.lpr"/>
85+
<Caret Line="132" Column="6" TopLine="113"/>
86+
</Position>
87+
<Position>
88+
<Filename Value="fixflags.lpr"/>
89+
<Caret Line="144" Column="17" TopLine="114"/>
90+
</Position>
91+
<Position>
92+
<Filename Value="fixflags.lpr"/>
93+
<Caret Line="40" Column="43" TopLine="6"/>
94+
</Position>
95+
<Position>
96+
<Filename Value="fixflags.lpr"/>
97+
<Caret Line="163" Column="9" TopLine="120"/>
98+
</Position>
99+
<Position>
100+
<Filename Value="pasext.pp"/>
101+
</Position>
102+
<Position>
103+
<Filename Value="pasext.pp"/>
104+
<Caret Line="962" Column="20" TopLine="921"/>
105+
</Position>
106+
<Position>
107+
<Filename Value="pasext.pp"/>
108+
<Caret Line="966" Column="20" TopLine="925"/>
109+
</Position>
110+
<Position>
111+
<Filename Value="fixflags.lpr"/>
112+
<Caret Line="202" Column="26" TopLine="177"/>
113+
</Position>
114+
<Position>
115+
<Filename Value="fixflags.lpr"/>
116+
<Caret Line="153" TopLine="130"/>
117+
</Position>
118+
<Position>
119+
<Filename Value="fixflags.lpr"/>
120+
<Caret Line="204" Column="40" TopLine="180"/>
121+
</Position>
122+
</JumpHistory>
17123
<RunParams>
18124
<FormatVersion Value="2"/>
19125
<Modes ActiveMode=""/>

0 commit comments

Comments
 (0)