makeskel.pp 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. {
  2. $Id$
  3. FPDoc - Free Pascal Documentation Tool
  4. Copyright (C) 2000 - 2003 by
  5. Areca Systems GmbH / Sebastian Guenther, [email protected]
  6. * Skeleton XML description file generator
  7. See the file COPYING, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. }
  13. program MakeSkel;
  14. uses
  15. SysUtils, Classes, Gettext,
  16. dGlobals, PasTree, PParser;
  17. resourcestring
  18. STitle = 'MakeSkel - FPDoc skeleton XML description file generator';
  19. SCopyright = '(c) 2000 - 2003 Areca Systems GmbH / Sebastian Guenther, [email protected]';
  20. SCmdLineHelp = 'See documentation for usage.';
  21. SCmdLineInvalidOption = 'Ignoring unknown option "%s"';
  22. SNoPackageNameProvided = 'Please specify a package name with --package=<name>';
  23. SDone = 'Done.';
  24. type
  25. TCmdLineAction = (actionHelp, actionConvert);
  26. TSkelEngine = class(TFPDocEngine)
  27. public
  28. function CreateElement(AClass: TPTreeElement; const AName: String;
  29. AParent: TPasElement; AVisibility :TPasMemberVisibility): TPasElement; override;
  30. end;
  31. const
  32. CmdLineAction: TCmdLineAction = actionConvert;
  33. var
  34. InputFiles, DescrFiles: TStringList;
  35. DocLang: String;
  36. Engine: TSkelEngine;
  37. DisableErrors,
  38. DisableSeealso,
  39. DisableArguments,
  40. DisableProtected,
  41. DisablePrivate,
  42. DisableFunctionResults: Boolean;
  43. EmitClassSeparator: Boolean;
  44. PackageName, OutputName: String;
  45. f: Text;
  46. function TSkelEngine.CreateElement(AClass: TPTreeElement; const AName: String;
  47. AParent: TPasElement; AVisibility : TPasMemberVisibility): TPasElement;
  48. begin
  49. Result := AClass.Create(AName, AParent);
  50. if AClass.InheritsFrom(TPasModule) then
  51. CurModule := TPasModule(Result);
  52. if Result.ClassType = TPasModule then
  53. begin
  54. WriteLn(f);
  55. WriteLn(f, '<!--');
  56. WriteLn(f, ' ====================================================================');
  57. WriteLn(f, ' ', Result.Name);
  58. WriteLn(f, ' ====================================================================');
  59. WriteLn(f, '-->');
  60. WriteLn(f);
  61. WriteLn(f, '<module name="', Result.Name, '">');
  62. WriteLn(f, '<short></short>');
  63. WriteLn(f, '<descr>');
  64. WriteLn(f, '</descr>');
  65. end else if Assigned(AParent) and (Length(AName) > 0) and
  66. (not DisableArguments or (Result.ClassType <> TPasArgument)) and
  67. (not DisableFunctionResults or (Result.ClassType <> TPasResultElement)) and
  68. (not DisablePrivate or (AVisibility<>visPrivate)) and
  69. (not DisableProtected or (AVisibility<>visProtected)) then
  70. begin
  71. WriteLn(f);
  72. if EmitClassSeparator and (Result.ClassType = TPasClassType) then
  73. begin
  74. WriteLn(f, '<!--');
  75. WriteLn(f, ' ********************************************************************');
  76. WriteLn(f, ' ', Result.PathName);
  77. WriteLn(f, ' ********************************************************************');
  78. WriteLn(f, '-->');
  79. WriteLn(f);
  80. end;
  81. Writeln(F,'<!-- ', Result.ElementTypeName,' Visibility: ',VisibilityNames[AVisibility], ' -->');
  82. WriteLn(f,'<element name="', Result.FullName, '">');
  83. WriteLn(f, '<short></short>');
  84. WriteLn(f, '<descr>');
  85. WriteLn(f, '</descr>');
  86. if not DisableErrors then
  87. begin
  88. WriteLn(f, '<errors>');
  89. WriteLn(f, '</errors>');
  90. end;
  91. if not DisableSeealso then
  92. begin
  93. WriteLn(f, '<seealso>');
  94. WriteLn(f, '</seealso>');
  95. end;
  96. WriteLn(f, '</element>');
  97. end;
  98. end;
  99. procedure InitOptions;
  100. begin
  101. InputFiles := TStringList.Create;
  102. DescrFiles := TStringList.Create;
  103. Engine := TSkelEngine.Create;
  104. end;
  105. procedure FreeOptions;
  106. begin
  107. Engine.Free;
  108. DescrFiles.Free;
  109. InputFiles.Free;
  110. end;
  111. procedure ParseOption(const s: String);
  112. procedure AddToFileList(List: TStringList; const FileName: String);
  113. var
  114. f: Text;
  115. s: String;
  116. begin
  117. if Copy(FileName, 1, 1) = '@' then
  118. begin
  119. Assign(f, Copy(FileName, 2, Length(FileName)));
  120. Reset(f);
  121. while not EOF(f) do
  122. begin
  123. ReadLn(f, s);
  124. List.Add(s);
  125. end;
  126. Close(f);
  127. end else
  128. List.Add(FileName);
  129. end;
  130. var
  131. i: Integer;
  132. Cmd, Arg: String;
  133. begin
  134. if (s = '-h') or (s = '--help') then
  135. CmdLineAction := actionHelp
  136. else if s = '--disable-arguments' then
  137. DisableArguments := True
  138. else if s = '--disable-errors' then
  139. DisableErrors := True
  140. else if s = '--disable-function-results' then
  141. DisableFunctionResults := True
  142. else if s = '--disable-seealso' then
  143. DisableSeealso := True
  144. else if s = '--disable-private' then
  145. DisablePrivate := True
  146. else if s = '--disable-protected' then
  147. begin
  148. DisableProtected := True;
  149. DisablePrivate :=True;
  150. end
  151. else if s = '--emitclassseparator' then
  152. EmitClassSeparator := True
  153. else
  154. begin
  155. i := Pos('=', s);
  156. if i > 0 then
  157. begin
  158. Cmd := Copy(s, 1, i - 1);
  159. Arg := Copy(s, i + 1, Length(s));
  160. end else
  161. begin
  162. Cmd := s;
  163. SetLength(Arg, 0);
  164. end;
  165. if (Cmd = '-i') or (Cmd = '--input') then
  166. AddToFileList(InputFiles, Arg)
  167. else if (Cmd = '-l') or (Cmd = '--lang') then
  168. DocLang := Arg
  169. else if (Cmd = '-o') or (Cmd = '--output') then
  170. OutputName := Arg
  171. else if Cmd = '--package' then
  172. PackageName := Arg
  173. else
  174. WriteLn(StdErr, Format(SCmdLineInvalidOption, [s]));
  175. end;
  176. end;
  177. procedure ParseCommandLine;
  178. var
  179. i: Integer;
  180. begin
  181. for i := 1 to ParamCount do
  182. ParseOption(ParamStr(i));
  183. end;
  184. var
  185. i: Integer;
  186. Module: TPasModule;
  187. begin
  188. {$IFDEF Unix}
  189. gettext.TranslateResourceStrings('/usr/local/share/locale/%s/LC_MESSAGES/makeskel.mo');
  190. {$ELSE}
  191. gettext.TranslateResourceStrings('intl/makeskel.%s.mo');
  192. {$ENDIF}
  193. WriteLn(STitle);
  194. WriteLn(SCopyright);
  195. WriteLn;
  196. InitOptions;
  197. ParseCommandLine;
  198. if CmdLineAction = actionHelp then
  199. WriteLn(SCmdLineHelp)
  200. else
  201. begin
  202. // Action is to create the XML skeleton
  203. if Length(PackageName) = 0 then
  204. begin
  205. WriteLn(SNoPackageNameProvided);
  206. Halt(2);
  207. end;
  208. Engine.SetPackageName(PackageName);
  209. // Translate internal documentation strings
  210. if Length(DocLang) > 0 then
  211. TranslateDocStrings(DocLang);
  212. Assign(f, OutputName);
  213. Rewrite(f);
  214. WriteLn(f, '<?xml version="1.0" encoding="ISO8859-1"?>');
  215. WriteLn(f, '<fpdoc-descriptions>');
  216. WriteLn(f, '<package name="', PackageName, '">');
  217. // Process all source files
  218. for i := 0 to InputFiles.Count - 1 do
  219. begin
  220. Module := ParseSource(Engine, InputFiles[i]);
  221. try
  222. WriteLn(f, '</module> <!-- ', Module.Name, ' -->');
  223. finally
  224. Module.Free;
  225. end;
  226. end;
  227. WriteLn(f, '</package>');
  228. WriteLn(f, '</fpdoc-descriptions>');
  229. Close(f);
  230. end;
  231. FreeOptions;
  232. WriteLn(SDone);
  233. end.
  234. {
  235. $Log$
  236. Revision 1.1 2003-03-17 23:03:20 michael
  237. + Initial import in CVS
  238. Revision 1.7 2003/03/13 22:02:13 sg
  239. * New version with many bugfixes and our own parser (now independent of the
  240. compiler source)
  241. Revision 1.6 2002/10/12 17:00:46 michael
  242. + Changes to be able to disable private/protected nodes in skeleton
  243. Revision 1.5 2002/10/11 18:41:50 sg
  244. * Now requires a package name on the command line via "--package=<name>",
  245. to match the recent changes in the engine
  246. * translation files are now searched at the usual location on Linux
  247. Revision 1.4 2002/05/24 00:13:22 sg
  248. * much improved new version, including many linking and output fixes
  249. Revision 1.3 2002/03/12 10:58:36 sg
  250. * reworked linking engine and internal structure
  251. Revision 1.2 2001/07/27 10:21:42 sg
  252. * Just a new, improved version ;)
  253. (detailed changelogs will be provided again with the next commits)
  254. Revision 1.1 2000/10/28 20:15:26 sg
  255. * Many internal architectural improvements (especially linking)
  256. * Improved writers
  257. }