diff --git a/components/codetools/basiccodetools.pas b/components/codetools/basiccodetools.pas index fa3078d740..973729ea66 100644 --- a/components/codetools/basiccodetools.pas +++ b/components/codetools/basiccodetools.pas @@ -1749,7 +1749,7 @@ var FindLen, TxtLen: integer; begin FindLen:=length(Find); TxtLen:=length(Txt); - if not CaseSensitive then begin + if CaseSensitive then begin while (FindStartPos<=FindLen) and (TxtStartPos<=TxtLen) and (Len>0) do begin if Find[FindStartPos]=Txt[TxtStartPos] then begin inc(FindStartPos); diff --git a/components/codetools/fileprocs.pas b/components/codetools/fileprocs.pas index 7c3b0e630b..5fa2389628 100644 --- a/components/codetools/fileprocs.pas +++ b/components/codetools/fileprocs.pas @@ -71,17 +71,20 @@ function SearchFileInPath(const Filename, BasePath, SearchPath, Delimiter: string; SearchLoUpCase: boolean): string; function FilenameIsMatching(const Mask, Filename: string; MatchExactly: boolean): boolean; - +function CompareFileExt(const Filename, Ext: string; + CaseSensitive: boolean): integer; implementation - // to get more detailed error messages consider the os {$IFNDEF win32} uses {$IFDEF Ver1_0} Linux {$ELSE} Unix {$ENDIF}; {$ENDIF} +var + UpChars: array[char] of char; + function CompareFilenames(const Filename1, Filename2: string): integer; begin {$IFDEF WIN32} @@ -626,6 +629,77 @@ begin //writeln(' [FilenameIsMatching] Result=',Result,' ',DirStartMask,',',length(Mask),' ',DirStartFile,',',length(Filename)); end; +function CompareFileExt(const Filename, Ext: string; + CaseSensitive: boolean): integer; +var + FileLen, FilePos, ExtLen, ExtPos: integer; + FileChar, ExtChar: char; +begin + FileLen:=length(Filename); + ExtLen:=length(Ext); + FilePos:=FileLen; + while (FilePos>=1) and (Filename[FilePos]<>'.') do dec(FilePos); + if FilePos<1 then begin + // no extension in filename + Result:=1; + exit; + end; + // skip point + inc(FilePos); + ExtPos:=1; + if (ExtPos<=ExtLen) and (Ext[1]='.') then inc(ExtPos); + // compare extensions + while true do begin + if FilePos<=FileLen then begin + if ExtPos<=ExtLen then begin + FileChar:=Filename[FilePos]; + ExtChar:=Ext[ExtPos]; + if not CaseSensitive then begin + FileChar:=UpChars[FileChar]; + ExtChar:=UpChars[ExtChar]; + end; + if FileChar=ExtChar then begin + inc(FilePos); + inc(ExtPos); + end else if FileChar>ExtChar then begin + Result:=1; + exit; + end else begin + Result:=-1; + exit; + end; + end else begin + // fileext longer than ext + Result:=1; + exit; + end; + end else begin + if ExtPos<=ExtLen then begin + // fileext shorter than ext + Result:=-1; + exit; + end else begin + // equal + Result:=0; + exit; + end; + end; + end; +end; + + +procedure InternalInit; +var + c: char; +begin + for c:=Low(char) to High(char) do begin + UpChars[c]:=upcase(c); + end; +end; + +initialization + InternalInit; + end. diff --git a/components/codetools/finddeclarationtool.pas b/components/codetools/finddeclarationtool.pas index 04b7af1797..5b49ee30c9 100644 --- a/components/codetools/finddeclarationtool.pas +++ b/components/codetools/finddeclarationtool.pas @@ -1029,8 +1029,8 @@ function TFindDeclarationTool.FindUnitSource(const AnUnitName, {$IFDEF ShowTriedFiles} //writeln(' unit "',copy(UnitLinks,UnitLinkStart,UnitLinkEnd-UnitLinkStart),'"'); {$ENDIF} - if AnsiCompareText(TheUnitName, - copy(UnitLinks,UnitLinkStart,UnitLinkEnd-UnitLinkStart))=0 + if CompareSubStrings(TheUnitName,UnitLinks,1, + UnitLinkStart,UnitLinkEnd-UnitLinkStart,false)=0 then begin // unit found -> parse filename UnitLinkStart:=UnitLinkEnd+1; @@ -1041,6 +1041,13 @@ function TFindDeclarationTool.FindUnitSource(const AnUnitName, if UnitLinkEnd>UnitLinkStart then begin CurFilename:=copy(UnitLinks,UnitLinkStart,UnitLinkEnd-UnitLinkStart); LoadFile(CurFilename,Result); + if Result=nil then begin + // try also different extensions + if CompareFileExt(CurFilename,'.pp',false)=0 then + LoadFile(ChangeFileExt(CurFilename,'.pas'),Result) + else + LoadFile(ChangeFileExt(CurFilename,'.pp'),Result); + end; exit; end; end else begin @@ -2998,6 +3005,7 @@ begin ReadNextAtom; ReadNextAtom; if (Scanner.PascalCompiler<>pcDelphi) + and Scanner.InitialValues.IsDefined('VER1_0') and Scanner.InitialValues.IsDefined('LINUX') then // ToDo: other OS than linux