[cmake-commits] alex committed CMakeLists.txt 1.393 1.394 cmDocumentation.cxx 1.66 1.67 cmDocumentation.h 1.31 1.32 cmDocumentationFormatter.h 1.5 1.6 cmDocumentationFormatterDocbook.cxx NONE 1.1 cmDocumentationFormatterDocbook.h NONE 1.1 cmDocumentationFormatterHTML.cxx 1.8 1.9 cmakemain.cxx 1.76 1.77

cmake-commits at cmake.org cmake-commits at cmake.org
Tue Feb 19 14:33:45 EST 2008


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv12467/Source

Modified Files:
	CMakeLists.txt cmDocumentation.cxx cmDocumentation.h 
	cmDocumentationFormatter.h cmDocumentationFormatterHTML.cxx 
	cmakemain.cxx 
Added Files:
	cmDocumentationFormatterDocbook.cxx 
	cmDocumentationFormatterDocbook.h 
Log Message:
ENH: add support for creating the documentation in docbook format
(http://www.oasis-open.org/docbook/xml/4.2/), which users can then convert
to other formats.
Tested with meinproc from KDE, which generates HTML pages which look good.

Alex



Index: cmDocumentation.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmDocumentation.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- cmDocumentation.h	24 Oct 2007 15:36:47 -0000	1.31
+++ cmDocumentation.h	19 Feb 2008 19:33:43 -0000	1.32
@@ -21,6 +21,7 @@
 #include "cmProperty.h"
 #include "cmDocumentationFormatter.h"
 #include "cmDocumentationFormatterHTML.h"
+#include "cmDocumentationFormatterDocbook.h"
 #include "cmDocumentationFormatterMan.h"
 #include "cmDocumentationFormatterText.h"
 #include "cmDocumentationFormatterUsage.h"
@@ -176,6 +177,7 @@
   std::vector<RequestedHelpItem> RequestedHelpItems;
   cmDocumentationFormatter* CurrentFormatter;
   cmDocumentationFormatterHTML HTMLFormatter;
+  cmDocumentationFormatterDocbook DocbookFormatter;
   cmDocumentationFormatterMan ManFormatter;
   cmDocumentationFormatterText TextFormatter;
   cmDocumentationFormatterUsage UsageFormatter;

Index: cmDocumentationFormatterHTML.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmDocumentationFormatterHTML.cxx,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- cmDocumentationFormatterHTML.cxx	17 Feb 2008 17:31:29 -0000	1.8
+++ cmDocumentationFormatterHTML.cxx	19 Feb 2008 19:33:43 -0000	1.9
@@ -32,24 +32,23 @@
 static void cmDocumentationPrintHTMLChar(std::ostream& os, char c)
 {
   // Use an escape sequence if necessary.
-  static std::map<char,std::string> escapes;
-  if (escapes.empty())
-    {
-    escapes['<'] = "&lt;";
-    escapes['>'] = "&gt;";
-    escapes['&'] = "&amp;";
-    escapes['\n'] = "<br>";
-    }
-
-  if (escapes.find(c) == escapes.end())
+  switch (c)
     {
-    // No escape sequence is needed.
-    os << c;
-    return;
-    }
-    
-  os << escapes[c];
-  return;
+    case '<': 
+      os << "&lt;";
+      break;
+    case '>':
+      os << "&gt;";
+      break;
+    case '&':
+      os << "&amp;";
+      break;
+    case '\n':
+      os << "<br>";
+      break;
+    default:
+      os << c;
+  }
 }
 
 //----------------------------------------------------------------------------

