cmDocumentation.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef _cmDocumentation_h
  14. #define _cmDocumentation_h
  15. #include "cmStandardIncludes.h"
  16. /** Class to generate documentation. */
  17. class cmDocumentation
  18. {
  19. public:
  20. cmDocumentation();
  21. ~cmDocumentation();
  22. // High-level interface for standard documents:
  23. /** Types of help provided. */
  24. enum Type { None, Usage, Single, SingleModule, SingleProperty,
  25. List, ModuleList, PropertyList,
  26. Full, HTML, Man, Copyright, Version };
  27. /**
  28. * Check command line arguments for documentation options. Returns
  29. * true if documentation options are found, and false otherwise.
  30. * When true is returned, PrintRequestedDocumentation should be
  31. * called.
  32. */
  33. bool CheckOptions(int argc, const char* const* argv);
  34. /**
  35. * Print help requested on the command line. Call after
  36. * CheckOptions returns true. Returns true on success, and false
  37. * otherwise. Failure can occur when output files specified on the
  38. * command line cannot be written.
  39. */
  40. bool PrintRequestedDocumentation(std::ostream& os);
  41. /** Print help of the given type. */
  42. bool PrintDocumentation(Type ht, std::ostream& os);
  43. /** Set the program name for standard document generation. */
  44. void SetName(const char* name);
  45. /** Set the program name section for standard document
  46. * generation. */
  47. void SetNameSection(const cmDocumentationEntry*);
  48. /** Set the program usage for standard document generation. */
  49. void SetUsageSection(const cmDocumentationEntry*);
  50. /** Set the program description for standard document generation. */
  51. void SetDescriptionSection(const cmDocumentationEntry*);
  52. /** Set the program options for standard document generation. */
  53. void SetOptionsSection(const cmDocumentationEntry*);
  54. /** Set the listfile commands for standard document generation. */
  55. void SetCommandsSection(const cmDocumentationEntry*);
  56. /** Set the listfile compat. commands for standard document generation. */
  57. void SetCompatCommandsSection(const cmDocumentationEntry*);
  58. /** Set the properties for standard document generation. */
  59. void SetPropertiesSection(const cmDocumentationEntry*);
  60. /** Set the generator descriptions for standard document generation. */
  61. void SetGeneratorsSection(const cmDocumentationEntry*);
  62. /** Set the see-also list of references to the other tools. */
  63. void SetSeeAlsoList(const cmDocumentationEntry*);
  64. // Low-level interface for custom documents:
  65. /** Forms of documentation output. */
  66. enum Form { TextForm, HTMLForm, ManForm, UsageForm };
  67. /** Internal class representing a section of the documentation.
  68. * Cares e.g. for the different section titles in the different
  69. * output formats.
  70. */
  71. class cmSection
  72. {
  73. public:
  74. /** Create a cmSection, with a special name for man-output mode. */
  75. cmSection(const char* name, const char* manName)
  76. :Name(name), ManName(manName) {}
  77. /** Has any content been added to this section or is it empty ? */
  78. bool IsEmpty() const
  79. { return this->Entries.empty(); }
  80. /** Clear contents. */
  81. void Clear()
  82. { this->Entries.clear(); }
  83. /** Return the name of this section for the given output form. */
  84. const char* GetName(Form form) const
  85. { return (form==ManForm?this->ManName.c_str():this->Name.c_str()); }
  86. /** Return a pointer to the first entry of this section. */
  87. cmDocumentationEntry *GetEntries()
  88. { return &this->Entries[0]; }
  89. /** Return a pointer to the first entry of this section. */
  90. const cmDocumentationEntry *GetEntries() const
  91. { return &this->Entries[0]; }
  92. /** Append an entry to this section. */
  93. void Append(const cmDocumentationEntry& entry)
  94. { this->Entries.push_back(entry); }
  95. /** Set the contents of this section. */
  96. void Set(const cmDocumentationEntry* header,
  97. const cmDocumentationEntry* section,
  98. const cmDocumentationEntry* footer);
  99. private:
  100. std::string Name;
  101. std::string ManName;
  102. std::vector<cmDocumentationEntry> Entries;
  103. };
  104. /**
  105. * Print documentation in the given form. All previously added
  106. * sections will be generated.
  107. */
  108. void Print(Form f, std::ostream& os);
  109. /**
  110. * Print documentation in the current form. All previously added
  111. * sections will be generated.
  112. */
  113. void Print(std::ostream& os);
  114. /**
  115. * Add a section of documentation. The cmDocumentationEntry pointer
  116. * should point at an array terminated by an all zero ({0,0,0})
  117. * entry. This can be used to generate custom help documents.
  118. */
  119. void AddSection(const char* name, const cmDocumentationEntry* d);
  120. /** Convenience function, does the same as above */
  121. void AddSection(const cmSection& section);
  122. /** Clear all previously added sections of help. */
  123. void ClearSections();
  124. /** Set cmake root so we can find installed files */
  125. void SetCMakeRoot(const char* root) { this->CMakeRoot = root;}
  126. private:
  127. void PrintHeader(const char* title, std::ostream& os);
  128. void PrintFooter(std::ostream& os);
  129. void PrintSection(std::ostream& os,
  130. const cmDocumentationEntry* section,
  131. const char* name);
  132. void PrintSectionText(std::ostream& os,
  133. const cmDocumentationEntry* section,
  134. const char* name);
  135. void PrintSectionHTML(std::ostream& os,
  136. const cmDocumentationEntry* section,
  137. const char* name);
  138. void PrintSectionMan(std::ostream& os, const cmDocumentationEntry* section,
  139. const char* name);
  140. void PrintSectionUsage(std::ostream& os,
  141. const cmDocumentationEntry* section,
  142. const char* name);
  143. void PrintFormatted(std::ostream& os, const char* text);
  144. void PrintPreformatted(std::ostream& os, const char* text);
  145. void PrintPreformattedText(std::ostream& os, const char* text);
  146. void PrintPreformattedHTML(std::ostream& os, const char* text);
  147. void PrintPreformattedMan(std::ostream& os, const char* text);
  148. void PrintParagraph(std::ostream& os, const char* text);
  149. void PrintParagraphText(std::ostream& os, const char* text);
  150. void PrintParagraphHTML(std::ostream& os, const char* text);
  151. void PrintParagraphMan(std::ostream& os, const char* text);
  152. void PrintColumn(std::ostream& os, const char* text);
  153. void PrintHTMLEscapes(std::ostream& os, const char* text);
  154. bool CreateSingleModule(const char* fname, const char* moduleName);
  155. bool CreateModulesSection();
  156. bool PrintCopyright(std::ostream& os);
  157. bool PrintVersion(std::ostream& os);
  158. bool PrintDocumentationList(std::ostream& os);
  159. bool PrintModuleList(std::ostream& os);
  160. bool PrintPropertyList(std::ostream& os);
  161. bool PrintDocumentationSingle(std::ostream& os);
  162. bool PrintDocumentationSingleModule(std::ostream& os);
  163. bool PrintDocumentationSingleProperty(std::ostream& os);
  164. bool PrintDocumentationUsage(std::ostream& os);
  165. bool PrintDocumentationFull(std::ostream& os);
  166. void PrintDocumentationCommand(std::ostream& os,
  167. cmDocumentationEntry* entry);
  168. void CreateUsageDocumentation();
  169. void CreateFullDocumentation();
  170. void CreateCurrentCommandDocumentation();
  171. void CreateCompatCommandDocumentation();
  172. void CreateModulesDocumentation();
  173. void CreatePropertiesDocumentation();
  174. void SetSection(const cmDocumentationEntry* header,
  175. const cmDocumentationEntry* section,
  176. const cmDocumentationEntry* footer,
  177. std::vector<cmDocumentationEntry>&);
  178. const char* GetNameString() const;
  179. bool IsOption(const char* arg) const;
  180. std::string NameString;
  181. cmSection NameSection;
  182. cmSection UsageSection;
  183. cmSection DescriptionSection;
  184. cmSection OptionsSection;
  185. cmSection CommandsSection;
  186. cmSection CompatCommandsSection;
  187. cmSection ModulesSection;
  188. cmSection PropertiesSection;
  189. cmSection GeneratorsSection;
  190. cmSection SeeAlsoSection;
  191. cmSection CopyrightSection;
  192. cmSection AuthorSection;
  193. std::string SeeAlsoString;
  194. std::string SingleCommand;
  195. std::string SingleModuleName;
  196. std::string SinglePropertyName;
  197. std::string CMakeRoot;
  198. std::vector< char* > ModuleStrings;
  199. std::vector< const char* > Names;
  200. std::vector< const cmDocumentationEntry* > Sections;
  201. Form CurrentForm;
  202. const char* TextIndent;
  203. int TextWidth;
  204. typedef std::map<Type, cmStdString> RequestedMapType;
  205. RequestedMapType RequestedMap;
  206. };
  207. #endif