cmDocumentation.cxx 26.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*=========================================================================

  Program:   CMake - Cross-Platform Makefile Generator
  Module:    $RCSfile$
  Language:  C++
  Date:      $Date$
  Version:   $Revision$

  Copyright (c) 2002 Kitware, Inc., Insight Consortium.  All rights reserved.
  See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#include "cmDocumentation.h"

#include "cmSystemTools.h"

//----------------------------------------------------------------------------
static const cmDocumentationEntry cmDocumentationStandardOptions[] =
{
  {"--copyright", "Print the CMake copyright and exit.", 0},
25
  {"--help", "Print usage information and exit.",
26
   "Usage describes the basic command line interface and its options."},
27
  {"--help-full", "Print full help and exit.",
28
29
30
31
32
   "Full help displays most of the documentation provided by the UNIX "
   "man page.  It is provided for use on non-UNIX platforms, but is "
   "also convenient if the man page is not installed."},
  {"--help-html", "Print full help in HTML format.",
   "This option is used by CMake authors to help produce web pages."},
Andy Cedilnik's avatar
Andy Cedilnik committed
33
  {"--help-man", "Print a UNIX man page and exit.",
34
35
36
37
38
   "This option is used by CMake authors to generate the UNIX man page."},
  {"--version", "Show program name/version banner and exit.", 0},
  {0,0,0}
};

39
40
41
42
43
44
45
46
//----------------------------------------------------------------------------
static const cmDocumentationEntry cmDocumentationCommandsHeader[] =
{
  {0,
   "The following commands are available in CMakeLists.txt code:", 0},
  {0,0,0}
};

47
48
49
50
51
52
53
54
//----------------------------------------------------------------------------
static const cmDocumentationEntry cmDocumentationGeneratorsHeader[] =
{
  {0,
   "The following generators are available on this platform:", 0},
  {0,0,0}
};

Andy Cedilnik's avatar
Andy Cedilnik committed
55
56
57
58
59
//----------------------------------------------------------------------------
const cmDocumentationEntry cmDocumentationMailingList[] =
{
  {0,
   "For help and discussion about using cmake, a mailing list is provided "
60
   "at cmake@www.cmake.org.  Please first read the full documentation at "
Andy Cedilnik's avatar
Andy Cedilnik committed
61
62
63
64
   "http://www.cmake.org before posting questions to the list.", 0},
  {0,0,0}
};

65
66
67
68
69
70
71
72
//----------------------------------------------------------------------------
const cmDocumentationEntry cmDocumentationAuthor[] =
{
  {0,
   "This manual page was generated by \"cmake --help-man\".", 0},
  {0,0,0}
};

73
74
75
76
//----------------------------------------------------------------------------
const cmDocumentationEntry cmDocumentationCopyright[] =
{
  {0,
77
78
   "Copyright (c) 2002 Kitware, Inc., Insight Consortium.  "
   "All rights reserved.", 0},
79
80
81
  {0,
   "Redistribution and use in source and binary forms, with or without "
   "modification, are permitted provided that the following conditions are "
82
83
   "met:", 0},
  {"",
84
   "Redistributions of source code must retain the above copyright notice, "
85
86
   "this list of conditions and the following disclaimer.", 0},
  {"",
87
88
   "Redistributions in binary form must reproduce the above copyright "
   "notice, this list of conditions and the following disclaimer in the "
89
   "documentation and/or other materials provided with the distribution.",
90
   0},
91
  {"",
92
93
94
   "The names of Kitware, Inc., the Insight Consortium, or the names of "
   "any consortium members, or of any contributors, may not be used to "
   "endorse or promote products derived from this software without "
95
96
   "specific prior written permission.", 0},
  {"",
97
   "Modified source versions must be plainly marked as such, and must "
98
   "not be misrepresented as being the original software.", 0},
99
100
101
102
103
104
105
106
107
108
109
  {0,
   "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "
   "``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT "
   "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR "
   "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR "
   "CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, "
   "EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, "
   "PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR "
   "PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF "
   "LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING "
   "NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS "
110
   "SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.", 0},
111
112
113
114
115
116
  {0, 0, 0}
};

