fpdocproj.pas 6.8 KB

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