mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 06:59:14 +02:00
MG: outputfilter can now find include files
git-svn-id: trunk@858 -
This commit is contained in:
parent
fdc0f18043
commit
bdf376450c
@ -1,6 +1,8 @@
|
|||||||
{
|
{
|
||||||
Simple functions for file access, not yet in fpc.
|
Simple functions
|
||||||
|
- for file access, not yet in fpc.
|
||||||
|
- recent list
|
||||||
|
- xmlconfig formats
|
||||||
}
|
}
|
||||||
unit IDEProcs;
|
unit IDEProcs;
|
||||||
|
|
||||||
@ -17,7 +19,7 @@ const
|
|||||||
EndOfLine:shortstring={$IFDEF win32}#13+{$ENDIF}#10;
|
EndOfLine:shortstring={$IFDEF win32}#13+{$ENDIF}#10;
|
||||||
|
|
||||||
// files
|
// files
|
||||||
function FilenameIsAbsolute(TheFilename: string):boolean;
|
function FilenameIsAbsolute(Filename: string):boolean;
|
||||||
function DirectoryExists(DirectoryName: string): boolean;
|
function DirectoryExists(DirectoryName: string): boolean;
|
||||||
function ForceDirectory(DirectoryName: string): boolean;
|
function ForceDirectory(DirectoryName: string): boolean;
|
||||||
function ExtractFileNameOnly(const AFilename: string): string;
|
function ExtractFileNameOnly(const AFilename: string): string;
|
||||||
@ -27,22 +29,24 @@ function FileIsReadable(const AFilename: string): boolean;
|
|||||||
function FileIsWritable(const AFilename: string): boolean;
|
function FileIsWritable(const AFilename: string): boolean;
|
||||||
function FileIsText(const AFilename: string): boolean;
|
function FileIsText(const AFilename: string): boolean;
|
||||||
function CompareFilenames(const Filename1, Filename2: string): integer;
|
function CompareFilenames(const Filename1, Filename2: string): integer;
|
||||||
|
function AppendPathDelim(const Path: string): string;
|
||||||
|
function SearchFileInPath(const Filename, BasePath, SearchPath,
|
||||||
|
Delimiter: string): string;
|
||||||
|
|
||||||
// XMLConfig
|
// XMLConfig
|
||||||
procedure LoadRecentList(XMLConfig: TXMLConfig; List: TStringList;
|
procedure LoadRecentList(XMLConfig: TXMLConfig; List: TStringList;
|
||||||
const Path: string);
|
const Path: string);
|
||||||
procedure SaveRecentList(XMLConfig: TXMLConfig; List: TStringList;
|
procedure SaveRecentList(XMLConfig: TXMLConfig; List: TStringList;
|
||||||
const Path: string);
|
const Path: string);
|
||||||
|
procedure AddToRecentList(const s: string; RecentList: TStringList;
|
||||||
|
Max: integer);
|
||||||
procedure LoadRect(XMLConfig: TXMLConfig; const Path:string; var ARect:TRect);
|
procedure LoadRect(XMLConfig: TXMLConfig; const Path:string; var ARect:TRect);
|
||||||
procedure SaveRect(XMLConfig: TXMLConfig; const Path:string; var ARect:TRect);
|
procedure SaveRect(XMLConfig: TXMLConfig; const Path:string; var ARect:TRect);
|
||||||
|
|
||||||
// various
|
|
||||||
procedure AddToRecentList(const s: string; RecentList: TStringList;
|
|
||||||
Max: integer);
|
|
||||||
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
|
||||||
// to get more detailed error messages consider the os
|
// to get more detailed error messages consider the os
|
||||||
{$IFDEF Win32}
|
{$IFDEF Win32}
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
@ -165,15 +169,15 @@ begin
|
|||||||
Result:=copy(Result,1,length(Result)-ExtLen);
|
Result:=copy(Result,1,length(Result)-ExtLen);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function FilenameIsAbsolute(TheFilename: string):boolean;
|
function FilenameIsAbsolute(Filename: string):boolean;
|
||||||
begin
|
begin
|
||||||
DoDirSeparators(TheFilename);
|
DoDirSeparators(Filename);
|
||||||
{$IFDEF win32}
|
{$IFDEF win32}
|
||||||
// windows
|
// windows
|
||||||
Result:=(copy(TheFilename,1,2)='\\') or ((length(TheFilename)>3) and
|
Result:=(copy(Filename,1,2)='\\') or ((length(Filename)>3) and
|
||||||
(upcase(TheFilename[1]) in ['A'..'Z']) and (copy(TheFilename,2,2)=':\'));
|
(upcase(Filename[1]) in ['A'..'Z']) and (copy(Filename,2,2)=':\'));
|
||||||
{$ELSE}
|
{$ELSE}
|
||||||
Result:=(TheFilename<>'') and (TheFilename[1]='/');
|
Result:=(Filename<>'') and (Filename[1]='/');
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -262,4 +266,42 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function AppendPathDelim(const Path: string): string;
|
||||||
|
begin
|
||||||
|
if (Path<>'') and (Path[length(Path)]<>PathDelim) then
|
||||||
|
Result:=Path+PathDelim
|
||||||
|
else
|
||||||
|
Result:=Path;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function SearchFileInPath(const Filename, BasePath, SearchPath,
|
||||||
|
Delimiter: string): string;
|
||||||
|
var
|
||||||
|
p, StartPos, l: integer;
|
||||||
|
CurPath, Base: string;
|
||||||
|
begin
|
||||||
|
if (Filename='')
|
||||||
|
or (FilenameIsAbsolute(Filename) and FileExists(Filename))
|
||||||
|
then begin
|
||||||
|
Result:=Filename;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
Base:=ExpandFilename(AppendPathDelim(BasePath));
|
||||||
|
StartPos:=1;
|
||||||
|
l:=length(SearchPath);
|
||||||
|
while StartPos<=l do begin
|
||||||
|
p:=StartPos;
|
||||||
|
while (p<=l) and (pos(SearchPath[p],Delimiter)<1) do inc(p);
|
||||||
|
CurPath:=Trim(copy(SearchPath,StartPos,p-StartPos));
|
||||||
|
if CurPath<>'' then begin
|
||||||
|
if not FilenameIsAbsolute(CurPath) then
|
||||||
|
CurPath:=Base+CurPath;
|
||||||
|
Result:=ExpandFilename(AppendPathDelim(CurPath)+Filename);
|
||||||
|
if FileExists(Result) then exit;
|
||||||
|
end;
|
||||||
|
StartPos:=p+1;
|
||||||
|
end;
|
||||||
|
Result:='';
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -29,7 +29,8 @@ uses
|
|||||||
IDEProcs;
|
IDEProcs;
|
||||||
|
|
||||||
type
|
type
|
||||||
TOnOutputString = procedure (const Value: String) of Object;
|
TOnOutputString = procedure(const Value: String) of Object;
|
||||||
|
TOnGetIncludePath = function(const Directory: string): string of object;
|
||||||
|
|
||||||
TOuputFilterOption = (
|
TOuputFilterOption = (
|
||||||
ofoSearchForFPCMessages, // scan for freepascal compiler messages
|
ofoSearchForFPCMessages, // scan for freepascal compiler messages
|
||||||
@ -51,11 +52,13 @@ type
|
|||||||
fLastMessageType: TOutputMessageType;
|
fLastMessageType: TOutputMessageType;
|
||||||
fCompilingHistory: TStringList;
|
fCompilingHistory: TStringList;
|
||||||
fMakeDirHistory: TStringList;
|
fMakeDirHistory: TStringList;
|
||||||
|
fOnGetIncludePath: TOnGetIncludePath;
|
||||||
fOnOutputString: TOnOutputString;
|
fOnOutputString: TOnOutputString;
|
||||||
fOptions: TOuputFilterOptions;
|
fOptions: TOuputFilterOptions;
|
||||||
fProject: TProject;
|
fProject: TProject;
|
||||||
fPrgSourceFilename: string;
|
fPrgSourceFilename: string;
|
||||||
procedure DoAddFilteredLine(const s: string);
|
procedure DoAddFilteredLine(const s: string);
|
||||||
|
function SearchIncludeFile(const ShortIncFilename: string): string;
|
||||||
public
|
public
|
||||||
procedure Execute(TheProcess: TProcess);
|
procedure Execute(TheProcess: TProcess);
|
||||||
function GetSourcePosition(const Line: string; var Filename:string;
|
function GetSourcePosition(const Line: string; var Filename:string;
|
||||||
@ -75,6 +78,8 @@ type
|
|||||||
property LastMessageType: TOutputMessageType read fLastMessageType;
|
property LastMessageType: TOutputMessageType read fLastMessageType;
|
||||||
property PrgSourceFilename: string
|
property PrgSourceFilename: string
|
||||||
read fPrgSourceFilename write fPrgSourceFilename;
|
read fPrgSourceFilename write fPrgSourceFilename;
|
||||||
|
property OnGetIncludePath: TOnGetIncludePath
|
||||||
|
read fOnGetIncludePath write fOnGetIncludePath;
|
||||||
property OnOutputString: TOnOutputString
|
property OnOutputString: TOnOutputString
|
||||||
read fOnOutputString write fOnOutputString;
|
read fOnOutputString write fOnOutputString;
|
||||||
property Options: TOuputFilterOptions read fOptions write fOptions;
|
property Options: TOuputFilterOptions read fOptions write fOptions;
|
||||||
@ -196,9 +201,11 @@ var i, j, FilenameEndPos: integer;
|
|||||||
begin
|
begin
|
||||||
Result:=false;
|
Result:=false;
|
||||||
if ('Compiling '=copy(s,1,length('Compiling '))) then begin
|
if ('Compiling '=copy(s,1,length('Compiling '))) then begin
|
||||||
|
// for example 'Compiling ./subdir/unit1.pas'
|
||||||
fLastMessageType:=omtFPC;
|
fLastMessageType:=omtFPC;
|
||||||
fLastErrorType:=etNone;
|
fLastErrorType:=etNone;
|
||||||
Result:=true;
|
Result:=true;
|
||||||
|
// add path to history
|
||||||
if fCompilingHistory=nil then fCompilingHistory:=TStringList.Create;
|
if fCompilingHistory=nil then fCompilingHistory:=TStringList.Create;
|
||||||
i:=length('Compiling ');
|
i:=length('Compiling ');
|
||||||
if (length(s)>=i+2) and (s[i+1]='.') and (s[i+2]=PathDelim) then
|
if (length(s)>=i+2) and (s[i+1]='.') and (s[i+2]=PathDelim) then
|
||||||
@ -299,9 +306,14 @@ begin
|
|||||||
end;
|
end;
|
||||||
end else
|
end else
|
||||||
SkipMessage:=false;
|
SkipMessage:=false;
|
||||||
|
// beautify compiler message
|
||||||
|
|
||||||
|
// the compiler always gives short filenames, even if it has gone into a
|
||||||
|
// subdirectory
|
||||||
|
// -> prepend the current subdirectory
|
||||||
Msg:=s;
|
Msg:=s;
|
||||||
if (fCompilingHistory<>nil) then begin
|
if (fCompilingHistory<>nil) then begin
|
||||||
Filename:=copy(s,1,FilenameEndPos);
|
Filename:=copy(Msg,1,FilenameEndPos);
|
||||||
if not FilenameIsAbsolute(Filename) then begin
|
if not FilenameIsAbsolute(Filename) then begin
|
||||||
i:=fCompilingHistory.Count-1;
|
i:=fCompilingHistory.Count-1;
|
||||||
while (i>=0) do begin
|
while (i>=0) do begin
|
||||||
@ -314,10 +326,18 @@ begin
|
|||||||
end;
|
end;
|
||||||
dec(i);
|
dec(i);
|
||||||
end;
|
end;
|
||||||
|
if i<0 then begin
|
||||||
|
// this file is not a compiled pascal soure
|
||||||
|
// -> search for include files
|
||||||
|
Filename:=SearchIncludeFile(Filename);
|
||||||
|
Msg:=Filename+copy(Msg,FileNameEndPos+1,length(Msg)-FileNameEndPos);
|
||||||
|
FileNameEndPos:=length(Filename);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if (ofoMakeFilenamesAbsolute in Options) then begin
|
if (ofoMakeFilenamesAbsolute in Options) then begin
|
||||||
Filename:=copy(s,1,FilenameEndPos);
|
Filename:=copy(Msg,1,FilenameEndPos);
|
||||||
if not FilenameIsAbsolute(Filename) then begin
|
if not FilenameIsAbsolute(Filename) then begin
|
||||||
Msg:=fCurrentDirectory+Msg;
|
Msg:=fCurrentDirectory+Msg;
|
||||||
end;
|
end;
|
||||||
@ -419,6 +439,48 @@ begin
|
|||||||
OnOutputString(s);
|
OnOutputString(s);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TOutputFilter.SearchIncludeFile(const ShortIncFilename: string
|
||||||
|
): string;
|
||||||
|
// search the include file and make it relative to the current start directory
|
||||||
|
var SearchedDirectories: TStringList;
|
||||||
|
FullDir, RelativeDir, IncludePath: string;
|
||||||
|
p: integer;
|
||||||
|
begin
|
||||||
|
if fCompilingHistory=nil then begin
|
||||||
|
Result:=ShortIncFilename;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
SearchedDirectories:=TStringList.Create;
|
||||||
|
try
|
||||||
|
// try every compiled pascal source
|
||||||
|
for p:=fCompilingHistory.Count-1 downto 0 do begin
|
||||||
|
RelativeDir:=AppendPathDelim(ExtractFilePath(fCompilingHistory[p]));
|
||||||
|
FullDir:=AppendPathDelim(ExpandFilename(fCurrentDirectory+RelativeDir));
|
||||||
|
if SearchedDirectories.IndexOf(FullDir)>=0 then continue;
|
||||||
|
// new directory start a search
|
||||||
|
if FileExists(FullDir+ShortIncFilename) then begin
|
||||||
|
// file found in search dir
|
||||||
|
Result:=RelativeDir+ShortIncFilename;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
if Assigned(OnGetIncludePath) then begin
|
||||||
|
// search with include path of directory
|
||||||
|
IncludePath:=OnGetIncludePath(FullDir);
|
||||||
|
Result:=SearchFileInPath(ShortIncFilename,FullDir,IncludePath,';');
|
||||||
|
if Result<>'' then begin
|
||||||
|
if LeftStr(Result,length(fCurrentDirectory))=fCurrentDirectory then
|
||||||
|
Result:=RightStr(Result,length(Result)-length(fCurrentDirectory));
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
SearchedDirectories.Add(FullDir);
|
||||||
|
end;
|
||||||
|
finally
|
||||||
|
SearchedDirectories.Free;
|
||||||
|
end;
|
||||||
|
Result:=ShortIncFilename;
|
||||||
|
end;
|
||||||
|
|
||||||
destructor TOutputFilter.Destroy;
|
destructor TOutputFilter.Destroy;
|
||||||
begin
|
begin
|
||||||
fFilteredOutput.Free;
|
fFilteredOutput.Free;
|
||||||
|
@ -1349,6 +1349,9 @@ end;
|
|||||||
|
|
||||||
{ =============================================================================
|
{ =============================================================================
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.33 2002/03/08 11:37:42 lazarus
|
||||||
|
MG: outputfilter can now find include files
|
||||||
|
|
||||||
Revision 1.32 2002/01/01 18:38:36 lazarus
|
Revision 1.32 2002/01/01 18:38:36 lazarus
|
||||||
MG: more wmsize messages :(
|
MG: more wmsize messages :(
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user