//----------------------------------------------------------------------------
cmDocumentation::cmDocumentation()
{
117
118
119
  this->CurrentForm = TextForm;
  this->TextIndent = "";
  this->TextWidth = 77;
120
121
122
}

//----------------------------------------------------------------------------
123
void cmDocumentation::PrintCopyright(std::ostream& os)
124
{
125
  os << "CMake version " CMake_VERSION_FULL "\n";
126
127
  for(const cmDocumentationEntry* op = cmDocumentationCopyright;
      op->brief; ++op)
128
129
130
    {
    if(op->name)
      {
131
132
133
      os << " * ";
      this->TextIndent = "    ";
      this->PrintColumn(os, op->brief);
134
135
136
      }
    else
      {
137
138
      this->TextIndent = "";
      this->PrintColumn(os, op->brief);
139
      }
140
141
    os << "\n";
    }
142
143
144
}

//----------------------------------------------------------------------------
145
void cmDocumentation::PrintVersion(std::ostream& os)
146
{
147
  os << "CMake version " CMake_VERSION_FULL "\n";
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
}

//----------------------------------------------------------------------------
void cmDocumentation::AddSection(const char* name,
                                 const cmDocumentationEntry* d)
{
  this->Names.push_back(name);
  this->Sections.push_back(d);
}

//----------------------------------------------------------------------------
void cmDocumentation::ClearSections()
{
  this->Names.erase(this->Names.begin(), this->Names.end());
  this->Sections.erase(this->Sections.begin(), this->Sections.end());
}

//----------------------------------------------------------------------------
void cmDocumentation::PrintDocumentation(Type ht, std::ostream& os)
{
  switch (ht)
169
    {
170
171
172
173
174
175
176
177
    case cmDocumentation::Usage:     this->PrintDocumentationUsage(os); break;
    case cmDocumentation::Full:      this->PrintDocumentationFull(os); break;
    case cmDocumentation::HTML:      this->PrintDocumentationHTML(os); break;
    case cmDocumentation::Man:       this->PrintDocumentationMan(os); break;
    case cmDocumentation::Copyright: this->PrintCopyright(os); break;
    case cmDocumentation::Version:   this->PrintVersion(os); break;
    default: break;
    }
178
179
180
}

//----------------------------------------------------------------------------
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
bool cmDocumentation::PrintRequestedDocumentation(std::ostream& os)
{
  bool result = true;
  
  // Loop over requested documentation types.
  for(RequestedMapType::const_iterator i = this->RequestedMap.begin();
      i != this->RequestedMap.end(); ++i)
    {
    // If a file name was given, use it.  Otherwise, default to the
    // given stream.
    std::ofstream* fout = 0;
    std::ostream* s = &os;
    if(i->second.length() > 0)
      {
#ifdef _WIN32
Brad King's avatar
Brad King committed
196
      fout = new std::ofstream(i->second.c_str(), std::ios::out | std::ios::binary);
197
#else
Brad King's avatar
Brad King committed
198
      fout = new std::ofstream(i->second.c_str(), std::ios::out);
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#endif
      if(fout)
        {
        s = fout;
        }
      else
        {
        result = false;
        }
      }
    
    // Print this documentation type to the stream.
    this->PrintDocumentation(i->first, *s);
    
    // Check for error.
    if(!*s)
      {
      result = false;
      }
    
    // Close the file if we wrote one.
    if(fout)
      {
      delete fout;
      }
    }
  return result;
}

