Optimize CompareFileExt in different ways. Comparison of FPC/Lazarus generated files can be case-sensitive.

git-svn-id: trunk@64374 -
This commit is contained in:
juha 2021-01-10 19:07:52 +00:00
parent 1acc3f5c74
commit 3ea7788cbf
28 changed files with 149 additions and 127 deletions

View File

@ -121,7 +121,7 @@ var
PkgName: String;
begin
Result:=false;
if CompareFileExt(AFilename,'.lpk',false)<>0 then exit;
if CompareFileExt(AFilename,'lpk',true)<>0 then exit;
PkgName:=ExtractFileNameOnly(AFilename);
if (PkgName='') or (not IsValidPkgName(PkgName)) then exit;
Result:=true;

View File

@ -5864,8 +5864,7 @@ begin
end;
procedure TCodeToolManager.DoOnGatherUserIdentifiers(
Sender: TIdentCompletionTool; const ContextFlags: TIdentifierListContextFlags
);
Sender: TIdentCompletionTool; const ContextFlags: TIdentifierListContextFlags);
begin
if Assigned(FOnGatherUserIdentifiers) then
FOnGatherUserIdentifiers(Sender, ContextFlags);
@ -5874,9 +5873,9 @@ end;
function TCodeToolManager.DoOnGetSrcPathForCompiledUnit(Sender: TObject;
const AFilename: string): string;
begin
if CompareFileExt(AFilename,'.ppu',false)=0 then
if CompareFileExt(AFilename,'ppu',true)=0 then
Result:=GetPPUSrcPathForDirectory(ExtractFilePath(AFilename))
else if CompareFileExt(AFilename,'.dcu',false)=0 then
else if CompareFileExt(AFilename,'dcu')=0 then
Result:=GetDCUSrcPathForDirectory(ExtractFilePath(AFilename))
else
Result:='';

View File

