VampDoc.dpr 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. {
  2. VampyreDoc Tool
  3. by Marek Mauder
  4. http://imaginglib.sourceforge.net
  5. The contents of this file are used with permission, subject to the Mozilla
  6. Public License Version 1.1 (the "License"); you may not use this file except
  7. in compliance with the License. You may obtain a copy of the License at
  8. http://www.mozilla.org/MPL/MPL-1.1.html
  9. Software distributed under the License is distributed on an "AS IS" basis,
  10. WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
  11. the specific language governing rights and limitations under the License.
  12. Info:
  13. - currently only for Delphi
  14. }
  15. {
  16. TODOS:
  17. - handle doc files with the same names but in different directories
  18. (they are overwritten now in producers with the next file)
  19. * solve url link targets - copy existing local refered files to output?
  20. - crosslink output with generated reference
  21. - add new mode: create toc XML file from hierarchy of crosslinked documents
  22. XHTML Producer:
  23. - remove frames from XHTML documentation and make output like texi2html
  24. CHM Producer:
  25. * relative links does not work in compiled files (see Root.xml's logo and
  26. stylesheets). Solve: put all existing referenced files to one dir,
  27. handle naming conflicts (i.e. path delims to dots) and set hhp option
  28. Flat=True
  29. - add table of contents page and set root as separate page
  30. outside toc tree
  31. }
  32. program VampDoc;
  33. {$APPTYPE CONSOLE}
  34. {$I ImagingOptions.inc}
  35. uses
  36. SysUtils,
  37. Classes,
  38. Helpers,
  39. ImagingUtility,
  40. DemoUtils,
  41. DOM,
  42. XMLRead,
  43. XHTMLProducer,
  44. CHMProducer;
  45. const
  46. sTitle = 'VampyreDoc';
  47. sVersion = '0.12';
  48. sAppTitle = sTitle + ' version ' + sVersion + sLineBreak +
  49. 'Copyright (c) 2004-2005 Marek Mauder' + sLineBreak;
  50. type
  51. TDocAction = (daGenDoc, daGenTOC, daGenTemplates, daHelp);
  52. var
  53. Action: TDocAction = daGenDoc;
  54. Project: TDocProject = nil;
  55. Producer: TDocProducer = nil;
  56. ProducerFormat: string = 'xhtml';//}'htmlhelp';
  57. OutputDir: string = {'doc';//}'..\Doc\_Final';
  58. InputFile: string = '..\Doc\VampyreDoc\Imaging.vdocproj';
  59. procedure ErrorProject(Exc: Exception);
  60. begin
  61. WriteLn('Error - when loading VampyreDoc project "' + InputFile +
  62. '". ' + sLineBreak + 'Exception Message: ' + Exc.Message + sLineBreak);
  63. Halt(1);
  64. end;
  65. procedure ErrorProducer;
  66. begin
  67. WriteLn('Error - unknown documentation producer selected "' + ProducerFormat +
  68. '".' + sLineBreak);
  69. Halt(1);
  70. end;
  71. procedure ErrorProcessing(Exc: Exception);
  72. begin
  73. WriteLn('Error - when processing documentation project "' + InputFile +
  74. '" with producer: ' + Producer.Name + '.' + sLineBreak +
  75. 'Exception Message: ' + Exc.Message + sLineBreak);
  76. Halt(1);
  77. end;
  78. procedure ErrorTemplates(Exc: Exception);
  79. begin
  80. WriteLn('Error - when generating TOC item templates for project "'
  81. + InputFile + '".' + sLineBreak +
  82. 'Exception Message: ' + Exc.Message + sLineBreak);
  83. Halt(1);
  84. end;
  85. function LoadProject(const FileName: string): TDocProject;
  86. var
  87. Doc: TXMLDocument;
  88. begin
  89. Result := nil;
  90. WriteLn('Loading project: ' + FileName);
  91. try
  92. XMLRead.ReadXMLFile(Doc, InputFile);
  93. Result := TDocProject.Create(Doc.DocumentElement, FileName);
  94. Doc.Free;
  95. except
  96. ErrorProject(GetExceptObject);
  97. end;
  98. WriteLn('Project successfuly loaded.');
  99. end;
  100. procedure PrintHelp;
  101. begin
  102. WriteLn('Help:');
  103. WriteLn;
  104. WriteLn('VampDoc [action] [format] [input] [output]');
  105. WriteLn;
  106. WriteLn('action:');
  107. WriteLn(' -doc generate documentation from .vdocproj file on input');
  108. WriteLn(' -toc generate TOC file from crosslinked documents (not functional now)');
  109. WriteLn(' -templates generate template documents based on TOC file');
  110. WriteLn(' -help|-h show this scren');
  111. WriteLn('format (only for -doc action):');
  112. WriteLn(' -f=xhtml set output format to XHTML');
  113. WriteLn(' -f=htmlhelp set output format to HTMLHelp (requires HTMLHelp compiler)');
  114. WriteLn('input:');
  115. WriteLn(' -i=filename input file must be valid .vdocproj file (for -doc and -templates)');
  116. WriteLn(' or VampyreDoc XML file (for -toc)');
  117. WriteLn('output:');
  118. WriteLn(' -o=dir root output directory for all generated files');
  119. WriteLn;
  120. WriteLn('Order of parameters is actually not important.');
  121. WriteLn('If any of the parameters is missing default ugly value is used.');
  122. WriteLn('See Vampyre Imaging Library documentation for more details about VampyreDoc.');
  123. WriteLn;
  124. end;
  125. procedure ParseOption(const Option: string);
  126. var
  127. S, Arg: string;
  128. I: LongInt;
  129. begin
  130. S := Option;
  131. if S = '-toc' then
  132. Action := daGenTOC
  133. else
  134. if S = '-doc' then
  135. Action := daGenDOC
  136. else
  137. if S = '-templates' then
  138. Action := daGenTemplates
  139. else
  140. if (S = '-h') or (S = '-help') then
  141. Action := daHelp
  142. else
  143. begin
  144. I := Pos('=', S);
  145. Arg := Copy(S, I + 1, MaxInt);
  146. Delete(S, I, MaxInt);
  147. if S = '-i' then
  148. InputFile := Arg
  149. else
  150. if S = '-o' then
  151. OutputDir := Arg
  152. else
  153. if S = '-f' then
  154. ProducerFormat := Arg;
  155. end;
  156. end;
  157. procedure ParseCmdLine;
  158. var
  159. I: LongInt;
  160. begin
  161. for I := 1 to ParamCount do
  162. ParseOption(ParamStr(I));
  163. end;
  164. begin
  165. ParseCmdLine;
  166. WriteLn(sAppTitle);
  167. case Action of
  168. daGenDoc:
  169. begin
  170. WriteLn('Action: Generate Documentation');
  171. Project := LoadProject(InputFile);
  172. if ProducerFormat = 'xhtml' then
  173. Producer := TXHTMLProducer.Create
  174. else
  175. if ProducerFormat = 'htmlhelp' then
  176. Producer := TCHMProducer.Create
  177. else
  178. ErrorProducer;
  179. WriteLn('Project processing started with producer: ' + Producer.Name);
  180. try
  181. OutputDir := ExpandFileTo(OutputDir, GetCurrentDir);
  182. Producer.Process(Project, OutputDir);
  183. except
  184. ErrorProcessing(GetExceptObject);
  185. end;
  186. WriteLn('Documentation produced in directory: ' + OutputDir);
  187. Project.Free;
  188. end;
  189. daGenTemplates:
  190. begin
  191. WriteLn('Action: Generate Templates');
  192. Project := LoadProject(InputFile);
  193. try
  194. GenerateTOCTemplates(Project);
  195. except
  196. ErrorTemplates(GetExceptObject);
  197. end;
  198. WriteLn('TOC item templates successfuly generated.');
  199. Project.Free;
  200. end;
  201. daGenTOC: PrintHelp;
  202. daHelp: PrintHelp;
  203. end;
  204. WriteLn;
  205. end.