makestub.pp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. {
  2. makestub - pas2js stub generator
  3. Copyright (C) 2017 - 2020 by Michael Van Canneyt [email protected]
  4. See the file COPYING.FPC, included in this distribution,
  5. for details about the copyright.
  6. This program is distributed in the hope that it will be useful,
  7. but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  9. }
  10. program makestub;
  11. {$mode objfpc}
  12. {$H+}
  13. uses SysUtils, Classes, custapp, stubcreator;
  14. Type
  15. { TStubCreatorApplication }
  16. TStubCreatorApplication = Class(TCustomApplication)
  17. Private
  18. FCreator : TStubCreator;
  19. procedure PrintUsage(S: String);
  20. Protected
  21. function ParseOptions : Boolean;
  22. Procedure DoRun; override;
  23. Public
  24. Constructor Create(AOwner : TComponent); override;
  25. Destructor Destroy; override;
  26. end;
  27. { TStubCreatorApplication }
  28. procedure TStubCreatorApplication.PrintUsage(S : String);
  29. begin
  30. if S<>'' then
  31. Writeln('Error : ',S);
  32. writeln('usage: stubcreator options');
  33. writeln;
  34. writeln('Where options is one or more of');
  35. Writeln('-h --help This text');
  36. writeln('-i --input=file Is the file to be read by the parser');
  37. writeln('-I --include=dir Add dir to include path');
  38. writeln('-o --output=file Output file name. If not specified, standard output is assumed ');
  39. Writeln('-c --config=filename Read ini file with configuration');
  40. Writeln('-H --header=filename Add file header using contents of file "filename"');
  41. Writeln('-f --forwardclasses[=list]');
  42. Writeln(' Generate forward definitions for list of classes. If empty, for all classes.');
  43. ExitCode:=Ord(S<>'');
  44. end;
  45. function TStubCreatorApplication.ParseOptions : Boolean;
  46. Var
  47. S : String;
  48. begin
  49. Result:=False;
  50. S:=CheckOptions('d:i:o:c:h:f:H:I:',['help','input:','output:','forwardclasses::',
  51. 'config:','linenumberwidth:','define:','header:',
  52. 'include:']);
  53. if (S<>'') or HasOption('h','help') then
  54. begin
  55. PrintUsage(S);
  56. Exit;
  57. end;
  58. FCreator.InputFileName:=GetOptionValue('i','input');
  59. FCreator.OutputFileName:=GetOptionValue('o','output');
  60. FCreator.HeaderFileName:=GetOptionValue('H','header');
  61. If HasOption('d','define') then
  62. for S in GetOptionValues('d','define') do
  63. FCreator.Defines.Add(S);
  64. If HasOption('I','include') then
  65. for S in GetOptionValues('i','include') do
  66. FCreator.IncludePaths.Add(S);
  67. if Hasoption('f','forwardclasses') then
  68. FCreator.ForwardClasses:=GetOptionValue('f','forwardclasses');
  69. if (FCreator.HeaderFileName<>'') and Not FileExists(FCreator.HeaderFileName) then
  70. begin
  71. PrintUsage(Format('Header file "%s"does not exist',[FCreator.HeaderFileName]));
  72. Exit;
  73. end;
  74. Result:=True;
  75. end;
  76. { TStubCreatorApplication }
  77. procedure TStubCreatorApplication.DoRun;
  78. begin
  79. Terminate;
  80. If not ParseOptions then
  81. exit;
  82. FCreator.Execute;
  83. end;
  84. constructor TStubCreatorApplication.Create(AOwner: TComponent);
  85. begin
  86. inherited Create(AOwner);
  87. FCreator:=TStubCreator.Create(Self);
  88. StopOnException:=True;
  89. end;
  90. destructor TStubCreatorApplication.Destroy;
  91. begin
  92. FreeAndNil(FCreator);
  93. inherited Destroy;
  94. end;
  95. Var
  96. Application : TStubCreatorApplication;
  97. begin
  98. Application:=TStubCreatorApplication.Create(Nil);
  99. Application.Initialize;
  100. Application.Run;
  101. Application.Free;
  102. end.