//----------------------------------------------------------------------------
bool cmDocumentation::CheckOptions(int argc, char** argv)
230
{
231
232
233
  // Providing zero arguments gives usage information.
  if(argc == 1)
    {
234
235
    this->RequestedMap[cmDocumentation::Usage] = "";
    return true;
236
237
238
    }
  
  // Search for supported help options.
239
  bool result = false;
240
  for(int i=1; i < argc; ++i)
241
    {
242
243
    // Check if this is a supported help option.
    Type type = cmDocumentation::None;
244
245
246
247
248
249
    if((strcmp(argv[i], "-help") == 0) ||
       (strcmp(argv[i], "--help") == 0) ||
       (strcmp(argv[i], "/?") == 0) ||
       (strcmp(argv[i], "-usage") == 0) ||
       (strcmp(argv[i], "-h") == 0) ||
       (strcmp(argv[i], "-H") == 0))
250
      {
251
252
253
254
255
      type = cmDocumentation::Usage;
      }
    else if(strcmp(argv[i], "--help-full") == 0)
      {
      type = cmDocumentation::Full;
256
      }
257
    else if(strcmp(argv[i], "--help-html") == 0)
258
      {
259
      type = cmDocumentation::HTML;
260
      }
261
    else if(strcmp(argv[i], "--help-man") == 0)
262
      {
263
      type = cmDocumentation::Man;
264
      }
265
    else if(strcmp(argv[i], "--copyright") == 0)
266
      {
267
      type = cmDocumentation::Copyright;
268
      }
269
270
271
272
    else if((strcmp(argv[i], "--version") == 0) || 
            (strcmp(argv[i], "-version") == 0) || 
            (strcmp(argv[i], "-V") == 0) || 
            (strcmp(argv[i], "/V") == 0))
273
      {
274
      type = cmDocumentation::Version;
275
      }
276
    if(type)
277
      {
278
279
280
281
282
283
284
285
286
287
288
289
      // This is a help option.  See if there is a file name given.
      result = true;
      if((i+1 < argc) && (argv[i+1][0] != '-') &&
         (strcmp(argv[i+1], "/V") != 0) && (strcmp(argv[i+1], "/?") != 0))
        {
        this->RequestedMap[type] = argv[i+1];
        i = i+1;
        }
      else
        {
        this->RequestedMap[type] = "";
        }
290
291
      }
    }
292
  return result;
293
294
}

295
//----------------------------------------------------------------------------
296
void cmDocumentation::Print(Form f, std::ostream& os)
297
{
298
  this->CurrentForm = f;
299
  for(unsigned int i=0; i < this->Sections.size(); ++i)
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
    {
    this->PrintSection(os, this->Sections[i], this->Names[i]);
    }
}

//----------------------------------------------------------------------------
void cmDocumentation::SetNameSection(const cmDocumentationEntry* section)
{
  this->SetSection(0, section, 0, this->NameSection);
}

//----------------------------------------------------------------------------
void cmDocumentation::SetUsageSection(const cmDocumentationEntry* section)
{
  this->SetSection(0, section, 0, this->UsageSection);
}

//----------------------------------------------------------------------------
void cmDocumentation::SetDescriptionSection(const cmDocumentationEntry* section)
{
  this->SetSection(0, section, 0, this->DescriptionSection);
}

//----------------------------------------------------------------------------
void cmDocumentation::SetOptionsSection(const cmDocumentationEntry* section)
{
  this->SetSection(0, section, cmDocumentationStandardOptions,
                   this->OptionsSection);
}

//----------------------------------------------------------------------------
void cmDocumentation::SetCommandsSection(const cmDocumentationEntry* section)
{
  this->SetSection(cmDocumentationCommandsHeader, section, 0,
                   this->CommandsSection);
}

337
338
339
340
341
342
343
//----------------------------------------------------------------------------
void cmDocumentation::SetGeneratorsSection(const cmDocumentationEntry* section)
{
  this->SetSection(cmDocumentationGeneratorsHeader, section, 0,
                   this->GeneratorsSection);
}

344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
//----------------------------------------------------------------------------
void cmDocumentation::SetSeeAlsoList(const cmDocumentationEntry* also)
{
  this->SeeAlsoString = ".B ";
  for(const cmDocumentationEntry* i = also; i->brief; ++i)
    {
    this->SeeAlsoString += i->brief;
    this->SeeAlsoString += (i+1)->brief? "(1), ":"(1)";    
    }
  cmDocumentationEntry e = {0, 0, 0};
  e.brief = this->SeeAlsoString.c_str();
  this->SeeAlsoSection.push_back(e);
  e.brief = 0;
  this->SeeAlsoSection.push_back(e);  
}

