Converter: Respect the "use same dfm" setting properly + clean RenameResourceDirectives code

git-svn-id: trunk@30510 -
This commit is contained in:
juha 2011-04-30 13:33:25 +00:00
parent 6befebb2f4
commit e002cb4bc6

View File

@ -79,8 +79,6 @@ type
fHasFormFile: boolean; fHasFormFile: boolean;
fLowerCaseRes: boolean; fLowerCaseRes: boolean;
fAddUnitEvent: TAddUnitEvent; fAddUnitEvent: TAddUnitEvent;
fDfmDirectiveStart: integer;
fDfmDirectiveEnd: integer;
// Delphi Function names to replace with FCL/LCL functions. // Delphi Function names to replace with FCL/LCL functions.
fDefinedProcNames: TStringList; fDefinedProcNames: TStringList;
// List of TFuncReplacement. // List of TFuncReplacement.
@ -254,61 +252,53 @@ var
ParamPos, ACleanPos: Integer; ParamPos, ACleanPos: Integer;
Key, LowKey, NewKey: String; Key, LowKey, NewKey: String;
s: string; s: string;
AlreadyIsLfm: Boolean;
begin begin
Result:=false; Result:=false;
AlreadyIsLfm:=false;
fDfmDirectiveStart:=-1;
fDfmDirectiveEnd:=-1;
ACleanPos:=1; ACleanPos:=1;
// find $R directive // find $R directive
with fCTLink.CodeTool do with fCTLink.CodeTool do
repeat repeat
ACleanPos:=FindNextCompilerDirectiveWithName(Src, ACleanPos, 'R', ACleanPos:=FindNextCompilerDirectiveWithName(Src, ACleanPos, 'R',
Scanner.NestedComments, ParamPos); Scanner.NestedComments, ParamPos);
if (ACleanPos<1) or (ACleanPos>SrcLen) or (ParamPos>SrcLen-6) then break; if (ACleanPos<1) or (ACleanPos>SrcLen) or (ParamPos>SrcLen-6) then break;
NewKey:=''; NewKey:='';
if (Src[ACleanPos]='{') and if (Src[ACleanPos]='{') and
(Src[ParamPos]='*') and (Src[ParamPos+1]='.') and (Src[ParamPos+5]='}') (Src[ParamPos]='*') and (Src[ParamPos+1]='.') and (Src[ParamPos+5]='}')
then begin then begin
Key:=copy(Src,ParamPos+2,3); Key:=copy(Src,ParamPos+2,3);
LowKey:=LowerCase(Key); LowKey:=LowerCase(Key);
// Form file resource rename or lowercase: // Form file resource rename or lowercase:
if (LowKey='dfm') or (LowKey='xfm') then begin if (LowKey='dfm') or (LowKey='xfm') then begin
if fCTLink.Settings.SupportDelphi then begin if fCTLink.Settings.SupportDelphi then begin
// Use the same dfm file. Lowercase existing key. // Use the same dfm file. Lowercase existing key.
if fCTLink.Settings.SameDfmFile and (Key<>LowKey) then if fCTLink.Settings.SameDfmFile then begin
if Key<>LowKey then
NewKey:=LowKey; NewKey:=LowKey;
// Later IFDEF will be added so that Delphi can still use .dfm.
fDfmDirectiveStart:=ACleanPos;
fDfmDirectiveEnd:=ParamPos+6;
end end
else // Change .dfm to .lfm. else begin
NewKey:='lfm'; // Add IFDEF for .lfm and .dfm allowing Delphi to use .dfm.
s:='{$IFNDEF FPC}'+LineEnding+
' {$R *.dfm}'+LineEnding+
'{$ELSE}'+LineEnding+
' {$R *.lfm}'+LineEnding+
'{$ENDIF}';
Result:=fCTLink.SrcCache.Replace(gtNone,gtNone,ACleanPos,ParamPos+6,s);
end;
end end
// If there already is .lfm, prevent adding IFDEF for .dfm / .lfm. else // Change .dfm to .lfm.
else if LowKey='lfm' then NewKey:='lfm';
AlreadyIsLfm:=true end
// lowercase {$R *.RES} to {$R *.res} // lowercase {$R *.RES} to {$R *.res}
else if (Key='RES') and fLowerCaseRes then else if (Key='RES') and fLowerCaseRes then
NewKey:=LowKey; NewKey:=LowKey;
// Now change code. // Change a single resource name.
if NewKey<>'' then if NewKey<>'' then begin
if not fCTLink.SrcCache.Replace(gtNone,gtNone,ParamPos+2,ParamPos+5,NewKey) then exit; if not fCTLink.SrcCache.Replace(gtNone,gtNone,ParamPos+2,ParamPos+5,NewKey) then
exit;
end; end;
ACleanPos:=FindCommentEnd(Src, ACleanPos, Scanner.NestedComments); end;
until false; ACleanPos:=FindCommentEnd(Src, ACleanPos, Scanner.NestedComments);
// if there is already .lfm file, don't add IFDEF for .dfm / .lfm. until false;
if fCTLink.Settings.SupportDelphi and (fDfmDirectiveStart<>-1)
and not AlreadyIsLfm then begin
// Add IFDEF for .lfm and .dfm allowing Delphi to use .dfm.
s:='{$IFNDEF FPC}'+LineEnding+
' {$R *.dfm}'+LineEnding+
'{$ELSE}'+LineEnding+
' {$R *.lfm}'+LineEnding+
'{$ENDIF}';
Result:=fCTLink.SrcCache.Replace(gtNone,gtNone,fDfmDirectiveStart,fDfmDirectiveEnd,s);
end;
Result:=true; Result:=true;
end; end;