View Issue Details

IDProjectCategoryView StatusLast Update
0027393PatchesIDEpublic2015-02-12 00:20
ReporterMaciej Izak Assigned ToMattias Gaertner  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionfixed 
Summary0027393: [Patch] Support for dotted named units like Generics.Collections
DescriptionSmall patch from FreeSparta project, related to 0027206
TagsNo tags attached.
Fixed in Revision47711
LazTarget-
Widgetset
Attached Files

Relationships

related to 0027206 resolvedSven Barth FPC [Patch] Christmas gift by FreeSparta : Generics.Collections 

Activities

Juha Manninen

2015-02-01 13:16

developer   ~0080722

Sounds good but the patch format is wrong. Neither "Kompare" nor "patch" recognize it.

$ patch -p0 < ~/patch/fileprocs.pas.patch
 patch: **** Only garbage was found in the patch input.

Maciej Izak

2015-02-01 15:19

developer  

correct_patch_for_ fileprocs.pas.patch (4,054 bytes)   
Index: components/codetools/fileprocs.pas
===================================================================
--- components/codetools/fileprocs.pas	(revision 47580)
+++ components/codetools/fileprocs.pas	(working copy)
@@ -1593,6 +1593,9 @@
     end;
   end;
 
+var
+  LastCharsEqual: Boolean;
+
   function CharsEqual(c1, c2: char): boolean;
   begin
     {$ifdef CaseInsensitiveFilenames}
@@ -1600,12 +1603,13 @@
     {$else}
     Result:=(c1=c2);
     {$endif}
+    LastCharsEqual:=Result;
   end;
 
 var
   DirStartMask, DirEndMask,
   DirStartFile, DirEndFile,
-  BracketMaskPos, BracketFilePos: integer;
+  BracketMaskPos, BracketFilePos, StarMaskPos, StarDirPos: integer;
   StopChar: LongInt;
   Fits: Boolean;
 
@@ -1622,12 +1626,28 @@
       end else if Mask[DirStartMask]='}' then begin
         // bracket found (= end of Or operator)
         // -> filename does not match
-        exit;
+        if (StarMaskPos > 0) and (DirStartFile<DirEndFile) then begin
+          DirStartMask:=StarMaskPos;
+          DirStartFile:=StarDirPos;
+          exit(true);
+        end else begin
+          exit;
+        end;
       end else if Mask[DirStartMask]=',' then begin
         // next Or found
         // -> reset filename position and compare
         inc(DirStartMask);
-        DirStartFile:=BracketFilePos;
+        if StarMaskPos = 0 then begin
+          DirStartFile:=BracketFilePos;
+        end else begin
+          if DirStartFile<DirEndFile then begin
+            DirStartMask:=StarMaskPos;
+            DirStartFile:=StarDirPos;
+          end else begin
+            StarMaskPos:=0;
+            DirStartFile:=BracketFilePos;
+          end;
+        end;
         exit(true);
       end;
     until false;
@@ -1654,6 +1674,7 @@
       // ' "',copy(Filename,DirStartFile,DirEndFile-DirStartFile),'"');
     // compare directories
     BracketMaskPos:=0;
+    StarMaskPos:=0;
     while (DirStartMask<DirEndMask) do begin
       //debugln(['FilenameIsMatching ',DirStartMask,' ',Mask[DirStartMask],' - ',DirStartFile,' ',Pchar(Filename)[DirStartFile-1]]);
       case Mask[DirStartMask] of
@@ -1667,6 +1688,7 @@
         end;
       '*':
         begin
+          StarMaskPos:=DirStartMask;
           inc(DirStartMask);
           Fits:=false;
           if (DirStartMask=DirEndMask) then begin
@@ -1686,6 +1708,7 @@
               do
                 inc(DirStartFile);
               Fits:=DirStartFile<DirEndFile;
+              StarDirPos := DirStartFile + 1;
             end;
           end;
           if (not Fits) and (not TryNextOr) then exit;
@@ -1704,19 +1727,25 @@
         if BracketMaskPos>0 then begin
           // Bracket operator fits complete
           // -> skip rest of Bracket operator
-          repeat
-            inc(DirStartMask);
-            if DirStartMask>=DirEndMask then exit; // error, missing }
-            if Mask[DirStartMask]=SpecialChar then begin
-              // special char -> next char is normal char
+          if LastCharsEqual and (DirStartFile>=DirEndFile) then
+          begin
+            repeat
               inc(DirStartMask);