@ -59,7 +59,7 @@ uses
CodeToolsStrConsts, ExprEval, DirectoryCacher, BasicCodeTools,
CodeToolsStructs, KeywordFuncLists, LinkScanner, FileProcs,
// LazUtils
LazStringUtils, LazFileUtils, LazFileCache,
LazStringUtils, LazFileUtils, FileUtil, LazFileCache,
LazUTF8, LazUTF8Classes, UTF8Process, LazDbgLog, AvgLvlTree, Laz2_XMLCfg;
const
@ -1966,7 +1966,7 @@ begin
if (Ext='.pas') or (Ext='.pp') or (Ext='.p') or (Ext='.ppu') then begin
File_Name:=ExtractFileNameOnly(Filename);
if (not Units.Contains(File_Name))
or ((Ext<>'.ppu') and (CompareFileExt(Units[File_Name],'ppu',false)=0))
or ((Ext<>'.ppu') and (CompareFileExt(Units[File_Name],'ppu',true)=0))
then
Units[File_Name]:=Filename;
end;
@ -2049,7 +2049,7 @@ begin
//if Pos('lazmkunit',Filename)>0 then
//debugln(['GatherUnitsInFPMSources ===== ',Filename]);
AVLNode:=Units.Tree.FindSuccessor(AVLNode);
if CompareFileExt(Filename,'ppu',false)<>0 then continue;
if CompareFileExt(Filename,'ppu',true)<>0 then continue;
// check if filename has the form
// /something/units/<FPCTarget>/<pkgname>/<unitname>.ppu
// and if there is /something/fpmkinst/<FPCTarget>/<pkgname>.fpm
@ -2134,7 +2134,7 @@ function GatherUnitSourcesInDirectory(Directory: string; MaxLevel: integer
if faDirectory and Info.Attr>0 then begin
if Lvl<MaxLevel then
Traverse(Dir+Filename+PathDelim,Tree,Lvl+1);
end else if FilenameIsPascalUnit(Filename) then begin
end else if FileProcs.FilenameIsPascalUnit(Filename) then begin
AnUnitName:=ExtractFileNameOnly(Filename);
if not Tree.Contains(AnUnitName) then
Tree[AnUnitName]:=Dir+Filename;
@ -2255,10 +2255,8 @@ begin
LastDirScore:=0;
for i:=0 to Files.Count-1 do begin
Filename:=Files[i];
if (CompareFileExt(Filename,'PAS',false)=0)
or (CompareFileExt(Filename,'PP',false)=0)
or (CompareFileExt(Filename,'P',false)=0)
then begin
// FileProcs also has FilenameIsPascalUnit();
if FileUtil.FilenameIsPascalUnit(Filename) then begin
if CompareFilenameOnly(PChar(Filename),length(Filename),'fpmake',6,true)=0
then
continue; // skip the fpmake.pp files
@ -2877,7 +2875,7 @@ begin
Item:=PStringToStringItem(Node.Data);
Unit_Name:=Item^.Name;
Filename:=Item^.Value;
if CompareFileExt(Filename,'.ppu',false)=0 then begin
if CompareFileExt(Filename,'ppu',true)=0 then begin
SrcFilename:=UnitToSource[Unit_Name];
if SrcFilename<>'' then begin
DuplicateFilenames:=UnitToDuplicates[Unit_Name];
@ -5414,8 +5412,7 @@ begin
end;
end;
function TDefineTree.GetDCUSrcPathForDirectory(const Directory: string
): string;
function TDefineTree.GetDCUSrcPathForDirectory(const Directory: string): string;
var Evaluator: TExpressionEvaluator;
begin
Evaluator:=GetDefinesForDirectory(Directory,true);
@ -9118,7 +9115,7 @@ begin
end;
// check if the system ppu exists
HasPPUs:=(Kind=pcFPC) and (Units<>nil)
and (CompareFileExt(Units['system'],'ppu',false)=0);
and (CompareFileExt(Units['system'],'ppu',true)=0);
// check compiler version define
if (CTConsoleVerbosity>=-1) and (Defines<>nil) then begin
case Kind of
@ -10424,7 +10421,7 @@ begin
if (ConfigCache.Units<>nil) then begin
UnitInFPCPath:=ConfigCache.Units[AnUnitName];
//if Pos('lazmkunit',AnUnitName)>0 then debugln(['TFPCUnitSetCache.GetUnitSrcFile UnitInFPCPath=',UnitInFPCPath]);
if (CompareFileExt(UnitInFPCPath,'ppu',false)=0) then begin
if (CompareFileExt(UnitInFPCPath,'ppu',true)=0) then begin
// there is a ppu
end else if UnitInFPCPath<>'' then begin
// there is a pp or pas in the FPC search path
@ -10476,7 +10473,7 @@ begin
if ConfigCache.Units=nil then exit;
Result:=ConfigCache.Units[AUnitName];
if Result='' then exit;
if CompareFileExt(Result,'.ppu',false)<>0 then
if CompareFileExt(Result,'ppu',true)<>0 then
Result:='';
end;

View File

@ -452,7 +452,7 @@ begin
end;
// try also different extensions
for pe:=Low(TCTPascalExtType) to High(TCTPascalExtType) do begin
if CompareFileExt(Filename,CTPascalExtension[pe],false)<>0 then
if CompareFileExtQuick(Filename,CTPascalExtension[pe])<>0 then
begin
AliasFilename:=ChangeFileExt(Filename,'.pas');
if FileExistsCached(AliasFilename) then begin
@ -869,7 +869,7 @@ begin
end;
// try different extensions too
for pe:=Low(TCTPascalExtType) to High(TCTPascalExtType) do begin
if CompareFileExt(Result,CTPascalExtension[pe],false)<>0 then
if CompareFileExtQuick(Result,CTPascalExtension[pe])<>0 then
begin
AliasFilename:=ChangeFileExt(Result,CTPascalExtension[pe]);
if FileExistsCached(AliasFilename) then begin

View File

@ -340,7 +340,7 @@ begin
Item:=PStringToStringItem(Node.Data);
aUnitName:=Item^.Name;
Filename:=Item^.Value;
if CompareFileExt(Filename,'ppu',false)=0 then begin
if CompareFileExt(Filename,'ppu',true)=0 then begin
// a ppu in the PPU search path
if UnitToSrc[aUnitName]='' then begin
inc(Cnt);
@ -390,7 +390,7 @@ begin
aUnitName:=Item^.Name;
Files:=Item^.Value;
PPUFile:=Units[aUnitName];
if CompareFileExt(PPUFile,'ppu',false)=0 then begin
if CompareFileExt(PPUFile,'ppu',true)=0 then begin
if Cnt=0 then writeln;
inc(Cnt);
writeln('WARNING: duplicate source file for ppu ',aUnitName,' files=',Files);
@ -437,7 +437,7 @@ begin
PPUFile:=ConfigCache.Units[AnUnitName];
if PPUFile='' then
writeln(' WARNING: ',AnUnitName,' is not in PPU search path')
else if CompareFileExt(PPUFile,'ppu',false)<>0 then
else if CompareFileExt(PPUFile,'ppu',true)<>0 then
writeln(' WARNING: fpc ppu search path has a source and not a ppu for ',AnUnitName,': ',PPUFile)
else
writeln(' in PPU search path: ',PPUFile);

View File

@ -697,7 +697,7 @@ begin
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then
continue;
Filename:=FileInfo.Name;
if (CompareFileExt(Filename,'ppu',false)<>0) then continue;
if (CompareFileExt(Filename,'ppu',true)<>0) then continue;
AUnitName:=ExtractFileNameOnly(Filename);
Filename:=AppendPathDelim(Directory)+Filename;
if not LazIsValidIdent(AUnitName,true,true) then begin

View File

@ -87,10 +87,16 @@ end;
function FilenameIsPascalUnit(const Filename: string): boolean;
var
i: Integer;
i, FnPos: Integer;
FnExt: String;
begin
FnPos := length(Filename);
while (FnPos>=1) and (Filename[FnPos]<>'.') do dec(FnPos);
if FnPos < 1 then
exit(false); // no extension in filename
FnExt := LowerCase(Copy(Filename, FnPos, length(FileName)));
for i:=Low(PascalFileExt) to High(PascalFileExt) do
if CompareFileExt(Filename,PascalFileExt[i],false)=0 then
if CompareStr(FnExt,PascalFileExt[i])=0 then
exit(true);
Result:=false;
end;

View File

@ -28,8 +28,9 @@ uses
function CompareFilenames(const Filename1, Filename2: string): integer; overload;
function CompareFilenamesIgnoreCase(const Filename1, Filename2: string): integer;
function CompareFileExt(const Filename, Ext: string;
CaseSensitive: boolean = False): integer;
function CompareFileExt(const Filename: string; Ext: string; CaseSensitive: boolean): integer;
function CompareFileExt(const Filename, Ext: string): integer;
function CompareFileExtQuick(const Filename: string; LowerExt: string): integer;
function CompareFilenameStarts(const Filename1, Filename2: string): integer;
function CompareFilenames(Filename1: PChar; Len1: integer;
Filename2: PChar; Len2: integer): integer; overload;
@ -262,37 +263,60 @@ begin
{$ENDIF}
end;
function CompareFileExt(const Filename, Ext: string; CaseSensitive: boolean): integer;
function CompareFileExt(const Filename: string; Ext: string; CaseSensitive: boolean): integer;
// Ext can contain a point or not
var
n, e : AnsiString;
FileLen, FilePos, ExtLen, ExtPos: integer;
FnExt: String;
FnPos: integer;
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);
// Filename
FnPos := length(Filename);
while (FnPos>=1) and (Filename[FnPos]<>'.') do dec(FnPos);
if FnPos < 1 then
exit(1); // no extension in filename
FnExt := Copy(Filename, FnPos+1, length(FileName)); // FnPos+1 skips point
// Ext
if (length(Ext) > 1) and (Ext[1] = '.') then
Delete(Ext, 1, 1);
// compare extensions
n := Copy(Filename, FilePos, length(FileName));
e := Copy(Ext, ExtPos, length(Ext));
if CaseSensitive then
Result := CompareStr(n, e)
Result := CompareStr(FnExt, Ext)
else
Result := UTF8CompareText(n, e);
if Result < 0
then Result := -1
else
if Result > 0 then Result := 1;
Result := UTF8CompareText(FnExt, Ext);
if Result < 0 then
Result := -1
else if Result > 0 then
Result := 1;
end;
function CompareFileExt(const Filename, Ext: string): integer;
begin
Result := CompareFileExt(Filename, Ext,
{$IFDEF CaseInsensitiveFilenames} False {$ELSE} True {$ENDIF} );
end;
function CompareFileExtQuick(const Filename: string; LowerExt: string): integer;
// Compares case-insensitively but only with ASCII characters.
// LowerExt must be lowercase. It can contain a point or not.
var
FnExt: String;
FnPos: integer;
begin
// Filename
FnPos := length(Filename);
while (FnPos>=1) and (Filename[FnPos]<>'.') do dec(FnPos);
if FnPos < 1 then
exit(1); // no extension in filename
FnExt := LowerCase(Copy(Filename, FnPos+1, length(FileName))); // FnPos+1 skips point
// Ext
if (length(LowerExt) > 1) and (LowerExt[1] = '.') then
Delete(LowerExt, 1, 1);
// compare extensions
Result := CompareStr(FnExt, LowerExt);
if Result < 0 then
Result := -1
else if Result > 0 then
Result := 1;
end;
function ExtractFileNameOnly(const AFilename: string): string;

