2
0

fpdocproj.pas 7.3 KB

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