Fix for UBSan build
[platform/upstream/doxygen.git] / src / eclipsehelp.cpp
1 /******************************************************************************
2  *
3  * Copyright (C) 1997-2012 by Dimitri van Heesch.
4  *
5  * Permission to use, copy, modify, and distribute this software and its
6  * documentation under the terms of the GNU General Public License is hereby 
7  * granted. No representations are made about the suitability of this software 
8  * for any purpose. It is provided "as is" without express or implied warranty.
9  * See the GNU General Public License for more details.
10  *
11  * Documents produced by Doxygen are derivative works derived from the
12  * input used in their production; they are not affected by this license.
13  *
14  */
15 #include "eclipsehelp.h"
16 #include "util.h"
17 #include "config.h"
18 #include "message.h"
19 #include "doxygen.h"
20
21 EclipseHelp::EclipseHelp() : m_depth(0), m_endtag(FALSE), m_tocfile(0) 
22 {
23 }
24
25 EclipseHelp::~EclipseHelp() 
26 {
27 }
28
29 void EclipseHelp::indent()
30 {
31   int i;
32   for (i=0; i<m_depth; i++)
33   {
34     m_tocstream << "  ";
35   }
36 }
37
38 void EclipseHelp::closedTag()
39 {
40   if (m_endtag) 
41   {
42     m_tocstream << "/>" << endl;
43     m_endtag = FALSE;
44   }
45 }
46
47 void EclipseHelp::openedTag()
48 {
49   if (m_endtag) 
50   {
51     m_tocstream << ">" << endl;
52     m_endtag = FALSE;
53   }
54 }
55
56 /*!
57  * \brief Initialize the Eclipse generator
58  *
59  * This method opens the XML TOC file and writes headers of the files.
60  * \sa finalize()
61  */
62 void EclipseHelp::initialize() 
63 {
64   // -- read path prefix from the configuration
65   //m_pathprefix = Config_getString("ECLIPSE_PATHPREFIX");
66   //if (m_pathprefix.isEmpty()) m_pathprefix = "html/";
67
68   // -- open the contents file 
69   QCString name = Config_getString("HTML_OUTPUT") + "/toc.xml";
70   m_tocfile = new QFile(name);
71   if (!m_tocfile->open(IO_WriteOnly)) 
72   {
73     err("Could not open file %s for writing\n", name.data());
74     exit(1);
75   }
76
77   // -- initialize its text stream
78   m_tocstream.setDevice(m_tocfile);
79   //m_tocstream.setEncoding(FTextStream::UnicodeUTF8);
80
81   // -- write the opening tag
82   QCString title = Config_getString("PROJECT_NAME");
83   if (title.isEmpty())
84   {
85     title = "Doxygen generated documentation";
86   }
87   m_tocstream << "<toc label=\"" << convertToXML(title) 
88               << "\" topic=\"" << convertToXML(m_pathprefix) 
89               << "index" << Doxygen::htmlFileExtension << "\">" << endl;
90   ++ m_depth;
91 }
92
93 /*!
94  * \brief Finish generation of the Eclipse specific help files
95  *
96  * This method writes footers of the files and closes them.
97  * \sa initialize()
98  */
99 void EclipseHelp::finalize() 
100 {
101   closedTag(); // -- close previous tag
102
103   // -- write ending tag 
104   --m_depth;
105   m_tocstream << "</toc>" << endl;
106
107   // -- close the content file
108   m_tocstream.unsetDevice();
109   m_tocfile->close();
110   delete m_tocfile; m_tocfile = 0;
111
112   QCString name = Config_getString("HTML_OUTPUT") + "/plugin.xml";
113   QFile pluginFile(name);
114   if (pluginFile.open(IO_WriteOnly))
115   {
116     QString docId = Config_getString("ECLIPSE_DOC_ID");
117     FTextStream t(&pluginFile);
118     t << "<plugin name=\""  << docId << "\" id=\"" << docId << "\"" << endl;
119     t << "        version=\"1.0.0\" provider-name=\"Doxygen\">" << endl;
120     t << "  <extension point=\"org.eclipse.help.toc\">" << endl;
121     t << "    <toc file=\"toc.xml\" primary=\"true\" />" << endl;
122     t << "  </extension>" << endl;
123     t << "</plugin>" << endl;
124   }
125 }
126
127 /*!
128  * \brief Increase the level of content hierarchy
129  */
130 void EclipseHelp::incContentsDepth() 
131 {
132   openedTag();
133   ++m_depth;
134 }
135
136 /*!
137  * \brief Decrease the level of content hierarchy
138  *
139  * It closes currently opened topic tag.
140  */
141 void EclipseHelp::decContentsDepth() 
142 {
143   // -- end of the opened topic
144   closedTag();
145   --m_depth;
146   indent();
147   m_tocstream << "</topic>" << endl;
148 }
149
150 /*!
151  * \brief Add an item to the content
152  *
153  * @param isDir Flag whether the argument \a file is a directory or a file entry
154  * @param name Name of the item
155  * @param ref URL of the item
156  * @param file Name of a file which the item is defined in (without extension)
157  * @param anchor Name of an anchor of the item.
158  * @param separateIndex not used.
159  * @param addToNavIndex not used.
160  * @param def not used.
161  */
162 void EclipseHelp::addContentsItem(
163     bool /* isDir */,
164     const char *name,
165     const char * /* ref */,
166     const char *file,
167     const char *anchor,
168     bool /* separateIndex */,
169     bool /* addToNavIndex */,
170     Definition * /*def*/) 
171 {
172   // -- write the topic tag 
173   closedTag();
174   indent();
175   m_tocstream << "<topic label=\"" << convertToXML(name) << "\"";
176   if (file) 
177   { 
178     m_tocstream << " href=\"" << convertToXML(m_pathprefix) 
179                 << file << Doxygen::htmlFileExtension;
180     if (anchor)
181     {
182       m_tocstream << "#" << anchor;
183     }
184     m_tocstream << "\"";
185   }
186   m_endtag = TRUE;
187 }
188
189 void EclipseHelp::addIndexItem(
190     Definition * /* context */,
191     MemberDef * /* md */,
192     const char * /* title */)
193 {
194 }
195
196 void EclipseHelp::addIndexFile(const char * /* name */) 
197 {
198 }
199
200 void EclipseHelp::addImageFile(const char * /* name */) 
201 {
202 }
203
204 void EclipseHelp::addStyleSheetFile(const char * /* name */) 
205 {
206 }
207