New optimized functions in LazUtils: FilenameExtIs and FilenameExtIn. Used instead of CompareFileExt and similar.

git-svn-id: trunk@64583 -
This commit is contained in:
juha 2021-02-15 08:43:50 +00:00
parent 9434f5f507
commit 3f78f0d62d
47 changed files with 250 additions and 249 deletions

View File

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

View File

@ -5873,9 +5873,9 @@ end;
function TCodeToolManager.DoOnGetSrcPathForCompiledUnit(Sender: TObject;
const AFilename: string): string;
begin
if CompareFileExt(AFilename,'ppu',true)=0 then
if FilenameExtIs(AFilename,'ppu',true) then
Result:=GetPPUSrcPathForDirectory(ExtractFilePath(AFilename))
else if CompareFileExt(AFilename,'dcu')=0 then
else if FilenameExtIs(AFilename,'dcu') then
Result:=GetDCUSrcPathForDirectory(ExtractFilePath(AFilename))
else
Result:='';

View File

@ -1939,10 +1939,7 @@ var
FileCount: Integer;
Abort: boolean;
FileInfo: TSearchRec;
ShortFilename: String;
Filename: String;
Ext: String;
File_Name: String;
ShortFilename, Filename, File_Name: String;
begin
// units sources
Units:=TStringToStringTree.Create(false);
@ -1965,11 +1962,11 @@ begin
continue;
//debugln(['GatherUnitsInSearchPaths ShortFilename=',ShortFilename,' IsDir=',(FileInfo.Attr and faDirectory)>0]);
Filename:=Directory+ShortFilename;
Ext:=LowerCase(ExtractFileExt(ShortFilename));
if (Ext='.pas') or (Ext='.pp') or (Ext='.p') or (Ext='.ppu') then begin
if FilenameExtIn(ShortFilename,['.pas','.pp','.p','.ppu']) then begin
File_Name:=ExtractFileNameOnly(Filename);
if (not Units.Contains(File_Name))
or ((Ext<>'.ppu') and (CompareFileExt(Units[File_Name],'ppu',true)=0))
or (not FilenameExtIs(ShortFilename,'.ppu',true)
and FilenameExtIs(Units[File_Name],'ppu',true) )
then
Units[File_Name]:=Filename;
end;
@ -1997,8 +1994,7 @@ begin
continue;
//debugln(['GatherUnitsInSearchPaths ShortFilename=',ShortFilename,' IsDir=',(FileInfo.Attr and faDirectory)>0]);
Filename:=Directory+ShortFilename;
Ext:=LowerCase(ExtractFileExt(ShortFilename));
if (Ext='.inc') then begin
if FilenameExtIs(ShortFilename,'.inc') then begin
File_Name:=ExtractFileName(Filename);
if (not Includes.Contains(File_Name))
then
@ -2052,7 +2048,7 @@ begin
//if Pos('lazmkunit',Filename)>0 then
//debugln(['GatherUnitsInFPMSources ===== ',Filename]);
AVLNode:=Units.Tree.FindSuccessor(AVLNode);
if CompareFileExt(Filename,'ppu',true)<>0 then continue;
if not FilenameExtIs(Filename,'ppu',true) then continue;
// check if filename has the form
// /something/units/<FPCTarget>/<pkgname>/<unitname>.ppu
// and if there is /something/fpmkinst/<FPCTarget>/<pkgname>.fpm
@ -2877,7 +2873,7 @@ begin
Item:=PStringToStringItem(Node.Data);
Unit_Name:=Item^.Name;
Filename:=Item^.Value;
if CompareFileExt(Filename,'ppu',true)=0 then begin
if FilenameExtIs(Filename,'ppu',true) then begin
SrcFilename:=UnitToSource[Unit_Name];
if SrcFilename<>'' then begin
DuplicateFilenames:=UnitToDuplicates[Unit_Name];
@ -3945,7 +3941,7 @@ begin
// dcc*.exe
if LazStartsText('dcc',ShortFilename)
and ((ExeExt='') or (CompareFileExt(Filename,ExeExt)=0))
and ( (ExeExt='') or FilenameExtIs(Filename,ExeExt) )
then
exit(pcDelphi);
@ -3980,7 +3976,7 @@ begin
// dcc*.exe
if (CompareFilenames(LeftStr(ShortFilename,3),'dcc')=0)
and ((ExeExt='') or (CompareFileExt(AFilename,ExeExt)=0))
and ( (ExeExt='') or FilenameExtIs(AFilename,ExeExt) )
then begin
Kind:=pcDelphi;
exit(true);
@ -4048,7 +4044,7 @@ begin
// allow ppcxxx.exe
if (LazStartsText('ppc',ShortFilename))
and ((ExeExt='') or (CompareFileExt(AFilename,ExeExt)=0))
and ( (ExeExt='') or FilenameExtIs(AFilename,ExeExt) )
then
exit(true);
@ -9111,7 +9107,7 @@ begin
end;
// check if the system ppu exists
HasPPUs:=(Kind=pcFPC) and (Units<>nil)
and (CompareFileExt(Units['system'],'ppu',true)=0);
and FilenameExtIs(Units['system'],'ppu',true);
// check compiler version define
if (CTConsoleVerbosity>=-1) and (Defines<>nil) then begin
case Kind of
@ -10417,7 +10413,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',true)=0) then begin
if FilenameExtIs(UnitInFPCPath,'ppu',true) then begin
// there is a ppu
end else if UnitInFPCPath<>'' then begin
// there is a pp or pas in the FPC search path
@ -10469,7 +10465,7 @@ begin
if ConfigCache.Units=nil then exit;
Result:=ConfigCache.Units[AUnitName];
if Result='' then exit;
if CompareFileExt(Result,'ppu',true)<>0 then
if not FilenameExtIs(Result,'ppu',true) 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 CompareFileExtQuick(Filename,CTPascalExtension[pe])<>0 then
if not FilenameExtIs(Filename,CTPascalExtension[pe]) 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 CompareFileExtQuick(Result,CTPascalExtension[pe])<>0 then
if not FilenameExtIs(Result,CTPascalExtension[pe]) then
begin
AliasFilename:=ChangeFileExt(Result,CTPascalExtension[pe]);
if FileExistsCached(AliasFilename) then begin

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',true)<>0) then continue;
if not FilenameExtIs(Filename,'ppu',true) then continue;
AUnitName:=ExtractFileNameOnly(Filename);
Filename:=AppendPathDelim(Directory)+Filename;
if not LazIsValidIdent(AUnitName,true,true) then begin

View File

@ -5,9 +5,11 @@ unit frmBaseConfigCodeGenerator;
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls,
StdCtrls, EditBtn, ComCtrls, RTTIGrids, CheckLst, fpddcodegen, Buttons,
ActnList, ButtonPanel, ldd_consts, SynEdit, SynHighlighterPas;
Classes, SysUtils, fpddcodegen,
Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls, EditBtn, ComCtrls,
RTTIGrids, CheckLst, Buttons, ActnList, ButtonPanel,
LazFileUtils,
ldd_consts, SynEdit, SynHighlighterPas;
type
@ -246,7 +248,7 @@ begin
NewName:=ExtractFileName(FEFile.FileName);
FLastName:=NewName;
// Strip off known extensions
if (IndexStr(LowerCase(ExtractFileExt(NewName)),['.pas','.pp','.inc','.lpr','.dpr'])<>-1) then
if FilenameExtIn(NewName,['.pas','.pp','.inc','.lpr','.dpr']) then
FCodeOptions.UnitName:=ChangeFileExt(NewName,'')
else
FCodeOptions.UnitName:=NewName;