Index: cmDocumentation.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmDocumentation.cxx,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- cmDocumentation.cxx	17 Feb 2008 19:04:01 -0000	1.66
+++ cmDocumentation.cxx	19 Feb 2008 19:33:43 -0000	1.67
@@ -324,6 +324,7 @@
 bool cmDocumentation::PrintDocumentation(Type ht, std::ostream& os)
 {
   if ((this->CurrentFormatter->GetForm() != HTMLForm) 
+       && (this->CurrentFormatter->GetForm() != DocbookForm)
        && (this->CurrentFormatter->GetForm() != ManForm))
     {
     this->PrintVersion(os);
@@ -636,6 +637,11 @@
     return cmDocumentation::HTMLForm;
     }
 
+  if (ext == ".DOCBOOK")
+    {
+    return cmDocumentation::DocbookForm;
+    }
+
   // ".1" to ".9" should be manpages
   if ((ext.length()==2) && (ext[1] >='1') && (ext[1]<='9'))
     {
@@ -1216,7 +1222,8 @@
   this->CreateCustomModulesSection();
   this->AddSectionToPrint("Description");
   this->AddSectionToPrint("Custom CMake Modules");
-  this->AddSectionToPrint("Copyright");
+// the custom modules are most probably not under Kitware's copyright, Alex
+//  this->AddSectionToPrint("Copyright");
   this->AddSectionToPrint("See Also");
 
   this->CurrentFormatter->PrintHeader(this->GetNameString(), os);
@@ -1373,6 +1380,9 @@
     case HTMLForm:
       this->CurrentFormatter = &this->HTMLFormatter;
       break;
+    case DocbookForm:
+      this->CurrentFormatter = &this->DocbookFormatter;
+      break;
     case ManForm:
       this->CurrentFormatter = &this->ManFormatter;
       break;

Index: cmakemain.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmakemain.cxx,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -d -r1.76 -r1.77
--- cmakemain.cxx	13 Dec 2007 22:56:49 -0000	1.76
+++ cmakemain.cxx	19 Feb 2008 19:33:43 -0000	1.77
@@ -105,81 +105,81 @@
    "Full documentation specific to the given command is displayed. "
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
-   "page, HTML and plain text."},
+   "page, HTML, DocBook and plain text."},
   {"--help-command-list [file]", "List available listfile commands and exit.",
    "The list contains all commands for which help may be obtained by using "
    "the --help-command argument followed by a command name. "
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
-   "page, HTML and plain text."},
+   "page, HTML, DocBook and plain text."},
   {"--help-commands [file]", "Print help for all commands and exit.",
    "Full documentation specific for all current command is displayed."
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
-   "page, HTML and plain text."},
+   "page, HTML, DocBook and plain text."},
   {"--help-compatcommands [file]", "Print help for compatibility commands. ",
    "Full documentation specific for all compatibility commands is displayed."
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
-   "page, HTML and plain text."},
+   "page, HTML, DocBook and plain text."},
   {"--help-module module [file]", "Print help for a single module and exit.",
    "Full documentation specific to the given module is displayed."
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
-   "page, HTML and plain text."},
+   "page, HTML, DocBook and plain text."},
   {"--help-module-list [file]", "List available modules and exit.",
    "The list contains all modules for which help may be obtained by using "
    "the --help-module argument followed by a module name. "
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
-   "page, HTML and plain text."},
+   "page, HTML, DocBook and plain text."},
   {"--help-modules [file]", "Print help for all modules and exit.",
    "Full documentation for all modules is displayed. "
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
-   "page, HTML and plain text."},
+   "page, HTML, DocBook and plain text."},
   {"--help-custom-modules [file]" , "Print help for all custom modules and "
    "exit.",
    "Full documentation for all custom modules is displayed. "
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
-   "page, HTML and plain text."},
+   "page, HTML, DocBook and plain text."},
   {"--help-property prop [file]", 
    "Print help for a single property and exit.",
    "Full documentation specific to the given property is displayed."
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
-   "page, HTML and plain text."},
+   "page, HTML, DocBook and plain text."},
   {"--help-property-list [file]", "List available properties and exit.",
    "The list contains all properties for which help may be obtained by using "
    "the --help-property argument followed by a property name.  If a file is "
    "specified, the help is written into it."
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
-   "page, HTML and plain text."},
+   "page, HTML, DocBook and plain text."},
   {"--help-properties [file]", "Print help for all properties and exit.",
    "Full documentation for all properties is displayed."
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
-   "page, HTML and plain text."},
+   "page, HTML, DocBook and plain text."},
   {"--help-variable var [file]", 
    "Print help for a single variable and exit.",
    "Full documentation specific to the given variable is displayed."
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
-   "page, HTML and plain text."},
+   "page, HTML, DocBook and plain text."},
   {"--help-variable-list [file]", "List documented variables and exit.",
    "The list contains all variables for which help may be obtained by using "
    "the --help-variable argument followed by a variable name.  If a file is "
    "specified, the help is written into it."
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
-   "page, HTML and plain text."},
+   "page, HTML, DocBook and plain text."},
   {"--help-variables [file]", "Print help for all variables and exit.",
    "Full documentation for all variables is displayed."
    "If a file is specified, the documentation is written into and the output "
    "format is determined depending on the filename suffix. Supported are man "
-   "page, HTML and plain text."},
+   "page, HTML, DocBook and plain text."},
   {0,0,0}
 };
 
