apiwizz: unicode file names

git-svn-id: trunk@46807 -
This commit is contained in:
mattias 2014-11-12 18:49:00 +00:00
parent d709e846a2
commit 91b4dfee8b

View File

@ -31,8 +31,8 @@ unit APIWizard;
interface interface
uses uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, LazUTF8Classes, LResources, Forms, Controls,
StdCtrls, Buttons, ExtCtrls, LCLproc, ComCtrls; Graphics, Dialogs, StdCtrls, Buttons, ExtCtrls, LCLproc, ComCtrls;
type type
@ -67,7 +67,17 @@ type
TProcType = (ptFunction, ptProcedure); TProcType = (ptFunction, ptProcedure);
TApiWidgetset = (awCarbon, awCocoa, awFpgui, awGtk, awGtk2, awGtk3, awNoGui, awQt, awWin32, awWinCE); TApiWidgetset = (
awCarbon,
awCocoa,
awFpgui,
awGtk,
awGtk2,
awGtk3,
awNoGui,
awQt,
awWin32,
awWinCE);
TApiWidgetsets = set of TApiWidgetset; TApiWidgetsets = set of TApiWidgetset;
TApiLine = class TApiLine = class
@ -89,7 +99,16 @@ const
DECL_OFFSET: array[TProctype] of Integer = (9, 10); DECL_OFFSET: array[TProctype] of Integer = (9, 10);
WS_NAME: array[TApiWidgetset] of string = ( WS_NAME: array[TApiWidgetset] of string = (
'carbon', 'cocoa', 'fpgui', 'gtk', 'gtk2', 'gtk3', 'nogui', 'qt', 'win32', 'wince', 'carbon',
'cocoa',
'fpgui',
'gtk',
'gtk2',
'gtk3',
'nogui',
'qt',
'win32',
'wince'
); );
function GetName(const ADeclaration: String): String; function GetName(const ADeclaration: String): String;
@ -129,7 +148,9 @@ begin
end; end;
function SplitDeclaration(const ADeclaration: String; var ProcType: TProcType; var ProcName: String; const ProcParams: TStringList): Boolean; function SplitDeclaration(const ADeclaration: String;
out ProcType: TProcType; out ProcName: String; const ProcParams: TStringList): Boolean;
function ProcessParams(Params: String): Boolean; function ProcessParams(Params: String): Boolean;
var var
n: Integer; n: Integer;
@ -327,14 +348,14 @@ var
StartFound: Boolean; StartFound: Boolean;
StartTag, EndTag: String; StartTag, EndTag: String;
Line, LineName: String; Line, LineName: String;
Lines: TStringList; Lines: TStringListUTF8;
n: Integer; n: Integer;
begin begin
AResult.Clear; AResult.Clear;
if not FileExistsUTF8(AFileName) then Exit; if not FileExistsUTF8(AFileName) then Exit;
Lines := TStringList.Create; Lines := TStringListUTF8.Create;
Lines.LoadFromFile(UTF8ToSys(AFileName)); Lines.LoadFromFile(AFileName);
StartFound := False; StartFound := False;
StartTag := Format('##apiwiz##s%s##', [ATag]); StartTag := Format('##apiwiz##s%s##', [ATag]);
@ -487,7 +508,7 @@ const
PROC_DESC: array[TProcType] of String = ('Function', 'Procedure'); PROC_DESC: array[TProcType] of String = ('Function', 'Procedure');
PROC_RESULT: array[TProcType] of String = ('Result := ', ''); PROC_RESULT: array[TProcType] of String = ('Result := ', '');
var var
ApiText, ProcLines, ProcParams: TStringList; ApiText, ProcLines, ProcParams: TStringListUTF8;
S, DeclarationText: String; S, DeclarationText: String;
ProcName, FileName, IntfBase: String; ProcName, FileName, IntfBase: String;
PlatformPrefix, PlatformDir, PlatformObject: String; PlatformPrefix, PlatformDir, PlatformObject: String;
@ -527,9 +548,9 @@ begin
end; end;
LineCount := 0; LineCount := 0;
ProcParams := TStringList.Create; ProcParams := TStringListUTF8.Create;
ApiText := TStringList.Create; ApiText := TStringListUTF8.Create;
ProcLines := TStringList.Create; ProcLines := TStringListUTF8.Create;
try try
for Line := 0 to txtDeclarations.Lines.Count - 1 do for Line := 0 to txtDeclarations.Lines.Count - 1 do
begin begin
@ -553,7 +574,7 @@ begin
//-------------------------------- //--------------------------------
// open winapih.inc / lclintfh.inc // open winapih.inc / lclintfh.inc
//-------------------------------- //--------------------------------
ApiText.LoadFromFile(UTF8ToSys(txtLazarus.text + '/lcl/include/' + FileName + 'h.inc')); ApiText.LoadFromFile(txtLazarus.text + '/lcl/include/' + FileName + 'h.inc');
Idx := FindInsertPoint(ApiText, 'ps', ProcName, FileName + 'h.inc', True); Idx := FindInsertPoint(ApiText, 'ps', ProcName, FileName + 'h.inc', True);
if Idx <> -1 if Idx <> -1
then begin then begin
@ -576,12 +597,12 @@ begin
InsertLines(Idx, ApiText, ProcLines); InsertLines(Idx, ApiText, ProcLines);
end; end;
end; end;
ApiText.SaveToFile(UTF8ToSys(txtLazarus.text + '/lcl/include/' + FileName + 'h.inc')); ApiText.SaveToFile(txtLazarus.text + '/lcl/include/' + FileName + 'h.inc');
end; end;
//------------------------------ //------------------------------
// open winapi.inc / lclintf.inc // open winapi.inc / lclintf.inc
//------------------------------ //------------------------------
ApiText.LoadFromFile(UTF8ToSys(txtLazarus.text + '/lcl/include/' + FileName + '.inc')); ApiText.LoadFromFile(txtLazarus.text + '/lcl/include/' + FileName + '.inc');
if rbIndependent.Checked if rbIndependent.Checked
then begin then begin
Idx := FindInsertPoint(ApiText, 'pi', ProcName, FileName + '.inc', False); Idx := FindInsertPoint(ApiText, 'pi', ProcName, FileName + '.inc', False);
@ -639,7 +660,7 @@ begin
if Idx <> -1 if Idx <> -1
then begin then begin
InsertLines(Idx, ApiText, ProcLines); InsertLines(Idx, ApiText, ProcLines);
ApiText.SaveToFile(UTF8ToSys(txtLazarus.text + '/lcl/include/' + FileName + '.inc')); ApiText.SaveToFile(txtLazarus.text + '/lcl/include/' + FileName + '.inc');
end; end;
// ++++++++++++++++++++++++++++++ // // ++++++++++++++++++++++++++++++ //
@ -650,7 +671,7 @@ begin
//------------------------------------------ //------------------------------------------
// open intfbasewinapi.inc / intfbaselcl.inc // open intfbasewinapi.inc / intfbaselcl.inc
//------------------------------------------ //------------------------------------------
ApiText.LoadFromFile(UTF8ToSys(txtLazarus.text + '/lcl/include/' + IntfBase)); ApiText.LoadFromFile(txtLazarus.text + '/lcl/include/' + IntfBase);
Idx := FindInsertPoint(ApiText, 'ps', ProcName, IntfBase, False); Idx := FindInsertPoint(ApiText, 'ps', ProcName, IntfBase, False);
if Idx <> -1 if Idx <> -1
then begin then begin
@ -673,7 +694,7 @@ begin
Add('end;'); Add('end;');
end; end;
InsertLines(Idx, ApiText, ProcLines); InsertLines(Idx, ApiText, ProcLines);
ApiText.SaveToFile(UTF8ToSys(txtLazarus.text + '/lcl/include/' + IntfBase)); ApiText.SaveToFile(txtLazarus.text + '/lcl/include/' + IntfBase);
end; end;
for WS := Low(WS) to High(Ws) do for WS := Low(WS) to High(Ws) do
@ -688,7 +709,7 @@ begin
//------------------ //------------------
// open *winapih.inc // open *winapih.inc
//------------------ //------------------
ApiText.LoadFromFile(UTF8ToSys(txtLazarus.text + '/lcl/interfaces/' + PlatformDir + '/' + PlatformPrefix + FileName + 'h.inc')); ApiText.LoadFromFile(txtLazarus.text + '/lcl/interfaces/' + PlatformDir + '/' + PlatformPrefix + FileName + 'h.inc');
Idx := FindInsertPoint(ApiText, 'ps', ProcName, PlatformPrefix + FileName + 'h.inc', True); Idx := FindInsertPoint(ApiText, 'ps', ProcName, PlatformPrefix + FileName + 'h.inc', True);
if IDX <> -1 if IDX <> -1
then begin then begin
@ -696,13 +717,13 @@ begin
CreateLeadingCR; CreateLeadingCR;
ProcLines.Add(DeclarationText + '; override;'); ProcLines.Add(DeclarationText + '; override;');
InsertLines(Idx, ApiText, ProcLines); InsertLines(Idx, ApiText, ProcLines);
ApiText.SaveToFile(UTF8ToSys(txtLazarus.text + '/lcl/interfaces/' + PlatformDir + '/' + PlatformPrefix + FileName + 'h.inc')); ApiText.SaveToFile(txtLazarus.text + '/lcl/interfaces/' + PlatformDir + '/' + PlatformPrefix + FileName + 'h.inc');
end; end;
//----------------- //-----------------
// open *winapi.inc // open *winapi.inc
//----------------- //-----------------
ApiText.LoadFromFile(UTF8ToSys(txtLazarus.text + '/lcl/interfaces/' + PlatformDir + '/' + PlatformPrefix + FileName + '.inc')); ApiText.LoadFromFile(txtLazarus.text + '/lcl/interfaces/' + PlatformDir + '/' + PlatformPrefix + FileName + '.inc');
Idx := FindInsertPoint(ApiText, 'ps', ProcName, PlatformPrefix + FileName + '.inc', False); Idx := FindInsertPoint(ApiText, 'ps', ProcName, PlatformPrefix + FileName + '.inc', False);
if Idx <> -1 if Idx <> -1
then begin then begin
@ -733,7 +754,7 @@ begin
Add('end;'); Add('end;');
end; end;
InsertLines(Idx, ApiText, ProcLines); InsertLines(Idx, ApiText, ProcLines);
ApiText.SaveToFile(UTF8ToSys(txtLazarus.text + '/lcl/interfaces/' + PlatformDir + '/' + PlatformPrefix + FileName + '.inc')); ApiText.SaveToFile(txtLazarus.text + '/lcl/interfaces/' + PlatformDir + '/' + PlatformPrefix + FileName + '.inc');
end; end;
end; end;
end; end;