View File

@ -165,7 +165,7 @@ end;
procedure TOpenFileFavToolButton.RefreshMenu(Sender: TObject);
var
xM, xSep: TMenuItem;
xFavoriteFile, xExt: string;
xFavoriteFile: string;
xMI, xAddToFav: TFileNameMenuItem;
xProj: TLazProject;
xMIndex: Integer;
@ -182,8 +182,7 @@ begin
xMI.FileName := xFavoriteFile;
xMI.Caption := xFavoriteFile;
xMI.OnClick := @mnuFavoriteFile;
xExt := ExtractFileExt(xFavoriteFile);
if SameFileName(xExt, '.lpi') or SameFileName(xExt, '.lpr') then
if FilenameExtIn(xFavoriteFile,['.lpi','.lpr']) then
xMI.ImageIndex := LoadProjectIconIntoImages(xFavoriteFile, DropdownMenu.Images, FIndex);
xM.Insert(xMIndex, xMI);

View File

@ -6,7 +6,7 @@ interface
uses
Classes, SysUtils, contnrs,
LazFglHash, LazLoggerBase, LazUTF8,
LazFglHash, LazLoggerBase, LazFileUtils, LazUTF8,
DbgIntfBaseTypes,
// FpDebug
macho, FpImgReaderMachoFile, FpImgReaderBase, fpDbgSymTable, FpDbgUtil;
@ -365,7 +365,7 @@ begin
dSYMFilename:=ChangeFileExt(PLoader.FileName, '.dSYM');
dSYMFilename:=dSYMFilename+'/Contents/Resources/DWARF/'+ExtractFileName(fname); // TDbgProcess.Name
if ExtractFileExt(dSYMFilename)='.app' then
if FilenameExtIs(dSYMFilename,'.app',true) then
dSYMFilename := ChangeFileExt(dSYMFilename,'');
if FileExists(dSYMFilename) then

View File

@ -620,15 +620,8 @@ begin
end;
class function TvHTMLVectorialReader.IsSupportedRasterImage(AFileName: string): Boolean;
var
lExt: string;
begin
Result := False;
lExt := LowerCase(ExtractFileExt(AFileName));
case lExt of
'.png', '.jpg', '.jpeg', '.bmp', '.xpm', '.gif':
Result := True
end;
Result := FilenameExtIn(AFileName,['.png','.jpg','.jpeg','.bmp','.xpm','.gif']);
end;
initialization

View File

@ -34,8 +34,12 @@ unit fpWebNewHTMLFileUnit;
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ButtonPanel,
StdCtrls, ComCtrls;
Classes, SysUtils,
Forms, Controls, Graphics, Dialogs, ButtonPanel, StdCtrls, ComCtrls,
FileUtil, LazFileUtils,
ProjectIntf, LazIDEIntf,
fpWebStrConsts;
type
@ -79,8 +83,6 @@ const
implementation
uses fpWebStrConsts, SrcEditorIntf, ProjectIntf, LazIDEIntf;
{$R *.lfm}
const
HTMLHeaders : array [0..7] of string =
@ -143,18 +145,17 @@ end;
procedure TfpWebNewHTMLFileForm.FillLinks;
var
i:integer;
S, Ext: string;
S: string;
begin
if Assigned(LazarusIDE) and Assigned(LazarusIDE.ActiveProject) then
begin
for i:=0 to LazarusIDE.ActiveProject.FileCount - 1 do
begin
S:=LazarusIDE.ActiveProject.Files[i].Filename;
Ext:=ExtractFileExt(S);
if CompareText(Ext, '.JS') = 0 then
if FilenameExtIs(S, '.JS') then
edtJS.Items.Add(S)
else
if CompareText(Ext, '.CSS') = 0 then
if FilenameExtIs(S, '.CSS') then
edtCSS.Items.Add(S);
end;
end;

View File