@@ -187,7 +187,13 @@
 static const char * cmDocumentationSeeAlso[][3] =
 {
   {0, "ccmake", 0},
+  {0, "cpack", 0},
   {0, "ctest", 0},
+  {0, "cmakecommands", 0},
+  {0, "cmakecompat", 0},
+  {0, "cmakemodules", 0},
+  {0, "cmakeprops", 0},
+  {0, "cmakevars", 0},
   {0, 0, 0}
 };
 

Index: CMakeLists.txt
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/CMakeLists.txt,v
retrieving revision 1.393
retrieving revision 1.394
diff -u -d -r1.393 -r1.394
--- CMakeLists.txt	7 Feb 2008 21:14:05 -0000	1.393
+++ CMakeLists.txt	19 Feb 2008 19:33:43 -0000	1.394
@@ -115,6 +115,7 @@
   cmDocumentation.cxx
   cmDocumentationFormatter.cxx
   cmDocumentationFormatterHTML.cxx
+  cmDocumentationFormatterDocbook.cxx
   cmDocumentationFormatterMan.cxx
   cmDocumentationFormatterText.cxx
   cmDocumentationFormatterUsage.cxx

--- NEW FILE: cmDocumentationFormatterDocbook.cxx ---
/*=========================================================================

  Program:   CMake - Cross-Platform Makefile Generator
  Module:    $RCSfile: cmDocumentationFormatterDocbook.cxx,v $
  Language:  C++
  Date:      $Date: 2008/02/19 19:33:43 $
  Version:   $Revision: 1.1 $

  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 "cmDocumentationFormatterDocbook.h"
#include "cmDocumentationSection.h"
//----------------------------------------------------------------------------

// this function is a copy of the one in the HTML formatter
// the three functions below are slightly modified copies
static bool cmDocumentationIsHyperlinkCharDocbook(char c)
{
  // This is not a complete list but works for CMake documentation.
  return ((c >= 'A' && c <= 'Z') ||
          (c >= 'a' && c <= 'z') ||
          (c >= '0' && c <= '9') ||
          c == '-' || c == '.' || c == '/' || c == '~' || c == '@' ||
          c == ':' || c == '_' || c == '&' || c == '?' || c == '=');
}

//----------------------------------------------------------------------------
static void cmDocumentationPrintDocbookChar(std::ostream& os, char c)
{
  // Use an escape sequence if necessary.
  switch(c)
  {
    case '<':
      os << "&lt;";
      break;
    case '>': 
      os << "&gt;";
      break;
    case '&':
      os << "&amp;";
      break;
    default:
      os << c;
  }
}

//----------------------------------------------------------------------------
const char* cmDocumentationPrintDocbookLink(std::ostream& os,const char* begin)
{
  // Look for the end of the link.
  const char* end = begin;
  while(cmDocumentationIsHyperlinkCharDocbook(*end))
    {
    ++end;
    }

  // Print the hyperlink itself.
  os << "<ulink url=\"";
  for(const char* c = begin; c != end; ++c)
    {
    cmDocumentationPrintDocbookChar(os, *c);
    }
  os << "\" />";

  return end;
}

//----------------------------------------------------------------------------
void cmDocumentationPrintDocbookEscapes(std::ostream& os, const char* text)
{
  // Hyperlink prefixes.
  static const char* hyperlinks[] = {"http://", "ftp://", "mailto:", 0};

  // Print each character.
  for(const char* p = text; *p;)
    {
    // Handle hyperlinks specially to make them active.
    bool found_hyperlink = false;
    for(const char** h = hyperlinks; !found_hyperlink && *h; ++h)
      {
      if(strncmp(p, *h, strlen(*h)) == 0)
        {
        p = cmDocumentationPrintDocbookLink(os, p);
        found_hyperlink = true;
        }
      }

    // Print other characters normally.
    if(!found_hyperlink)
      {
      cmDocumentationPrintDocbookChar(os, *p++);
      }
    }
}


cmDocumentationFormatterDocbook::cmDocumentationFormatterDocbook()
:cmDocumentationFormatter()
{
}

void cmDocumentationFormatterDocbook
::PrintSection(std::ostream& os,
               const cmDocumentationSection &section,
               const char* name)
{
  if(name)
    {
    std::string id = "section_";
    id += name;
    if (this->EmittedLinkIds.find(id) == this->EmittedLinkIds.end())
      {
      this->EmittedLinkIds.insert(id);
      os << "<sect1 id=\"section_" << name << "\">\n"
            "<title>\n" << name << "</title>\n";
      }
    else
      {
      static unsigned int i=0;
      i++;
      os << "<sect1 id=\"section_" << name << i << "\">\n"
            "<title>\n" << name << "</title>\n";
      }
    }

  const std::vector<cmDocumentationEntry> &entries = 
    section.GetEntries();

  os << "<itemizedlist>\n";
  for(std::vector<cmDocumentationEntry>::const_iterator op 
        = entries.begin(); op != entries.end(); ++ op )
    {
    if(op->Name.size())
      {
      os << "    <listitem><link linkend=\"command_";
      cmDocumentationPrintDocbookEscapes(os, op->Name.c_str());
      os << "\"><emphasis><literal>";
      cmDocumentationPrintDocbookEscapes(os, op->Name.c_str());
      os << "</literal></emphasis></link></listitem>";
      }
    }
  os << "</itemizedlist>\n" ;

  for(std::vector<cmDocumentationEntry>::const_iterator op = entries.begin(); 
      op != entries.end();)
    {
    if(op->Name.size())
      {
      for(;op != entries.end() && op->Name.size(); ++op)
        {
        if(op->Name.size())
          {
          os << "    <para id=\"command_";
          cmDocumentationPrintDocbookEscapes(os, op->Name.c_str());

          // make sure that each id exists only once, e.g. 
          // command_COMPILE_DEFINITIONS exists at least twice. Since it seems
          // not easily possible to determine which link refers to which id, 
          // we have at least to make sure that the duplicated id's get a 
          // different name (by appending an increasing number), Alex
          std::string id = "command_";
          id += op->Name;
          if (this->EmittedLinkIds.find(id) == this->EmittedLinkIds.end())
            {
            this->EmittedLinkIds.insert(id);
            }
          else
            {
            static unsigned int i=0;
            i++;
            os << i;
            }
          // continue as normal...

          os << "\"><sect2><title>";
          cmDocumentationPrintDocbookEscapes(os, op->Name.c_str());
          os << "</title></sect2> ";
          }
        cmDocumentationPrintDocbookEscapes(os, op->Brief.c_str());
        if(op->Name.size())
          {
          os << "</para>\n";
          }

        if(op->Full.size())
          {
          // a line break seems to be simply a line break with docbook
          os << "\n    ";  
          this->PrintFormatted(os, op->Full.c_str());
          }
        os << "\n";
        }
      }
    else
      {
      this->PrintFormatted(os, op->Brief.c_str());
      os << "\n";
      ++op;
      }
    }
  if(name)
    {
    os << "</sect1>\n";
    }
}

void cmDocumentationFormatterDocbook::PrintPreformatted(std::ostream& os, 
                                                     const char* text)
{
  os << "<literallayout>";
  cmDocumentationPrintDocbookEscapes(os, text);
  os << "</literallayout>\n    ";
}

void cmDocumentationFormatterDocbook::PrintParagraph(std::ostream& os, 
                                                  const char* text)
{
  os << "<para>";
  cmDocumentationPrintDocbookEscapes(os, text);
  os << "</para>";
}

//----------------------------------------------------------------------------
void cmDocumentationFormatterDocbook::PrintHeader(const char* name, 
                                               std::ostream& os)
{
  // this one is used to ensure that we don't create multiple link targets
  // with the same name. We can clear it here since we are at the 
  // start of a document here.
  this->EmittedLinkIds.clear();

  os << "<?xml version=\"1.0\" ?>\n"
        "<!DOCTYPE article PUBLIC \"-//OASIS//DTD DocBook V4.2//EN\" "
        "\"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd\" [\n"
        "<!ENTITY % addindex \"IGNORE\">\n"
        "<!ENTITY % English \"INCLUDE\"> ]>\n"
        "<article>\n"
        "<articleinfo>\n"
        "<title>" << name << "</title>\n"
        "</articleinfo>\n";
}

//----------------------------------------------------------------------------
void cmDocumentationFormatterDocbook::PrintFooter(std::ostream& os)
{
  os << "</article>\n";
}


Index: cmDocumentationFormatter.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmDocumentationFormatter.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- cmDocumentationFormatter.h	24 Oct 2007 15:36:47 -0000	1.5
+++ cmDocumentationFormatter.h	19 Feb 2008 19:33:43 -0000	1.6
@@ -36,7 +36,7 @@
     CompatCommands, Copyright, Version };
 
   /** Forms of documentation output.  */
