cmDocumentation.cxx 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmDocumentation.h"
  11. #include "cmSystemTools.h"
  12. #include "cmVersion.h"
  13. #include "cmRST.h"
  14. #include <cmsys/Directory.hxx>
  15. #include <cmsys/Glob.hxx>
  16. #include <ctype.h>
  17. #include <algorithm>
  18. //----------------------------------------------------------------------------
  19. static const char *cmDocumentationStandardOptions[][2] =
  20. {
  21. {"--help,-help,-usage,-h,-H,/?",
  22. "Print usage information and exit."},
  23. {"--version,-version,/V [<f>]",
  24. "Print version number and exit."},
  25. {"--help-manual <man> [<f>]",
  26. "Print one help manual and exit."},
  27. {"--help-manual-list [<f>]",
  28. "List help manuals available and exit."},
  29. {"--help-command <cmd> [<f>]",
  30. "Print help for one command and exit."},
  31. {"--help-command-list [<f>]",
  32. "List commands with help available and exit."},
  33. {"--help-commands [<f>]",
  34. "Print cmake-commands manual and exit."},
  35. {"--help-module <mod> [<f>]",
  36. "Print help for one module and exit."},
  37. {"--help-module-list [<f>]",
  38. "List modules with help available and exit."},
  39. {"--help-modules [<f>]",
  40. "Print cmake-modules manual and exit."},
  41. {"--help-policy <cmp> [<f>]",
  42. "Print help for one policy and exit."},
  43. {"--help-policy-list [<f>]",
  44. "List policies with help available and exit."},
  45. {"--help-policies [<f>]",
  46. "Print cmake-policies manual and exit."},
  47. {"--help-property <prop> [<f>]",
  48. "Print help for one property and exit."},
  49. {"--help-property-list [<f>]",
  50. "List properties with help available and exit."},
  51. {"--help-properties [<f>]",
  52. "Print cmake-properties manual and exit."},
  53. {"--help-variable var [<f>]",
  54. "Print help for one variable and exit."},
  55. {"--help-variable-list [<f>]",
  56. "List variables with help available and exit."},
  57. {"--help-variables [<f>]",
  58. "Print cmake-variables manual and exit."},
  59. {0,0}
  60. };
  61. //----------------------------------------------------------------------------
  62. static const char *cmDocumentationGeneratorsHeader[][2] =
  63. {
  64. {0,
  65. "The following generators are available on this platform:"},
  66. {0,0}
  67. };
  68. //----------------------------------------------------------------------------
  69. cmDocumentation::cmDocumentation()
  70. {
  71. this->addCommonStandardDocSections();
  72. this->ShowGenerators = true;
  73. }
  74. //----------------------------------------------------------------------------
  75. cmDocumentation::~cmDocumentation()
  76. {
  77. for(std::map<std::string,cmDocumentationSection *>::iterator i =
  78. this->AllSections.begin();
  79. i != this->AllSections.end(); ++i)
  80. {
  81. delete i->second;
  82. }
  83. }
  84. //----------------------------------------------------------------------------
  85. bool cmDocumentation::PrintVersion(std::ostream& os)
  86. {
  87. os <<
  88. this->GetNameString() <<
  89. " version " << cmVersion::GetCMakeVersion() << "\n"
  90. "\n"
  91. "CMake suite maintained by Kitware, Inc. (kitware.com).\n"
  92. ;
  93. return true;
  94. }
  95. //----------------------------------------------------------------------------
  96. bool cmDocumentation::PrintDocumentation(Type ht, std::ostream& os)
  97. {
  98. switch (ht)
  99. {
  100. case cmDocumentation::Usage:
  101. return this->PrintDocumentationUsage(os);
  102. case cmDocumentation::OneManual:
  103. return this->PrintHelpOneManual(os);
  104. case cmDocumentation::OneCommand:
  105. return this->PrintHelpOneCommand(os);
  106. case cmDocumentation::OneModule:
  107. return this->PrintHelpOneModule(os);
  108. case cmDocumentation::OnePolicy:
  109. return this->PrintHelpOnePolicy(os);
  110. case cmDocumentation::OneProperty:
  111. return this->PrintHelpOneProperty(os);
  112. case cmDocumentation::OneVariable:
  113. return this->PrintHelpOneVariable(os);
  114. case cmDocumentation::ListManuals:
  115. return this->PrintHelpListManuals(os);
  116. case cmDocumentation::ListCommands:
  117. return this->PrintHelpListCommands(os);
  118. case cmDocumentation::ListModules:
  119. return this->PrintHelpListModules(os);
  120. case cmDocumentation::ListProperties:
  121. return this->PrintHelpListProperties(os);
  122. case cmDocumentation::ListVariables:
  123. return this->PrintHelpListVariables(os);
  124. case cmDocumentation::ListPolicies:
  125. return this->PrintHelpListPolicies(os);
  126. case cmDocumentation::Version:
  127. return this->PrintVersion(os);
  128. default: return false;
  129. }
  130. }
  131. //----------------------------------------------------------------------------
  132. bool cmDocumentation::PrintRequestedDocumentation(std::ostream& os)
  133. {
  134. int count = 0;
  135. bool result = true;
  136. // Loop over requested documentation types.
  137. for(std::vector<RequestedHelpItem>::const_iterator
  138. i = this->RequestedHelpItems.begin();
  139. i != this->RequestedHelpItems.end();
  140. ++i)
  141. {
  142. this->CurrentArgument = i->Argument;
  143. // If a file name was given, use it. Otherwise, default to the
  144. // given stream.
  145. std::ofstream* fout = 0;
  146. std::ostream* s = &os;
  147. if(i->Filename.length() > 0)
  148. {
  149. fout = new std::ofstream(i->Filename.c_str(), std::ios::out);
  150. if(fout)
  151. {
  152. s = fout;
  153. }
  154. else
  155. {
  156. result = false;
  157. }
  158. }
  159. else if(++count > 1)
  160. {
  161. os << "\n\n";
  162. }
  163. // Print this documentation type to the stream.
  164. if(!this->PrintDocumentation(i->HelpType, *s) || !*s)
  165. {
  166. result = false;
  167. }
  168. // Close the file if we wrote one.
  169. if(fout)
  170. {
  171. delete fout;
  172. }
  173. }
  174. return result;
  175. }
  176. #define GET_OPT_ARGUMENT(target) \
  177. if((i+1 < argc) && !this->IsOption(argv[i+1])) \
  178. { \
  179. target = argv[i+1]; \
  180. i = i+1; \
  181. };
  182. void cmDocumentation::WarnFormFromFilename(
  183. cmDocumentation::RequestedHelpItem& request)
  184. {
  185. std::string ext = cmSystemTools::GetFilenameLastExtension(request.Filename);
  186. ext = cmSystemTools::UpperCase(ext);
  187. if ((ext == ".HTM") || (ext == ".HTML"))
  188. {
  189. request.HelpType = cmDocumentation::None;
  190. cmSystemTools::Message("Warning: HTML help format no longer supported");
  191. }
  192. else if (ext == ".DOCBOOK")
  193. {
  194. request.HelpType = cmDocumentation::None;
  195. cmSystemTools::Message("Warning: Docbook help format no longer supported");
  196. }
  197. // ".1" to ".9" should be manpages
  198. else if ((ext.length()==2) && (ext[1] >='1') && (ext[1]<='9'))
  199. {
  200. request.HelpType = cmDocumentation::None;
  201. cmSystemTools::Message("Warning: Man help format no longer supported");
  202. }
  203. }
  204. //----------------------------------------------------------------------------
  205. void cmDocumentation::addCommonStandardDocSections()
  206. {
  207. cmDocumentationSection *sec;
  208. sec = new cmDocumentationSection("Options","OPTIONS");
  209. sec->Append(cmDocumentationStandardOptions);
  210. this->AllSections["Options"] = sec;
  211. }
  212. //----------------------------------------------------------------------------
  213. void cmDocumentation::addCMakeStandardDocSections()
  214. {
  215. cmDocumentationSection *sec;
  216. sec = new cmDocumentationSection("Generators","GENERATORS");
  217. sec->Append(cmDocumentationGeneratorsHeader);
  218. this->AllSections["Generators"] = sec;
  219. }
  220. //----------------------------------------------------------------------------
  221. void cmDocumentation::addCTestStandardDocSections()
  222. {
  223. // This is currently done for backward compatibility reason
  224. // We may suppress some of these.
  225. addCMakeStandardDocSections();
  226. }
  227. //----------------------------------------------------------------------------
  228. void cmDocumentation::addCPackStandardDocSections()
  229. {
  230. cmDocumentationSection *sec;
  231. sec = new cmDocumentationSection("Generators","GENERATORS");
  232. sec->Append(cmDocumentationGeneratorsHeader);
  233. this->AllSections["Generators"] = sec;
  234. }
  235. //----------------------------------------------------------------------------
  236. bool cmDocumentation::CheckOptions(int argc, const char* const* argv,
  237. const char* exitOpt)
  238. {
  239. // Providing zero arguments gives usage information.
  240. if(argc == 1)
  241. {
  242. RequestedHelpItem help;
  243. help.HelpType = cmDocumentation::Usage;
  244. this->RequestedHelpItems.push_back(help);
  245. return true;
  246. }
  247. // Search for supported help options.
  248. bool result = false;
  249. for(int i=1; i < argc; ++i)
  250. {
  251. if(exitOpt && strcmp(argv[i], exitOpt) == 0)
  252. {
  253. return result;
  254. }
  255. RequestedHelpItem help;
  256. // Check if this is a supported help option.
  257. if((strcmp(argv[i], "-help") == 0) ||
  258. (strcmp(argv[i], "--help") == 0) ||
  259. (strcmp(argv[i], "/?") == 0) ||
  260. (strcmp(argv[i], "-usage") == 0) ||
  261. (strcmp(argv[i], "-h") == 0) ||
  262. (strcmp(argv[i], "-H") == 0))
  263. {
  264. help.HelpType = cmDocumentation::Usage;
  265. GET_OPT_ARGUMENT(help.Argument);
  266. help.Argument = cmSystemTools::LowerCase(help.Argument);
  267. // special case for single command
  268. if (!help.Argument.empty())
  269. {
  270. help.HelpType = cmDocumentation::OneCommand;
  271. }
  272. }
  273. else if(strcmp(argv[i], "--help-properties") == 0)
  274. {
  275. help.HelpType = cmDocumentation::OneManual;
  276. help.Argument = "cmake-properties.7";
  277. GET_OPT_ARGUMENT(help.Filename);
  278. this->WarnFormFromFilename(help);
  279. }
  280. else if(strcmp(argv[i], "--help-policies") == 0)
  281. {
  282. help.HelpType = cmDocumentation::OneManual;
  283. help.Argument = "cmake-policies.7";
  284. GET_OPT_ARGUMENT(help.Filename);
  285. this->WarnFormFromFilename(help);
  286. }
  287. else if(strcmp(argv[i], "--help-variables") == 0)
  288. {
  289. help.HelpType = cmDocumentation::OneManual;
  290. help.Argument = "cmake-variables.7";
  291. GET_OPT_ARGUMENT(help.Filename);
  292. this->WarnFormFromFilename(help);
  293. }
  294. else if(strcmp(argv[i], "--help-modules") == 0)
  295. {
  296. help.HelpType = cmDocumentation::OneManual;
  297. help.Argument = "cmake-modules.7";
  298. GET_OPT_ARGUMENT(help.Filename);
  299. this->WarnFormFromFilename(help);
  300. }
  301. else if(strcmp(argv[i], "--help-custom-modules") == 0)
  302. {
  303. GET_OPT_ARGUMENT(help.Filename);
  304. cmSystemTools::Message(
  305. "Warning: --help-custom-modules no longer supported");
  306. return true;
  307. }
  308. else if(strcmp(argv[i], "--help-commands") == 0)
  309. {
  310. help.HelpType = cmDocumentation::OneManual;
  311. help.Argument = "cmake-commands.7";
  312. GET_OPT_ARGUMENT(help.Filename);
  313. this->WarnFormFromFilename(help);
  314. }
  315. else if(strcmp(argv[i], "--help-compatcommands") == 0)
  316. {
  317. GET_OPT_ARGUMENT(help.Filename);
  318. cmSystemTools::Message(
  319. "Warning: --help-compatcommands no longer supported");
  320. return true;
  321. }
  322. else if(strcmp(argv[i], "--help-full") == 0)
  323. {
  324. GET_OPT_ARGUMENT(help.Filename);
  325. cmSystemTools::Message("Warning: --help-full no longer supported");
  326. return true;
  327. }
  328. else if(strcmp(argv[i], "--help-html") == 0)
  329. {
  330. GET_OPT_ARGUMENT(help.Filename);
  331. cmSystemTools::Message("Warning: --help-html no longer supported");
  332. return true;
  333. }
  334. else if(strcmp(argv[i], "--help-man") == 0)
  335. {
  336. GET_OPT_ARGUMENT(help.Filename);
  337. cmSystemTools::Message("Warning: --help-man no longer supported");
  338. return true;
  339. }
  340. else if(strcmp(argv[i], "--help-command") == 0)
  341. {
  342. help.HelpType = cmDocumentation::OneCommand;
  343. GET_OPT_ARGUMENT(help.Argument);
  344. GET_OPT_ARGUMENT(help.Filename);
  345. help.Argument = cmSystemTools::LowerCase(help.Argument);
  346. this->WarnFormFromFilename(help);
  347. }
  348. else if(strcmp(argv[i], "--help-module") == 0)
  349. {
  350. help.HelpType = cmDocumentation::OneModule;
  351. GET_OPT_ARGUMENT(help.Argument);
  352. GET_OPT_ARGUMENT(help.Filename);
  353. this->WarnFormFromFilename(help);
  354. }
  355. else if(strcmp(argv[i], "--help-property") == 0)
  356. {
  357. help.HelpType = cmDocumentation::OneProperty;
  358. GET_OPT_ARGUMENT(help.Argument);
  359. GET_OPT_ARGUMENT(help.Filename);
  360. this->WarnFormFromFilename(help);
  361. }
  362. else if(strcmp(argv[i], "--help-policy") == 0)
  363. {
  364. help.HelpType = cmDocumentation::OnePolicy;
  365. GET_OPT_ARGUMENT(help.Argument);
  366. GET_OPT_ARGUMENT(help.Filename);
  367. this->WarnFormFromFilename(help);
  368. }
  369. else if(strcmp(argv[i], "--help-variable") == 0)
  370. {
  371. help.HelpType = cmDocumentation::OneVariable;
  372. GET_OPT_ARGUMENT(help.Argument);
  373. GET_OPT_ARGUMENT(help.Filename);
  374. this->WarnFormFromFilename(help);
  375. }
  376. else if(strcmp(argv[i], "--help-manual") == 0)
  377. {
  378. help.HelpType = cmDocumentation::OneManual;
  379. GET_OPT_ARGUMENT(help.Argument);
  380. GET_OPT_ARGUMENT(help.Filename);
  381. this->WarnFormFromFilename(help);
  382. }
  383. else if(strcmp(argv[i], "--help-command-list") == 0)
  384. {
  385. help.HelpType = cmDocumentation::ListCommands;
  386. GET_OPT_ARGUMENT(help.Filename);
  387. }
  388. else if(strcmp(argv[i], "--help-module-list") == 0)
  389. {
  390. help.HelpType = cmDocumentation::ListModules;
  391. GET_OPT_ARGUMENT(help.Filename);
  392. }
  393. else if(strcmp(argv[i], "--help-property-list") == 0)
  394. {
  395. help.HelpType = cmDocumentation::ListProperties;
  396. GET_OPT_ARGUMENT(help.Filename);
  397. }
  398. else if(strcmp(argv[i], "--help-variable-list") == 0)
  399. {
  400. help.HelpType = cmDocumentation::ListVariables;
  401. GET_OPT_ARGUMENT(help.Filename);
  402. }
  403. else if(strcmp(argv[i], "--help-policy-list") == 0)
  404. {
  405. help.HelpType = cmDocumentation::ListPolicies;
  406. GET_OPT_ARGUMENT(help.Filename);
  407. }
  408. else if(strcmp(argv[i], "--help-manual-list") == 0)
  409. {
  410. help.HelpType = cmDocumentation::ListManuals;
  411. GET_OPT_ARGUMENT(help.Filename);
  412. }
  413. else if(strcmp(argv[i], "--copyright") == 0)
  414. {
  415. GET_OPT_ARGUMENT(help.Filename);
  416. cmSystemTools::Message("Warning: --copyright no longer supported");
  417. return true;
  418. }
  419. else if((strcmp(argv[i], "--version") == 0) ||
  420. (strcmp(argv[i], "-version") == 0) ||
  421. (strcmp(argv[i], "/V") == 0))
  422. {
  423. help.HelpType = cmDocumentation::Version;
  424. GET_OPT_ARGUMENT(help.Filename);
  425. }
  426. if(help.HelpType != None)
  427. {
  428. // This is a help option. See if there is a file name given.
  429. result = true;
  430. this->RequestedHelpItems.push_back(help);
  431. }
  432. }
  433. return result;
  434. }
  435. //----------------------------------------------------------------------------
  436. void cmDocumentation::SetName(const char* name)
  437. {
  438. this->NameString = name?name:"";
  439. }
  440. //----------------------------------------------------------------------------
  441. void cmDocumentation::SetSection(const char *name,
  442. cmDocumentationSection *section)
  443. {
  444. if (this->AllSections.find(name) != this->AllSections.end())
  445. {
  446. delete this->AllSections[name];
  447. }
  448. this->AllSections[name] = section;
  449. }
  450. //----------------------------------------------------------------------------
  451. void cmDocumentation::SetSection(const char *name,
  452. std::vector<cmDocumentationEntry> &docs)
  453. {
  454. cmDocumentationSection *sec =
  455. new cmDocumentationSection(name,
  456. cmSystemTools::UpperCase(name).c_str());
  457. sec->Append(docs);
  458. this->SetSection(name,sec);
  459. }
  460. //----------------------------------------------------------------------------
  461. void cmDocumentation::SetSection(const char *name,
  462. const char *docs[][2])
  463. {
  464. cmDocumentationSection *sec =
  465. new cmDocumentationSection(name,
  466. cmSystemTools::UpperCase(name).c_str());
  467. sec->Append(docs);
  468. this->SetSection(name,sec);
  469. }
  470. //----------------------------------------------------------------------------
  471. void cmDocumentation
  472. ::SetSections(std::map<std::string,cmDocumentationSection *> &sections)
  473. {
  474. for (std::map<std::string,cmDocumentationSection *>::const_iterator
  475. it = sections.begin(); it != sections.end(); ++it)
  476. {
  477. this->SetSection(it->first.c_str(),it->second);
  478. }
  479. }
  480. //----------------------------------------------------------------------------
  481. void cmDocumentation::PrependSection(const char *name,
  482. const char *docs[][2])
  483. {
  484. cmDocumentationSection *sec = 0;
  485. if (this->AllSections.find(name) == this->AllSections.end())
  486. {
  487. sec = new cmDocumentationSection
  488. (name, cmSystemTools::UpperCase(name).c_str());
  489. this->SetSection(name,sec);
  490. }
  491. else
  492. {
  493. sec = this->AllSections[name];
  494. }
  495. sec->Prepend(docs);
  496. }
  497. //----------------------------------------------------------------------------
  498. void cmDocumentation::PrependSection(const char *name,
  499. std::vector<cmDocumentationEntry> &docs)
  500. {
  501. cmDocumentationSection *sec = 0;
  502. if (this->AllSections.find(name) == this->AllSections.end())
  503. {
  504. sec = new cmDocumentationSection
  505. (name, cmSystemTools::UpperCase(name).c_str());
  506. this->SetSection(name,sec);
  507. }
  508. else
  509. {
  510. sec = this->AllSections[name];
  511. }
  512. sec->Prepend(docs);
  513. }
  514. //----------------------------------------------------------------------------
  515. void cmDocumentation::AppendSection(const char *name,
  516. const char *docs[][2])
  517. {
  518. cmDocumentationSection *sec = 0;
  519. if (this->AllSections.find(name) == this->AllSections.end())
  520. {
  521. sec = new cmDocumentationSection
  522. (name, cmSystemTools::UpperCase(name).c_str());
  523. this->SetSection(name,sec);
  524. }
  525. else
  526. {
  527. sec = this->AllSections[name];
  528. }
  529. sec->Append(docs);
  530. }
  531. //----------------------------------------------------------------------------
  532. void cmDocumentation::AppendSection(const char *name,
  533. std::vector<cmDocumentationEntry> &docs)
  534. {
  535. cmDocumentationSection *sec = 0;
  536. if (this->AllSections.find(name) == this->AllSections.end())
  537. {
  538. sec = new cmDocumentationSection
  539. (name, cmSystemTools::UpperCase(name).c_str());
  540. this->SetSection(name,sec);
  541. }
  542. else
  543. {
  544. sec = this->AllSections[name];
  545. }
  546. sec->Append(docs);
  547. }
  548. //----------------------------------------------------------------------------
  549. void cmDocumentation::AppendSection(const char *name,
  550. cmDocumentationEntry &docs)
  551. {
  552. std::vector<cmDocumentationEntry> docsVec;
  553. docsVec.push_back(docs);
  554. this->AppendSection(name,docsVec);
  555. }
  556. //----------------------------------------------------------------------------
  557. void cmDocumentation::PrependSection(const char *name,
  558. cmDocumentationEntry &docs)
  559. {
  560. std::vector<cmDocumentationEntry> docsVec;
  561. docsVec.push_back(docs);
  562. this->PrependSection(name,docsVec);
  563. }
  564. //----------------------------------------------------------------------------
  565. void cmDocumentation::GlobHelp(std::vector<std::string>& files,
  566. std::string const& pattern)
  567. {
  568. cmsys::Glob gl;
  569. std::string findExpr =
  570. cmSystemTools::GetCMakeRoot() + "/Help/" + pattern + ".rst";
  571. if(gl.FindFiles(findExpr))
  572. {
  573. files = gl.GetFiles();
  574. }
  575. }
  576. //----------------------------------------------------------------------------
  577. void cmDocumentation::PrintNames(std::ostream& os,
  578. std::string const& pattern)
  579. {
  580. std::vector<std::string> files;
  581. this->GlobHelp(files, pattern);
  582. std::vector<std::string> names;
  583. for (std::vector<std::string>::const_iterator i = files.begin();
  584. i != files.end(); ++i)
  585. {
  586. std::string line;
  587. std::ifstream fin(i->c_str());
  588. while(fin && cmSystemTools::GetLineFromStream(fin, line))
  589. {
  590. if(!line.empty() && (isalnum(line[0]) || line[0] == '<'))
  591. {
  592. names.push_back(line);
  593. break;
  594. }
  595. }
  596. }
  597. std::sort(names.begin(), names.end());
  598. for (std::vector<std::string>::iterator i = names.begin();
  599. i != names.end(); ++i)
  600. {
  601. os << *i << "\n";
  602. }
  603. }
  604. //----------------------------------------------------------------------------
  605. bool cmDocumentation::PrintFiles(std::ostream& os,
  606. std::string const& pattern)
  607. {
  608. bool found = false;
  609. std::vector<std::string> files;
  610. this->GlobHelp(files, pattern);
  611. std::sort(files.begin(), files.end());
  612. cmRST r(os, cmSystemTools::GetCMakeRoot() + "/Help");
  613. for (std::vector<std::string>::const_iterator i = files.begin();
  614. i != files.end(); ++i)
  615. {
  616. found = r.ProcessFile(i->c_str()) || found;
  617. }
  618. return found;
  619. }
  620. //----------------------------------------------------------------------------
  621. bool cmDocumentation::PrintHelpOneManual(std::ostream& os)
  622. {
  623. std::string mname = this->CurrentArgument;
  624. std::string::size_type mlen = mname.length();
  625. if(mlen > 3 && mname[mlen-3] == '(' &&
  626. mname[mlen-1] == ')')
  627. {
  628. mname = mname.substr(0, mlen-3) + "." + mname[mlen-2];
  629. }
  630. if(this->PrintFiles(os, "manual/" + mname) ||
  631. this->PrintFiles(os, "manual/" + mname + ".[0-9]"))
  632. {
  633. return true;
  634. }
  635. // Argument was not a manual. Complain.
  636. os << "Argument \"" << this->CurrentArgument.c_str()
  637. << "\" to --help-manual is not an available manual. "
  638. << "Use --help-manual-list to see all available manuals.\n";
  639. return false;
  640. }
  641. //----------------------------------------------------------------------------
  642. bool cmDocumentation::PrintHelpListManuals(std::ostream& os)
  643. {
  644. this->PrintNames(os, "manual/*");
  645. return true;
  646. }
  647. //----------------------------------------------------------------------------
  648. bool cmDocumentation::PrintHelpOneCommand(std::ostream& os)
  649. {
  650. std::string cname = cmSystemTools::LowerCase(this->CurrentArgument);
  651. if(this->PrintFiles(os, "command/" + cname))
  652. {
  653. return true;
  654. }
  655. // Argument was not a command. Complain.
  656. os << "Argument \"" << this->CurrentArgument.c_str()
  657. << "\" to --help-command is not a CMake command. "
  658. << "Use --help-command-list to see all commands.\n";
  659. return false;
  660. }
  661. //----------------------------------------------------------------------------
  662. bool cmDocumentation::PrintHelpListCommands(std::ostream& os)
  663. {
  664. this->PrintNames(os, "command/*");
  665. return true;
  666. }
  667. //----------------------------------------------------------------------------
  668. bool cmDocumentation::PrintHelpOneModule(std::ostream& os)
  669. {
  670. std::string mname = this->CurrentArgument;
  671. if(this->PrintFiles(os, "module/" + mname))
  672. {
  673. return true;
  674. }
  675. // Argument was not a module. Complain.
  676. os << "Argument \"" << this->CurrentArgument.c_str()
  677. << "\" to --help-module is not a CMake module.\n";
  678. return false;
  679. }
  680. //----------------------------------------------------------------------------
  681. bool cmDocumentation::PrintHelpListModules(std::ostream& os)
  682. {
  683. std::vector<std::string> files;
  684. this->GlobHelp(files, "module/*");
  685. std::vector<std::string> modules;
  686. for (std::vector<std::string>::iterator fi = files.begin();
  687. fi != files.end(); ++fi)
  688. {
  689. std::string module = cmSystemTools::GetFilenameName(*fi);
  690. modules.push_back(module.substr(0, module.size()-4));
  691. }
  692. std::sort(modules.begin(), modules.end());
  693. for (std::vector<std::string>::iterator i = modules.begin();
  694. i != modules.end(); ++i)
  695. {
  696. os << *i << "\n";
  697. }
  698. return true;
  699. }
  700. //----------------------------------------------------------------------------
  701. bool cmDocumentation::PrintHelpOneProperty(std::ostream& os)
  702. {
  703. std::string pname = cmSystemTools::HelpFileName(this->CurrentArgument);
  704. if(this->PrintFiles(os, "prop_*/" + pname))
  705. {
  706. return true;
  707. }
  708. // Argument was not a property. Complain.
  709. os << "Argument \"" << this->CurrentArgument.c_str()
  710. << "\" to --help-property is not a CMake property. "
  711. << "Use --help-property-list to see all properties.\n";
  712. return false;
  713. }
  714. //----------------------------------------------------------------------------
  715. bool cmDocumentation::PrintHelpListProperties(std::ostream& os)
  716. {
  717. this->PrintNames(os, "prop_*/*");
  718. return true;
  719. }
  720. //----------------------------------------------------------------------------
  721. bool cmDocumentation::PrintHelpOnePolicy(std::ostream& os)
  722. {
  723. std::string pname = this->CurrentArgument;
  724. std::vector<std::string> files;
  725. if(this->PrintFiles(os, "policy/" + pname))
  726. {
  727. return true;
  728. }
  729. // Argument was not a policy. Complain.
  730. os << "Argument \"" << this->CurrentArgument.c_str()
  731. << "\" to --help-policy is not a CMake policy.\n";
  732. return false;
  733. }
  734. //----------------------------------------------------------------------------
  735. bool cmDocumentation::PrintHelpListPolicies(std::ostream& os)
  736. {
  737. this->PrintNames(os, "policy/*");
  738. return true;
  739. }
  740. //----------------------------------------------------------------------------
  741. bool cmDocumentation::PrintHelpOneVariable(std::ostream& os)
  742. {
  743. std::string vname = cmSystemTools::HelpFileName(this->CurrentArgument);
  744. if(this->PrintFiles(os, "variable/" + vname))
  745. {
  746. return true;
  747. }
  748. // Argument was not a variable. Complain.
  749. os << "Argument \"" << this->CurrentArgument.c_str()
  750. << "\" to --help-variable is not a defined variable. "
  751. << "Use --help-variable-list to see all defined variables.\n";
  752. return false;
  753. }
  754. //----------------------------------------------------------------------------
  755. bool cmDocumentation::PrintHelpListVariables(std::ostream& os)
  756. {
  757. this->PrintNames(os, "variable/*");
  758. return true;
  759. }
  760. //----------------------------------------------------------------------------
  761. bool cmDocumentation::PrintDocumentationUsage(std::ostream& os)
  762. {
  763. std::map<std::string,cmDocumentationSection*>::iterator si;
  764. si = this->AllSections.find("Usage");
  765. if(si != this->AllSections.end())
  766. {
  767. this->Formatter.PrintSection(os, *si->second);
  768. }
  769. si = this->AllSections.find("Options");
  770. if(si != this->AllSections.end())
  771. {
  772. this->Formatter.PrintSection(os, *si->second);
  773. }
  774. if(this->ShowGenerators)
  775. {
  776. si = this->AllSections.find("Generators");
  777. if(si != this->AllSections.end())
  778. {
  779. this->Formatter.PrintSection(os, *si->second);
  780. }
  781. }
  782. return true;
  783. }
  784. //----------------------------------------------------------------------------
  785. const char* cmDocumentation::GetNameString() const
  786. {
  787. if(this->NameString.length() > 0)
  788. {
  789. return this->NameString.c_str();
  790. }
  791. else
  792. {
  793. return "CMake";
  794. }
  795. }
  796. //----------------------------------------------------------------------------
  797. bool cmDocumentation::IsOption(const char* arg) const
  798. {
  799. return ((arg[0] == '-') || (strcmp(arg, "/V") == 0) ||
  800. (strcmp(arg, "/?") == 0));
  801. }