fpdocproj.pas 6.7 KB

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