@ -22,8 +22,7 @@ unit WebLazIDEIntf;
interface
uses
Classes, SysUtils, fpWeb, fpHTML, fpdatasetform, IDEExternToolIntf,
Controls, Dialogs, forms, LazIDEIntf, ProjectIntf, SrcEditorIntf, IDEMsgIntf,
Classes, SysUtils, fpWeb, fpHTML, fpdatasetform,
fpextjs, extjsjson, extjsxml, fpjsonrpc, jstree,jsparser,
fpextdirect,fpwebdata,
{$IF FPC_FULLVERSION>=30004}
@ -35,7 +34,12 @@ uses
fpoauth2,
fpoauth2ini,
{$ENDIF}
webjsonrpc, fpWebStrConsts;
webjsonrpc,
Controls, Dialogs, Forms,
LazFileUtils,
IDEExternToolIntf, ProjectIntf,
LazIDEIntf, SrcEditorIntf, IDEMsgIntf,
fpWebStrConsts;
type
{ TCGIApplicationDescriptor }
@ -1096,7 +1100,6 @@ function TJSSyntaxChecker.CheckSource(Sender: TObject; var Handled: boolean
Var
AE : TSourceEditorInterface;
E : String;
S : TStringStream;
begin
@ -1106,9 +1109,8 @@ begin
AE:=SourceEditorManagerIntf.ActiveEditor;
If (AE<>Nil) then
begin
E:=ExtractFileExt(AE.FileName);
FSFN:=ExtractFileName(AE.FileName);
Handled:=CompareText(E,'.js')=0;
Handled:=FilenameExtIs(AE.FileName,'.js');
If Handled then
begin
S:=TStringStream.Create(AE.SourceText);

View File

@ -31,12 +31,12 @@ function CompareFilenamesIgnoreCase(const Filename1, Filename2: string): integer
function CompareFilenameStarts(const Filename1, Filename2: string): integer;
function CompareFilenames(Filename1: PChar; Len1: integer;
Filename2: PChar; Len2: integer): integer; overload;
function CompareFilenamesP(Filename1, Filename2: PChar;
IgnoreCase: boolean = false // false = use default
): integer;
function CompareFilenamesP(Filename1, Filename2: PChar; IgnoreCase: 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 FilenameExtIs(const Filename,Ext: string; CaseSensitive: boolean=false): boolean;
function FilenameExtIn(const Filename: string; Exts: array of string;
CaseSensitive: boolean=false): boolean;
function DirPathExists(DirectoryName: string): boolean;
function DirectoryIsWritable(const DirectoryName: string): boolean;
@ -318,8 +318,7 @@ begin
{$ENDIF}
end;
function CompareFilenamesP(Filename1, Filename2: PChar;
IgnoreCase: boolean = false): integer;
function CompareFilenamesP(Filename1, Filename2: PChar; IgnoreCase: boolean): integer;
{$IFDEF darwin}
var
F1: CFStringRef;
@ -398,28 +397,78 @@ begin
{$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.
function FilenameExtIs(const Filename, Ext: string; CaseSensitive: boolean): boolean;
// Return True if Filename has an extension Ext.
// Ext can contain a point or not. Case-insensitive comparison supports only ASCII.
var
FnExt: String;
FnPos: integer;
FnExtLen, ExtLen: integer;
FnStart, FnEnd, FnP, ExtP: PChar;
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
FnStart := PChar(Filename);
FnEnd := FnStart + Length(Filename) - 1;
FnP := FnEnd;
while (FnP >= FnStart) and (FnP^ <> '.') do
Dec(FnP);
if FnP < FnStart then
exit(False); // no extension in filename
Inc(FnP); // Skip '.' in Filename
FnExtLen := 1 + FnEnd - FnP;
// Ext
if (length(LowerExt) > 1) and (LowerExt[1] = '.') then
Delete(LowerExt, 1, 1);
ExtLen := Length(Ext);
ExtP := PChar(Ext);
if ExtP^ = '.' then
begin
Inc(ExtP); // Skip '.' in Ext
Dec(ExtLen);
end;
if ExtLen <> FnExtLen then
exit(False); // Ext has different length than Filename
// compare extensions
Result := CompareStr(FnExt, LowerExt);
if Result < 0 then
Result := -1
else if Result > 0 then
Result := 1;
if CaseSensitive then
Result := StrLComp(ExtP, FnP, ExtLen) = 0
else
Result := StrLIComp(ExtP, FnP, ExtLen) = 0
end;
function FilenameExtIn(const Filename: string; Exts: array of string;
CaseSensitive: boolean): boolean;
// Return True if Filename's extension is one of Exts.
// Ext can contain a point or not. Case-insensitive comparison supports only ASCII.
var
FnExtLen, ExtLen, i: integer;
FnStart, FnEnd, FnP, ExtP: PChar;
begin
// Filename
FnStart := PChar(Filename);
FnEnd := FnStart + Length(Filename) - 1;
FnP := FnEnd;
while (FnP >= FnStart) and (FnP^ <> '.') do
Dec(FnP);
if FnP < FnStart then
exit(False); // no extension in filename
Inc(FnP); // Skip '.' in Filename
FnExtLen := 1 + FnEnd - FnP;
// Extensions
for i := low(Exts) to high(Exts) do
begin
ExtLen := Length(Exts[i]);
ExtP := PChar(Exts[i]);
if ExtP^ = '.' then
begin
Inc(ExtP); // Skip '.' in Ext
Dec(ExtLen);
end;
if ExtLen <> FnExtLen then
continue; // Ext has different length than Filename
// compare extensions
if CaseSensitive then
Result := StrLComp(ExtP, FnP, ExtLen) = 0
else
Result := StrLIComp(ExtP, FnP, ExtLen) = 0;
if Result then exit;
end;
Result := False;
end;
{$IFDEF darwin}

View File

@ -432,7 +432,7 @@ begin
Result:=false;
AUnitName:='';
Language:='';
if CompareFileExtQuick(Filename, 'po')=0 then
if FilenameExtIs(Filename, 'po') then
begin
NameWithoutExt:=ExtractFileNameWithoutExt(Filename);
Ext:=ExtractFileExt(NameWithoutExt);
@ -540,9 +540,9 @@ begin
// Update po file with lrj, rst/rsj of RSTFiles
for i:=0 to RSTFiles.Count-1 do begin
Filename:=RSTFiles[i];
ExtLrj := (CompareFileExtQuick(Filename,'lrj')=0);
if ExtLrj or (CompareFileExtQuick(Filename,'rst')=0) or
(CompareFileExtQuick(Filename,'rsj')=0) then
ExtLrj := FilenameExtIs(Filename,'lrj');
if ExtLrj or FilenameExtIs(Filename,'rst') or
FilenameExtIs(Filename,'rsj') then
try
//DebugLn('');
//DebugLn(['AddFiles2Po Filename="',Filename,'"']);
@ -552,7 +552,7 @@ begin
if ExtLrj then
BasePOFile.UpdateStrings(InputLines, stLrj)
else
if CompareFileExtQuick(Filename,'rsj')=0 then
if FilenameExtIs(Filename,'rsj') then
BasePOFile.UpdateStrings(InputLines, stRsj)
else
BasePOFile.UpdateStrings(InputLines, stRst);

View File

@ -272,7 +272,7 @@ var
begin
Result := FileName;
{$IFnDEF WINCE}
if (LowerCase(ExtractFileExt(FileName)) = '.lnk') then
if FilenameExtIs(FileName, '.lnk') then
begin
if (CoCreateInstance(CLSID_ShellLink, nil, CLSCTX_INPROC_SERVER,
IShellLinkW, ShellLinkW) = S_OK) then

View File

@ -317,7 +317,7 @@ var
begin
try
repeat
if CompareFileExtQuick(SR.Name, 'lpk') = 0 then
if FilenameExtIs(SR.Name, 'lpk') then
begin
PackageData := TPackageData.Create;
PackageData.FName := SR.Name;
@ -385,7 +385,7 @@ var
for I := 0 to SLExcludedFiles.Count - 1 do
begin
DebugLn(['OPM IsAllowed: ExcFile=', SLExcludedFiles.Strings[I], ', AName=', AName]);
if CompareFileExt(AName, SLExcludedFiles.Strings[I], False) = 0 then
if FilenameExtIs(AName, SLExcludedFiles.Strings[I]) then
begin
Result := False;
Break;

View File

@ -257,7 +257,7 @@ begin
For I:=0 to PRJ.FileCount-1 do
begin
PF:=PRJ.Files[i];
if CompareFileExtQuick(PF.Filename,'html')=0 then
if FilenameExtIs(PF.Filename,'html') then
begin
L.AddObject(PF.FileName,PF);
If PF.CustomData[PJSIsProjectHTMLFile]='1' then

View File

@ -276,6 +276,7 @@ begin
Name:='Template Project';
FVariables:=TStringList.Create;
FIgnoreExts:=TStringList.Create;
{$IF FPC_FULLVERSION>=30200}FIgnoreExts.UseLocale := false;{$ENDIF}
FIgnoreExts.CommaText:='.lpr,.lps,.lfm,.lrs,.ico,.res,.lpi,.bak';
end;
@ -326,7 +327,6 @@ Var
I : Integer;
AFile: TLazProjectFile;
FN : String;
B : Boolean;
L : TStringList;
begin
@ -343,13 +343,12 @@ begin
For I:=0 to FTemplate.FileCount-1 do
begin
FN:=FTemplate.FileNames[I];
B:=CompareText(ExtractFileExt(FN),'.lpr')=0;
If B then
If FilenameExtIs(FN,'lpr') then
begin
FN:=FProjectDirectory+FTemplate.TargetFileName(FN,FVariables);
AFile:=AProject.CreateProjectFile(FN);
AFile.IsPartOfProject:=true;
AProject.AddFile(AFile,Not B);
AProject.AddFile(AFile,False);
AProject.MainFileID:=0;
L:=TStringList.Create;
try
@ -373,7 +372,7 @@ Function TTemplateProjectDescriptor.CreateStartFiles(AProject: TLazProject) : TM
Var
I : Integer;
E,FN : String;
FN : String;
begin
if Assigned(FTemplate) then
@ -382,8 +381,7 @@ begin
For I:=0 to FTemplate.FileCount-1 do
begin
FN:=FTemplate.FileNames[I];
E:=ExtractFileExt(FN);
If (FIgnoreExts.IndexOf(E)=-1) then
If (FIgnoreExts.IndexOf(ExtractFileExt(FN))=-1) then
begin
FN:=FProjectDirectory+FTemplate.TargetFileName(FN,FVariables);
LazarusIDE.DoOpenEditorFile(FN, -1, -1, [ofProjectLoading,ofQuiet,ofAddToProject]);

View File

@ -108,8 +108,8 @@ uses
{$ENDIF}
propedits,
sqlstringspropertyeditordlg,
controls,
forms,
controls, forms,
LazFileUtils,
{$IFDEF HASLIBLOADER}
sqldblib,
{$ENDIF}
@ -665,7 +665,6 @@ function TSQLSyntaxChecker.CheckSource(Sender: TObject; var Handled: boolean
Var
AE : TSourceEditorInterface;
E : String;
S : TStringStream;
begin
@ -675,9 +674,8 @@ begin
AE:=SourceEditorManagerIntf.ActiveEditor;
If (AE<>Nil) then
begin
E:=ExtractFileExt(AE.FileName);
FSFN:=ExtractFileName(AE.FileName);
Handled:=CompareText(E,'.sql')=0;
Handled:=FilenameExtIs(AE.FileName,'sql');
If Handled then
begin
S:=TStringStream.Create(AE.SourceText);

View File

@ -2632,16 +2632,14 @@ var
Reg : TRegistry;
Ext : string;
{$ifndef MSWindows}
ExtU: string;
i : integer;
{$ENDIF}
begin
Result := '';
Ext := ExtractFileExt(TheFileName);
{$ifndef MSWindows}
ExtU := AnsiLowerCase(Ext);
for i := 0 to high(MimeTypeExt) do
if MimeTypeExt[i] = ExtU then
if CompareText(MimeTypeExt[i], Ext) = 0 then
begin
result := MimeTypes[i];
break;

View File

@ -385,15 +385,13 @@ end;
function WikiFilenameToPage(Filename: string): string;
var
Ext: String;
p: Integer;
begin
Result:=ExtractFileName(Filename);
if Result='' then exit;
// delete .xml
Ext:=lowercase(ExtractFileExt(Result));
if Ext='.xml' then
Result:=LeftStr(Result,length(Result)-length(Ext));
if FilenameExtIs(Result,'.xml') then
Result:=LeftStr(Result,length(Result)-4);
// delete case id
p:=length(Result);
while (p>=1) and (Result[p] in ['0'..'9','a'..'z']) do

View File

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

View File

@ -35,7 +35,7 @@ uses
// LCL
Forms, Controls,
// LazUtils
AvgLvlTree,
LazFileUtils, AvgLvlTree,
// codetools
StdCodeTools, CodeTree, CodeAtom, CodeCache,
LinkScanner, KeywordFuncLists, SourceChanger, CodeToolsStrConsts,
@ -521,11 +521,9 @@ end;
function TMainUsedUnits.UsesSectionNode: TCodeTreeNode;
var
s: String;
IsPackage: Boolean;
begin
s:=ExtractFileExt(fOwnerTool.fFilename);
IsPackage := (s='.dpk') or (s='.lpk');
IsPackage := FilenameExtIn(fOwnerTool.fFilename,['.dpk','.lpk'],True);
Result:=fCTLink.CodeTool.FindMainUsesNode(IsPackage);
end;

View File

@ -226,7 +226,7 @@ begin
end;
if ok then
begin
if CompareFileExtQuick(FileListBox1.Items[i], 'lrs') = 0 then
if FilenameExtIs(FileListBox1.Items[i], 'lrs') then
begin
if ConvertMeLRS(tmp) then
begin

View File

@ -275,7 +275,6 @@ end;
procedure TLazarusBuilder.CleanDir(Dir: string; Recursive: boolean = true);
var
FileInfo: TSearchRec;
Ext: String;
Filename: TFilename;
begin
Dir:=AppendPathDelim(TrimFilename(Dir));
@ -292,8 +291,7 @@ begin
CleanDir(Filename)
end
else begin
Ext:=LowerCase(ExtractFileExt(FileInfo.Name));
if (Ext='.ppu') or (Ext='.o') or (Ext='.rst') or (Ext='.rsj') then begin
if FilenameExtIn(FileInfo.Name,['.ppu','.o','.rst','.rsj']) then begin
if not DeleteFileUTF8(Filename) then
debugln(['Error : (lazarus) Clean directory: failed to delete file "',Filename,'"']);
end;

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',true)<>0 then exit;
if not FilenameExtIs(AFilename,'ppu',true) then exit;
Result:=true;
end;
@ -1537,7 +1537,7 @@ function TBuildManager.CheckAmbiguousSources(const AFilename: string;
end;
var
Ext, LowExt: string;
LowExt: string;
i: integer;
begin
Result:=mrOk;
@ -1546,8 +1546,7 @@ begin
and not Compiling then exit;
if FilenameHasPascalExt(AFilename) then begin
Ext:=ExtractFileExt(AFilename);
LowExt:=lowercase(Ext);
LowExt:=lowercase(ExtractFileExt(AFilename));
for i:=Low(PascalFileExt) to High(PascalFileExt) do begin
if LowExt<>PascalFileExt[i] then begin
Result:=CheckFile(ChangeFileExt(AFilename,PascalFileExt[i]));
@ -1688,7 +1687,7 @@ begin
or ((FileInfo.Attr and faDirectory)<>0) then continue;
if FilenameHasPascalExt(FileInfo.Name) then
CurUnitTree:=SourceUnitTree
else if (CompareFileExt(FileInfo.Name,CompiledExt,true)=0) then
else if FilenameExtIs(FileInfo.Name,CompiledExt,true) then
CurUnitTree:=CompiledUnitTree
else
continue;

View File

@ -476,7 +476,7 @@ begin
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then
continue;
// check extension
if CompareFileExt(FileInfo.Name,'ppu',true)=0 then
if FilenameExtIs(FileInfo.Name,'ppu',true) then
Result.Add(Directory+FileInfo.Name);
until FindNextUTF8(FileInfo)<>0;
end;
@ -625,7 +625,7 @@ begin
Node:=CfgCache.Units.Tree.FindLowest;
while Node<>nil do begin
Item:=PStringToStringItem(Node.Data);
if (Item^.Value<>'') and (CompareFileExt(Item^.Value,'ppu',true)=0) then
if (Item^.Value<>'') and FilenameExtIs(Item^.Value,'ppu',true) then
CheckFileAge(Item^.Value);
Node:=CfgCache.Units.Tree.FindSuccessor(Node);
end;
@ -804,9 +804,7 @@ begin
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then
continue;
// check extension
if (CompareFileExt(FileInfo.Name,'ppu',true)<>0)
and (CompareFileExt(FileInfo.Name,'o',true)<>0)
then
if not FilenameExtIn(FileInfo.Name, ['ppu','o'], true) then
continue;
PPUFiles.Add(Directory+FileInfo.Name);
until FindNextUTF8(FileInfo)<>0;

View File

@ -1387,7 +1387,7 @@ var
while Node<>nil do begin
Item:=PStringToStringItem(Node.Data);
Filename:=Item^.Value;
if (CompareFileExt(Filename,'ppu',true)=0) then begin
if FilenameExtIs(Filename,'ppu',true) 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 (CompareFileExtQuick(aFilename,Ext)<>0) then
if (Ext<>'') and not FilenameExtIs(aFilename,Ext) 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', true)=0 then
if FilenameExtIs(MsgLine.Filename, 'lpr', true) then
// a lpr does not use a unit => not important
MsgLine.Urgency:=mluVerbose
else if FilenameIsAbsolute(MsgLine.Filename)

View File

@ -352,7 +352,7 @@ begin
System.Move(p^,Filename[1],length(Filename));
Filename:=TrimFilename(Filename);
if FilenameIsAbsolute(Filename)
and ((GetExeExt='') or (ExtractFileExt(Filename)=GetExeExt))
and ( (GetExeExt='') or FilenameExtIs(Filename,GetExeExt) )
and IsFileExecutable(Filename) then begin
Handled:=true;
MsgLine:=CreateMsgLine(OutputIndex);

View File

@ -729,7 +729,7 @@ begin
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='') then
continue;
// check extension
if CompareFileExt(FileInfo.Name,Ext,false)=0 then begin
if FilenameExtIs(FileInfo.Name,Ext,false) then begin
Result:=AppendPathDelim(Directory)+FileInfo.Name;
break;
end;

View File

@ -209,7 +209,7 @@ var
i: Integer;
Item: PItem;
j: Integer;
OutputFilename, OtherRSTFilename, Ext, OtherExt: String;
OutputFilename, OtherRSTFilename: String;
begin
Result:=true;
if (RSTDirectory='') or (PODirectory='') then exit;// nothing to do
@ -236,8 +236,7 @@ begin
// collect all rst/po files that needs update
for i:=0 to Files.Count-1 do begin
RSTFilename:=RSTDirectory+Files[i];
Ext:=LowerCase(ExtractFileExt(RSTFilename));
if (Ext<>'.rst') and (Ext<>'.rsj') and (Ext<>'.lrj') then
if not FilenameExtIn(RSTFilename,['.rst','.rsj','.lrj']) then
continue;
if POFilename='' then
OutputFilename:=PODirectory+ChangeFileExt(Files[i],'.pot')
@ -260,24 +259,23 @@ begin
end else begin
// there is already a source file for this .po file
//debugln(['ConvertRSTFiles found another source: ',RSTFilename]);
if (Ext='.rsj') or (Ext='.rst') or (Ext='.lrj') then begin
// rsj are created by FPC 2.7.1+, rst by older => use only the newest
for j:=Item^.RSTFileList.Count-1 downto 0 do begin
OtherRSTFilename:=Item^.RSTFileList[j];
//debugln(['ConvertRSTFiles old: ',OtherRSTFilename]);
OtherExt:=LowerCase(ExtractFileExt(OtherRSTFilename));
if (OtherExt='.rsj') or (OtherExt='.rst') or (OtherExt='.lrj') then begin
if FileAgeCached(RSTFilename)<=FileAgeCached(OtherRSTFilename) then
begin
// this one is older => skip
//debugln(['ConvertRSTFiles ',RSTFilename,' is older => skip']);
RSTFilename:='';
break;
end else begin
// this one is newer
//debugln(['ConvertRSTFiles ',RSTFilename,' is newer => ignoring old']);
Item^.RSTFileList.Delete(j);
end;
// Already checked earlier.
Assert(FilenameExtIn(RSTFilename,['.rst','.rsj','.lrj']), 'ConvertRSTFiles: Wrong Ext');
// rsj are created by FPC 2.7.1+, rst by older => use only the newest
for j:=Item^.RSTFileList.Count-1 downto 0 do begin
OtherRSTFilename:=Item^.RSTFileList[j];
//debugln(['ConvertRSTFiles old: ',OtherRSTFilename]);
if FilenameExtIn(OtherRSTFilename,['.rsj','.rst','.lrj']) then begin
if FileAgeCached(RSTFilename)<=FileAgeCached(OtherRSTFilename) then
begin
// this one is older => skip
//debugln(['ConvertRSTFiles ',RSTFilename,' is older => skip']);
RSTFilename:='';
break;
end else begin
// this one is newer
//debugln(['ConvertRSTFiles ',RSTFilename,' is newer => ignoring old']);
Item^.RSTFileList.Delete(j);
end;
end;
end;
@ -383,11 +381,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 CompareFileExtQuick(Filename,'lrj')=0 then
if FilenameExtIs(Filename,'lrj') then
FileType:=stLrj
else if CompareFileExtQuick(Filename,'rst')=0 then
else if FilenameExtIs(Filename,'rst') then
FileType:=stRst
else if CompareFileExtQuick(Filename,'rsj')=0 then
else if FilenameExtIs(Filename,'rsj') 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',true)=0 then
if FilenameExtIs(fXMLConfig.Filename,'lpk',true) then
begin
try
FileVersion:=fXMLConfig.GetValue(PkgVersionPath,2);

View File

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

View File

@ -232,7 +232,6 @@ var
DirCache: TCTDirectoryCache;
i: Integer;
Filename: PChar;
Ext: String;
aFile: TICCFile;
j: Integer;
begin
@ -242,9 +241,8 @@ begin
if (DirCache=nil) or (DirCache.Listing=nil) then exit;
for i:=0 to DirCache.Listing.Count-1 do begin
Filename:=DirCache.Listing.GetFilename(i);
Ext:=lowercase(ExtractFileExt(Filename));
if ((Ext='.pas') or (Ext='.pp') or (Ext='.p') or (Ext='.ppu'))
and (SysUtils.CompareText(anUnitName,ExtractFileNameOnly(Filename))=0)
if FilenameExtIn(Filename,['.pas','.pp','.p','.ppu'])
and (CompareText(anUnitName,ExtractFileNameOnly(Filename))=0)
then begin
j:=Files.Count-1;
while (j>=0) and (CompareFilenames(Files[j].Filename,Filename)<>0) do
@ -338,7 +336,7 @@ begin
FileNode:=nil;
for i:=0 to Files.Count-1 do begin
aFile:=Files[i];
if CompareFileExt(aFile.Filename,'ppu',true)=0 then
if FilenameExtIs(aFile.Filename,'ppu',true) 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', true)=0 then
if FilenameExtIs(Filename,'lpi', true) 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',true)=0 then begin
if FilenameExtIs(Filename,'lpk',true) 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',true)=0 then
end else if FilenameExtIs(Filename,'lpi',true) then
Result:=BuildProject(Filename)
else if CompareFileExt(Filename,'lpr',true)=0 then begin
else if FilenameExtIs(Filename,'lpr',true) then begin
Filename:=ChangeFileExt(Filename,'.lpi');
if FileExists(Filename) then
Result:=BuildProject(Filename)
@ -1058,7 +1058,7 @@ begin
PkgFilename:='';
if pvPkgSearch in fPkgGraphVerbosity then
debugln(['Info: (lazarus) [TLazBuildApplication.AddPackagesToInstallList] "',PackageNamesOrFiles[i],'"']);
if CompareFileExt(PackageNamesOrFiles[i],'lpk',true)=0 then
if FilenameExtIs(PackageNamesOrFiles[i],'lpk',true) then
PkgFilename:=ExpandFileNameUTF8(PackageNamesOrFiles[i])
else if IsValidPkgName(PackageNamesOrFiles[i]) then begin
PackageLink:=TLazPackageLink(LazPackageLinks.FindLinkWithPkgName(PackageNamesOrFiles[i]));
@ -1119,7 +1119,7 @@ begin
begin
// Look for package name in all known packages
PkgFilename:=PackageNamesOrFiles[i];
if CompareFileExt(PkgFilename,'lpk',true)<>0 then begin
if not FilenameExtIs(PkgFilename,'lpk',true) then begin
ErrorMsg+=PkgFilename+' is not a package (.lpk), so it is not registered.'+LineEnding;
continue;
end;

View File

@ -2314,10 +2314,10 @@ begin
// try command line project
if (CmdLineFiles<>nil) and (CmdLineFiles.Count>0) then begin
AProjectFilename:=CmdLineFiles[0];
if (CompareFileExt(AProjectFilename,'lpr',true)=0) then
if FilenameExtIs(AProjectFilename,'lpr',true) then
AProjectFilename:=ChangeFileExt(AProjectFilename,'.lpi');
// only try to load .lpi files, other files are loaded later
if (CompareFileExt(AProjectFilename,'lpi',true)=0) then begin
if FilenameExtIs(AProjectFilename,'lpi',true) then begin
AProjectFilename:=CleanAndExpandFilename(AProjectFilename);
if FileExistsUTF8(AProjectFilename) then begin
CmdLineFiles.Delete(0);
@ -2403,7 +2403,7 @@ begin
// => create a project
DoNewProject(ProjectDescriptorEmptyProject);
end;
if CompareFileExt(AFilename,'lpk',true)=0 then begin
if FilenameExtIs(AFilename,'lpk',true) then begin
if PkgBoss.DoOpenPackageFile(AFilename,[pofAddToRecent,pofMultiOpen],true)=mrAbort
then
break;
@ -6460,7 +6460,7 @@ begin
end;
// if there is a project info file, load that instead
if CompareFileExtQuick(AFileName, 'lpi') <> 0 then begin
if not FilenameExtIs(AFileName, 'lpi') then begin
LpiFile := ChangeFileExt(AFileName,'.lpi');
if FileExistsUTF8(LpiFile) then
AFileName:=LpiFile; // load instead of program file the project info file
@ -7103,7 +7103,7 @@ function TMainIDE.CleanUpTestUnitOutputDir(Dir: string): TModalResult;
var
Files: TStrings;
i: Integer;
Filename, Ext: String;
Filename: String;
begin
Dir:=AppendPathDelim(Dir);
Files:=TStringList.Create;
@ -7111,10 +7111,7 @@ begin
CodeToolBoss.DirectoryCachePool.GetListing(Dir,Files,false);
for i:=0 to Files.Count-1 do begin
Filename:=Files[i];
Ext:=ExtractFileExt(Filename);
if (SysUtils.CompareText(Ext,'.ppu')=0)
or (SysUtils.CompareText(Ext,'.o')=0)
then begin
if FilenameExtIn(Filename,['.ppu','.o']) then begin
Result:=DeleteFileInteractive(Dir+Filename,[]);
if Result<>mrOk then exit;
end;
@ -7556,9 +7553,9 @@ procedure TMainIDE.DoExecuteRemoteControl;
AProjectFilename:='';
for i:=Files.Count-1 downto 0 do begin
AProjectFilename:=Files[0];
if (CompareFileExt(AProjectFilename,'lpr',true)=0) then
if FilenameExtIs(AProjectFilename,'lpr',true) then
AProjectFilename:=ChangeFileExt(AProjectFilename,'.lpi');
if (CompareFileExt(AProjectFilename,'lpi',true)=0) then begin
if FilenameExtIs(AProjectFilename,'lpi',true) then begin
// open a project
Files.Delete(i); // remove from the list
AProjectFilename:=CleanAndExpandFilename(AProjectFilename);
@ -7587,7 +7584,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',true)=0 then begin
if FilenameExtIs(AFilename,'lpk',true) then begin
if PkgBoss.DoOpenPackageFile(AFilename,[pofAddToRecent],true)=mrAbort
then
break;
@ -8893,7 +8890,7 @@ begin
if (ActiveUnitInfo.Component=nil)
and (ActiveUnitInfo.Source<>nil) then begin
if (CompareFileExtQuick(ActiveUnitInfo.Filename,'inc')=0) then begin
if FilenameExtIs(ActiveUnitInfo.Filename,'inc') then begin
// include file => get unit
UnitCodeBuf:=CodeToolBoss.GetMainCode(ActiveUnitInfo.Source);
if (UnitCodeBuf<>nil) and (UnitCodeBuf<>ActiveUnitInfo.Source) then begin
@ -8907,7 +8904,7 @@ begin
end;
end;
end;
if (CompareFileExt(ActiveUnitInfo.Filename,'lfm',true)=0) then begin
if FilenameExtIs(ActiveUnitInfo.Filename,'lfm',true) then begin
// lfm file => get unit
aFilename:=GetUnitFileOfLFM(ActiveUnitInfo.Filename);
if aFilename<>'' then begin
@ -12567,7 +12564,7 @@ begin
end;
end;
end
else if CompareFileExtQuick(AnUnitInfo.Filename,'inc')=0 then
else if FilenameExtIs(AnUnitInfo.Filename,'inc') then
OkToAdd:=CheckDirIsInSearchPath(AnUnitInfo,True);
if OkToAdd then
;

View File

@ -502,7 +502,6 @@ procedure TOpenFileToolButton.RefreshMenu(Sender: TObject);
procedure AddFile(const AFileName: string; const AOnClick: TNotifyEvent);
var
AMenuItem: TOpenFileMenuItem;
xExt: string;
begin
AMenuItem := TOpenFileMenuItem.Create(DropdownMenu);
DropdownMenu.Items.Add(AMenuItem);
@ -510,8 +509,7 @@ procedure TOpenFileToolButton.RefreshMenu(Sender: TObject);
AMenuItem.FileName := AFileName;
AMenuItem.Caption := ShortDisplayFilename(AFilename);
AMenuItem.Hint := AFilename; // Hint is not shown, it just holds the full filename.
xExt := ExtractFileExt(AFileName);
if SameFileName(xExt, '.lpi') or SameFileName(xExt, '.lpr') then
if FilenameExtIn(AFileName,['.lpi','.lpr']) then
AMenuItem.ImageIndex := LoadProjectIconIntoImages(AFileName, DropdownMenu.Images, FIndex);
end;

View File

@ -6965,8 +6965,7 @@ begin
CurFilename:=ASrcEdit.FileName;
ShortFileName:=ExtractFileName(CurFilename);
MainCodeBuf:=nil;
if FilenameHasPascalExt(ShortFileName)
or (CompareFileExtQuick(ShortFileName,'inc')=0) then
if FilenameHasPascalExt(ShortFileName) or FilenameExtIs(ShortFileName,'inc') then
MainCodeBuf:=CodeToolBoss.GetMainCode(ASrcEdit.CodeBuffer)
else if FilenameIsPascalSource(ShortFileName) then
MainCodeBuf:=ASrcEdit.CodeBuffer;
@ -6989,16 +6988,14 @@ begin
MaybeAddPopup('.s');
end;
// ToDo: unit resources
if (CompareFileExt(ShortFileName,'lfm',true)=0)
or (CompareFileExtQuick(ShortFileName,'dfm')=0) then begin
if FilenameExtIs(ShortFileName,'lfm',true)
or FilenameExtIs(ShortFileName,'dfm') then begin
MaybeAddPopup('.pas');
MaybeAddPopup('.pp');
MaybeAddPopup('.p');
end;
if (CompareFileExt(ShortFileName,'lpi',true)=0)
or (CompareFileExt(ShortFileName,'lpk',true)=0) then begin
AddContextPopupMenuItem(
Format(lisOpenLfm,[ShortFileName]),true,@OnPopupMenuOpenFile);
if FilenameExtIn(ShortFileName, ['lpi','lpk'], true) then begin
AddContextPopupMenuItem(Format(lisOpenLfm,[ShortFileName]),true,@OnPopupMenuOpenFile);
end;
FPDocSrc:=LazarusHelp.GetFPDocFilenameForSource(CurFilename,false,AnOwner);
if FPDocSrc<>'' then
@ -8064,10 +8061,9 @@ 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',true)=0 then
MainIDEInterface.DoOpenProjectFile(aFilename,
[ofOnlyIfExists,ofAddToRecent,ofUseCache])
else if CompareFileExt(aFilename,'lpk',true)=0 then
if FilenameExtIs(aFilename,'lpi',true) then
MainIDEInterface.DoOpenProjectFile(aFilename,[ofOnlyIfExists,ofAddToRecent,ofUseCache])
else if FilenameExtIs(aFilename,'lpk',true) then
PackageEditingInterface.DoOpenPackageFile(aFilename,[pofAddToRecent],false)
else
MainIDEInterface.DoOpenEditorFile(aFilename,
@ -10190,8 +10186,7 @@ begin
CurFilename:=SrcEdit.FileName;
ShortFileName:=ExtractFileName(CurFilename);
MainCodeBuf:=nil;
if FilenameHasPascalExt(ShortFileName)
or (CompareFileExtQuick(ShortFileName,'inc')=0) then
if FilenameHasPascalExt(ShortFileName) or FilenameExtIs(ShortFileName,'inc') then
MainCodeBuf:=CodeToolBoss.GetMainCode(SrcEdit.CodeBuffer)
else if FilenameIsPascalSource(ShortFileName) then
MainCodeBuf:=SrcEdit.CodeBuffer;

View File

@ -1030,7 +1030,7 @@ var
SourceType: String;
begin
if ([ofProjectLoading,ofRegularFile]*FFlags=[]) and (MainIDE.ToolStatus=itNone)
and (CompareFileExtQuick(FFilename,'lpi')=0) then begin
and FilenameExtIs(FFilename,'lpi',true) then begin
// this is a project info file -> load whole project
Result:=MainIDE.DoOpenProjectFile(FFilename,[ofAddToRecent]);
if Result = mrOK then
@ -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',true)=0) then
if FilenameExtIs(FFilename,'lpi',true) 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',true)=0) then
if FilenameExtIs(FFilename,'lpk',true) then
begin
case
IDEQuestionDialog(lisOpenPackage,
@ -1851,7 +1851,7 @@ begin
OkToAdd:=True;
if IsPascal then
OkToAdd:=CheckDirIsInSearchPath(ActiveUnitInfo,False)
else if CompareFileExtQuick(ActiveUnitInfo.Filename,'inc')=0 then
else if FilenameExtIs(ActiveUnitInfo.Filename,'inc') then
OkToAdd:=CheckDirIsInSearchPath(ActiveUnitInfo,True);
if OkToAdd then begin
ActiveUnitInfo.IsPartOfProject:=true;
@ -4140,7 +4140,7 @@ begin
+dlgFilterAll+'|'+GetAllFilesMask;
if OpenDialog.Execute then begin
AFilename:=GetPhysicalFilenameCached(ExpandFileNameUTF8(OpenDialog.Filename),false);
if CompareFileExt(AFilename,'lpi',true)<>0 then begin
if not FilenameExtIs(AFilename,'lpi',true) then begin
// not a lpi file
// check if it is a program source
@ -5779,9 +5779,9 @@ begin
end;
// check, if a .lfm file is opened in the source editor
if (LFMUnitInfo=nil) or
((CompareFileExt(LFMUnitInfo.Filename,'lfm',true)<>0) and
(CompareFileExtQuick(LFMUnitInfo.Filename,'dfm')<>0)) then
if (LFMUnitInfo=nil)
or not ( FilenameExtIs(LFMUnitInfo.Filename,'lfm',true) or
FilenameExtIs(LFMUnitInfo.Filename,'dfm') ) then
begin
if not Quiet then
begin
@ -6381,7 +6381,7 @@ begin
end;
end;
try
if (CompareFileExt(LFMFilename,'lfm',true)<>0) then
if not FilenameExtIs(LFMFilename,'lfm',true) then
begin
// no lfm format -> keep old info
exit(true);
@ -7403,7 +7403,7 @@ begin
// Do not care if this fails. A user may have removed the line from source.
Project1.RemoveCreateFormFromProjectFile(AnUnitInfo.ComponentName);
end;
if CompareFileExtQuick(AnUnitInfo.Filename,'inc')=0 then
if FilenameExtIs(AnUnitInfo.Filename,'inc') then
// include file
if FilenameIsAbsolute(AnUnitInfo.Filename) then
ObsoleteIncPaths:=MergeSearchPaths(ObsoleteIncPaths,UnitPath);
@ -7417,7 +7417,7 @@ begin
UnitPath:=ChompPathDelim(ExtractFilePath(AnUnitInfo.Filename));
if FilenameIsPascalUnit(AnUnitInfo.Filename) then
ObsoleteUnitPaths:=RemoveSearchPaths(ObsoleteUnitPaths,UnitPath);
if CompareFileExtQuick(AnUnitInfo.Filename,'inc')=0 then
if FilenameExtIs(AnUnitInfo.Filename,'inc') then
ObsoleteIncPaths:=RemoveSearchPaths(ObsoleteIncPaths,UnitPath);
end;
AnUnitInfo:=AnUnitInfo.NextPartOfProject;

View File

@ -481,11 +481,8 @@ end;
function TTransferMacroList.MF_NameOnly(const Filename:string;
const Data: PtrInt; var Abort: boolean):string;
var Ext:string;
begin
Result:=ExtractFileName(Filename);
Ext:=ExtractFileExt(Result);
Result:=copy(Result,1,length(Result)-length(Ext));
Result:=ChangeFileExt(ExtractFileName(Filename),'');
end;
function TTransferMacroList.MF_MakeDir(const Filename: string;

View File

@ -1363,7 +1363,7 @@ function LFMtoLRSfile(const LFMfilename: string):boolean;
var
LFMFileStream, LRSFileStream: TFileStream;
LFMMemStream, LRSMemStream: TMemoryStream;
LRSfilename, LFMfilenameExt: string;
LRSfilename: string;
begin
Result:=true;
try
@ -1374,9 +1374,7 @@ begin
LFMMemStream.SetSize(LFMFileStream.Size);
LFMMemStream.CopyFrom(LFMFileStream,LFMFileStream.Size);
LFMMemStream.Position:=0;
LFMfilenameExt:=ExtractFileExt(LFMfilename);
LRSfilename:=copy(LFMfilename,1,
length(LFMfilename)-length(LFMfilenameExt))+'.lrs';
LRSfilename:=ChangeFileExt(LFMfilename,'.lrs');
Result:=LFMtoLRSstream(LFMMemStream,LRSMemStream);
if not Result then exit;
LRSMemStream.Position:=0;

View File

@ -141,7 +141,6 @@ type
function CheckInterPkgFiles(IDEObject: TObject;
PkgList: TFPList; out FilesChanged: boolean
): boolean; // returns false if user cancelled
function FilenameIsCompiledSource(aFilename: string): boolean;
implementation
@ -175,6 +174,11 @@ begin
Result:=CompareText(F1.ShortFilename,F2.ShortFilename);
end;
function FilenameIsCompiledSource(aFilename: string): boolean;
begin
Result:=FilenameExtIn(aFilename,['.ppu','.o','.rst','.rsj']);
end;
{ TPGIPAmbiguousFileGroup }
function TPGIPAmbiguousFileGroup.Add(SrcFile, PPUFile: TPGInterPkgFile): integer;
@ -623,7 +627,6 @@ var
var
Files: TStrings;
aFilename: String;
Ext: String;
AnUnitName: String;
NewFile: TPGInterPkgFile;
begin
@ -642,18 +645,16 @@ var
begin
if (aFilename='') or (aFilename='.') or (aFilename='..') then continue;
if CompareFilenames(aFilename,'fpmake.pp')=0 then continue;
Ext:=LowerCase(ExtractFileExt(aFilename));
AnUnitName:='';
case Ext of
'.ppu','.o','.rst','.rsj','.pas','.pp','.p':
begin
AnUnitName:=ExtractFileNameOnly(aFilename);
if not IsDottedIdentifier(AnUnitName) then continue;
end;
'.inc', '.lfm', '.dfm': ;
if FilenameExtIn(aFilename,['.ppu','.o','.rst','.rsj','.pas','.pp','.p']) then
begin
AnUnitName:=ExtractFileNameOnly(aFilename);
if not IsDottedIdentifier(AnUnitName) then continue;
end
else if FilenameExtIn(aFilename,['.inc', '.lfm', '.dfm']) then
begin {Do nothing} end
else
continue;
end;
NewFile:=TPGInterPkgFile.Create(AppendPathDelim(Dir)+aFilename,
AnUnitName,OwnerInfo);
FullFiles.Add(NewFile);
@ -710,7 +711,7 @@ var
Node:=Node.Successor;
OFile:=TPGInterPkgFile(ONode.Data);
if not FilenameIsCompiledSource(OFile.ShortFilename) then continue;
if CompareFileExt(OFile.ShortFilename,'ppu',true)=0 then continue;
if FilenameExtIs(OFile.ShortFilename,'ppu',true) then continue;
// search corresponding .ppu
PPUFileName:=ChangeFileExt(OFile.FullFilename,'.ppu');
SearchFile:=TPGInterPkgFile.Create(PPUFileName,'',nil);
@ -1093,13 +1094,5 @@ begin
end;
end;
function FilenameIsCompiledSource(aFilename: string): boolean;
var
Ext: String;
begin
Ext:=lowercase(ExtractFileExt(aFilename));
Result:=(Ext='.ppu') or (Ext='.o') or (Ext='.rst') or (Ext='.rsj');
end;
end.

View File

@ -310,7 +310,7 @@ var
begin
Result:=false;
if not FilenameIsAbsolute(LPKFilename) then exit;
if CompareFilenames(ExtractFileExt(LPKFilename),'.lpk')<>0 then exit;
if not FilenameExtIs(LPKFilename,'.lpk') then exit;
PkgName:=ExtractFileNameOnly(LPKFilename);
if not IsValidPkgName(PkgName) then exit;
Result:=true;

View File

@ -901,13 +901,13 @@ var
begin
HasName:=ExtractFileNameOnly(AFilename)<>'';
if HasName then begin
if CompareFileExt(AFilename,'lfm',true)=0 then
if FilenameExtIs(AFilename,'lfm',true) then
exit(pftLFM)
else if CompareFileExt(AFilename,'lrs',true)=0 then
else if FilenameExtIs(AFilename,'lrs',true) then
exit(pftLRS)
else if CompareFileExtQuick(AFilename,'inc')=0 then
else if FilenameExtIs(AFilename,'inc') then
exit(pftInclude)
else if CompareFileExtQuick(AFilename,'xml')=0 then
else if FilenameExtIs(AFilename,'xml') then
exit(pftIssues)
else if FilenameHasPascalExt(AFilename) then begin
Result:=pftUnit;
@ -2072,8 +2072,8 @@ var
begin
Result:='';
AFilename:=TrimFilename(DefaultFilename);
if (CompareFileExt(AFilename,'lpk',true)<>0)
or (SysUtils.CompareText(ExtractFileNameOnly(AFilename),PackageName)<>0) then
if not FilenameExtIs(AFilename,'lpk',true)
or (CompareText(ExtractFileNameOnly(AFilename),PackageName)<>0) then
exit;
if not FilenameIsAbsolute(AFilename) then begin
CurDir:=GetDependencyOwnerDirectory(Self);

View File

@ -392,7 +392,7 @@ procedure TLazPackageLinks.UpdateGlobalLinks;
begin
Result:=false;
PkgName:='';
if CompareFileExt(Filename,'lpl',true)<>0 then exit;
if not FilenameExtIs(Filename,'lpl',true) 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',true)<>0 then continue;
if not FilenameExtIs(LPLFilename,'lpl',true) then continue;
if (not ParseFilename(Files[i],NewPkgName,PkgVersion))
then begin
DebugLn('Warning: (lazarus) suspicious pkg link file found (name): ',LPLFilename);

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',true)=0 then begin
end else if FilenameExtIs(FileInfo.Name,'lpk',true) 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',true)=0 then begin
end else if FilenameExtIs(FileInfo.Name,'lpl',true) then begin
ScanLink(Dir+FileInfo.Name,Links);
end;
until FindNextUTF8(FileInfo)<>0;