fpdocproj.pas 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. unit fpdocproj;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils;
  6. Type
  7. { TFPDocPackage }
  8. TFPDocPackage = Class(TCollectionItem)
  9. private
  10. FContent: String;
  11. FDescriptions: TStrings;
  12. FIMports: TStrings;
  13. FinPuts: TStrings;
  14. FName: String;
  15. FOutput: String;
  16. Public
  17. constructor Create(ACollection: TCollection); override;
  18. destructor destroy; override;
  19. procedure Assign(Source : TPersistent); override;
  20. Property Name : String Read FName Write FName;
  21. Property Inputs : TStrings Read FinPuts;
  22. Property Descriptions : TStrings Read FDescriptions;
  23. Property Imports : TStrings read FIMports;
  24. Property ContentFile : String Read FContent Write FContent;
  25. Property Output : String Read FOutput Write FOutput;
  26. end;
  27. { TFPDocPackages }
  28. TFPDocPackages = Class(TCollection)
  29. private
  30. function GetP(AIndex : Integer): TFPDocPackage;
  31. procedure SetP(AIndex : Integer; const AValue: TFPDocPackage);
  32. Public
  33. Function IndexOfPackage(Const AName : String) : Integer;
  34. Function FindPackage(Const AName : String) : TFPDOcPackage;
  35. Property Packages[AIndex : Integer] : TFPDocPackage Read GetP Write SetP; Default;
  36. end;
  37. { TEngineOptions }
  38. TEngineOptions = Class(TPersistent)
  39. private
  40. FBackEndoptions: TStrings;
  41. FCPUTarget: String;
  42. FDefaultPackageName: String;
  43. FFormat: String;
  44. FHidePrivate: Boolean;
  45. FHideProtected: Boolean;
  46. FIO: Boolean;
  47. FLanguage: String;
  48. FMoDir: String;
  49. FOSTarget: String;
  50. FSOPE: Boolean;
  51. FWarnNoNode: Boolean;
  52. FDontTrim : Boolean;
  53. procedure SetBackendOptions(const AValue: TStrings);
  54. Public
  55. Constructor Create;
  56. Destructor Destroy; override;
  57. procedure Assign(Source : TPersistent); override;
  58. Published
  59. Property OSTarget : String Read FOSTarget Write FOStarget;
  60. Property CPUTarget : String Read FCPUTarget Write FCPUTarget;
  61. Property Language : String Read FLanguage Write fLanguage;
  62. Property Backend : String Read FFormat Write FFormat;
  63. Property BackendOptions : TStrings Read FBackEndoptions Write SetBackendOptions;
  64. Property StopOnParseError : Boolean Read FSOPE Write FSOPE;
  65. Property HideProtected : Boolean Read FHideProtected Write FHideProtected;
  66. Property WarnNoNode : Boolean Read FWarnNoNode Write FWarnNoNode;
  67. Property ShowPrivate : Boolean Read FHidePrivate Write FHidePrivate;
  68. Property InterfaceOnly : Boolean Read FIO Write FIO;
  69. Property MoDir : String Read FMoDir Write FMODir;
  70. Property DefaultPackageName : String Read FDefaultPackageName Write FDefaultPackageName;
  71. Property DontTrim : Boolean Read FDontTrim Write FDontTrim;
  72. end;
  73. { TFPDocProject }
  74. TFPDocProject = Class(TComponent)
  75. private
  76. FOptions: TEngineOptions;
  77. FPackages: TFPDocPackages;
  78. procedure setOptions(const AValue: TEngineOptions);
  79. Public
  80. Constructor Create(AOwner : TComponent); override;
  81. Destructor Destroy; override;
  82. Published
  83. Property Packages : TFPDocPackages Read FPackages Write FPackages;
  84. Property Options : TEngineOptions Read FOptions Write setOptions;
  85. end;
  86. Procedure SplitInputFileOption(Const AInputFile : String; Out AFile,AOption : String);
  87. implementation
  88. Procedure SplitInputFileOption(Const AInputFile : String; Out AFile,AOption : String);
  89. Function GetNextWord(Var s : string) : String;
  90. Const
  91. WhiteSpace = [' ',#9,#10,#13];
  92. var
  93. i,j: integer;
  94. begin
  95. I:=1;
  96. While (I<=Length(S)) and (S[i] in WhiteSpace) do
  97. Inc(I);
  98. J:=I;
  99. While (J<=Length(S)) and (not (S[J] in WhiteSpace)) do
  100. Inc(J);
  101. if (I<=Length(S)) then
  102. Result:=Copy(S,I,J-I);
  103. Delete(S,1,J);
  104. end;
  105. Var
  106. S,W,F,O : String;
  107. begin
  108. S:=AInputFile;
  109. O:='';
  110. F:='';
  111. While (S<>'') do
  112. begin
  113. W:=GetNextWord(S);
  114. If (W<>'') then
  115. begin
  116. if W[1]='-' then
  117. begin
  118. if (O<>'') then
  119. O:=O+' ';
  120. o:=O+W;
  121. end
  122. else
  123. F:=W;
  124. end;
  125. end;
  126. AFile:=F;
  127. AOption:=O;
  128. end;
  129. { TEngineOptions }
  130. procedure TEngineOptions.SetBackendOptions(const AValue: TStrings);
  131. begin
  132. if FBackEndoptions=AValue then exit;
  133. FBackEndoptions.Assign(AValue);
  134. end;
  135. constructor TEngineOptions.Create;
  136. begin
  137. FBackendOptions:=TStringList.Create;
  138. end;
  139. destructor TEngineOptions.Destroy;
  140. begin
  141. FreeAndNil(FBackendOptions);
  142. inherited Destroy;
  143. end;
  144. procedure TEngineOptions.Assign(Source: TPersistent);
  145. var
  146. O : TEngineOptions;
  147. begin
  148. if (Source is TEngineOptions) then
  149. begin
  150. O:=Source as TEngineOptions;
  151. FBackEndoptions.Assign(O.BackendOptions);
  152. FCPUTarget:=O.CPUTarget;
  153. FFormat:=O.Backend;
  154. FLanguage:=O.Language;
  155. FOSTarget:=O.OSTarget;
  156. FSOPE:=O.StopOnParseError;
  157. HideProtected:=O.HideProtected;
  158. WarnNoNode:=O.WarnNoNode;
  159. ShowPrivate:=O.ShowPrivate;
  160. InterfaceOnly:=O.InterfaceOnly;
  161. MoDir:=O.MoDir;
  162. end
  163. else
  164. inherited Assign(Source);
  165. end;
  166. { TFPDocProject }
  167. procedure TFPDocProject.setOptions(const AValue: TEngineOptions);
  168. begin
  169. if FOptions=AValue then exit;
  170. FOptions.Assign(AValue);
  171. end;
  172. constructor TFPDocProject.Create(AOwner: TComponent);
  173. begin
  174. inherited Create(AOwner);
  175. FPackages:=TFPDocPackages.Create(TFPDocPackage);
  176. FOptions:=TEngineOptions.Create;
  177. end;
  178. destructor TFPDocProject.Destroy;
  179. begin
  180. FreeAndNil(Foptions);
  181. FreeAndNil(FPackages);
  182. inherited Destroy;
  183. end;
  184. { TFPDocPackages }
  185. function TFPDocPackages.GetP(AIndex : Integer): TFPDocPackage;
  186. begin
  187. Result:=TFPDocPackage(Items[AIndex]);
  188. end;
  189. procedure TFPDocPackages.SetP(AIndex : Integer; const AValue: TFPDocPackage);
  190. begin
  191. Items[AIndex]:=AValue;
  192. end;
  193. function TFPDocPackages.IndexOfPackage(const AName: String): Integer;
  194. begin
  195. Result:=Count-1;
  196. While (Result>=0) and (CompareText(GetP(Result).Name,AName)<>0) do
  197. Dec(Result)
  198. end;
  199. function TFPDocPackages.FindPackage(const AName: String): TFPDOcPackage;
  200. Var
  201. I : Integer;
  202. begin
  203. I:=IndexOfPackage(AName);
  204. If (I=-1) then
  205. Result:=Nil
  206. else
  207. Result:=GetP(I);
  208. end;
  209. { TFPDocPackage }
  210. constructor TFPDocPackage.Create(ACollection: TCollection);
  211. begin
  212. inherited Create(ACollection);
  213. FImports:=TStringList.Create;
  214. FDescriptions:=TStringList.Create;
  215. FInputs:=TStringList.Create;
  216. end;
  217. destructor TFPDocPackage.destroy;
  218. begin
  219. FreeAndNil(FDescriptions);
  220. FreeAndNil(FIMports);
  221. FreeAndNil(FinPuts);
  222. inherited destroy;
  223. end;
  224. procedure TFPDocPackage.Assign(Source: TPersistent);
  225. Var
  226. P : TFPDocPackage;
  227. begin
  228. If Source is TFPDocPackage then
  229. begin
  230. P:=Source as TFPDocPackage;
  231. Fname:=P.Name;
  232. FContent:=P.ContentFile;
  233. FImports.Assign(P.Imports);
  234. FInputs.Assign(P.Inputs);
  235. FDescriptions.Assign(P.Descriptions);
  236. end
  237. else
  238. inherited Assign(Source);
  239. end;
  240. end.