fpdocproj.pas 7.2 KB

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