-            end else if Mask[DirStartMask]='}' then begin
-              // bracket found (= end of Or operator)
-              inc(DirStartMask);
-              break;
-            end;
-          until false;
-          BracketMaskPos:=0;
+              if DirStartMask>=DirEndMask then exit; // error, missing }
+              if Mask[DirStartMask]=SpecialChar then begin
+                // special char -> next char is normal char
+                inc(DirStartMask);
+              end else if Mask[DirStartMask]='}' then begin
+                // bracket found (= end of Or operator)
+                inc(DirStartMask);
+                break;
+              end;
+            until false;
+            BracketMaskPos:=0;
+          end else begin
+            Dec(DirStartMask);
+            if (not TryNextOr) then exit;
+          end;
           continue;
         end else begin
           // treat as normal character

Maciej Izak

2015-02-01 15:21

developer   ~0080725

Sorry for confusion. New version of patch is available.

Juha Manninen

2015-02-01 18:08

developer   ~0080736

Last edited: 2015-02-01 18:22

View 2 revisions

Can you please explain what exactly does it do?
I tested the IDE without the patch and Ctrl-Click jumps between dotted named units without problems. I don't see other problems either.
What problem exactly does your patch fix?

Maciej Izak

2015-02-01 18:34

developer   ~0080740

At the first run of IDE after installation, Lazarus can't find units in fpcsrc directory with dotted names like Generics.Collections and Generics.Defaults.

Paul Ishenin

2015-02-11 03:11

manager   ~0080945

Better to simplify testing if possible. In this particular case I would suggest to test function output with different arguments. E.g.:
FilenameIsMatching('{*.pas,*.pp,*.p,*.inc,Makefile.fpc}', 'math.pp', True) returns True
FilenameIsMatching('{*.pas,*.pp,*.p,*.inc,Makefile.fpc}', 'Generics.Collections.pas', True) returns False

The problem is that FilenameIsMatching compares from file start and checks till '.'

Paul Ishenin

2015-02-11 04:15

manager  

fileprocs.pas.patch (1,191 bytes)   
Index: components/codetools/fileprocs.pas
===================================================================
--- components/codetools/fileprocs.pas	(revision 47701)
+++ components/codetools/fileprocs.pas	(working copy)
@@ -1608,7 +1608,7 @@
   DirStartMask, DirEndMask,
   DirStartFile, DirEndFile,
   BracketMaskPos, BracketFilePos: integer;
-  StopChar: LongInt;
+  StopChar, EndingLength: LongInt;
   Fits: Boolean;
 
   function TryNextOr: boolean;
@@ -1680,13 +1680,14 @@
                 inc(StopChar);
               inc(StopChar);
             end;
+            EndingLength := StopChar;
+            while ((EndingLength < DirEndMask) and not (Mask[EndingLength] in [',','}'])) do
+              inc(EndingLength);
+            EndingLength := EndingLength - StopChar;
             if StopChar>=DirEndMask then
               Fits:=true
             else begin
-              while (DirStartFile<DirEndFile)
-              and (not CharsEqual(Filename[DirStartFile],Mask[StopChar]))
-              do
-                inc(DirStartFile);
+              DirStartFile := DirEndFile - EndingLength;
               Fits:=DirStartFile<DirEndFile;
             end;
           end;
fileprocs.pas.patch (1,191 bytes)   

Paul Ishenin

2015-02-11 04:17

manager   ~0080948

I don't understand the suggested patch and made an own. In case of '*' my code simple skips checks till the rest of the mask.

Mattias Gaertner

2015-02-12 00:20

manager   ~0080968

I rewrote the function and added tests.

Issue History

Date Modified Username Field Change
2015-02-01 10:36 Maciej Izak New Issue
2015-02-01 10:36 Maciej Izak File Added: fileprocs.pas.patch
2015-02-01 13:10 Juha Manninen Relationship added related to 0027206
2015-02-01 13:16 Juha Manninen Note Added: 0080722
2015-02-01 15:19 Maciej Izak File Added: correct_patch_for_ fileprocs.pas.patch
2015-02-01 15:21 Maciej Izak Note Added: 0080725
2015-02-01 18:08 Juha Manninen Note Added: 0080736
2015-02-01 18:22 Juha Manninen Note Edited: 0080736 View Revisions
2015-02-01 18:34 Maciej Izak Note Added: 0080740
2015-02-01 21:07 Juha Manninen Assigned To => Mattias Gaertner
2015-02-01 21:07 Juha Manninen Status new => assigned
2015-02-11 03:11 Paul Ishenin Note Added: 0080945
2015-02-11 04:14 Paul Ishenin File Deleted: fileprocs.pas.patch
2015-02-11 04:15 Paul Ishenin File Added: fileprocs.pas.patch
2015-02-11 04:17 Paul Ishenin Note Added: 0080948
2015-02-12 00:20 Mattias Gaertner Fixed in Revision => 47711
2015-02-12 00:20 Mattias Gaertner LazTarget => -
2015-02-12 00:20 Mattias Gaertner Note Added: 0080968
2015-02-12 00:20 Mattias Gaertner Status assigned => resolved
2015-02-12 00:20 Mattias Gaertner Resolution open => fixed