started parsing Delphi dof and cfg files

git-svn-id: trunk@8788 -
This commit is contained in:
mattias 2006-02-20 23:48:13 +00:00
parent 8ee1876b6e
commit fb16ad9a8f
5 changed files with 111 additions and 10 deletions

View File

@ -3761,6 +3761,7 @@ begin
d('../ide'
+';../ideintf'
+';../components/codetools'
+';../components/synedit'
+';../lcl'
+';../lcl/interfaces/'+WidgetType)
+';'+SrcPath

View File

@ -44,7 +44,7 @@ uses
// Components
SynEdit, CodeCache, CodeToolManager, DefineTemplates,
// IDE
DialogProcs, IDEProcs, LazarusIDEStrConsts;
Project, DialogProcs, IDEProcs, LazarusIDEStrConsts;
type
TDelphi2LazarusDialog = class(TForm)
@ -74,6 +74,14 @@ function ConvertLFMtoLRSfile(const LFMFilename: string): TModalResult;
function CheckDelphiProjectExt(const Filename: string): TModalResult;
function CreateLPRFileForDPRFile(const DelphiProjectFilename: string;
AddLRSCode: boolean; var LPRCode: TCodeBuffer): TModalResult;
function ExtractOptionsFromDPR(DPRCode: TCodeBuffer;
AProject: TProject): TModalResult;
function FindDelphiDOF(const DelphiFilename: string): string;
function ExtractOptionsFromDOF(const DOFFilename: string;
AProject: TProject): TModalResult;
function FindDelphiCFG(const DelphiFilename: string): string;
function ExtractOptionsFromCFG(const CFGFilename: string;
AProject: TProject): TModalResult;
implementation
@ -369,6 +377,47 @@ begin
Result:=mrOk;
end;
function ExtractOptionsFromDPR(DPRCode: TCodeBuffer; AProject: TProject
): TModalResult;
begin
// TODO remove compiler directives in code and put them into AProject
Result:=mrOk;
end;
function FindDelphiDOF(const DelphiFilename: string): string;
var
Filename: String;
begin
Result:=ChangeFileExt(DelphiFilename,'.dof');
Filename:=FindDiskFileCaseInsensitive(Result);
if Filename<>'' then
Result:=Filename;
end;
function ExtractOptionsFromDOF(const DOFFilename: string; AProject: TProject
): TModalResult;
begin
// TODO parse .dof file and put options into AProject
Result:=mrOk;
end;
function FindDelphiCFG(const DelphiFilename: string): string;
var
Filename: String;
begin
Result:=ChangeFileExt(DelphiFilename,'.cfg');
Filename:=FindDiskFileCaseInsensitive(Result);
if Filename<>'' then
Result:=Filename;
end;
function ExtractOptionsFromCFG(const CFGFilename: string; AProject: TProject
): TModalResult;
begin
// TODO parse .cfg file and put options into AProject
Result:=mrOk;
end;
initialization
{$I delphiunit2laz.lrs}

View File

@ -8224,6 +8224,8 @@ var
i: Integer;
CurUnitInfo: TUnitInfo;
MainUnitInfo: TUnitInfo;
DOFFilename: String;
CFGFilename: String;
begin
debugln('TMainIDE.DoConvertDelphiProject DelphiFilename="',DelphiFilename,'"');
if MessagesView<>nil then MessagesView.Clear;
@ -8251,7 +8253,6 @@ begin
if CodeToolBoss.ErrorMessage<>'' then DoJumpToCodeToolBossError;
exit;
end;
// close old project
debugln('TMainIDE.DoConvertDelphiProject closing current project ...');
If Project1<>nil then begin
@ -8261,12 +8262,6 @@ begin
end;
end;
// TODO: get all compiler options from .dpr
// TODO: read .dof file
// TODO: read .cfg file
// TODO: get all search paths
// TODO: get all needed packages
// switch codetools to new project directory
CodeToolBoss.GlobalValues.Variables[ExternalMacroStart+'ProjPath']:=
ExpandFilename(ExtractFilePath(LPRCode.Filename));
@ -8288,6 +8283,26 @@ begin
Project1.CompilerOptions.CompilerPath:='$(CompPath)';
UpdateCaption;
IncreaseCompilerParseStamp;
// TODO: get all compiler options from .dpr
Result:=ExtractOptionsFromDPR(LPRCode,Project1);
if Result<>mrOk then exit;
// TODO: read .dof file
DOFFilename:=FindDelphiDOF(DelphiFilename);
if FileExists(DOFFilename) then begin
Result:=ExtractOptionsFromDOF(DOFFilename,Project1);
if Result<>mrOk then exit;
end;
// TODO: read .cfg file
CFGFilename:=FindDelphiCFG(DelphiFilename);
if FileExists(CFGFilename) then begin
Result:=ExtractOptionsFromCFG(CFGFilename,Project1);
if Result<>mrOk then exit;
end;
// TODO: get all needed packages
// add and load default required packages
// TODO: add packages
@ -8331,7 +8346,7 @@ begin
+NotFoundUnits,mtWarning,[mbIgnore,mbAbort],0);
if Result<>mrIgnore then exit;
end;
// add all units to the project
debugln('TMainIDE.DoConvertDelphiProject adding all project units to project ...');
for i:=0 to FoundInUnits.Count-1 do begin
@ -8339,7 +8354,11 @@ begin
TUnitInfo(CurUnitInfo).Filename:=FoundInUnits[i];
Project1.AddFile(CurUnitInfo,false);
end;
// set search paths to find all project units
Project1.CompilerOptions.OtherUnitFiles:=
Project1.SourceDirectories.CreateSearchPathFromAllFiles;
DebugLn('TMainIDE.DoConvertDelphiProject UnitPath="',Project1.CompilerOptions.OtherUnitFiles,'"');
// save project
debugln('TMainIDE.DoConvertDelphiProject Saving new project ...');
Result:=DoSaveProject([]);

View File

@ -96,6 +96,7 @@ function SearchFileInPath(const Filename, BasePath, SearchPath,
function SearchAllFilesInPath(const Filename, BasePath, SearchPath,
Delimiter: string; Flags: TSearchFileInPathFlags): TStrings;
function FindDiskFilename(const Filename: string): string;
function FindDiskFileCaseInsensitive(const Filename: string): string;
// file actions
function ReadFileToString(const Filename: string): string;

View File

@ -1217,6 +1217,37 @@ begin
until StartPos>length(Result);
end;
function FindDiskFileCaseInsensitive(const Filename: string): string;
var
FileInfo: TSearchRec;
ShortFilename: String;
CurDir: String;
begin
Result:='';
CurDir:=ExtractFilePath(Filename);
if SysUtils.FindFirst(CurDir+GetAllFilesMask,faAnyFile,
FileInfo)=0
then begin
ShortFilename:=ExtractFilename(Filename);
repeat
// check if special file
if (FileInfo.Name='.') or (FileInfo.Name='..') or (FileInfo.Name='')
then
continue;
if CompareText(FileInfo.Name,ShortFilename)=0 then begin
if FileInfo.Name=ShortFilename then begin
// fits exactly
Result:=Filename;
exit;
end;
// fits case insensitive
Result:=CurDir+FileInfo.Name;
// search further
end;
until SysUtils.FindNext(FileInfo)<>0;
end;
end;
function GetAllFilesMask: string;
begin
{$IFDEF MSWINDOWS}