cmDocumentation.cxx 26 KB

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