Skip to content

Commit 275c9a5

Browse files
FIX: Ui
ADD: recursive .inc files
1 parent c0a213a commit 275c9a5

File tree

5 files changed

+56
-26
lines changed

5 files changed

+56
-26
lines changed

src/unit1.lfm

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ object Form1: TForm1
3939
end
4040
object Label1: TLabel
4141
Left = 304
42-
Height = 16
42+
Height = 15
4343
Top = 160
44-
Width = 140
44+
Width = 122
4545
Caption = 'Nothing loaded, please'
4646
end
4747
object Button1: TButton
@@ -64,9 +64,9 @@ object Form1: TForm1
6464
end
6565
object Label2: TLabel
6666
Left = 368
67-
Height = 16
67+
Height = 15
6868
Top = 208
69-
Width = 13
69+
Width = 11
7070
Caption = 'or'
7171
end
7272
object MainMenu1: TMainMenu

src/unit1.pas

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(******************************************************************************)
22
(* FPC Understand 30.03.2023 *)
33
(* *)
4-
(* Version : 0.25 *)
4+
(* Version : 0.27 *)
55
(* *)
66
(* Author : Uwe Schächterle (Corpsman) *)
77
(* *)
@@ -64,6 +64,8 @@
6464
(* 0.25 - ADD: Code preview / review feature *)
6565
(* ADD: Mark nodes with comments *)
6666
(* 0.26 - FIX: Line index after {$I ...} *)
67+
(* 0.27 - ADD: Support recursive {$I ...} *)
68+
(* FIX: Set carety when showing code editor *)
6769
(* *)
6870
(* Known Bugs : - if a project holds 2 units with the same name *)
6971
(* the dependency graph will merge them to one *)

src/unit13.lfm

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ object Form13: TForm13
1010
LCLVersion = '3.99.0.0'
1111
OnCloseQuery = FormCloseQuery
1212
OnCreate = FormCreate
13+
OnShow = FormShow
1314
object Button1: TButton
1415
Left = 717
1516
Height = 25

src/unit13.pas

+14
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
Procedure Button2Click(Sender: TObject);
4545
Procedure FormCloseQuery(Sender: TObject; Var CanClose: Boolean);
4646
Procedure FormCreate(Sender: TObject);
47+
Procedure FormShow(Sender: TObject);
4748
Procedure MenuItem1Click(Sender: TObject);
4849
Procedure MenuItem2Click(Sender: TObject);
4950
Procedure ScrollBox1Resize(Sender: TObject);
@@ -55,6 +56,7 @@
5556
frelativeFilename: String;
5657
fAbsoluteFilename: String;
5758
fFrameNameCounter: integer;
59+
fformShowOnce: Boolean;
5860
Procedure RepositionAllComments;
5961
Function AddLineMark(Line: Integer): TCommentFrame;
6062
Procedure RemoveLineMark(Line: integer);
@@ -96,6 +98,15 @@
9698
Splitter1.Align := alRight;
9799
SynEdit1.Align := alClient;
98100
fFrameNameCounter := 0;
101+
fformShowOnce := true;
102+
End;
103+
104+
Procedure TForm13.FormShow(Sender: TObject);
105+
Begin
106+
If fformShowOnce Then Begin
107+
fformShowOnce := false;
108+
SynEdit1.SetFocus;
109+
End;
99110
End;
100111

101112
Procedure TForm13.MenuItem1Click(Sender: TObject);
@@ -114,6 +125,7 @@
114125
showmessage('Error, nothing to export.');
115126
exit;
116127
End;
128+
c := Nil;
117129
setlength(c, ScrollBox1.ComponentCount);
118130
For i := 0 To high(c) Do Begin
119131
c[i].Line := (ScrollBox1.Components[i] As TCommentFrame).Line;
@@ -320,6 +332,8 @@
320332
SynEdit1.TopLine := SynEdit1.Lines.Count - 1;
321333
SynEdit1.Invalidate;
322334
SynEdit1.TopLine := aLine;
335+
SynEdit1.CaretY := aLine;
336+
fformShowOnce := true; // Synedit1.setfocus triggern
323337
End;
324338
caption := 'File preview: ' + ExtractFileName(frelativeFilename);
325339
ShowModal;

src/upascallexer.pas

