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>
|
||||
<Description Value="The IDE extension usefull for C headers convertion"/>
|
||||
<License Value="LGPL"/>
|
||||
<Version Minor="8"/>
|
||||
<Files Count="6">
|
||||
<Version Minor="9"/>
|
||||
<Files Count="5">
|
||||
<Item1>
|
||||
<Filename Value="tosourceeditor.pas"/>
|
||||
<HasRegisterProc Value="True"/>
|
||||
@ -37,10 +37,6 @@
|
||||
<Filename Value="converteridesettings.pas"/>
|
||||
<UnitName Value="converteridesettings"/>
|
||||
</Item5>
|
||||
<Item6>
|
||||
<Filename Value="extconvdialog.lfm"/>
|
||||
<Type Value="LFM"/>
|
||||
</Item6>
|
||||
</Files>
|
||||
<Type Value="RunAndDesignTime"/>
|
||||
<RequiredPkgs Count="3">
|
||||
|
@ -75,6 +75,7 @@ begin
|
||||
try
|
||||
ini:=TIniFile.Create(FileName);
|
||||
try
|
||||
ini.WriteBool('Tool', 'UseExt', UseExtTool);
|
||||
ini.WriteString('Tool', 'Exe', ExtTool);
|
||||
ini.WriteString('Tool', 'DefineFile', DefineFile);
|
||||
finally
|
||||
@ -91,6 +92,7 @@ begin
|
||||
try
|
||||
ini:=TIniFile.Create(FileName);
|
||||
try
|
||||
UseExtTool:=ini.ReadBool('Tool', 'UseExt', UseExtTool);
|
||||
ExtTool:=ini.ReadString('Tool', 'Exe', ExtTool);
|
||||
DefineFile:=ini.ReadString('Tool', 'DefineFile',DefineFile);
|
||||
finally
|
||||
|
@ -20,6 +20,7 @@ unit cparsertypes;
|
||||
|
||||
interface
|
||||
|
||||
|
||||
{$ifdef fpc}{$mode delphi}{$h+}{$endif}
|
||||
|
||||
uses
|
||||
@ -2077,5 +2078,4 @@ initialization
|
||||
ParseNamePart:=@ParseCNamePart;
|
||||
ParsePreproc:=@ParseDefPreproc;
|
||||
|
||||
|
||||
end.
|
||||
|
@ -1680,6 +1680,5 @@ begin
|
||||
Result:=Copy(Result, 1, length(Result)-1);
|
||||
end;
|
||||
|
||||
|
||||
end.
|
||||
|
||||
|
@ -15,7 +15,7 @@ object CtoPasConfig: TCtoPasConfig
|
||||
Top = 8
|
||||
Width = 622
|
||||
Anchors = [akTop, akLeft, akRight, akBottom]
|
||||
PageIndex = 0
|
||||
PageIndex = 1
|
||||
TabOrder = 0
|
||||
object pageMain: TPage
|
||||
Caption = 'Main'
|
||||
@ -191,23 +191,38 @@ object CtoPasConfig: TCtoPasConfig
|
||||
ClientWidth = 616
|
||||
ClientHeight = 382
|
||||
object edtExtTool: TEdit
|
||||
AnchorSideTop.Control = chkUseExternal
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 13
|
||||
Height = 22
|
||||
Top = 6
|
||||
Top = 32
|
||||
Width = 511
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Top = 10
|
||||
TabOrder = 0
|
||||
end
|
||||
object Button1: TButton
|
||||
AnchorSideTop.Control = chkUseExternal
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 538
|
||||
Height = 20
|
||||
Top = 6
|
||||
Top = 32
|
||||
Width = 70
|
||||
Anchors = [akTop, akRight]
|
||||
AutoSize = True
|
||||
BorderSpacing.Top = 10
|
||||
Caption = 'Select'
|
||||
OnClick = Button1Click
|
||||
TabOrder = 1
|
||||
end
|
||||
object chkUseExternal: TCheckBox
|
||||
Left = 13
|
||||
Height = 18
|
||||
Top = 4
|
||||
Width = 163
|
||||
Caption = 'Use external converter'
|
||||
TabOrder = 2
|
||||
end
|
||||
end
|
||||
end
|
||||
object OpenDialog1: TOpenDialog
|
||||
|
@ -17,6 +17,7 @@ type
|
||||
btnSelect:TButton;
|
||||
btnEdit:TButton;
|
||||
Button2:TButton;
|
||||
chkUseExternal:TCheckBox;
|
||||
chkRecordsPacked:TCheckBox;
|
||||
chkFuncAreExt:TCheckBox;
|
||||
chkEnums:TCheckBox;
|
||||
@ -134,6 +135,7 @@ begin
|
||||
Memo1.Lines.Assign(ConvSettings.CtoPasTypes);
|
||||
edtDefines.Text:=DefineFile;
|
||||
edtExtTool.Text:=ExtTool;
|
||||
chkUseExternal.Checked:=UseExtTool;
|
||||
end;
|
||||
|
||||
procedure TCtoPasConfig.UIToSettings;
|
||||
@ -145,6 +147,7 @@ begin
|
||||
ConvSettings.CtoPasTypes.Assign(Memo1.Lines);
|
||||
DefineFile:=edtDefines.Text;
|
||||
ExtTool:=edtExtTool.Text;
|
||||
UseExtTool:=chkUseExternal.Checked;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -25,20 +25,12 @@ interface
|
||||
uses
|
||||
Classes, SysUtils, Dialogs, LCLType, LCLIntf, Forms,
|
||||
Menus, MenuIntf, SrcEditorIntf, process, LazIDEIntf, IDEMsgIntf,
|
||||
extconvdialog, converteridesettings, cconvconfig;
|
||||
extconvdialog, converteridesettings, cconvconfig, ctopasconvert;
|
||||
|
||||
procedure Register;
|
||||
|
||||
implementation
|
||||
|
||||
type
|
||||
TErrorInfo = record
|
||||
isError : Boolean;
|
||||
Error : AnsiString;
|
||||
ErrorPos : TPoint;
|
||||
end;
|
||||
|
||||
|
||||
function GetErrorInfo(const errstr: AnsiString; var error: TerrorInfo): Boolean;
|
||||
var
|
||||
i : Integer;
|
||||
@ -58,7 +50,7 @@ begin
|
||||
i:=Pos(' ', d);
|
||||
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;
|
||||
|
||||
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;
|
||||
i:=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;
|
||||
i:=Pos(' ', d);
|
||||
if i>=1 then begin
|
||||
@ -159,6 +153,24 @@ begin
|
||||
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;
|
||||
begin
|
||||
Result:=False;
|
||||
@ -174,8 +186,22 @@ begin
|
||||
if Result then cconvconfig.LoadFromFile(ConvFile, ConvSettings)
|
||||
else ShowMessage('Error: '+ txt);
|
||||
|
||||
end else
|
||||
txt:='';
|
||||
end else begin
|
||||
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;
|
||||
|
||||
var
|
||||
@ -192,6 +218,7 @@ var
|
||||
err : TErrorInfo;
|
||||
line : TIDEMessageLine;
|
||||
parts : TStringList;
|
||||
lcnt : Integer;
|
||||
begin
|
||||
if parsing then Exit;
|
||||
if not Assigned(SourceEditorManagerIntf) or not Assigned(SourceEditorManagerIntf.ActiveEditor) then Exit;
|
||||
@ -216,14 +243,17 @@ begin
|
||||
if p.Y>0 then begin
|
||||
inc(p.Y, st.Y-1);
|
||||
st.X:=1;
|
||||
lcnt:=editor.LineCount;
|
||||
editor.ReplaceText(st, p, s);
|
||||
lcnt:=editor.LineCount-lcnt;
|
||||
if Assigned(CtoPasConfig) then
|
||||
CtoPasConfig.SettingsToUI;
|
||||
end;
|
||||
end else
|
||||
lcnt:=0;
|
||||
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
|
||||
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;
|
||||
try
|
||||
parts.Values['Type']:='Chelper';
|
||||
|
Reference in New Issue
Block a user