cmDocumentation.h 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 properties for standard document generation. */
  57. void SetPropertiesSection(const cmDocumentationEntry*);
  58. /** Set the generator descriptions for standard document generation. */
  59. void SetGeneratorsSection(const cmDocumentationEntry*);
  60. /** Set the see-also list of references to the other tools. */
  61. void SetSeeAlsoList(const cmDocumentationEntry*);
  62. // Low-level interface for custom documents:
  63. /** Forms of documentation output. */
  64. enum Form { TextForm, HTMLForm, ManForm, UsageForm };
  65. /** Internal class representing a section of the documentation.
  66. * Cares e.g. for the different section titles in the different
  67. * output formats.
  68. */
  69. class cmSection
  70. {
  71. public:
  72. /** Create a cmSection, with a special name for man-output mode. */
  73. cmSection(const char* name, const char* manName)
  74. :Name(name), ManName(manName) {}
  75. /** Has any content been added to this section or is it empty ? */
  76. bool IsEmpty() const
  77. { return this->Entries.empty(); }
  78. /** Clear contents. */
  79. void Clear()
  80. { this->Entries.clear(); }
  81. /** Return the name of this section for the given output form. */
  82. const char* GetName(Form form) const
  83. { return (form==ManForm?this->ManName.c_str():this->Name.c_str()); }
  84. /** Return a pointer to the first entry of this section. */
  85. cmDocumentationEntry *GetEntries()
  86. { return &this->Entries[0]; }
  87. /** Return a pointer to the first entry of this section. */
  88. const cmDocumentationEntry *GetEntries() const
  89. { return &this->Entries[0]; }
  90. /** Append an entry to this section. */
  91. void Append(const cmDocumentationEntry& entry)
  92. { this->Entries.push_back(entry); }
  93. /** Set the contents of this section. */
  94. void Set(const cmDocumentationEntry* header,
  95. const cmDocumentationEntry* section,
  96. const cmDocumentationEntry* footer);
  97. private:
  98. std::string Name;
  99. std::string ManName;
  100. std::vector<cmDocumentationEntry> Entries;
  101. };
  102. /**
  103. * Print documentation in the given form. All previously added
  104. * sections will be generated.
  105. */
  106. void Print(Form f, std::ostream& os);
  107. /**
  108. * Print documentation in the current form. All previously added
  109. * sections will be generated.
  110. */
  111. void Print(std::ostream& os);
  112. /**
  113. * Add a section of documentation. The cmDocumentationEntry pointer
  114. * should point at an array terminated by an all zero ({0,0,0})
  115. * entry. This can be used to generate custom help documents.
  116. */
  117. void AddSection(const char* name, const cmDocumentationEntry* d);
  118. /** Convenience function, does the same as above */
  119. void AddSection(const cmSection& section);
  120. /** Clear all previously added sections of help. */
  121. void ClearSections();
  122. /** Set cmake root so we can find installed files */
  123. void SetCMakeRoot(const char* root) { this->CMakeRoot = root;}
  124. private:
  125. void PrintHeader(const char* title, std::ostream& os);
  126. void PrintFooter(std::ostream& os);
  127. void PrintSection(std::ostream& os,
  128. const cmDocumentationEntry* section,
  129. const char* name);
  130. void PrintSectionText(std::ostream& os,
  131. const cmDocumentationEntry* section,
  132. const char* name);
  133. void PrintSectionHTML(std::ostream& os,
  134. const cmDocumentationEntry* section,
  135. const char* name);
  136. void PrintSectionMan(std::ostream& os, const cmDocumentationEntry* section,
  137. const char* name);
  138. void PrintSectionUsage(std::ostream& os,
  139. const cmDocumentationEntry* section,
  140. const char* name);
  141. void PrintFormatted(std::ostream& os, const char* text);
  142. void PrintPreformatted(std::ostream& os, const char* text);
  143. void PrintPreformattedText(std::ostream& os, const char* text);
  144. void PrintPreformattedHTML(std::ostream& os, const char* text);
  145. void PrintPreformattedMan(std::ostream& os, const char* text);
  146. void PrintParagraph(std::ostream& os, const char* text);
  147. void PrintParagraphText(std::ostream& os, const char* text);
  148. void PrintParagraphHTML(std::ostream& os, const char* text);
  149. void PrintParagraphMan(std::ostream& os, const char* text);
  150. void PrintColumn(std::ostream& os, const char* text);
  151. void PrintHTMLEscapes(std::ostream& os, const char* text);
  152. bool CreateSingleModule(const char* fname, const char* moduleName);
  153. bool CreateModulesSection();
  154. bool PrintCopyright(std::ostream& os);
  155. bool PrintVersion(std::ostream& os);
  156. bool PrintDocumentationList(std::ostream& os);
  157. bool PrintModuleList(std::ostream& os);
  158. bool PrintPropertyList(std::ostream& os);
  159. bool PrintDocumentationSingle(std::ostream& os);
  160. bool PrintDocumentationSingleModule(std::ostream& os);
  161. bool PrintDocumentationSingleProperty(std::ostream& os);
  162. bool PrintDocumentationUsage(std::ostream& os);
  163. bool PrintDocumentationFull(std::ostream& os);
  164. void PrintDocumentationCommand(std::ostream& os,
  165. cmDocumentationEntry* entry);
  166. void CreateUsageDocumentation();
  167. void CreateFullDocumentation();
  168. void SetSection(const cmDocumentationEntry* header,
  169. const cmDocumentationEntry* section,
  170. const cmDocumentationEntry* footer,
  171. std::vector<cmDocumentationEntry>&);
  172. const char* GetNameString() const;
  173. bool IsOption(const char* arg) const;
  174. std::string NameString;
  175. cmSection NameSection;
  176. cmSection UsageSection;
  177. cmSection DescriptionSection;
  178. cmSection OptionsSection;
  179. cmSection CommandsSection;
  180. cmSection CompatCommandsSection;
  181. cmSection ModulesSection;
  182. cmSection PropertiesSection;
  183. cmSection GeneratorsSection;
  184. cmSection SeeAlsoSection;
  185. cmSection CopyrightSection;
  186. cmSection AuthorSection;
  187. std::string SeeAlsoString;
  188. std::string SingleCommand;
  189. std::string SingleModuleName;
  190. std::string SinglePropertyName;
  191. std::string CMakeRoot;
  192. std::vector< char* > ModuleStrings;
  193. std::vector< const char* > Names;
  194. std::vector< const cmDocumentationEntry* > Sections;
  195. Form CurrentForm;
  196. const char* TextIndent;
  197. int TextWidth;
  198. typedef std::map<Type, cmStdString> RequestedMapType;
  199. RequestedMapType RequestedMap;
  200. };
  201. #endif