-  enum Form { TextForm, HTMLForm, ManForm, UsageForm };
+  enum Form { TextForm, HTMLForm, ManForm, UsageForm, DocbookForm };
 };
 
 class cmDocumentationSection;

--- NEW FILE: cmDocumentationFormatterDocbook.h ---
/*=========================================================================

  Program:   CMake - Cross-Platform Makefile Generator
  Module:    $RCSfile: cmDocumentationFormatterDocbook.h,v $
  Language:  C++
  Date:      $Date: 2008/02/19 19:33:43 $
  Version:   $Revision: 1.1 $

  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.

=========================================================================*/
#ifndef _cmDocumentationFormatterDocbook_h
#define _cmDocumentationFormatterDocbook_h

#include "cmStandardIncludes.h"

#include "cmDocumentationFormatter.h"

/** Class to print the documentation as Docbook.
 http://www.oasis-open.org/docbook/xml/4.2/   */
class cmDocumentationFormatterDocbook : public cmDocumentationFormatter
{
public:
  cmDocumentationFormatterDocbook();

  virtual cmDocumentationEnums::Form GetForm() const
                                  { return cmDocumentationEnums::DocbookForm;}

  virtual void PrintHeader(const char* name, std::ostream& os);
  virtual void PrintFooter(std::ostream& os);
  virtual void PrintSection(std::ostream& os,
                            const cmDocumentationSection& section,
                            const char* name);
  virtual void PrintPreformatted(std::ostream& os, const char* text);
  virtual void PrintParagraph(std::ostream& os, const char* text);
private:
  std::set<std::string> EmittedLinkIds;
};

#endif



More information about the Cmake-commits mailing list