+34-21
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(******************************************************************************)
22
(* upascallexer 19.04.2023 *)
33
(* *)
4-
(* Version : 0.05 *)
4+
(* Version : 0.06 *)
55
(* *)
66
(* Author : Uwe Schächterle (Corpsman) *)
77
(* *)
@@ -27,6 +27,7 @@
2727
(* 0.03 - Start with unittests, fix "invalid" ( * Parsing *)
2828
(* 0.04 - Berücksichtigen von {$I ...} *)
2929
(* 0.05 - Fix Linecounting von {$I ...} *)
30+
(* 0.06 - Support recursive includes *)
3031
(* *)
3132
(******************************************************************************)
3233
Unit upascallexer;
@@ -357,17 +358,18 @@
357358
Procedure TPascalLexer.DoLex(Const Stream: TStream);
358359

359360
Var
360-
BlockLineCounting: Boolean; // Wenn True, dann werden die ZeilenNummern nicht "Erhöht" wenn CRT gelesen wird.
361+
BlockLineCounting: integer; // Wenn True, dann werden die ZeilenNummern nicht "Erhöht" wenn CRT gelesen wird.
361362

362363
Procedure HToken(); //Inline;
363364
Begin
364365
If atoken = '~DisableLineCounter~' Then Begin
365-
BlockLineCounting := true;
366+
inc(BlockLineCounting);
366367
atoken := '';
367368
exit;
368369
End;
369370
If atoken = '~EnableLineCounter~' Then Begin
370-
BlockLineCounting := false;
371+
dec(BlockLineCounting);
372+
If BlockLineCounting < 0 Then BlockLineCounting := 0;
371373
atoken := '';
372374
exit;
373375
End;
@@ -404,7 +406,7 @@
404406
i, mSize: Int64;
405407
Begin
406408
aToken := '';
407-
BlockLineCounting := false;
409+
BlockLineCounting := 0;
408410
State := sCollectToken;
409411
CommentDetphCounter := 0;
410412
pc := #0;
@@ -672,7 +674,7 @@
672674
inc(aEmptyLine);
673675
End;
674676
If (c = LB) Then Begin
675-
If (Not BlockLineCounting) Then Begin
677+
If (BlockLineCounting = 0) Then Begin
676678
inc(aLine);
677679
End;
678680
inc(aParsedLine);
@@ -690,20 +692,16 @@
690692
End;
691693

692694
Procedure TPascalLexer.LexFile(Const Filename: String);
693-
Var
694-
m: TMemoryStream;
695-
sl2, sl: TStringList;
696-
i: integer;
697-
s, t: String;
698-
Begin
699-
sl := TStringList.Create;
700-
Try
701-
sl.LoadFromFile(Filename);
702-
// Auflösen der Includierten Dateien, ja das ist ein Böser Hack ..
703-
If assigned(OnResolveFileRequest) And (pos('{$I ', sl.text) <> 0) Then Begin
704-
For i := 0 To sl.Count - 1 Do Begin
705-
If pos('{$I ', sl[i]) <> 0 Then Begin
706-
s := sl[i];
695+
Procedure IncludeIncludes(Const Content: TStringList);
696+
Var
697+
sl2: TStringList;
698+
i: integer;
699+
s, t: String;
700+
Begin
701+
If (pos('{$I ', content.text) <> 0) Then Begin
702+
For i := content.Count - 1 Downto 0 Do Begin
703+
If pos('{$I ', content[i]) <> 0 Then Begin
704+
s := content[i];
707705
s := copy(s, pos('{$I ', s) + 4, length(s));
708706
t := copy(s, pos('}', s) + 1, length(s)); // Retten dessen was nach dem Include kommt.
709707
s := copy(s, 1, pos('}', s) - 1);
@@ -712,12 +710,27 @@
712710
If s <> '' Then Begin
713711
sl2 := TStringList.Create;
714712
sl2.LoadFromFile(s);
715-
sl[i] := ' ~DisableLineCounter~ ' + sl2.Text + ' ~EnableLineCounter~ ' + t;
713+
IncludeIncludes(sl2); // Falls includes, includes machen ..
714+
content[i] := ' ~DisableLineCounter~ ' + sl2.Text + ' ~EnableLineCounter~ ' + t;
716715
sl2.free;
717716
End;
718717
End;
719718
End;
720719
End;
720+
End;
721+
722+
Var
723+
m: TMemoryStream;
724+
sl: TStringList;
725+
726+
Begin
727+
sl := TStringList.Create;
728+
Try
729+
sl.LoadFromFile(Filename);
730+
// Rekursives Auflösen der Includierten Dateien
731+
If assigned(OnResolveFileRequest) Then Begin
732+
IncludeIncludes(sl);
733+
End;
721734
m := TMemoryStream.Create;
722735
sl.SaveToStream(m);
723736
Try

0 commit comments

Comments
 (0)