360
361
362
363
364
365
366
367
368
369
370
371
//----------------------------------------------------------------------------
void cmDocumentation::PrintSection(std::ostream& os,
                                   const cmDocumentationEntry* section,
                                   const char* name)
{
  switch (this->CurrentForm)
    {
    case TextForm: this->PrintSectionText(os, section, name); break;
    case HTMLForm: this->PrintSectionHTML(os, section, name); break;
    case ManForm: this->PrintSectionMan(os, section, name); break;
    case UsageForm: this->PrintSectionUsage(os, section, name); break;
    }
372
373
}

374
//----------------------------------------------------------------------------
375
376
377
void cmDocumentation::PrintSectionText(std::ostream& os,
                                       const cmDocumentationEntry* section,
                                       const char* name)
378
{
379
380
  if(name)
    {
381
382
383
    os <<
      "---------------------------------------"
      "---------------------------------------\n";
384
385
    os << name << "\n\n";
    }
386
  if(!section) { return; }
387
  for(const cmDocumentationEntry* op = section; op->brief; ++op)
388
    {
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
    if(op->name)
      {
      if(op->name[0])
        {
        os << "  " << op->name << "\n";
        }
      this->TextIndent = "       ";
      this->PrintFormatted(os, op->brief);
      if(op->full)
        {
        os << "\n";
        this->PrintFormatted(os, op->full);
        }
      }
    else
      {
      this->TextIndent = "";
      this->PrintFormatted(os, op->brief);
      }
    os << "\n";
    }  
}

//----------------------------------------------------------------------------
void cmDocumentation::PrintSectionHTML(std::ostream& os,
                                       const cmDocumentationEntry* section,
                                       const char* name)
{
  if(name)
    {
    os << "<h2>" << name << "</h2>\n";
420
    }
421
  if(!section) { return; }
422
423
424
425
426
427
428
429
  for(const cmDocumentationEntry* op = section; op->brief;)
    {
    if(op->name)
      {
      os << "<ul>\n";
      for(;op->name;++op)
        {
        os << "  <li>\n";
430
431
432
433
434
435
        if(op->name[0])
          {
          os << "    <b><code>";
          this->PrintHTMLEscapes(os, op->name);
          os << "</code></b>: ";
          }
436
437
438
        this->PrintHTMLEscapes(os, op->brief);
        if(op->full)
          {
439
440
          os << "<br>\n    ";
          this->PrintFormatted(os, op->full);
441
442
443
444
445
446
447
448
          }
        os << "\n";
        os << "  </li>\n";
        }
      os << "</ul>\n";
      }
    else
      {
449
      this->PrintFormatted(os, op->brief);
450
451
452
453
454
455
456
      os << "\n";
      ++op;
      }
    }
}

//----------------------------------------------------------------------------
457
458
459
void cmDocumentation::PrintSectionMan(std::ostream& os,
                                      const cmDocumentationEntry* section,
                                      const char* name)
460
{
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
  if(name)
    {
    os << ".SH " << name << "\n";
    }
  if(!section) { return; }
  for(const cmDocumentationEntry* op = section; op->brief; ++op)
    {
    if(op->name)
      {
      os << ".TP\n"
         << ".B " << (op->name[0]?op->name:"*") << "\n";
      this->PrintFormatted(os, op->brief);
      this->PrintFormatted(os, op->full);
      }
    else
      {
      os << ".PP\n";
      this->PrintFormatted(os, op->brief);
      }
    }  
}

//----------------------------------------------------------------------------
void cmDocumentation::PrintSectionUsage(std::ostream& os,
                                        const cmDocumentationEntry* section,
                                        const char* name)
{
  if(name)
    {
    os << name << "\n";
    }
492
493
494
495
496
  if(!section) { return; }
  for(const cmDocumentationEntry* op = section; op->brief; ++op)
    {
    if(op->name)
      {
497
      os << "  " << op->name;
498
499
500
      this->TextIndent = "                             ";
      int align = static_cast<int>(strlen(this->TextIndent))-4;
      for(int i = static_cast<int>(strlen(op->name)); i < align; ++i)
501
502
503
        {
        os << " ";
        }
504
505
506
      os << "= ";
      this->PrintColumn(os, op->brief);
      os << "\n";
507
508
509
510
      }
    else
      {
      os << "\n";
511
512
      this->TextIndent = "";
      this->PrintFormatted(os, op->brief);
513
      }
514
    }
515
  os << "\n";
516
517
518
}

