2
0

fpdoc.pp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. {
  2. $Id$
  3. FPDoc - Free Pascal Documentation Tool
  4. Copyright (C) 2000 - 2003 by
  5. Areca Systems GmbH / Sebastian Guenther, [email protected]
  6. See the file COPYING, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. }
  12. program FPDoc;
  13. uses
  14. SysUtils, Classes, Gettext, DOM, XMLWrite, PasTree, PParser,
  15. dGlobals, // GLobal definitions, constants.
  16. dwriter, // TFPDocWriter definition.
  17. dwlinear, // Linear (abstract) writer
  18. dw_LaTeX, // TLaTex writer
  19. dw_XML, // XML writer
  20. dw_HTML, // HTML writer
  21. dw_ipf, // IPF writer
  22. dw_txt; // TXT writer
  23. const
  24. OSTarget: String = {$I %FPCTARGETOS%};
  25. CPUTarget: String = {$I %FPCTARGETCPU%};
  26. var
  27. Backend : String;
  28. BackendOptions : TStrings;
  29. InputFiles, DescrFiles: TStringList;
  30. PackageName, DocLang, ContentFile : String;
  31. Engine: TFPDocEngine;
  32. Procedure Usage(AnExitCode : Byte);
  33. begin
  34. Writeln(SCmdLineHelp);
  35. Halt(AnExitCode);
  36. end;
  37. procedure InitOptions;
  38. begin
  39. InputFiles := TStringList.Create;
  40. DescrFiles := TStringList.Create;
  41. BackendOptions := TStringList.Create;
  42. Engine := TFPDocEngine.Create;
  43. end;
  44. procedure FreeOptions;
  45. begin
  46. Engine.Free;
  47. BackendOptions.Free;
  48. DescrFiles.Free;
  49. InputFiles.Free;
  50. end;
  51. procedure ReadContentFile(const AParams: String);
  52. var
  53. i: Integer;
  54. begin
  55. i := Pos(',', AParams);
  56. Engine.ReadContentFile(Copy(AParams, 1, i - 1),
  57. Copy(AParams, i + 1, Length(AParams)));
  58. end;
  59. procedure ParseOption(const s: String);
  60. procedure AddToFileList(List: TStringList; const FileName: String);
  61. var
  62. f: Text;
  63. s: String;
  64. begin
  65. if Copy(FileName, 1, 1) = '@' then
  66. begin
  67. Assign(f, Copy(FileName, 2, Length(FileName)));
  68. Reset(f);
  69. while not EOF(f) do
  70. begin
  71. ReadLn(f, s);
  72. List.Add(s);
  73. end;
  74. Close(f);
  75. end else
  76. List.Add(FileName);
  77. end;
  78. var
  79. i: Integer;
  80. Cmd, Arg: String;
  81. begin
  82. if (s = '-h') or (s = '--help') then
  83. Usage(0)
  84. else if s = '--hide-protected' then
  85. Engine.HideProtected := True
  86. else if s = '--warn-no-node' then
  87. Engine.WarnNoNode := True
  88. else if s = '--show-private' then
  89. Engine.HidePrivate := False
  90. else
  91. begin
  92. i := Pos('=', s);
  93. if i > 0 then
  94. begin
  95. Cmd := Copy(s, 1, i - 1);
  96. Arg := Copy(s, i + 1, Length(s));
  97. end
  98. else
  99. begin
  100. Cmd := s;
  101. SetLength(Arg, 0);
  102. end;
  103. if Cmd = '--descr' then
  104. AddToFileList(DescrFiles, Arg)
  105. else if (Cmd = '-f') or (Cmd = '--format') then
  106. begin
  107. Arg:=UpperCase(Arg);
  108. If FindWriterClass(Arg)=-1 then
  109. WriteLn(StdErr, Format(SCmdLineInvalidFormat, [Arg]))
  110. else
  111. BackEnd:=Arg;
  112. end
  113. else if (Cmd = '-l') or (Cmd = '--lang') then
  114. DocLang := Arg
  115. else if (Cmd = '-i') or (Cmd = '--input') then
  116. AddToFileList(InputFiles, Arg)
  117. else if (Cmd = '-o') or (Cmd = '--output') then
  118. Engine.Output := Arg
  119. else if Cmd = '--content' then
  120. ContentFile := Arg
  121. else if Cmd = '--import' then
  122. ReadContentFile(Arg)
  123. else if Cmd = '--package' then
  124. PackageName := Arg
  125. else if Cmd = '--ostarget' then
  126. OSTarget := Arg
  127. else if Cmd = '--cputarget' then
  128. CPUTarget := Arg
  129. else
  130. begin
  131. BackendOptions.Add(Cmd);
  132. BackendOptions.Add(Arg);
  133. end;
  134. end;
  135. end;
  136. procedure ParseCommandLine;
  137. var
  138. i: Integer;
  139. begin
  140. for i := 1 to ParamCount do
  141. ParseOption(ParamStr(i));
  142. If (BackEnd='') then
  143. BackEnd:='html';
  144. if (PackageName='') then
  145. begin
  146. Writeln(SNeedPackageName);
  147. Usage(1);
  148. end;
  149. end;
  150. procedure CreateDocumentation;
  151. var
  152. i: Integer;
  153. WriterClass : TFPDocWriterClass;
  154. Writer : TFPDocWriter;
  155. begin
  156. for i := 0 to DescrFiles.Count - 1 do
  157. Engine.AddDocFile(DescrFiles[i]);
  158. Engine.SetPackageName(PackageName);
  159. if Length(DocLang) > 0 then
  160. TranslateDocStrings(DocLang);
  161. for i := 0 to InputFiles.Count - 1 do
  162. try
  163. ParseSource(Engine, InputFiles[i], OSTarget, CPUTarget);
  164. except
  165. on e: EParserError do
  166. WriteLn(StdErr, Format('%s(%d,%d): %s',
  167. [e.Filename, e.Row, e.Column, e.Message]));
  168. end;
  169. WriterClass:=GetWriterClass(Backend);
  170. Writer:=WriterClass.Create(Engine.Package,Engine);
  171. With Writer do
  172. Try
  173. If BackendOptions.Count>0 then
  174. for I:=0 to ((BackendOptions.Count-1) div 2) do
  175. If not InterPretOption(BackendOptions[I*2],BackendOptions[I*2+1]) then
  176. WriteLn(StdErr, Format(SCmdLineInvalidOption,[BackendOptions[I*2]+' '+BackendOptions[I*2+1]]));
  177. WriteDoc;
  178. Finally
  179. Free;
  180. end;
  181. if Length(ContentFile) > 0 then
  182. Engine.WriteContentFile(ContentFile);
  183. end;
  184. begin
  185. {$IFDEF Unix}
  186. gettext.TranslateResourceStrings('/usr/local/share/locale/%s/LC_MESSAGES/fpdoc.mo');
  187. {$ELSE}
  188. gettext.TranslateResourceStrings('intl/fpdoc.%s.mo');
  189. {$ENDIF}
  190. WriteLn(STitle);
  191. WriteLn(SCopyright);
  192. WriteLn;
  193. InitOptions;
  194. Try
  195. ParseCommandLine;
  196. CreateDocumentation;
  197. WriteLn(SDone);
  198. Finally
  199. FreeOptions;
  200. end;
  201. end.
  202. {
  203. $Log$
  204. Revision 1.7 2005-01-12 21:11:41 michael
  205. + New structure for writers. Implemented TXT writer
  206. Revision 1.6 2005/01/09 15:59:50 michael
  207. + Split out latex writer to linear and latex writer
  208. Revision 1.5 2004/08/28 18:03:23 michael
  209. + Added warning if docnode not found (option --warn-no-node
  210. Revision 1.4 2003/10/08 11:41:54 yuri
  211. + Initial OS/2 IPF support added
  212. Revision 1.3 2003/03/27 17:14:13 sg
  213. * Added --ostarget and --cputarget
  214. Revision 1.2 2003/03/18 19:28:44 michael
  215. + Some changes to output handling, more suitable for tex output
  216. Revision 1.1 2003/03/17 23:03:20 michael
  217. + Initial import in CVS
  218. Revision 1.13 2003/03/13 22:02:13 sg
  219. * New version with many bugfixes and our own parser (now independent of the
  220. compiler source)
  221. Revision 1.12 2002/10/12 17:09:45 michael
  222. + Added check for package name
  223. Revision 1.11 2002/05/24 00:13:22 sg
  224. * much improved new version, including many linking and output fixes
  225. Revision 1.10 2002/03/12 10:58:36 sg
  226. * reworked linking engine and internal structure
  227. Revision 1.9 2002/01/08 13:00:06 michael
  228. + Added correct array handling and syntax highlighting is now optional
  229. Revision 1.8 2001/12/17 23:24:11 sg
  230. * Added "--package" switch
  231. * Now uses translation files written in lower-case
  232. Revision 1.7 2001/07/27 12:17:20 sg
  233. * Added "--html-search" command line argument
  234. Revision 1.6 2001/07/27 10:21:42 sg
  235. * Just a new, improved version ;)
  236. (detailed changelogs will be provided again with the next commits)
  237. }