View File

@ -432,7 +432,7 @@ begin
Result:=false;
AUnitName:='';
Language:='';
if CompareFileExt(Filename, '.po', false)=0 then
if CompareFileExtQuick(Filename, 'po')=0 then
begin
NameWithoutExt:=ExtractFileNameWithoutExt(Filename);
Ext:=ExtractFileExt(NameWithoutExt);
@ -514,6 +514,7 @@ var
BasePoFile: TPoFile;
i: Integer;
E: EPOFileError;
ExtLrj: Boolean;
begin
Result := false;
@ -539,19 +540,19 @@ begin
// Update po file with lrj, rst/rsj of RSTFiles
for i:=0 to RSTFiles.Count-1 do begin
Filename:=RSTFiles[i];
if (CompareFileExt(Filename,'.lrj')=0) or
(CompareFileExt(Filename,'.rst')=0) or
(CompareFileExt(Filename,'.rsj')=0) then
ExtLrj := (CompareFileExtQuick(Filename,'lrj')=0);
if ExtLrj or (CompareFileExtQuick(Filename,'rst')=0) or
(CompareFileExtQuick(Filename,'rsj')=0) then
try
//DebugLn('');
//DebugLn(['AddFiles2Po Filename="',Filename,'"']);
InputLines.Clear;
InputLines.LoadFromFile(FileName);
if CompareFileExt(Filename,'.lrj')=0 then
if ExtLrj then
BasePOFile.UpdateStrings(InputLines, stLrj)
else
if CompareFileExt(Filename,'.rsj')=0 then
if CompareFileExtQuick(Filename,'rsj')=0 then
BasePOFile.UpdateStrings(InputLines, stRsj)
else
BasePOFile.UpdateStrings(InputLines, stRst);