//----------------------------------------------------------------------------
519
void cmDocumentation::PrintFormatted(std::ostream& os, const char* text)
520
{
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
  if(!text)
    {
    return;
    }
  const char* ptr = text;
  while(*ptr)
    {
    // Any ptrs starting in a space are treated as preformatted text.
    std::string preformatted;
    while(*ptr == ' ')
      {
      for(char ch = *ptr; ch && ch != '\n'; ++ptr, ch = *ptr)
        {
        preformatted.append(1, ch);
        }
      if(*ptr)
        {
        ++ptr;
        preformatted.append(1, '\n');
        }
      }
    if(preformatted.length())
      {
      this->PrintPreformatted(os, preformatted.c_str());
      }
    
    // Other ptrs are treated as paragraphs.
    std::string paragraph;
    for(char ch = *ptr; ch && ch != '\n'; ++ptr, ch = *ptr)
      {
      paragraph.append(1, ch);
      }
    if(*ptr)
      {
      ++ptr;
      paragraph.append(1, '\n');
      }
    if(paragraph.length())
      {
      this->PrintParagraph(os, paragraph.c_str());
      }
    }
563
564
565
}

//----------------------------------------------------------------------------
566
void cmDocumentation::PrintPreformatted(std::ostream& os, const char* text)
567
{
568
  switch (this->CurrentForm)
569
    {
570
571
572
573
    case TextForm: this->PrintPreformattedText(os, text); break;
    case HTMLForm: this->PrintPreformattedHTML(os, text); break;
    case ManForm: this->PrintPreformattedMan(os, text); break;
    case UsageForm: this->PrintPreformattedText(os, text); break;
574
575
576
577
    }
}

//----------------------------------------------------------------------------
578
void cmDocumentation::PrintParagraph(std::ostream& os, const char* text)
579
{
580
581
582
583
584
585
586
  switch (this->CurrentForm)
    {
    case TextForm: this->PrintParagraphText(os, text); break;
    case HTMLForm: this->PrintParagraphHTML(os, text); break;
    case ManForm: this->PrintParagraphMan(os, text); break;
    case UsageForm: this->PrintParagraphText(os, text); break;
    }
587
588
589
}

//----------------------------------------------------------------------------
590
void cmDocumentation::PrintPreformattedText(std::ostream& os, const char* text)
591
{
592
593
  bool newline = true;
  for(const char* ptr = text; *ptr; ++ptr)
594
    {
595
    if(newline)
596
      {
597
598
      os << this->TextIndent;
      newline = false;
599
      }
600
601
    os << *ptr;
    if(*ptr == '\n')
602
      {
603
      newline = true;
604
605
      }
    }
606
  os << "\n";
607
608
609
}

//----------------------------------------------------------------------------
610
void cmDocumentation::PrintParagraphText(std::ostream& os, const char* text)
611
{
612
613
614
615
616
617
618
619
620
621
622
  os << this->TextIndent;
  this->PrintColumn(os, text);
  os << "\n";
}

//----------------------------------------------------------------------------
void cmDocumentation::PrintPreformattedHTML(std::ostream& os, const char* text)
{
  os << "<pre>";
  this->PrintHTMLEscapes(os, text);
  os << "</pre>\n    ";
623
624
625
}

//----------------------------------------------------------------------------
626
void cmDocumentation::PrintParagraphHTML(std::ostream& os, const char* text)
627
{
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
  os << "<p>";
  this->PrintHTMLEscapes(os, text);
}

//----------------------------------------------------------------------------
void cmDocumentation::PrintPreformattedMan(std::ostream& os, const char* text)
{
  os << text << "\n";
}

//----------------------------------------------------------------------------
void cmDocumentation::PrintParagraphMan(std::ostream& os, const char* text)
{
  os << text << "\n\n";
}

