fpdocproj.pas 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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. Writeln('aFile *',aFile,'* options : *',O,'*');
  130. AOption:=O;
  131. end;
  132. { TEngineOptions }
  133. procedure TEngineOptions.SetBackendOptions(const AValue: TStrings);
  134. begin
  135. if FBackEndoptions=AValue then exit;
  136. FBackEndoptions.Assign(AValue);
  137. end;
  138. constructor TEngineOptions.Create;
  139. begin
  140. FBackendOptions:=TStringList.Create;
  141. end;
  142. destructor TEngineOptions.Destroy;
  143. begin
  144. FreeAndNil(FBackendOptions);
  145. inherited Destroy;
  146. end;
  147. procedure TEngineOptions.Assign(Source: TPersistent);
  148. var
  149. O : TEngineOptions;
  150. begin
  151. if (Source is TEngineOptions) then
  152. begin
  153. O:=Source as TEngineOptions;
  154. FBackEndoptions.Assign(O.BackendOptions);
  155. FCPUTarget:=O.CPUTarget;
  156. FFormat:=O.Backend;
  157. FLanguage:=O.Language;
  158. FOSTarget:=O.OSTarget;
  159. FSOPE:=O.StopOnParseError;
  160. HideProtected:=O.HideProtected;
  161. WarnNoNode:=O.WarnNoNode;
  162. ShowPrivate:=O.ShowPrivate;
  163. InterfaceOnly:=O.InterfaceOnly;
  164. MoDir:=O.MoDir;
  165. end
  166. else
  167. inherited Assign(Source);
  168. end;
  169. { TFPDocProject }
  170. procedure TFPDocProject.setOptions(const AValue: TEngineOptions);
  171. begin
  172. if FOptions=AValue then exit;
  173. FOptions.Assign(AValue);
  174. end;
  175. constructor TFPDocProject.Create(AOwner: TComponent);
  176. begin
  177. inherited Create(AOwner);
  178. FPackages:=TFPDocPackages.Create(TFPDocPackage);
  179. FOptions:=TEngineOptions.Create;
  180. end;
  181. destructor TFPDocProject.Destroy;
  182. begin
  183. FreeAndNil(Foptions);
  184. FreeAndNil(FPackages);
  185. inherited Destroy;
  186. end;
  187. { TFPDocPackages }
  188. function TFPDocPackages.GetP(AIndex : Integer): TFPDocPackage;
  189. begin
  190. Result:=TFPDocPackage(Items[AIndex]);
  191. end;
  192. procedure TFPDocPackages.SetP(AIndex : Integer; const AValue: TFPDocPackage);
  193. begin
  194. Items[AIndex]:=AValue;
  195. end;
  196. function TFPDocPackages.IndexOfPackage(const AName: String): Integer;
  197. begin
  198. Result:=Count-1;
  199. While (Result>=0) and (CompareText(GetP(Result).Name,AName)<>0) do
  200. Dec(Result)
  201. end;
  202. function TFPDocPackages.FindPackage(const AName: String): TFPDOcPackage;
  203. Var
  204. I : Integer;
  205. begin
  206. I:=IndexOfPackage(AName);
  207. If (I=-1) then
  208. Result:=Nil
  209. else
  210. Result:=GetP(I);
  211. end;
  212. { TFPDocPackage }
  213. constructor TFPDocPackage.Create(ACollection: TCollection);
  214. begin
  215. inherited Create(ACollection);
  216. FImports:=TStringList.Create;
  217. FDescriptions:=TStringList.Create;
  218. FInputs:=TStringList.Create;
  219. end;
  220. destructor TFPDocPackage.destroy;
  221. begin
  222. FreeAndNil(FDescriptions);
  223. FreeAndNil(FIMports);
  224. FreeAndNil(FinPuts);
  225. inherited destroy;
  226. end;
  227. procedure TFPDocPackage.Assign(Source: TPersistent);
  228. Var
  229. P : TFPDocPackage;
  230. begin
  231. If Source is TFPDocPackage then
  232. begin
  233. P:=Source as TFPDocPackage;
  234. Fname:=P.Name;
  235. FContent:=P.ContentFile;
  236. FImports.Assign(P.Imports);
  237. FInputs.Assign(P.Inputs);
  238. FDescriptions.Assign(P.Descriptions);
  239. end
  240. else
  241. inherited Assign(Source);
  242. end;
  243. end.