fpdoc.pp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. {
  2. FPDoc - Free Pascal Documentation Tool
  3. Copyright (C) 2000 - 2003 by
  4. Areca Systems GmbH / Sebastian Guenther, [email protected]
  5. See the file COPYING, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. }
  11. program FPDoc;
  12. uses
  13. SysUtils, Classes, Gettext, custapp,
  14. dGlobals, // GLobal definitions, constants.
  15. dwriter, // TFPDocWriter definition.
  16. dwlinear, // Linear (abstract) writer
  17. dw_LaTeX, // TLaTex writer
  18. dw_XML, // XML writer
  19. dw_dxml, // Delphi XML doc.
  20. dw_HTML, // HTML writer
  21. dw_ipflin, // IPF writer (new linear output)
  22. dw_man, // Man page writer
  23. dw_linrtf, // linear RTF writer
  24. dw_txt, fpdocproj, mkfpdoc; // TXT writer
  25. Type
  26. { TFPDocAplication }
  27. TFPDocAplication = Class(TCustomApplication)
  28. private
  29. FCreator : TFPDocCreator;
  30. FPackage : TFPDocPackage;
  31. FDryRun,
  32. FProjectFile : Boolean;
  33. FWriteProjectFile : String;
  34. Protected
  35. procedure OutputLog(Sender: TObject; const Msg: String);
  36. procedure ParseCommandLine;
  37. procedure Parseoption(const S: String);
  38. Procedure Usage(AnExitCode : Byte);
  39. Procedure DoRun; override;
  40. Public
  41. Constructor Create(AOwner : TComponent); override;
  42. Destructor Destroy; override;
  43. Function SelectedPackage : TFPDocPackage;
  44. end;
  45. Procedure TFPDocAplication.Usage(AnExitCode : Byte);
  46. Var
  47. I,P : Integer;
  48. S : String;
  49. L : TStringList;
  50. C : TFPDocWriterClass;
  51. Backend : String;
  52. begin
  53. Writeln(Format(SCmdLineHelp,[ExtractFileName(Paramstr(0))]));
  54. Writeln(SUsageOption010);
  55. Writeln(SUsageOption020);
  56. Writeln(SUsageOption030);
  57. Writeln(SUsageOption040);
  58. Writeln(SUsageOption050);
  59. Writeln(SUsageOption060);
  60. Writeln(SUsageOption070);
  61. Writeln(SUsageOption080);
  62. Writeln(SUsageOption090);
  63. Writeln(SUsageOption100);
  64. Writeln(SUsageOption110);
  65. Writeln(SUsageOption120);
  66. Writeln(SUsageOption130);
  67. Writeln(SUsageOption140);
  68. Writeln(SUsageOption150);
  69. Writeln(SUsageOption160);
  70. Writeln(SUsageOption170);
  71. Writeln(SUsageOption180);
  72. Writeln(SUsageOption190);
  73. Writeln(SUsageOption200);
  74. Writeln(SUsageOption210);
  75. Writeln(SUsageOption220);
  76. Writeln(SUsageOption230);
  77. L:=TStringList.Create;
  78. Try
  79. Backend:=FCreator.OPtions.Backend;
  80. If (Backend='') then
  81. begin
  82. Writeln;
  83. Writeln(SUsageFormats);
  84. EnumWriters(L);
  85. For I:=0 to L.Count-1 do
  86. begin
  87. S:=L[i];
  88. P:=Pos('=',S);
  89. Writeln(Format(' %s - %s',[Copy(S,1,P-1)+Space(10-p),Copy(S,P+1,Length(S))]));
  90. end;
  91. Writeln(SUsageBackendHelp);
  92. end
  93. else
  94. begin
  95. Writeln;
  96. Writeln(Format(SUsageFormatSpecific,[Lowercase(backend)]));
  97. C:=GetWriterClass(Backend);
  98. C.Usage(L);
  99. If L.Count>0 then
  100. For I:=0 to (L.Count-1) div 2 do
  101. begin
  102. S:=L[i*2];
  103. Writeln(Format('%s %s',[S+Space(30-Length(S)),L[(i*2)+1]]));
  104. end;
  105. end;
  106. Finally
  107. L.Free;
  108. end;
  109. Halt(AnExitCode);
  110. end;
  111. destructor TFPDocAplication.Destroy;
  112. begin
  113. FreeAndNil(FCreator);
  114. Inherited;
  115. end;
  116. function TFPDocAplication.SelectedPackage: TFPDocPackage;
  117. begin
  118. Result:=FPackage;
  119. if (FPackage=Nil) or (FPackage.Name='') then
  120. begin
  121. Writeln(SNeedPackageName);
  122. Usage(1);
  123. end;
  124. end;
  125. procedure TFPDocAplication.OutputLog(Sender: TObject; const Msg: String);
  126. begin
  127. Writeln(StdErr,Msg);
  128. end;
  129. procedure TFPDocAplication.ParseCommandLine;
  130. Function ProjectOpt(Const s : string) : boolean;
  131. begin
  132. Result:=(Copy(s,1,3)='-p=') or (Copy(s,1,10)='--project=');
  133. end;
  134. Function PackageOpt(Const s : string) : boolean;
  135. begin
  136. Result:=((Copy(s,1,3)='-a=') or (Copy(s,1,10)='--package='));
  137. end;
  138. var
  139. i : Integer;
  140. s : string;
  141. begin
  142. // Check project
  143. for i := 1 to ParamCount do
  144. begin
  145. s:=ParamStr(I);
  146. If ProjectOpt(S) then
  147. ParseOption(s);
  148. If (FCreator.Packages.Count=1) then
  149. FPackage:=FCreator.Packages[0]
  150. else if (FCreator.Options.DefaultPackageName<>'') then
  151. Fpackage:=FCreator.Packages.FindPackage(FCreator.Options.DefaultPackageName);
  152. end;
  153. If FCreator.Project.Packages.Count=0 then
  154. begin
  155. FPackage:=FCreator.Packages.Add as TFPDocPackage;
  156. end;
  157. // Check package
  158. for i := 1 to ParamCount do
  159. begin
  160. s:=ParamStr(I);
  161. If PackageOpt(S) then
  162. ParseOption(s);
  163. end;
  164. for i := 1 to ParamCount do
  165. begin
  166. s:=ParamStr(I);
  167. If Not (ProjectOpt(s) or PackageOpt(S)) then
  168. ParseOption(s);
  169. end;
  170. SelectedPackage; // Will print error if none available.
  171. end;
  172. procedure TFPDocAplication.Parseoption(Const S : String);
  173. procedure AddToFileList(List: TStrings; const FileName: String);
  174. var
  175. f: Text;
  176. s: String;
  177. begin
  178. if Copy(FileName, 1, 1) = '@' then
  179. begin
  180. AssignFile(f, Copy(FileName, 2, Length(FileName)));
  181. Reset(f);
  182. while not EOF(f) do
  183. begin
  184. ReadLn(f, s);
  185. List.Add(s);
  186. end;
  187. Close(f);
  188. end else
  189. List.Add(FileName);
  190. end;
  191. var
  192. i: Integer;
  193. Cmd, Arg: String;
  194. begin
  195. if (s = '-h') or (s = '--help') then
  196. Usage(0)
  197. else if s = '--hide-protected' then
  198. FCreator.Options.HideProtected := True
  199. else if s = '--warn-no-node' then
  200. FCreator.Options.WarnNoNode := True
  201. else if s = '--show-private' then
  202. FCreator.Options.ShowPrivate := False
  203. else if s = '--stop-on-parser-error' then
  204. FCreator.Options.StopOnParseError := True
  205. else if s = '--dont-trim' then
  206. FCreator.Options.donttrim := True
  207. else
  208. begin
  209. i := Pos('=', s);
  210. if i > 0 then
  211. begin
  212. Cmd := Copy(s, 1, i - 1);
  213. Arg := Copy(s, i + 1, Length(s));
  214. end
  215. else
  216. begin
  217. Cmd := s;
  218. SetLength(Arg, 0);
  219. end;
  220. if (Cmd = '--project') or (Cmd='-p') then
  221. begin
  222. FProjectFile:=True;
  223. FCreator.LoadProjectFile(Arg);
  224. end
  225. else if (Cmd = '--descr') then
  226. AddToFileList(SelectedPackage.Descriptions, Arg)
  227. else if (Cmd = '-f') or (Cmd = '--format') then
  228. begin
  229. Arg:=UpperCase(Arg);
  230. If FindWriterClass(Arg)=-1 then
  231. WriteLn(StdErr, Format(SCmdLineInvalidFormat, [Arg]))
  232. else
  233. FCreator.Options.BackEnd:=Arg;
  234. end
  235. else if (Cmd = '-l') or (Cmd = '--lang') then
  236. FCreator.Options.Language := Arg
  237. else if (Cmd = '-i') or (Cmd = '--input') then
  238. AddToFileList(SelectedPackage.Inputs, Arg)
  239. else if (Cmd = '-o') or (Cmd = '--output') then
  240. SelectedPackage.Output := Arg
  241. else if (Cmd = '-v') or (Cmd = '--verbose') then
  242. FCreator.Verbose:=true
  243. else if (Cmd = '-n') or (Cmd = '--dry-run') then
  244. FDryRun:=True
  245. else if Cmd = '--content' then
  246. SelectedPackage.ContentFile := Arg
  247. else if Cmd = '--import' then
  248. SelectedPackage.Imports.Add(Arg)
  249. else if Cmd = '--package' then
  250. begin
  251. If FProjectFile then
  252. FPackage:=FCreator.Packages.FindPackage(Arg)
  253. else
  254. FPackage.Name:=Arg;
  255. end
  256. else if Cmd = '--ostarget' then
  257. FCreator.Options.OSTarget := Arg
  258. else if Cmd = '--cputarget' then
  259. FCreator.Options.CPUTarget := Arg
  260. else if Cmd = '--mo-dir' then
  261. FCreator.Options.modir := Arg
  262. else if Cmd = '--parse-impl' then
  263. FCreator.Options.InterfaceOnly:=false
  264. else if Cmd = '--write-project' then
  265. FWriteProjectFile:=Arg
  266. else
  267. begin
  268. FCreator.Options.BackendOptions.Add(Cmd);
  269. FCreator.Options.BackendOptions.Add(Arg);
  270. end;
  271. end;
  272. end;
  273. Procedure TFPDocAplication.DoRun;
  274. begin
  275. {$IFDEF Unix}
  276. gettext.TranslateResourceStrings('/usr/local/share/locale/%s/LC_MESSAGES/fpdoc.mo');
  277. {$ELSE}
  278. gettext.TranslateResourceStrings('intl/fpdoc.%s.mo');
  279. {$ENDIF}
  280. WriteLn(STitle);
  281. WriteLn(Format(SVersion, [DefFPCVersion, DefFPCDate]));
  282. WriteLn(SCopyright);
  283. WriteLn;
  284. ParseCommandLine;
  285. if (FWriteProjectFile<>'') then
  286. FCreator.CreateProjectFile(FWriteProjectFile)
  287. else
  288. FCreator.CreateDocumentation(FPackage,FDryRun);
  289. WriteLn(SDone);
  290. Terminate;
  291. end;
  292. constructor TFPDocAplication.Create(AOwner: TComponent);
  293. begin
  294. inherited Create(AOwner);
  295. StopOnException:=true;
  296. FCreator:=TFPDocCreator.Create(Self);
  297. FCreator.OnLog:=@OutputLog;
  298. end;
  299. begin
  300. With TFPDocAplication.Create(Nil) do
  301. try
  302. Run;
  303. finally
  304. Free;
  305. end;
  306. end.