cmDocumentation.cxx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  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. #include "cmDocumentation.h"
  14. #include "cmSystemTools.h"
  15. //----------------------------------------------------------------------------
  16. static const cmDocumentationEntry cmDocumentationStandardOptions[] =
  17. {
  18. {"--copyright", "Print the CMake copyright and exit.", 0},
  19. {"--help", "Print usage information and exit.",
  20. "Usage describes the basic command line interface and its options."},
  21. {"--help-full", "Print full help and exit.",
  22. "Full help displays most of the documentation provided by the UNIX "
  23. "man page. It is provided for use on non-UNIX platforms, but is "
  24. "also convenient if the man page is not installed."},
  25. {"--help-html", "Print full help in HTML format.",
  26. "This option is used by CMake authors to help produce web pages."},
  27. {"--help-man", "Print a UNIX man page and exit.",
  28. "This option is used by CMake authors to generate the UNIX man page."},
  29. {"--version", "Show program name/version banner and exit.", 0},
  30. {0,0,0}
  31. };
  32. //----------------------------------------------------------------------------
  33. static const cmDocumentationEntry cmDocumentationCommandsHeader[] =
  34. {
  35. {0,
  36. "The following commands are available in CMakeLists.txt code:", 0},
  37. {0,0,0}
  38. };
  39. //----------------------------------------------------------------------------
  40. const cmDocumentationEntry cmDocumentationMailingList[] =
  41. {
  42. {0,
  43. "For help and discussion about using cmake, a mailing list is provided "
  44. "at [email protected]. Please first read the full documentation at "
  45. "http://www.cmake.org before posting questions to the list.", 0},
  46. {0,0,0}
  47. };
  48. //----------------------------------------------------------------------------
  49. const cmDocumentationEntry cmDocumentationAuthor[] =
  50. {
  51. {0,
  52. "This manual page was generated by \"cmake --help-man\".", 0},
  53. {0,0,0}
  54. };
  55. //----------------------------------------------------------------------------
  56. const cmDocumentationEntry cmDocumentationCopyright[] =
  57. {
  58. {0,
  59. "Copyright (c) 2002 Kitware, Inc., Insight Consortium. "
  60. "All rights reserved.", 0},
  61. {0,
  62. "Redistribution and use in source and binary forms, with or without "
  63. "modification, are permitted provided that the following conditions are "
  64. "met:", 0},
  65. {"",
  66. "Redistributions of source code must retain the above copyright notice, "
  67. "this list of conditions and the following disclaimer.", 0},
  68. {"",
  69. "Redistributions in binary form must reproduce the above copyright "
  70. "notice, this list of conditions and the following disclaimer in the "
  71. "documentation and/or other materials provided with the distribution.",
  72. 0},
  73. {"",
  74. "The names of Kitware, Inc., the Insight Consortium, or the names of "
  75. "any consortium members, or of any contributors, may not be used to "
  76. "endorse or promote products derived from this software without "
  77. "specific prior written permission.", 0},
  78. {"",
  79. "Modified source versions must be plainly marked as such, and must "
  80. "not be misrepresented as being the original software.", 0},
  81. {0,
  82. "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "
  83. "``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT "
  84. "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR "
  85. "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR "
  86. "CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, "
  87. "EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, "
  88. "PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR "
  89. "PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF "
  90. "LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING "
  91. "NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS "
  92. "SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.", 0},
  93. {0, 0, 0}
  94. };
  95. //----------------------------------------------------------------------------
  96. cmDocumentation::cmDocumentation()
  97. {
  98. this->CurrentForm = TextForm;
  99. this->TextIndent = "";
  100. this->TextWidth = 77;
  101. }
  102. //----------------------------------------------------------------------------
  103. void cmDocumentation::PrintCopyright(std::ostream& os)
  104. {
  105. os << "CMake version " CMake_VERSION_STRING "\n";
  106. for(const cmDocumentationEntry* op = cmDocumentationCopyright;
  107. op->brief; ++op)
  108. {
  109. if(op->name)
  110. {
  111. os << " * ";
  112. this->TextIndent = " ";
  113. this->PrintColumn(os, op->brief);
  114. }
  115. else
  116. {
  117. this->TextIndent = "";
  118. this->PrintColumn(os, op->brief);
  119. }
  120. os << "\n";
  121. }
  122. }
  123. //----------------------------------------------------------------------------
  124. void cmDocumentation::PrintVersion(std::ostream& os)
  125. {
  126. os << "CMake version " CMake_VERSION_STRING "\n";
  127. }
  128. //----------------------------------------------------------------------------
  129. void cmDocumentation::AddSection(const char* name,
  130. const cmDocumentationEntry* d)
  131. {
  132. this->Names.push_back(name);
  133. this->Sections.push_back(d);
  134. }
  135. //----------------------------------------------------------------------------
  136. void cmDocumentation::ClearSections()
  137. {
  138. this->Names.erase(this->Names.begin(), this->Names.end());
  139. this->Sections.erase(this->Sections.begin(), this->Sections.end());
  140. }
  141. //----------------------------------------------------------------------------
  142. void cmDocumentation::PrintDocumentation(Type ht, std::ostream& os)
  143. {
  144. switch (ht)
  145. {
  146. case cmDocumentation::Usage: this->PrintDocumentationUsage(os); break;
  147. case cmDocumentation::Full: this->PrintDocumentationFull(os); break;
  148. case cmDocumentation::HTML: this->PrintDocumentationHTML(os); break;
  149. case cmDocumentation::Man: this->PrintDocumentationMan(os); break;
  150. case cmDocumentation::Copyright: this->PrintCopyright(os); break;
  151. case cmDocumentation::Version: this->PrintVersion(os); break;
  152. default: break;
  153. }
  154. }
  155. //----------------------------------------------------------------------------
  156. cmDocumentation::Type cmDocumentation::CheckOptions(int argc, char** argv)
  157. {
  158. // Providing zero arguments gives usage information.
  159. if(argc == 1)
  160. {
  161. return cmDocumentation::Usage;
  162. }
  163. // Search for supported help options.
  164. for(int i=1; i < argc; ++i)
  165. {
  166. if((strcmp(argv[i], "-help") == 0) ||
  167. (strcmp(argv[i], "--help") == 0) ||
  168. (strcmp(argv[i], "/?") == 0) ||
  169. (strcmp(argv[i], "-usage") == 0) ||
  170. (strcmp(argv[i], "-h") == 0) ||
  171. (strcmp(argv[i], "-H") == 0))
  172. {
  173. return cmDocumentation::Usage;
  174. }
  175. if(strcmp(argv[i], "--help-full") == 0)
  176. {
  177. return cmDocumentation::Full;
  178. }
  179. if(strcmp(argv[i], "--help-html") == 0)
  180. {
  181. return cmDocumentation::HTML;
  182. }
  183. if(strcmp(argv[i], "--help-man") == 0)
  184. {
  185. return cmDocumentation::Man;
  186. }
  187. if(strcmp(argv[i], "--copyright") == 0)
  188. {
  189. return cmDocumentation::Copyright;
  190. }
  191. if((strcmp(argv[i], "--version") == 0) ||
  192. (strcmp(argv[i], "-version") == 0) ||
  193. (strcmp(argv[i], "-V") == 0) ||
  194. (strcmp(argv[i], "/V") == 0))
  195. {
  196. return cmDocumentation::Version;
  197. }
  198. }
  199. return cmDocumentation::None;
  200. }
  201. //----------------------------------------------------------------------------
  202. void cmDocumentation::Print(Form f, std::ostream& os)
  203. {
  204. this->CurrentForm = f;
  205. for(unsigned int i=0; i < this->Sections.size(); ++i)
  206. {
  207. this->PrintSection(os, this->Sections[i], this->Names[i]);
  208. }
  209. }
  210. //----------------------------------------------------------------------------
  211. void cmDocumentation::SetNameSection(const cmDocumentationEntry* section)
  212. {
  213. this->SetSection(0, section, 0, this->NameSection);
  214. }
  215. //----------------------------------------------------------------------------
  216. void cmDocumentation::SetUsageSection(const cmDocumentationEntry* section)
  217. {
  218. this->SetSection(0, section, 0, this->UsageSection);
  219. }
  220. //----------------------------------------------------------------------------
  221. void cmDocumentation::SetDescriptionSection(const cmDocumentationEntry* section)
  222. {
  223. this->SetSection(0, section, 0, this->DescriptionSection);
  224. }
  225. //----------------------------------------------------------------------------
  226. void cmDocumentation::SetOptionsSection(const cmDocumentationEntry* section)
  227. {
  228. this->SetSection(0, section, cmDocumentationStandardOptions,
  229. this->OptionsSection);
  230. }
  231. //----------------------------------------------------------------------------
  232. void cmDocumentation::SetCommandsSection(const cmDocumentationEntry* section)
  233. {
  234. this->SetSection(cmDocumentationCommandsHeader, section, 0,
  235. this->CommandsSection);
  236. }
  237. //----------------------------------------------------------------------------
  238. void cmDocumentation::PrintSection(std::ostream& os,
  239. const cmDocumentationEntry* section,
  240. const char* name)
  241. {
  242. switch (this->CurrentForm)
  243. {
  244. case TextForm: this->PrintSectionText(os, section, name); break;
  245. case HTMLForm: this->PrintSectionHTML(os, section, name); break;
  246. case ManForm: this->PrintSectionMan(os, section, name); break;
  247. case UsageForm: this->PrintSectionUsage(os, section, name); break;
  248. }
  249. }
  250. //----------------------------------------------------------------------------
  251. void cmDocumentation::PrintSectionText(std::ostream& os,
  252. const cmDocumentationEntry* section,
  253. const char* name)
  254. {
  255. if(name)
  256. {
  257. os << name << "\n\n";
  258. }
  259. if(!section) { return; }
  260. for(const cmDocumentationEntry* op = section; op->brief; ++op)
  261. {
  262. if(op->name)
  263. {
  264. if(op->name[0])
  265. {
  266. os << " " << op->name << "\n";
  267. }
  268. this->TextIndent = " ";
  269. this->PrintFormatted(os, op->brief);
  270. if(op->full)
  271. {
  272. os << "\n";
  273. this->PrintFormatted(os, op->full);
  274. }
  275. }
  276. else
  277. {
  278. this->TextIndent = "";
  279. this->PrintFormatted(os, op->brief);
  280. }
  281. os << "\n";
  282. }
  283. }
  284. //----------------------------------------------------------------------------
  285. void cmDocumentation::PrintSectionHTML(std::ostream& os,
  286. const cmDocumentationEntry* section,
  287. const char* name)
  288. {
  289. if(name)
  290. {
  291. os << "<h2>" << name << "</h2>\n";
  292. }
  293. if(!section) { return; }
  294. for(const cmDocumentationEntry* op = section; op->brief;)
  295. {
  296. if(op->name)
  297. {
  298. os << "<ul>\n";
  299. for(;op->name;++op)
  300. {
  301. os << " <li>\n";
  302. if(op->name[0])
  303. {
  304. os << " <b><code>";
  305. this->PrintHTMLEscapes(os, op->name);
  306. os << "</code></b>: ";
  307. }
  308. this->PrintHTMLEscapes(os, op->brief);
  309. if(op->full)
  310. {
  311. os << "<br>\n ";
  312. this->PrintFormatted(os, op->full);
  313. }
  314. os << "\n";
  315. os << " </li>\n";
  316. }
  317. os << "</ul>\n";
  318. }
  319. else
  320. {
  321. this->PrintFormatted(os, op->brief);
  322. os << "\n";
  323. ++op;
  324. }
  325. }
  326. }
  327. //----------------------------------------------------------------------------
  328. void cmDocumentation::PrintSectionMan(std::ostream& os,
  329. const cmDocumentationEntry* section,
  330. const char* name)
  331. {
  332. if(name)
  333. {
  334. os << ".SH " << name << "\n";
  335. }
  336. if(!section) { return; }
  337. for(const cmDocumentationEntry* op = section; op->brief; ++op)
  338. {
  339. if(op->name)
  340. {
  341. os << ".TP\n"
  342. << ".B " << (op->name[0]?op->name:"*") << "\n";
  343. this->PrintFormatted(os, op->brief);
  344. this->PrintFormatted(os, op->full);
  345. }
  346. else
  347. {
  348. os << ".PP\n";
  349. this->PrintFormatted(os, op->brief);
  350. }
  351. }
  352. }
  353. //----------------------------------------------------------------------------
  354. void cmDocumentation::PrintSectionUsage(std::ostream& os,
  355. const cmDocumentationEntry* section,
  356. const char* name)
  357. {
  358. if(name)
  359. {
  360. os << name << "\n";
  361. }
  362. if(!section) { return; }
  363. for(const cmDocumentationEntry* op = section; op->brief; ++op)
  364. {
  365. if(op->name)
  366. {
  367. os << " " << op->name;
  368. this->TextIndent = " ";
  369. int align = static_cast<int>(strlen(this->TextIndent))-4;
  370. for(int i = static_cast<int>(strlen(op->name)); i < align; ++i)
  371. {
  372. os << " ";
  373. }
  374. os << "= ";
  375. this->PrintColumn(os, op->brief);
  376. os << "\n";
  377. }
  378. else
  379. {
  380. os << "\n";
  381. this->TextIndent = "";
  382. this->PrintFormatted(os, op->brief);
  383. }
  384. }
  385. os << "\n";
  386. }
  387. //----------------------------------------------------------------------------
  388. void cmDocumentation::PrintFormatted(std::ostream& os, const char* text)
  389. {
  390. if(!text)
  391. {
  392. return;
  393. }
  394. const char* ptr = text;
  395. while(*ptr)
  396. {
  397. // Any ptrs starting in a space are treated as preformatted text.
  398. std::string preformatted;
  399. while(*ptr == ' ')
  400. {
  401. for(char ch = *ptr; ch && ch != '\n'; ++ptr, ch = *ptr)
  402. {
  403. preformatted.append(1, ch);
  404. }
  405. if(*ptr)
  406. {
  407. ++ptr;
  408. preformatted.append(1, '\n');
  409. }
  410. }
  411. if(preformatted.length())
  412. {
  413. this->PrintPreformatted(os, preformatted.c_str());
  414. }
  415. // Other ptrs are treated as paragraphs.
  416. std::string paragraph;
  417. for(char ch = *ptr; ch && ch != '\n'; ++ptr, ch = *ptr)
  418. {
  419. paragraph.append(1, ch);
  420. }
  421. if(*ptr)
  422. {
  423. ++ptr;
  424. paragraph.append(1, '\n');
  425. }
  426. if(paragraph.length())
  427. {
  428. this->PrintParagraph(os, paragraph.c_str());
  429. }
  430. }
  431. }
  432. //----------------------------------------------------------------------------
  433. void cmDocumentation::PrintPreformatted(std::ostream& os, const char* text)
  434. {
  435. switch (this->CurrentForm)
  436. {
  437. case TextForm: this->PrintPreformattedText(os, text); break;
  438. case HTMLForm: this->PrintPreformattedHTML(os, text); break;
  439. case ManForm: this->PrintPreformattedMan(os, text); break;
  440. case UsageForm: this->PrintPreformattedText(os, text); break;
  441. }
  442. }
  443. //----------------------------------------------------------------------------
  444. void cmDocumentation::PrintParagraph(std::ostream& os, const char* text)
  445. {
  446. switch (this->CurrentForm)
  447. {
  448. case TextForm: this->PrintParagraphText(os, text); break;
  449. case HTMLForm: this->PrintParagraphHTML(os, text); break;
  450. case ManForm: this->PrintParagraphMan(os, text); break;
  451. case UsageForm: this->PrintParagraphText(os, text); break;
  452. }
  453. }
  454. //----------------------------------------------------------------------------
  455. void cmDocumentation::PrintPreformattedText(std::ostream& os, const char* text)
  456. {
  457. bool newline = true;
  458. for(const char* ptr = text; *ptr; ++ptr)
  459. {
  460. if(newline)
  461. {
  462. os << this->TextIndent;
  463. newline = false;
  464. }
  465. os << *ptr;
  466. if(*ptr == '\n')
  467. {
  468. newline = true;
  469. }
  470. }
  471. os << "\n";
  472. }
  473. //----------------------------------------------------------------------------
  474. void cmDocumentation::PrintParagraphText(std::ostream& os, const char* text)
  475. {
  476. os << this->TextIndent;
  477. this->PrintColumn(os, text);
  478. os << "\n";
  479. }
  480. //----------------------------------------------------------------------------
  481. void cmDocumentation::PrintPreformattedHTML(std::ostream& os, const char* text)
  482. {
  483. os << "<pre>";
  484. this->PrintHTMLEscapes(os, text);
  485. os << "</pre>\n ";
  486. }
  487. //----------------------------------------------------------------------------
  488. void cmDocumentation::PrintParagraphHTML(std::ostream& os, const char* text)
  489. {
  490. os << "<p>";
  491. this->PrintHTMLEscapes(os, text);
  492. }
  493. //----------------------------------------------------------------------------
  494. void cmDocumentation::PrintPreformattedMan(std::ostream& os, const char* text)
  495. {
  496. os << text << "\n";
  497. }
  498. //----------------------------------------------------------------------------
  499. void cmDocumentation::PrintParagraphMan(std::ostream& os, const char* text)
  500. {
  501. os << text << "\n\n";
  502. }
  503. //----------------------------------------------------------------------------
  504. void cmDocumentation::PrintColumn(std::ostream& os, const char* text)
  505. {
  506. // Print text arranged in an indented column of fixed witdh.
  507. const char* l = text;
  508. int column = 0;
  509. bool newSentence = false;
  510. bool firstLine = true;
  511. int width = this->TextWidth - static_cast<int>(strlen(this->TextIndent));
  512. // Loop until the end of the text.
  513. while(*l)
  514. {
  515. // Parse the next word.
  516. const char* r = l;
  517. while(*r && (*r != '\n') && (*r != ' ')) { ++r; }
  518. // Does it fit on this line?
  519. if(r-l < (width-column-(newSentence?1:0)))
  520. {
  521. // Word fits on this line.
  522. if(r > l)
  523. {
  524. if(column)
  525. {
  526. // Not first word on line. Separate from the previous word
  527. // by a space, or two if this is a new sentence.
  528. if(newSentence)
  529. {
  530. os << " ";
  531. column += 2;
  532. }
  533. else
  534. {
  535. os << " ";
  536. column += 1;
  537. }
  538. }
  539. else
  540. {
  541. // First word on line. Print indentation unless this is the
  542. // first line.
  543. os << (firstLine?"":this->TextIndent);
  544. }
  545. // Print the word.
  546. os.write(l, static_cast<long>(r-l));
  547. newSentence = (*(r-1) == '.');
  548. }
  549. if(*r == '\n')
  550. {
  551. // Text provided a newline. Start a new line.
  552. os << "\n";
  553. ++r;
  554. column = 0;
  555. firstLine = false;
  556. }
  557. else
  558. {
  559. // No provided newline. Continue this line.
  560. column += static_cast<long>(r-l);
  561. }
  562. }
  563. else
  564. {
  565. // Word does not fit on this line. Start a new line.
  566. os << "\n";
  567. firstLine = false;
  568. if(r > l)
  569. {
  570. os << this->TextIndent;
  571. os.write(l, static_cast<long>(r-l));
  572. column = static_cast<long>(r-l);
  573. newSentence = (*(r-1) == '.');
  574. }
  575. }
  576. // Move to beginning of next word. Skip over whitespace.
  577. l = r;
  578. while(*l && (*l == ' ')) { ++l; }
  579. }
  580. }
  581. //----------------------------------------------------------------------------
  582. void cmDocumentation::PrintHTMLEscapes(std::ostream& os, const char* text)
  583. {
  584. static cmDocumentationEntry escapes[] =
  585. {
  586. {"<", "&lt;", 0},
  587. {">", "&gt;", 0},
  588. {"&", "&amp;", 0},
  589. {"\n", "<br>", 0},
  590. {0,0,0}
  591. };
  592. for(const char* p = text; *p; ++p)
  593. {
  594. bool found = false;
  595. for(const cmDocumentationEntry* op = escapes; !found && op->name; ++op)
  596. {
  597. if(op->name[0] == *p)
  598. {
  599. os << op->brief;
  600. found = true;
  601. }
  602. }
  603. if(!found)
  604. {
  605. os << *p;
  606. }
  607. }
  608. }
  609. //----------------------------------------------------------------------------
  610. void cmDocumentation::PrintDocumentationUsage(std::ostream& os)
  611. {
  612. this->CreateUsageDocumentation();
  613. this->Print(UsageForm, os);
  614. }
  615. //----------------------------------------------------------------------------
  616. void cmDocumentation::PrintDocumentationFull(std::ostream& os)
  617. {
  618. this->CreateFullDocumentation();
  619. this->Print(TextForm, os);
  620. }
  621. //----------------------------------------------------------------------------
  622. void cmDocumentation::PrintDocumentationHTML(std::ostream& os)
  623. {
  624. this->CreateFullDocumentation();
  625. os << "<html><body>\n";
  626. this->Print(HTMLForm, os);
  627. os << "</body></html>\n";
  628. }
  629. //----------------------------------------------------------------------------
  630. void cmDocumentation::PrintDocumentationMan(std::ostream& os)
  631. {
  632. this->CreateManDocumentation();
  633. os << ".TH CMake 1 \""
  634. << cmSystemTools::GetCurrentDateTime("%B %d, %Y").c_str()
  635. << "\" \"CMake " CMake_VERSION_STRING "\"\n";
  636. this->Print(ManForm, os);
  637. }
  638. //----------------------------------------------------------------------------
  639. void cmDocumentation::CreateUsageDocumentation()
  640. {
  641. this->ClearSections();
  642. if(!this->NameSection.empty())
  643. {
  644. this->AddSection("Name", &this->NameSection[0]);
  645. }
  646. if(!this->UsageSection.empty())
  647. {
  648. this->AddSection("Usage", &this->UsageSection[0]);
  649. }
  650. if(!this->OptionsSection.empty())
  651. {
  652. this->AddSection("Command-Line Options", &this->OptionsSection[0]);
  653. }
  654. }
  655. //----------------------------------------------------------------------------
  656. void cmDocumentation::CreateFullDocumentation()
  657. {
  658. this->ClearSections();
  659. if(!this->NameSection.empty())
  660. {
  661. this->AddSection("Name", &this->NameSection[0]);
  662. }
  663. if(!this->UsageSection.empty())
  664. {
  665. this->AddSection("Usage", &this->UsageSection[0]);
  666. }
  667. if(!this->DescriptionSection.empty())
  668. {
  669. this->AddSection(0, &this->DescriptionSection[0]);
  670. }
  671. if(!this->OptionsSection.empty())
  672. {
  673. this->AddSection("Command-Line Options", &this->OptionsSection[0]);
  674. }
  675. if(!this->CommandsSection.empty())
  676. {
  677. this->AddSection("Listfile Commands", &this->CommandsSection[0]);
  678. }
  679. this->AddSection("Copyright", cmDocumentationCopyright);
  680. this->AddSection("Mailing List", cmDocumentationMailingList);
  681. }
  682. //----------------------------------------------------------------------------
  683. void cmDocumentation::CreateManDocumentation()
  684. {
  685. this->ClearSections();
  686. if(!this->NameSection.empty())
  687. {
  688. this->AddSection("NAME", &this->NameSection[0]);
  689. }
  690. if(!this->UsageSection.empty())
  691. {
  692. this->AddSection("SYNOPSIS", &this->UsageSection[0]);
  693. }
  694. if(!this->DescriptionSection.empty())
  695. {
  696. this->AddSection("DESCRIPTION", &this->DescriptionSection[0]);
  697. }
  698. if(!this->OptionsSection.empty())
  699. {
  700. this->AddSection("OPTIONS", &this->OptionsSection[0]);
  701. }
  702. if(!this->CommandsSection.empty())
  703. {
  704. this->AddSection("COMMANDS", &this->CommandsSection[0]);
  705. }
  706. this->AddSection("COPYRIGHT", cmDocumentationCopyright);
  707. this->AddSection("MAILING LIST", cmDocumentationMailingList);
  708. this->AddSection("AUTHOR", cmDocumentationAuthor);
  709. }
  710. //----------------------------------------------------------------------------
  711. void cmDocumentation::SetSection(const cmDocumentationEntry* header,
  712. const cmDocumentationEntry* section,
  713. const cmDocumentationEntry* footer,
  714. std::vector<cmDocumentationEntry>& vec)
  715. {
  716. vec.erase(vec.begin(), vec.end());
  717. if(header)
  718. {
  719. for(const cmDocumentationEntry* op = header; op->brief; ++op)
  720. {
  721. vec.push_back(*op);
  722. }
  723. }
  724. if(section)
  725. {
  726. for(const cmDocumentationEntry* op = section; op->brief; ++op)
  727. {
  728. vec.push_back(*op);
  729. }
  730. }
  731. if(footer)
  732. {
  733. for(const cmDocumentationEntry* op = footer; op->brief; ++op)
  734. {
  735. vec.push_back(*op);
  736. }
  737. }
  738. cmDocumentationEntry empty = {0,0,0};
  739. vec.push_back(empty);
  740. }