summaryrefslogtreecommitdiff
path: root/Source/cmDocumentationFormatter.cxx
blob: 6762d6677f78f89c7e365edec0b18c6f8c0e1c9d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
/*============================================================================
  CMake - Cross Platform Makefile Generator
  Copyright 2000-2009 Kitware, Inc., Insight Software Consortium

  Distributed under the OSI-approved BSD License (the "License");
  see accompanying file Copyright.txt for details.

  This software is distributed WITHOUT ANY WARRANTY; without even the
  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the License for more information.
============================================================================*/
#include "cmDocumentationFormatter.h"

cmDocumentationFormatter::cmDocumentationFormatter()
{
}

cmDocumentationFormatter::~cmDocumentationFormatter()
{
}

void cmDocumentationFormatter::PrintFormatted(std::ostream& os, 
                                              const char* text)
{
  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());
      }
    }
}

//----------------------------------------------------------------------------
std::string
cmDocumentationFormatter::ComputeSectionLinkPrefix(std::string const& name)
{
  // Map from section name to a prefix for links pointing within the
  // section.  For example, the commands section should have HTML
  // links to each command with names like #command:ADD_EXECUTABLE.
  if(name.find("Command") != name.npos)
    {
    return "command";
    }
  else if(name.find("Propert") != name.npos)
    {
    if(name.find("Global") != name.npos)
      {
      return "prop_global";
      }
    else if(name.find("Direct") != name.npos)
      {
      return "prop_dir";
      }
    else if(name.find("Target") != name.npos)
      {
      return "prop_tgt";
      }
    else if(name.find("Test") != name.npos)
      {
      return "prop_test";
      }
    else if(name.find("Source") != name.npos)
      {
      return "prop_sf";
      }
    return "property";
    }
  else if(name.find("Variable") != name.npos)
    {
    return "variable";
    }
  else if(name.find("Polic") != name.npos)
    {
    return "policy";
    }
  else if(name.find("Module") != name.npos)
    {
    return "module";
    }
  else if(name.find("Name") != name.npos ||
          name.find("Introduction") != name.npos)
    {
    return "name";
    }
  else if(name.find("Usage") != name.npos)
    {
    return "usage";
    }
  else if(name.find("Description") != name.npos)
    {
    return "desc";
    }
  else if(name.find("Generators") != name.npos)
    {
    return "gen";
    }
  else if(name.find("Options") != name.npos)
    {
    return "opt";
    }
  else if(name.find("Copyright") != name.npos)
    {
    return "copy";
    }
  else if(name.find("See Also") != name.npos)
    {
    return "see";
    }
  else if(name.find("SingleItem") != name.npos)
    {
    return "single_item";
    }
  else
    {
    std::cerr
      << "WARNING: ComputeSectionLinkPrefix failed for \"" << name << "\""
      << std::endl;
    return "other";
    }
}