mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-07 14:38:01 +02:00
ide: using SearchFileInSearchPath
This commit is contained in:
parent
64adc6945d
commit
3d5b43f3b1
@ -654,7 +654,7 @@ var
|
||||
MakeIDECfgFilename: string;
|
||||
begin
|
||||
MakeIDECfgFilename:=GetMakeIDEConfigFilename;
|
||||
DebugLn(['SpecialIdeConfig MAKE MakeIDECfgFilename=',MakeIDECfgFilename,' ',FileExistsUTF8(MakeIDECfgFilename)]);
|
||||
//DebugLn(['SpecialIdeConfig MAKE MakeIDECfgFilename=',MakeIDECfgFilename,' ',FileExistsUTF8(MakeIDECfgFilename)]);
|
||||
if (FileExistsUTF8(MakeIDECfgFilename)) then begin
|
||||
// If a file name contains spaces, a file name whould need to be quoted.
|
||||
// Using a single quote is not possible, it is used already in the
|
||||
|
@ -2038,9 +2038,9 @@ begin
|
||||
Result:='';
|
||||
end else begin
|
||||
Result:=ExtractFileNameOnly(AnUnitInfo.Filename)+ResourceFileExt;
|
||||
Result:=FileUtil.SearchFileInPath(Result,'',
|
||||
Result:=SearchFileInSearchPath(Result,'',
|
||||
CodeToolBoss.GetIncludePathForDirectory(ExtractFilePath(AnUnitInfo.Filename)),
|
||||
';',[sffDontSearchInBasePath,sffSearchLoUpCase,sffFile]);
|
||||
[TSPSearchFileFlag.SearchLoUpCase]);
|
||||
end;
|
||||
if (Result='') and UseDefaultIfNotFound then
|
||||
Result:=GetDefaultLRSFilename(AnUnitInfo);
|
||||
|
@ -2005,7 +2005,7 @@ function TCodeHelpManager.ExpandFPDocLinkID(const LinkID,
|
||||
if BaseDir='' then exit;
|
||||
if not IDEMacros.CreateAbsoluteSearchPath(SearchPath,BaseDir) then exit;
|
||||
FPDocFilename:=AUnitName+'.xml';
|
||||
Result:=SearchFileInPath(FPDocFilename,'',SearchPath,';',ctsfcDefault);
|
||||
Result:=SearchFileInSearchPath(FPDocFilename,'',SearchPath);
|
||||
end;
|
||||
|
||||
var
|
||||
@ -2144,7 +2144,7 @@ function TCodeHelpManager.GetLinkedFPDocNode(StartFPDocFile: TLazFPDocFile;
|
||||
Result:='';
|
||||
if not IDEMacros.CreateAbsoluteSearchPath(SearchPath,BaseDir) then exit;
|
||||
//DebugLn(['FindFPDocFilename BaseDir=',BaseDir,' SearchPath=',SearchPath,' UnitName=',AUnitname]);
|
||||
Result:=SearchFileInPath(AUnitName+'.xml',BaseDir,SearchPath,';',ctsfcDefault);
|
||||
Result:=SearchFileInSearchPath(AUnitName+'.xml',BaseDir,SearchPath);
|
||||
end;
|
||||
|
||||
function FindElement(StartPos: integer; aFPDocFile: TLazFPDocFile): boolean;
|
||||
|
@ -45,7 +45,7 @@ uses
|
||||
// IDEIntf
|
||||
LazIDEIntf, IDEUtils,
|
||||
// IdeConfig
|
||||
EnvironmentOpts, LazConf, TransferMacros, IDECmdLine,
|
||||
EnvironmentOpts, LazConf, TransferMacros, IDECmdLine, SearchPathProcs,
|
||||
// IDE
|
||||
LazarusIDEStrConsts, etMakeMsgParser;
|
||||
|
||||
@ -2570,7 +2570,7 @@ begin
|
||||
end;
|
||||
Dir:=ChompPathDelim(TrimFilename(ExtractFilePath(UnitSrcFilename)));
|
||||
IncPath:=CodeToolBoss.GetIncludePathForDirectory(Dir);
|
||||
IncFilename:=SearchFileInPath(ShortFilename,Dir,IncPath,';',ctsfcDefault);
|
||||
IncFilename:=SearchFileInSearchPath(ShortFilename,Dir,IncPath);
|
||||
//debugln(['TIDEFPCParser.FindSrcViaPPU Dir="',Dir,'" IncPath="',IncPath,'" ShortFilename="',ShortFilename,'" IncFilename="',IncFilename,'"']);
|
||||
if IncFilename<>'' then begin
|
||||
MsgLine.Filename:=IncFilename;
|
||||
|
@ -88,8 +88,17 @@ function SearchDirectoryInSearchPath(SearchPath: TStrings;
|
||||
const Directory: string; DirStartPos: integer = 0): integer; overload;
|
||||
function SearchDirectoryInMaskedSearchPath(const SearchPath, Directory: string;
|
||||
DirStartPos: integer = 1): integer; overload;
|
||||
|
||||
type
|
||||
TSPSearchFileFlag = (
|
||||
DontSearchInBasePath, // do not search in BasePath, search only in SearchPath.
|
||||
SearchLoUpCase,
|
||||
Executable // file must be executable
|
||||
);
|
||||
TSPSearchFileFlags = set of TSPSearchFileFlag;
|
||||
|
||||
function SearchFileInSearchPath(const Filename, BasePath: string;
|
||||
SearchPath: string; Flags: TSearchFileInPathFlags = []): string; overload;
|
||||
SearchPath: string; Flags: TSPSearchFileFlags = []): string; overload;
|
||||
procedure CollectFilesInSearchPath(const SearchPath: string;
|
||||
Files: TFilenameToStringTree; const Value: string = ''); overload;
|
||||
|
||||
@ -622,13 +631,14 @@ begin
|
||||
end;
|
||||
|
||||
function SearchFileInSearchPath(const Filename, BasePath: string;
|
||||
SearchPath: string; Flags: TSearchFileInPathFlags): string;
|
||||
SearchPath: string; Flags: TSPSearchFileFlags): string;
|
||||
|
||||
function Fits(const s: string): boolean;
|
||||
begin
|
||||
Result:=false;
|
||||
if s='' then exit;
|
||||
if (sffExecutable in Flags) and not FileIsExecutableCached(s) then exit;
|
||||
if (TSPSearchFileFlag.Executable in Flags) and not FileIsExecutableCached(s) then
|
||||
exit;
|
||||
SearchFileInSearchPath:=s;
|
||||
Result:=true;
|
||||
end;
|
||||
@ -645,23 +655,28 @@ begin
|
||||
exit('');
|
||||
// check if filename absolute
|
||||
if FilenameIsAbsolute(Filename) then begin
|
||||
if FileExistsCached(Filename) then
|
||||
Result:=CleanAndExpandFilename(Filename)
|
||||
else
|
||||
Result:=ResolveDots(Filename);
|
||||
if not FileExistsCached(Filename) then
|
||||
Result:='';
|
||||
exit;
|
||||
end;
|
||||
Base:=CleanAndExpandDirectory(BasePath);
|
||||
// search in current directory
|
||||
if (not (sffDontSearchInBasePath in Flags)) and FileExistsCached(Base+Filename) then
|
||||
exit(ResolveDots(Base+Filename));
|
||||
if ExtractFilePath(Filename)<>'' then
|
||||
exit('');
|
||||
|
||||
if [sffDontSearchInBasePath,sffSearchLoUpCase,sffExecutable]*Flags<>[] then
|
||||
raise Exception.Create('SearchFileInSearchPath flag is not supported');
|
||||
if BasePath<>'' then
|
||||
Base:=CleanAndExpandDirectory(BasePath)
|
||||
else
|
||||
Base:='';
|
||||
|
||||
if sffSearchLoUpCase in Flags then
|
||||
// search in current directory
|
||||
if (Base<>'') and not (TSPSearchFileFlag.DontSearchInBasePath in Flags) then
|
||||
begin
|
||||
Result:=Base+Filename;
|
||||
if FileExistsCached(Result) {$IFDEF Unix}and not DirPathExistsCached(Result){$ENDIF} then
|
||||
exit;
|
||||
end;
|
||||
|
||||
if TSPSearchFileFlag.SearchLoUpCase in Flags then
|
||||
FileCase:=ctsfcLoUpCase
|
||||
else
|
||||
FileCase:=ctsfcDefault;
|
||||
|
@ -3038,7 +3038,7 @@ var
|
||||
|
||||
SearchFile:=AFilename;
|
||||
SearchPath:=AllIncPaths;
|
||||
Result:=FileUtil.SearchFileInPath(SearchFile,BaseDir,SearchPath,';',[]);
|
||||
Result:=SearchFileInSearchPath(SearchFile,BaseDir,SearchPath);
|
||||
{$IFDEF VerboseFindSourceFile}
|
||||
debugln(['SearchIndirectIncludeFile Result="',Result,'"']);
|
||||
{$ENDIF}
|
||||
@ -3053,7 +3053,7 @@ var
|
||||
Filename:='';
|
||||
SearchPath:=RemoveSearchPaths(TheSearchPath,AlreadySearchedPaths);
|
||||
if SearchPath<>'' then begin
|
||||
Filename:=FileUtil.SearchFileInPath(SearchFile,BaseDir,SearchPath,';',[]);
|
||||
Filename:=SearchFileInSearchPath(SearchFile,BaseDir,SearchPath);
|
||||
{$IFDEF VerboseFindSourceFile}
|
||||
debugln(['FindSourceFile trying "',SearchPath,'" Filename="',Filename,'"']);
|
||||
{$ENDIF}
|
||||
|
Loading…
Reference in New Issue
Block a user