makeskel.pp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. OSTarget: String = {$I %FPCTARGETOS%};
  34. CPUTarget: String = {$I %FPCTARGETCPU%};
  35. var
  36. InputFiles, DescrFiles: TStringList;
  37. DocLang: String;
  38. Engine: TSkelEngine;
  39. DisableErrors,
  40. DisableSeealso,
  41. DisableArguments,
  42. DisableProtected,
  43. DisablePrivate,
  44. DisableFunctionResults: Boolean;
  45. EmitClassSeparator: Boolean;
  46. PackageName, OutputName: String;
  47. f: Text;
  48. function TSkelEngine.CreateElement(AClass: TPTreeElement; const AName: String;
  49. AParent: TPasElement; AVisibility : TPasMemberVisibility): TPasElement;
  50. begin
  51. Result := AClass.Create(AName, AParent);
  52. if AClass.InheritsFrom(TPasModule) then
  53. CurModule := TPasModule(Result);
  54. if Result.ClassType = TPasModule then
  55. begin
  56. WriteLn(f);
  57. WriteLn(f, '<!--');
  58. WriteLn(f, ' ====================================================================');
  59. WriteLn(f, ' ', Result.Name);
  60. WriteLn(f, ' ====================================================================');
  61. WriteLn(f, '-->');
  62. WriteLn(f);
  63. WriteLn(f, '<module name="', Result.Name, '">');
  64. WriteLn(f, '<short></short>');
  65. WriteLn(f, '<descr>');
  66. WriteLn(f, '</descr>');
  67. end else if Assigned(AParent) and (Length(AName) > 0) and
  68. (not DisableArguments or (Result.ClassType <> TPasArgument)) and
  69. (not DisableFunctionResults or (Result.ClassType <> TPasResultElement)) and
  70. (not DisablePrivate or (AVisibility<>visPrivate)) and
  71. (not DisableProtected or (AVisibility<>visProtected)) then
  72. begin
  73. WriteLn(f);
  74. if EmitClassSeparator and (Result.ClassType = TPasClassType) then
  75. begin
  76. WriteLn(f, '<!--');
  77. WriteLn(f, ' ********************************************************************');
  78. WriteLn(f, ' ', Result.PathName);
  79. WriteLn(f, ' ********************************************************************');
  80. WriteLn(f, '-->');
  81. WriteLn(f);
  82. end;
  83. Writeln(F,'<!-- ', Result.ElementTypeName,' Visibility: ',VisibilityNames[AVisibility], ' -->');
  84. WriteLn(f,'<element name="', Result.FullName, '">');
  85. WriteLn(f, '<short></short>');
  86. WriteLn(f, '<descr>');
  87. WriteLn(f, '</descr>');
  88. if not DisableErrors then
  89. begin
  90. WriteLn(f, '<errors>');
  91. WriteLn(f, '</errors>');
  92. end;
  93. if not DisableSeealso then
  94. begin
  95. WriteLn(f, '<seealso>');
  96. WriteLn(f, '</seealso>');
  97. end;
  98. WriteLn(f, '</element>');
  99. end;
  100. end;
  101. procedure InitOptions;
  102. begin
  103. InputFiles := TStringList.Create;
  104. DescrFiles := TStringList.Create;
  105. end;
  106. procedure FreeOptions;
  107. begin
  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. MOFilename: string;
  188. begin
  189. {$IFDEF Unix}
  190. MOFilename:='/usr/local/share/locale/%s/LC_MESSAGES/makeskel.mo';
  191. {$ELSE}
  192. MOFilename:='intl/makeskel.%s.mo';
  193. {$ENDIF}
  194. if FileExists(MOFilename) then
  195. gettext.TranslateResourceStrings(MOFilename)
  196. else
  197. writeln('NOTE: unable to find tranlation file ',MOFilename);
  198. WriteLn(STitle);
  199. WriteLn(SCopyright);
  200. WriteLn;
  201. InitOptions;
  202. ParseCommandLine;
  203. if CmdLineAction = actionHelp then
  204. WriteLn(SCmdLineHelp)
  205. else
  206. begin
  207. // Action is to create the XML skeleton
  208. if Length(PackageName) = 0 then
  209. begin
  210. WriteLn(SNoPackageNameProvided);
  211. Halt(2);
  212. end;
  213. // Translate internal documentation strings
  214. if Length(DocLang) > 0 then
  215. TranslateDocStrings(DocLang);
  216. Assign(f, OutputName);
  217. Rewrite(f);
  218. WriteLn(f, '<?xml version="1.0" encoding="ISO8859-1"?>');
  219. WriteLn(f, '<fpdoc-descriptions>');
  220. WriteLn(f, '<package name="', PackageName, '">');
  221. // Process all source files
  222. for i := 0 to InputFiles.Count - 1 do
  223. begin
  224. Engine := TSkelEngine.Create;
  225. try
  226. Engine.SetPackageName(PackageName);
  227. Module := ParseSource(Engine, InputFiles[i], OSTarget, CPUTarget);
  228. WriteLn(f, '</module> <!-- ', Module.Name, ' -->');
  229. finally
  230. Engine.Free;
  231. end;
  232. end;
  233. WriteLn(f, '</package>');
  234. WriteLn(f, '</fpdoc-descriptions>');
  235. Close(f);
  236. end;
  237. FreeOptions;
  238. WriteLn(SDone);
  239. end.
  240. {
  241. $Log$
  242. Revision 1.4 2003-09-02 13:26:47 mattias
  243. MG: makeskel now ignores missing translation file
  244. Revision 1.3 2003/05/07 16:31:32 sg
  245. * Fixed a severe memory corruption problem on termination
  246. Revision 1.2 2003/03/28 13:01:36 michael
  247. + Patch from Charlie/iNQ to work with new scanner/parser
  248. Revision 1.1 2003/03/17 23:03:20 michael
  249. + Initial import in CVS
  250. }