//----------------------------------------------------------------------------
void cmDocumentation::PrintColumn(std::ostream& os, const char* text)
{
  // Print text arranged in an indented column of fixed witdh.
648
649
650
  const char* l = text;
  int column = 0;
  bool newSentence = false;
651
  bool firstLine = true;
652
  int width = this->TextWidth - static_cast<int>(strlen(this->TextIndent));
653
654
  
  // Loop until the end of the text.
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
  while(*l)
    {
    // Parse the next word.
    const char* r = l;
    while(*r && (*r != '\n') && (*r != ' ')) { ++r; }
    
    // Does it fit on this line?
    if(r-l < (width-column-(newSentence?1:0)))
      {
      // Word fits on this line.
      if(r > l)
        {
        if(column)
          {
          // Not first word on line.  Separate from the previous word
          // by a space, or two if this is a new sentence.
          if(newSentence)
            {
            os << "  ";
            column += 2;
            }
          else
            {
            os << " ";
            column += 1;
            }
          }
        else
          {
          // First word on line.  Print indentation unless this is the
          // first line.
686
          os << (firstLine?"":this->TextIndent);
687
688
689
690
691
692
693
694
695
696
697
698
699
          }
        
        // Print the word.
        os.write(l, static_cast<long>(r-l));
        newSentence = (*(r-1) == '.');
        }
      
      if(*r == '\n')
        {
        // Text provided a newline.  Start a new line.
        os << "\n";
        ++r;
        column = 0;
700
        firstLine = false;
701
702
703
704
705
706
707
708
709
710
711
        }
      else
        {
        // No provided newline.  Continue this line.
        column += static_cast<long>(r-l);
        }
      }
    else
      {
      // Word does not fit on this line.  Start a new line.
      os << "\n";
712
      firstLine = false;
713
714
      if(r > l)
        {
715
        os << this->TextIndent;
716
717
718
719
720
721
722
723
724
725
726
727
728
        os.write(l, static_cast<long>(r-l));
        column = static_cast<long>(r-l);
        newSentence = (*(r-1) == '.');
        }
      }
    
    // Move to beginning of next word.  Skip over whitespace.
    l = r;
    while(*l && (*l == ' ')) { ++l; }    
    }
}

//----------------------------------------------------------------------------
729
void cmDocumentation::PrintHTMLEscapes(std::ostream& os, const char* text)
730
{
731
732
733
734
735
736
737
738
739
  static cmDocumentationEntry escapes[] =
  {
    {"<", "&lt;", 0},
    {">", "&gt;", 0},
    {"&", "&amp;", 0},
    {"\n", "<br>", 0},
    {0,0,0}
  };
  for(const char* p = text; *p; ++p)
740
    {
741
742
    bool found = false;
    for(const cmDocumentationEntry* op = escapes; !found && op->name; ++op)
743
      {
744
      if(op->name[0] == *p)
745
        {
746
747
        os << op->brief;
        found = true;
748
749
        }
      }
750
    if(!found)
751
      {
752
      os << *p;
753
754
755
756
757
      }
    }
}

//----------------------------------------------------------------------------
758
void cmDocumentation::PrintDocumentationUsage(std::ostream& os)
759
{
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
  this->CreateUsageDocumentation();
  this->Print(UsageForm, os);
}

//----------------------------------------------------------------------------
void cmDocumentation::PrintDocumentationFull(std::ostream& os)
{
  this->CreateFullDocumentation();
  this->Print(TextForm, os);
}

//----------------------------------------------------------------------------
void cmDocumentation::PrintDocumentationHTML(std::ostream& os)
{
  this->CreateFullDocumentation();
  os << "<html><body>\n";
  this->Print(HTMLForm, os);
  os << "</body></html>\n";
}

//----------------------------------------------------------------------------
void cmDocumentation::PrintDocumentationMan(std::ostream& os)
{
  this->CreateManDocumentation();
  os << ".TH CMake 1 \""
     << cmSystemTools::GetCurrentDateTime("%B %d, %Y").c_str()
786
     << "\" \"CMake " CMake_VERSION_FULL "\"\n";
787
788
789
790
791
792
793
794
795
796
797
798
799
800
  this->Print(ManForm, os);
}