View File

@ -992,7 +992,7 @@ var
StartTime, EndTime: TDateTime;
s: string;
begin
if CompareFileExt(fSettings.MainFilename,'.dproj',false)=0 then begin
if CompareFileExtQuick(fSettings.MainFilename,'dproj')=0 then begin
fErrorMsg := lisConvDprojFileNotSupportedYet;
Exit(mrCancel);
end;
@ -1010,7 +1010,7 @@ begin
fLazPMainFilename:=fSettings.DelphiToLazFilename(fSettings.MainFilename,
fLazPMainSuffix, false);
// Find Delphi project / package file name
if CompareFileExt(fSettings.MainFilename,fDelphiPSuffix,false)=0 then
if CompareFileExtQuick(fSettings.MainFilename,fDelphiPSuffix)=0 then
fDelphiPFilename:=fSettings.MainFilename
else
fDelphiPFilename:=ChangeFileExt(fSettings.MainFilename,fDelphiPSuffix);

View File

@ -872,7 +872,7 @@ procedure TBuildManager.RescanCompilerDefines(ResetBuildTarget,
if ConfigCache.Units=nil then exit;
AFilename:=ConfigCache.Units['system'];
if AFilename='' then exit;
if CompareFileExt(AFilename,'.ppu',false)<>0 then exit;
if CompareFileExt(AFilename,'ppu',true)<>0 then exit;
Result:=true;
end;
@ -1688,7 +1688,7 @@ begin
or ((FileInfo.Attr and faDirectory)<>0) then continue;
if FilenameIsPascalUnit(FileInfo.Name) then
CurUnitTree:=SourceUnitTree
else if (CompareFileExt(FileInfo.Name,CompiledExt,false)=0) then
else if (CompareFileExt(FileInfo.Name,CompiledExt,true)=0) then
CurUnitTree:=CompiledUnitTree
else
continue;

View File

@ -456,8 +456,7 @@ begin
Result:=mrOk;
end;
function TCheckCompilerOptsDlg.FindAllPPUFiles(const AnUnitPath: string
): TStrings;
function TCheckCompilerOptsDlg.FindAllPPUFiles(const AnUnitPath: string): TStrings;
var
Directory: String;
p: Integer;
@ -476,8 +475,7 @@ begin
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then
continue;
// check extension
if CompareFileExt(FileInfo.Name,'.ppu',
{$IFDEF MSWINDOWS}false{$ELSE}true{$ENDIF})=0 then
if CompareFileExt(FileInfo.Name,'ppu',true)=0 then
Result.Add(Directory+FileInfo.Name);
until FindNextUTF8(FileInfo)<>0;
end;
@ -626,7 +624,7 @@ begin
Node:=CfgCache.Units.Tree.FindLowest;
while Node<>nil do begin
Item:=PStringToStringItem(Node.Data);
if (Item^.Value<>'') and (CompareFileExt(Item^.Value,'.ppu',false)=0) then
if (Item^.Value<>'') and (CompareFileExt(Item^.Value,'ppu',true)=0) then
CheckFileAge(Item^.Value);
Node:=CfgCache.Units.Tree.FindSuccessor(Node);
end;
@ -805,10 +803,8 @@ begin
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then
continue;
// check extension
if (CompareFileExt(FileInfo.Name,'.ppu',
{$IFDEF MSWINDOWS}false{$ELSE}true{$ENDIF})<>0)
and (CompareFileExt(FileInfo.Name,'.o',
{$IFDEF MSWINDOWS}false{$ELSE}true{$ENDIF})<>0)
if (CompareFileExt(FileInfo.Name,'ppu',true)<>0)
and (CompareFileExt(FileInfo.Name,'o',true)<>0)
then
continue;
PPUFiles.Add(Directory+FileInfo.Name);

View File

@ -1387,7 +1387,7 @@ var
while Node<>nil do begin
Item:=PStringToStringItem(Node.Data);
Filename:=Item^.Value;
if (CompareFileExt(Filename,'ppu',false)=0) then begin
if (CompareFileExt(Filename,'ppu',true)=0) then begin
// search source in fpc sources
Filename:=UnitSet.GetUnitSrcFile(ExtractFileNameOnly(Filename));
end;

View File

@ -1948,7 +1948,7 @@ var
begin
if ExtractFileName(aFilename)='' then exit;
Ext:=GetTargetFileExt;
if (Ext<>'') and (CompareFileExt(aFilename,Ext)<>0) then
if (Ext<>'') and (CompareFileExtQuick(aFilename,Ext)<>0) then
aFilename:=aFilename+Ext;
//DebugLn('Filename is ',AFilename,' in AppendDefaultExt');
end;

View File

@ -1894,7 +1894,7 @@ begin
begin
MsgLine.Urgency:=mluVerbose;
end else if HideHintsUnitNotUsedInMainSource then begin
if CompareFileExt(MsgLine.Filename, 'lpr', false)=0 then
if CompareFileExt(MsgLine.Filename, 'lpr', true)=0 then
// a lpr does not use a unit => not important
MsgLine.Urgency:=mluVerbose
else if FilenameIsAbsolute(MsgLine.Filename)

View File

@ -383,11 +383,11 @@ begin
// Update po file with lrj or/and rst/rsj files
for i:=0 to SrcFiles.Count-1 do begin
Filename:=SrcFiles[i];
if CompareFileExt(Filename,'.lrj',false)=0 then
if CompareFileExtQuick(Filename,'lrj')=0 then
FileType:=stLrj
else if CompareFileExt(Filename,'.rst',false)=0 then
else if CompareFileExtQuick(Filename,'rst')=0 then
FileType:=stRst
else if CompareFileExt(Filename,'.rsj',false)=0 then
else if CompareFileExtQuick(Filename,'rsj')=0 then
FileType:=stRsj
else
continue;

View File

@ -204,7 +204,7 @@ begin
else begin
// default: depending on file type
Result:=DefaultCompilerOptPath;
if CompareFileExt(fXMLConfig.Filename,'.lpk',false)=0 then
if CompareFileExt(fXMLConfig.Filename,'lpk',true)=0 then
begin
try
FileVersion:=fXMLConfig.GetValue(PkgVersionPath,2);

View File

@ -328,7 +328,7 @@ var
function CheckPPU(const AnUnitName: string): boolean;
begin
if (CfgCache.Units=nil)
or (CompareFileExt(CfgCache.Units[AnUnitName],'ppu',false)<>0) then
or (CompareFileExt(CfgCache.Units[AnUnitName],'ppu',true)<>0) then
begin
Note:=Format(lisPpuNotFoundCheckYourFpcCfg, [AnUnitName]);
Result:=false;

View File

@ -338,7 +338,7 @@ begin
FileNode:=nil;
for i:=0 to Files.Count-1 do begin
aFile:=Files[i];
if CompareFileExt(aFile.Filename,'.ppu',false)=0 then
if CompareFileExt(aFile.Filename,'ppu',true)=0 then
inc(PPUCount)
else
inc(SrcCount);

View File

@ -387,7 +387,7 @@ begin
Package:=TLazPackageLink(LazPackageLinks.FindLinkWithPkgName(OriginalFileName));
if Package=nil then begin
// Not found after everything we tried
if CompareFileExt(Filename,'.lpi')=0 then
if CompareFileExt(Filename,'lpi', true)=0 then
Error(ErrorFileNotFound,'file not found: '+OriginalFilename)
else
Error(ErrorFileNotFound,'package not found: '+OriginalFilename);
@ -416,15 +416,15 @@ begin
end
else begin
// File exists:
if CompareFileExt(Filename,'.lpk')=0 then begin
if CompareFileExt(Filename,'lpk',true)=0 then begin
case PackageAction of
lpaBuild: Result:=BuildPackage(Filename);
lpaInstall: Result:=true; // this is handled in AddPackagesToInstallList
lpaAddPkgLinks: Result:=true;
end;
end else if CompareFileExt(Filename,'.lpi')=0 then
end else if CompareFileExt(Filename,'lpi',true)=0 then
Result:=BuildProject(Filename)
else if CompareFileExt(Filename,'.lpr')=0 then begin
else if CompareFileExt(Filename,'lpr',true)=0 then begin
Filename:=ChangeFileExt(Filename,'.lpi');
if FileExists(Filename) then
Result:=BuildProject(Filename)
@ -1061,7 +1061,7 @@ begin
PkgFilename:='';
if pvPkgSearch in fPkgGraphVerbosity then
debugln(['Info: (lazarus) [TLazBuildApplication.AddPackagesToInstallList] "',PackageNamesOrFiles[i],'"']);
if CompareFileExt(PackageNamesOrFiles[i],'.lpk')=0 then
if CompareFileExt(PackageNamesOrFiles[i],'lpk',true)=0 then
PkgFilename:=ExpandFileNameUTF8(PackageNamesOrFiles[i])
else if IsValidPkgName(PackageNamesOrFiles[i]) then begin
PackageLink:=TLazPackageLink(LazPackageLinks.FindLinkWithPkgName(PackageNamesOrFiles[i]));
@ -1122,7 +1122,7 @@ begin
begin
// Look for package name in all known packages
PkgFilename:=PackageNamesOrFiles[i];
if CompareFileExt(PkgFilename,'.lpk')<>0 then begin
if CompareFileExt(PkgFilename,'lpk',true)<>0 then begin
ErrorMsg+=PkgFilename+' is not a package (.lpk), so it is not registered.'+LineEnding;
continue;
end;

View File

@ -2327,10 +2327,10 @@ begin
// try command line project
if (CmdLineFiles<>nil) and (CmdLineFiles.Count>0) then begin
AProjectFilename:=CmdLineFiles[0];
if (CompareFileExt(AProjectFilename,'.lpr',false)=0) then
if (CompareFileExt(AProjectFilename,'lpr',true)=0) then
AProjectFilename:=ChangeFileExt(AProjectFilename,'.lpi');
// only try to load .lpi files, other files are loaded later
if (CompareFileExt(AProjectFilename,'.lpi',false)=0) then begin
if (CompareFileExt(AProjectFilename,'lpi',true)=0) then begin
AProjectFilename:=CleanAndExpandFilename(AProjectFilename);
if FileExistsUTF8(AProjectFilename) then begin
CmdLineFiles.Delete(0);
@ -2416,7 +2416,7 @@ begin
// => create a project
DoNewProject(ProjectDescriptorEmptyProject);
end;
if CompareFileExt(AFilename,'.lpk',false)=0 then begin
if CompareFileExt(AFilename,'lpk',true)=0 then begin
if PkgBoss.DoOpenPackageFile(AFilename,[pofAddToRecent,pofMultiOpen],true)=mrAbort
then
break;
@ -7567,9 +7567,9 @@ procedure TMainIDE.DoExecuteRemoteControl;
AProjectFilename:='';
for i:=Files.Count-1 downto 0 do begin
AProjectFilename:=Files[0];
if (CompareFileExt(AProjectFilename,'.lpr',false)=0) then
if (CompareFileExt(AProjectFilename,'lpr',true)=0) then
AProjectFilename:=ChangeFileExt(AProjectFilename,'.lpi');
if (CompareFileExt(AProjectFilename,'.lpi',false)=0) then begin
if (CompareFileExt(AProjectFilename,'lpi',true)=0) then begin
// open a project
Files.Delete(i); // remove from the list
AProjectFilename:=CleanAndExpandFilename(AProjectFilename);
@ -7598,7 +7598,7 @@ procedure TMainIDE.DoExecuteRemoteControl;
for i:=0 to Files.Count-1 do begin
AFilename:=CleanAndExpandFilename(Files.Strings[i]);
DebugLn(['Hint: (lazarus) TMainIDE.DoExecuteRemoteControl.OpenFiles AFilename="',AFilename,'"']);
if CompareFileExt(AFilename,'.lpk',false)=0 then begin
if CompareFileExt(AFilename,'lpk',true)=0 then begin
if PkgBoss.DoOpenPackageFile(AFilename,[pofAddToRecent],true)=mrAbort
then
break;
@ -8904,7 +8904,7 @@ begin
if (ActiveUnitInfo.Component=nil)
and (ActiveUnitInfo.Source<>nil) then begin
if (CompareFileExt(ActiveUnitInfo.Filename,'.inc',false)=0) then begin
if (CompareFileExtQuick(ActiveUnitInfo.Filename,'inc')=0) then begin
// include file => get unit
UnitCodeBuf:=CodeToolBoss.GetMainCode(ActiveUnitInfo.Source);
if (UnitCodeBuf<>nil) and (UnitCodeBuf<>ActiveUnitInfo.Source) then begin
@ -8918,7 +8918,7 @@ begin
end;
end;
end;
if (CompareFileExt(ActiveUnitInfo.Filename,'.lfm',false)=0) then begin
if (CompareFileExt(ActiveUnitInfo.Filename,'lfm',true)=0) then begin
// lfm file => get unit
aFilename:=GetUnitFileOfLFM(ActiveUnitInfo.Filename);
if aFilename<>'' then begin
@ -12586,7 +12586,7 @@ begin
end;
end;
end
else if CompareFileExt(AnUnitInfo.Filename,'inc',false)=0 then
else if CompareFileExtQuick(AnUnitInfo.Filename,'inc')=0 then
OkToAdd:=CheckDirIsInSearchPath(AnUnitInfo,True);
if OkToAdd then
;

View File

@ -6977,7 +6977,7 @@ begin
ShortFileName:=ExtractFileName(CurFilename);
MainCodeBuf:=nil;
if FilenameIsPascalUnit(ShortFileName)
or (CompareFileExt(ShortFileName,'.inc',true)=0) then
or (CompareFileExtQuick(ShortFileName,'inc')=0) then
MainCodeBuf:=CodeToolBoss.GetMainCode(ASrcEdit.CodeBuffer)
else if FilenameIsPascalSource(ShortFileName) then
MainCodeBuf:=ASrcEdit.CodeBuffer;
@ -7000,14 +7000,14 @@ begin
MaybeAddPopup('.s');
end;
// ToDo: unit resources
if (CompareFileExt(ShortFileName,'.lfm',true)=0)
or (CompareFileExt(ShortFileName,'.dfm',true)=0) then begin
if (CompareFileExt(ShortFileName,'lfm',true)=0)
or (CompareFileExtQuick(ShortFileName,'dfm')=0) then begin
MaybeAddPopup('.pas');
MaybeAddPopup('.pp');
MaybeAddPopup('.p');
end;
if (CompareFileExt(ShortFileName,'.lpi',true)=0)
or (CompareFileExt(ShortFileName,'.lpk',true)=0) then begin
if (CompareFileExt(ShortFileName,'lpi',true)=0)
or (CompareFileExt(ShortFileName,'lpk',true)=0) then begin
AddContextPopupMenuItem(
Format(lisOpenLfm,[ShortFileName]),true,@OnPopupMenuOpenFile);
end;
@ -8075,10 +8075,10 @@ begin
aFilename:=copy(aFilename,p,length(aFilename)-(length(ResStr)-2));
if not FilenameIsAbsolute(aFilename) then
aFilename:=TrimFilename(ExtractFilePath(GetActiveSE.Filename)+aFilename);
if CompareFileExt(aFilename,'.lpi')=0 then
if CompareFileExt(aFilename,'lpi',true)=0 then
MainIDEInterface.DoOpenProjectFile(aFilename,
[ofOnlyIfExists,ofAddToRecent,ofUseCache])
else if CompareFileExt(aFilename,'.lpk')=0 then
else if CompareFileExt(aFilename,'lpk',true)=0 then
PackageEditingInterface.DoOpenPackageFile(aFilename,[pofAddToRecent],false)
else
MainIDEInterface.DoOpenEditorFile(aFilename,
@ -10202,7 +10202,7 @@ begin
ShortFileName:=ExtractFileName(CurFilename);
MainCodeBuf:=nil;
if FilenameIsPascalUnit(ShortFileName)
or (CompareFileExt(ShortFileName,'.inc',true)=0) then
or (CompareFileExtQuick(ShortFileName,'inc')=0) then
MainCodeBuf:=CodeToolBoss.GetMainCode(SrcEdit.CodeBuffer)
else if FilenameIsPascalSource(ShortFileName) then
MainCodeBuf:=SrcEdit.CodeBuffer;

View File

@ -1255,7 +1255,7 @@ begin
if ([ofRegularFile,ofRevert,ofProjectLoading]*FFlags=[])
and FilenameIsAbsolute(FFilename) and FileExistsCached(FFilename) then begin
// check if file is a lazarus project (.lpi)
if (CompareFileExt(FFilename,'.lpi',false)=0) then
if (CompareFileExt(FFilename,'lpi',true)=0) then
begin
case
IDEQuestionDialog(lisOpenProject, Format(lisOpenTheProject, [FFilename]),
@ -1273,7 +1273,7 @@ begin
end;
// check if file is a lazarus package (.lpk)
if (CompareFileExt(FFilename,'.lpk',false)=0) then
if (CompareFileExt(FFilename,'lpk',true)=0) then
begin
case
IDEQuestionDialog(lisOpenPackage,
@ -1851,7 +1851,7 @@ begin
OkToAdd:=True;
if FilenameIsPascalUnit(ActiveUnitInfo.Filename) then
OkToAdd:=CheckDirIsInSearchPath(ActiveUnitInfo,False)
else if CompareFileExt(ActiveUnitInfo.Filename,'inc',false)=0 then
else if CompareFileExtQuick(ActiveUnitInfo.Filename,'inc')=0 then
OkToAdd:=CheckDirIsInSearchPath(ActiveUnitInfo,True);
if OkToAdd then begin
ActiveUnitInfo.IsPartOfProject:=true;
@ -4143,7 +4143,7 @@ begin
+dlgFilterAll+'|'+GetAllFilesMask;
if OpenDialog.Execute then begin
AFilename:=GetPhysicalFilenameCached(ExpandFileNameUTF8(OpenDialog.Filename),false);
if CompareFileExt(AFilename,'.lpi')<>0 then begin
if CompareFileExt(AFilename,'lpi',true)<>0 then begin
// not a lpi file
// check if it is a program source
@ -5785,8 +5785,8 @@ begin
// check, if a .lfm file is opened in the source editor
if (LFMUnitInfo=nil) or
((CompareFileExt(LFMUnitInfo.Filename,'.lfm',false)<>0) and
(CompareFileExt(LFMUnitInfo.Filename,'.dfm',false)<>0)) then
((CompareFileExt(LFMUnitInfo.Filename,'lfm',true)<>0) and
(CompareFileExtQuick(LFMUnitInfo.Filename,'dfm')<>0)) then
begin
if not Quiet then
begin
@ -6386,7 +6386,7 @@ begin
end;
end;
try
if (CompareFileExt(LFMFilename,'lfm')<>0) then
if (CompareFileExt(LFMFilename,'lfm',true)<>0) then
begin
// no lfm format -> keep old info
exit(true);
@ -7408,7 +7408,7 @@ begin
// Do not care if this fails. A user may have removed the line from source.
Project1.RemoveCreateFormFromProjectFile(AnUnitInfo.ComponentName);
end;
if CompareFileExt(AnUnitInfo.Filename,'.inc',false)=0 then
if CompareFileExtQuick(AnUnitInfo.Filename,'inc')=0 then
// include file
if FilenameIsAbsolute(AnUnitInfo.Filename) then
ObsoleteIncPaths:=MergeSearchPaths(ObsoleteIncPaths,UnitPath);
@ -7422,7 +7422,7 @@ begin
UnitPath:=ChompPathDelim(ExtractFilePath(AnUnitInfo.Filename));
if FilenameIsPascalUnit(AnUnitInfo.Filename) then
ObsoleteUnitPaths:=RemoveSearchPaths(ObsoleteUnitPaths,UnitPath);
if CompareFileExt(AnUnitInfo.Filename,'.inc',false)=0 then
if CompareFileExtQuick(AnUnitInfo.Filename,'inc')=0 then
ObsoleteIncPaths:=RemoveSearchPaths(ObsoleteIncPaths,UnitPath);
end;
AnUnitInfo:=AnUnitInfo.NextPartOfProject;

View File

@ -710,7 +710,7 @@ var
Node:=Node.Successor;
OFile:=TPGInterPkgFile(ONode.Data);
if not FilenameIsCompiledSource(OFile.ShortFilename) then continue;
if CompareFileExt(OFile.ShortFilename,'.ppu',false)=0 then continue;
if CompareFileExt(OFile.ShortFilename,'ppu',true)=0 then continue;
// search corresponding .ppu
PPUFileName:=ChangeFileExt(OFile.FullFilename,'.ppu');
SearchFile:=TPGInterPkgFile.Create(PPUFileName,'',nil);

View File

@ -899,13 +899,13 @@ var
begin
HasName:=ExtractFileNameOnly(AFilename)<>'';
if HasName then begin
if CompareFileExt(AFilename,'.lfm',true)=0 then
if CompareFileExt(AFilename,'lfm',true)=0 then
exit(pftLFM)
else if CompareFileExt(AFilename,'.lrs',true)=0 then
else if CompareFileExt(AFilename,'lrs',true)=0 then
exit(pftLRS)
else if CompareFileExt(AFilename,'.inc',true)=0 then
else if CompareFileExtQuick(AFilename,'inc')=0 then
exit(pftInclude)
else if CompareFileExt(AFilename,'.xml',true)=0 then
else if CompareFileExtQuick(AFilename,'xml')=0 then
exit(pftIssues)
else if FilenameIsPascalUnit(AFilename) then begin
Result:=pftUnit;
@ -2070,7 +2070,7 @@ var
begin
Result:='';
AFilename:=TrimFilename(DefaultFilename);
if (CompareFileExt(AFilename,'lpk')<>0)
if (CompareFileExt(AFilename,'lpk',true)<>0)
or (SysUtils.CompareText(ExtractFileNameOnly(AFilename),PackageName)<>0) then
exit;
if not FilenameIsAbsolute(AFilename) then begin

View File

@ -392,7 +392,7 @@ procedure TLazPackageLinks.UpdateGlobalLinks;
begin
Result:=false;
PkgName:='';
if CompareFileExt(Filename,'.lpl',false)<>0 then exit;
if CompareFileExt(Filename,'lpl',true)<>0 then exit;
StartPos:=1;
// parse identifier
if (StartPos>length(Filename))
@ -463,7 +463,7 @@ begin
LazDir:=EnvironmentOptions.GetParsedLazarusDirectory;
for i:=0 to Files.Count-1 do begin
LPLFilename:=GlobalLinksDir+Files[i];
if CompareFileExt(LPLFilename,'lpl')<>0 then continue;
if CompareFileExt(LPLFilename,'lpl',true)<>0 then continue;
if (not ParseFilename(Files[i],NewPkgName,PkgVersion))
then begin
DebugLn('Warning: (lazarus) suspicious pkg link file found (name): ',LPLFilename);

View File

@ -3530,14 +3530,13 @@ var
OpenEditor: Boolean;
begin
// replace macros
if pofConvertMacros in Flags then begin
if pofConvertMacros in Flags then
if not GlobalMacroList.SubstituteStr(AFilename) then exit(mrCancel);
end;
AFilename:=GetPhysicalFilenameCached(CleanAndExpandFilename(AFilename),false);
// check file extension
if (CompareFileExt(AFilename,'.lpk',false)<>0)
if (CompareFileExt(AFilename,'lpk',true)<>0)
and (not (pofRevert in Flags)) then begin
DoQuestionDlg(lisPkgMangInvalidFileExtension,
Format(lisPkgMangTheFileIsNotALazarusPackage, [AFilename]));

View File

@ -227,7 +227,7 @@ begin
if (FileInfo.Attr and faDirectory)>0 then begin
// scan sub directories too
ScanPackages(AppendPathDelim(Dir+FileInfo.Name),Packages);
end else if CompareFileExt(FileInfo.Name,'.lpk',false)=0 then begin
end else if CompareFileExt(FileInfo.Name,'lpk',true)=0 then begin
ScanPackage(Dir+FileInfo.Name,Packages);
end;
until FindNextUTF8(FileInfo)<>0;
@ -272,7 +272,7 @@ begin
continue;
if (FileInfo.Attr and faDirectory)>0 then begin
// skip
end else if CompareFileExt(FileInfo.Name,'.lpl',false)=0 then begin
end else if CompareFileExt(FileInfo.Name,'lpl',true)=0 then begin
ScanLink(Dir+FileInfo.Name,Links);
end;
until FindNextUTF8(FileInfo)<>0;