You've already forked lazarus-ccr
chelper: added internal converter into the package. todo: fix leaks and improve performance
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1295 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -14,8 +14,8 @@
|
|||||||
</CompilerOptions>
|
</CompilerOptions>
|
||||||
<Description Value="The IDE extension usefull for C headers convertion"/>
|
<Description Value="The IDE extension usefull for C headers convertion"/>
|
||||||
<License Value="LGPL"/>
|
<License Value="LGPL"/>
|
||||||
<Version Minor="8"/>
|
<Version Minor="9"/>
|
||||||
<Files Count="6">
|
<Files Count="5">
|
||||||
<Item1>
|
<Item1>
|
||||||
<Filename Value="tosourceeditor.pas"/>
|
<Filename Value="tosourceeditor.pas"/>
|
||||||
<HasRegisterProc Value="True"/>
|
<HasRegisterProc Value="True"/>
|
||||||
@ -37,10 +37,6 @@
|
|||||||
<Filename Value="converteridesettings.pas"/>
|
<Filename Value="converteridesettings.pas"/>
|
||||||
<UnitName Value="converteridesettings"/>
|
<UnitName Value="converteridesettings"/>
|
||||||
</Item5>
|
</Item5>
|
||||||
<Item6>
|
|
||||||
<Filename Value="extconvdialog.lfm"/>
|
|
||||||
<Type Value="LFM"/>
|
|
||||||
</Item6>
|
|
||||||
</Files>
|
</Files>
|
||||||
<Type Value="RunAndDesignTime"/>
|
<Type Value="RunAndDesignTime"/>
|
||||||
<RequiredPkgs Count="3">
|
<RequiredPkgs Count="3">
|
||||||
|
@ -75,6 +75,7 @@ begin
|
|||||||
try
|
try
|
||||||
ini:=TIniFile.Create(FileName);
|
ini:=TIniFile.Create(FileName);
|
||||||
try
|
try
|
||||||
|
ini.WriteBool('Tool', 'UseExt', UseExtTool);
|
||||||
ini.WriteString('Tool', 'Exe', ExtTool);
|
ini.WriteString('Tool', 'Exe', ExtTool);
|
||||||
ini.WriteString('Tool', 'DefineFile', DefineFile);
|
ini.WriteString('Tool', 'DefineFile', DefineFile);
|
||||||
finally
|
finally
|
||||||
@ -91,6 +92,7 @@ begin
|
|||||||
try
|
try
|
||||||
ini:=TIniFile.Create(FileName);
|
ini:=TIniFile.Create(FileName);
|
||||||
try
|
try
|
||||||
|
UseExtTool:=ini.ReadBool('Tool', 'UseExt', UseExtTool);
|
||||||
ExtTool:=ini.ReadString('Tool', 'Exe', ExtTool);
|
ExtTool:=ini.ReadString('Tool', 'Exe', ExtTool);
|
||||||
DefineFile:=ini.ReadString('Tool', 'DefineFile',DefineFile);
|
DefineFile:=ini.ReadString('Tool', 'DefineFile',DefineFile);
|
||||||
finally
|
finally
|
||||||
|
@ -20,6 +20,7 @@ unit cparsertypes;
|
|||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
|
|
||||||
{$ifdef fpc}{$mode delphi}{$h+}{$endif}
|
{$ifdef fpc}{$mode delphi}{$h+}{$endif}
|
||||||
|
|
||||||
uses
|
uses
|
||||||
@ -2077,5 +2078,4 @@ initialization
|
|||||||
ParseNamePart:=@ParseCNamePart;
|
ParseNamePart:=@ParseCNamePart;
|
||||||
ParsePreproc:=@ParseDefPreproc;
|
ParsePreproc:=@ParseDefPreproc;
|
||||||
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -1680,6 +1680,5 @@ begin
|
|||||||
Result:=Copy(Result, 1, length(Result)-1);
|
Result:=Copy(Result, 1, length(Result)-1);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ object CtoPasConfig: TCtoPasConfig
|
|||||||
Top = 8
|
Top = 8
|
||||||
Width = 622
|
Width = 622
|
||||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||||
PageIndex = 0
|
PageIndex = 1
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
object pageMain: TPage
|
object pageMain: TPage
|
||||||
Caption = 'Main'
|
Caption = 'Main'
|
||||||
@ -191,23 +191,38 @@ object CtoPasConfig: TCtoPasConfig
|
|||||||
ClientWidth = 616
|
ClientWidth = 616
|
||||||
ClientHeight = 382
|
ClientHeight = 382
|
||||||
object edtExtTool: TEdit
|
object edtExtTool: TEdit
|
||||||
|
AnchorSideTop.Control = chkUseExternal
|
||||||
|
AnchorSideTop.Side = asrBottom
|
||||||
Left = 13
|
Left = 13
|
||||||
Height = 22
|
Height = 22
|
||||||
Top = 6
|
Top = 32
|
||||||
Width = 511
|
Width = 511
|
||||||
Anchors = [akTop, akLeft, akRight]
|
Anchors = [akTop, akLeft, akRight]
|
||||||
|
BorderSpacing.Top = 10
|
||||||
TabOrder = 0
|
TabOrder = 0
|
||||||
end
|
end
|
||||||
object Button1: TButton
|
object Button1: TButton
|
||||||
|
AnchorSideTop.Control = chkUseExternal
|
||||||
|
AnchorSideTop.Side = asrBottom
|
||||||
Left = 538
|
Left = 538
|
||||||
Height = 20
|
Height = 20
|
||||||
Top = 6
|
Top = 32
|
||||||
Width = 70
|
Width = 70
|
||||||
Anchors = [akTop, akRight]
|
Anchors = [akTop, akRight]
|
||||||
|
AutoSize = True
|
||||||
|
BorderSpacing.Top = 10
|
||||||
Caption = 'Select'
|
Caption = 'Select'
|
||||||
OnClick = Button1Click
|
OnClick = Button1Click
|
||||||
TabOrder = 1
|
TabOrder = 1
|
||||||
end
|
end
|
||||||
|
object chkUseExternal: TCheckBox
|
||||||
|
Left = 13
|
||||||
|
Height = 18
|
||||||
|
Top = 4
|
||||||
|
Width = 163
|
||||||
|
Caption = 'Use external converter'
|
||||||
|
TabOrder = 2
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
object OpenDialog1: TOpenDialog
|
object OpenDialog1: TOpenDialog
|
||||||
|
@ -17,6 +17,7 @@ type
|
|||||||
btnSelect:TButton;
|
btnSelect:TButton;
|
||||||
btnEdit:TButton;
|
btnEdit:TButton;
|
||||||
Button2:TButton;
|
Button2:TButton;
|
||||||
|
chkUseExternal:TCheckBox;
|
||||||
chkRecordsPacked:TCheckBox;
|
chkRecordsPacked:TCheckBox;
|
||||||
chkFuncAreExt:TCheckBox;
|
chkFuncAreExt:TCheckBox;
|
||||||
chkEnums:TCheckBox;
|
chkEnums:TCheckBox;
|
||||||
@ -134,6 +135,7 @@ begin
|
|||||||
Memo1.Lines.Assign(ConvSettings.CtoPasTypes);
|
Memo1.Lines.Assign(ConvSettings.CtoPasTypes);
|
||||||
edtDefines.Text:=DefineFile;
|
edtDefines.Text:=DefineFile;
|
||||||
edtExtTool.Text:=ExtTool;
|
edtExtTool.Text:=ExtTool;
|
||||||
|
chkUseExternal.Checked:=UseExtTool;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCtoPasConfig.UIToSettings;
|
procedure TCtoPasConfig.UIToSettings;
|
||||||
@ -145,6 +147,7 @@ begin
|
|||||||
ConvSettings.CtoPasTypes.Assign(Memo1.Lines);
|
ConvSettings.CtoPasTypes.Assign(Memo1.Lines);
|
||||||
DefineFile:=edtDefines.Text;
|
DefineFile:=edtDefines.Text;
|
||||||
ExtTool:=edtExtTool.Text;
|
ExtTool:=edtExtTool.Text;
|
||||||
|
UseExtTool:=chkUseExternal.Checked;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
@ -25,20 +25,12 @@ interface
|
|||||||
uses
|
uses
|
||||||
Classes, SysUtils, Dialogs, LCLType, LCLIntf, Forms,
|
Classes, SysUtils, Dialogs, LCLType, LCLIntf, Forms,
|
||||||
Menus, MenuIntf, SrcEditorIntf, process, LazIDEIntf, IDEMsgIntf,
|
Menus, MenuIntf, SrcEditorIntf, process, LazIDEIntf, IDEMsgIntf,
|
||||||
extconvdialog, converteridesettings, cconvconfig;
|
extconvdialog, converteridesettings, cconvconfig, ctopasconvert;
|
||||||
|
|
||||||
procedure Register;
|
procedure Register;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
type
|
|
||||||
TErrorInfo = record
|
|
||||||
isError : Boolean;
|
|
||||||
Error : AnsiString;
|
|
||||||
ErrorPos : TPoint;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
function GetErrorInfo(const errstr: AnsiString; var error: TerrorInfo): Boolean;
|
function GetErrorInfo(const errstr: AnsiString; var error: TerrorInfo): Boolean;
|
||||||
var
|
var
|
||||||
i : Integer;
|
i : Integer;
|
||||||
@ -58,7 +50,7 @@ begin
|
|||||||
i:=Pos(' ', d);
|
i:=Pos(' ', d);
|
||||||
Val( copy(d, 1, i-1), error.ErrorPos.X, err);
|
Val( copy(d, 1, i-1), error.ErrorPos.X, err);
|
||||||
|
|
||||||
error.Error:=Copy(d, i+1, length(d));
|
error.ErrorMsg:=Copy(d, i+1, length(d));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function DoExtConvert(const t: AnsiString; ParseAll: Boolean; var EndPos: TPoint; var error: TErrorInfo): AnsiString;
|
function DoExtConvert(const t: AnsiString; ParseAll: Boolean; var EndPos: TPoint; var error: TErrorInfo): AnsiString;
|
||||||
@ -136,8 +128,10 @@ begin
|
|||||||
if st.Count=0 then Exit;
|
if st.Count=0 then Exit;
|
||||||
i:=0;
|
i:=0;
|
||||||
d:=st[0];
|
d:=st[0];
|
||||||
if GetErrorInfo(d, error) then d:=st[1];
|
if GetErrorInfo(d, error) then begin
|
||||||
|
st.Delete(0);
|
||||||
|
d:=st[0];
|
||||||
|
end;
|
||||||
if d='' then Exit;
|
if d='' then Exit;
|
||||||
i:=Pos(' ', d);
|
i:=Pos(' ', d);
|
||||||
if i>=1 then begin
|
if i>=1 then begin
|
||||||
@ -159,6 +153,24 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function StringFromFile(const FileName: AnsiString): AnsiString;
|
||||||
|
var
|
||||||
|
fs : TFileStream;
|
||||||
|
begin
|
||||||
|
Result:='';
|
||||||
|
if not FileExists(FileName) then Exit;
|
||||||
|
try
|
||||||
|
fs:=TFileStream.Create(FileName, fmOpenRead or fmShareDenyNone);
|
||||||
|
try
|
||||||
|
SetLength(Result, fs.Size);
|
||||||
|
fs.Read(Result[1], fs.Size);
|
||||||
|
finally
|
||||||
|
fs.Free;
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
function DoConvertCode(const t: AnsiString; ParseAll: Boolean; var EndPoint: TPoint; var txt: AnsiString; var error: TErrorInfo): Boolean;
|
function DoConvertCode(const t: AnsiString; ParseAll: Boolean; var EndPoint: TPoint; var txt: AnsiString; var error: TErrorInfo): Boolean;
|
||||||
begin
|
begin
|
||||||
Result:=False;
|
Result:=False;
|
||||||
@ -174,8 +186,22 @@ begin
|
|||||||
if Result then cconvconfig.LoadFromFile(ConvFile, ConvSettings)
|
if Result then cconvconfig.LoadFromFile(ConvFile, ConvSettings)
|
||||||
else ShowMessage('Error: '+ txt);
|
else ShowMessage('Error: '+ txt);
|
||||||
|
|
||||||
end else
|
end else begin
|
||||||
txt:='';
|
try
|
||||||
|
if FileExists(DefineFile) then
|
||||||
|
ConvSettings.CustomDefines:=StringFromFile(DefineFile)
|
||||||
|
else
|
||||||
|
ConvSettings.CustomDefines:='';
|
||||||
|
txt:=ConvertCode(t, EndPoint, ParseAll, error, ConvSettings);
|
||||||
|
Result:=true;
|
||||||
|
|
||||||
|
except
|
||||||
|
on E: Exception do begin
|
||||||
|
ShowMessage('Error: '+e.Message);
|
||||||
|
Result:=False;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
var
|
var
|
||||||
@ -192,6 +218,7 @@ var
|
|||||||
err : TErrorInfo;
|
err : TErrorInfo;
|
||||||
line : TIDEMessageLine;
|
line : TIDEMessageLine;
|
||||||
parts : TStringList;
|
parts : TStringList;
|
||||||
|
lcnt : Integer;
|
||||||
begin
|
begin
|
||||||
if parsing then Exit;
|
if parsing then Exit;
|
||||||
if not Assigned(SourceEditorManagerIntf) or not Assigned(SourceEditorManagerIntf.ActiveEditor) then Exit;
|
if not Assigned(SourceEditorManagerIntf) or not Assigned(SourceEditorManagerIntf.ActiveEditor) then Exit;
|
||||||
@ -216,14 +243,17 @@ begin
|
|||||||
if p.Y>0 then begin
|
if p.Y>0 then begin
|
||||||
inc(p.Y, st.Y-1);
|
inc(p.Y, st.Y-1);
|
||||||
st.X:=1;
|
st.X:=1;
|
||||||
|
lcnt:=editor.LineCount;
|
||||||
editor.ReplaceText(st, p, s);
|
editor.ReplaceText(st, p, s);
|
||||||
|
lcnt:=editor.LineCount-lcnt;
|
||||||
if Assigned(CtoPasConfig) then
|
if Assigned(CtoPasConfig) then
|
||||||
CtoPasConfig.SettingsToUI;
|
CtoPasConfig.SettingsToUI;
|
||||||
end;
|
end else
|
||||||
|
lcnt:=0;
|
||||||
if err.isError then begin
|
if err.isError then begin
|
||||||
inc(err.ErrorPos.Y, st.Y-1);
|
inc(err.ErrorPos.Y, st.Y-1+lcnt);
|
||||||
if Assigned(IDEMessagesWindow) then begin
|
if Assigned(IDEMessagesWindow) then begin
|
||||||
s:=Format('%s(%d,%d) Chelper: %s', [ExtractFileName(editor.FileName), err.ErrorPos.Y,err.ErrorPos.X, err.Error]);
|
with err do s:=Format('%s(%d,%d) Chelper: %s', [ExtractFileName(editor.FileName), ErrorPos.Y,ErrorPos.X, ErrorMsg]);
|
||||||
parts:=TStringList.Create;
|
parts:=TStringList.Create;
|
||||||
try
|
try
|
||||||
parts.Values['Type']:='Chelper';
|
parts.Values['Type']:='Chelper';
|
||||||
|
Reference in New Issue
Block a user