//----------------------------------------------------------------------------
void cmDocumentation::CreateUsageDocumentation()
{
  this->ClearSections();
  if(!this->UsageSection.empty())
    {
    this->AddSection("Usage", &this->UsageSection[0]);
    }
  if(!this->OptionsSection.empty())
    {
    this->AddSection("Command-Line Options", &this->OptionsSection[0]);
801
    }
802
803
804
805
  if(!this->GeneratorsSection.empty())
    {
    this->AddSection("Generators", &this->GeneratorsSection[0]);
    }
806
807
808
}

//----------------------------------------------------------------------------
809
void cmDocumentation::CreateFullDocumentation()
810
{
811
812
  this->ClearSections();
  if(!this->NameSection.empty())
813
    {
814
    this->AddSection("Name", &this->NameSection[0]);
815
    }
816
817
818
819
820
821
822
823
824
825
826
827
  if(!this->UsageSection.empty())
    {
    this->AddSection("Usage", &this->UsageSection[0]);
    }
  if(!this->DescriptionSection.empty())
    {
    this->AddSection(0, &this->DescriptionSection[0]);
    }
  if(!this->OptionsSection.empty())
    {
    this->AddSection("Command-Line Options", &this->OptionsSection[0]);
    }
828
829
830
831
  if(!this->GeneratorsSection.empty())
    {
    this->AddSection("Generators", &this->GeneratorsSection[0]);
    }
832
833
834
835
836
837
  if(!this->CommandsSection.empty())
    {
    this->AddSection("Listfile Commands", &this->CommandsSection[0]);
    }
  this->AddSection("Copyright", cmDocumentationCopyright);
  this->AddSection("Mailing List", cmDocumentationMailingList);
838
839
840
}

//----------------------------------------------------------------------------
841
void cmDocumentation::CreateManDocumentation()
842
{
843
844
  this->ClearSections();
  if(!this->NameSection.empty())
845
    {
846
    this->AddSection("NAME", &this->NameSection[0]);
847
    }
848
  if(!this->UsageSection.empty())
849
    {
850
    this->AddSection("SYNOPSIS", &this->UsageSection[0]);
851
    }
852
853
854
855
856
857
858
859
  if(!this->DescriptionSection.empty())
    {
    this->AddSection("DESCRIPTION", &this->DescriptionSection[0]);
    }
  if(!this->OptionsSection.empty())
    {
    this->AddSection("OPTIONS", &this->OptionsSection[0]);
    }
860
861
862
863
  if(!this->GeneratorsSection.empty())
    {
    this->AddSection("GENERATORS", &this->GeneratorsSection[0]);
    }
864
865
866
867
868
  if(!this->CommandsSection.empty())
    {
    this->AddSection("COMMANDS", &this->CommandsSection[0]);
    }
  this->AddSection("COPYRIGHT", cmDocumentationCopyright);
869
870
871
872
873
  this->AddSection("MAILING LIST", cmDocumentationMailingList);  
  if(!this->SeeAlsoSection.empty())
    {
    this->AddSection("SEE ALSO", &this->SeeAlsoSection[0]);
    }
874
  this->AddSection("AUTHOR", cmDocumentationAuthor);
875
}
876
877

//----------------------------------------------------------------------------
878
879
880
881
void cmDocumentation::SetSection(const cmDocumentationEntry* header,
                                 const cmDocumentationEntry* section,
                                 const cmDocumentationEntry* footer,
                                 std::vector<cmDocumentationEntry>& vec)
882
{
883
884
  vec.erase(vec.begin(), vec.end());
  if(header)
885
    {
886
887
888
889
890
891
892
893
894
895
896
    for(const cmDocumentationEntry* op = header; op->brief; ++op)
      {
      vec.push_back(*op);
      }
    }
  if(section)
    {
    for(const cmDocumentationEntry* op = section; op->brief; ++op)
      {
      vec.push_back(*op);
      }
897
    }
898
  if(footer)
899
    {
900
    for(const cmDocumentationEntry* op = footer; op->brief; ++op)
901
      {
902
      vec.push_back(*op);
903
904
905
      }
    }
  cmDocumentationEntry empty = {0,0,0};
906
  vec.push_back(empty);  
907
}