Fix for UBSan build
[platform/upstream/doxygen.git] / src / cmdmapper.cpp
1 /******************************************************************************
2  *
3  * 
4  *
5  *
6  * Copyright (C) 1997-2012 by Dimitri van Heesch.
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation under the terms of the GNU General Public License is hereby 
10  * granted. No representations are made about the suitability of this software 
11  * for any purpose. It is provided "as is" without express or implied warranty.
12  * See the GNU General Public License for more details.
13  *
14  * Documents produced by Doxygen are derivative works derived from the
15  * input used in their production; they are not affected by this license.
16  *
17  */
18
19 #include "cmdmapper.h"
20
21 /** Call representing a mapping from a command name to a command ID. */
22 struct CommandMap
23 {
24   const char *cmdName;
25   int cmdId;
26 };
27
28 CommandMap cmdMap[] =
29 {
30   { "a",             CMD_EMPHASIS },
31   { "addindex",      CMD_ADDINDEX },
32   { "anchor",        CMD_ANCHOR },
33   { "arg",           CMD_LI },
34   { "attention",     CMD_ATTENTION },
35   { "author",        CMD_AUTHOR },
36   { "authors",       CMD_AUTHORS },
37   { "b",             CMD_BOLD },
38   { "c",             CMD_CODE },
39   { "cite",          CMD_CITE },
40   { "code",          CMD_STARTCODE },
41   { "copydoc",       CMD_COPYDOC },
42   { "copybrief",     CMD_COPYBRIEF },
43   { "copydetails",   CMD_COPYDETAILS },
44   { "copyright",     CMD_COPYRIGHT },
45   { "date",          CMD_DATE },
46   { "dontinclude",   CMD_DONTINCLUDE },
47   { "dotfile",       CMD_DOTFILE },
48   { "e",             CMD_EMPHASIS },
49   { "em",            CMD_EMPHASIS },
50   { "endcode",       CMD_ENDCODE },
51   { "endhtmlonly",   CMD_ENDHTMLONLY },
52   { "endlatexonly",  CMD_ENDLATEXONLY },
53   { "endlink",       CMD_ENDLINK },
54   { "endsecreflist", CMD_ENDSECREFLIST },
55   { "endverbatim",   CMD_ENDVERBATIM },
56   { "endxmlonly",    CMD_ENDXMLONLY },
57   { "exception",     CMD_EXCEPTION },
58   { "form",          CMD_FORMULA },
59   { "htmlinclude",   CMD_HTMLINCLUDE },
60   { "htmlonly",      CMD_HTMLONLY },
61   { "image",         CMD_IMAGE },
62   { "include",       CMD_INCLUDE },
63   { "internal",      CMD_INTERNAL },
64   { "invariant",     CMD_INVARIANT },
65   { "javalink",      CMD_JAVALINK },
66   { "latexonly",     CMD_LATEXONLY },
67   { "li",            CMD_LI },
68   { "line",          CMD_LINE },
69   { "link",          CMD_LINK },
70   { "n",             CMD_LINEBREAK },
71   { "note",          CMD_NOTE },
72   { "p",             CMD_CODE },
73   { "par",           CMD_PAR },
74   { "param",         CMD_PARAM },
75   { "post",          CMD_POST },
76   { "pre",           CMD_PRE },
77   { "ref",           CMD_REF },
78   { "refitem",       CMD_SECREFITEM },
79   { "remark",        CMD_REMARK },
80   { "remarks",       CMD_REMARK },
81   { "result",        CMD_RETURN },
82   { "return",        CMD_RETURN },
83   { "returns",       CMD_RETURN },
84   { "retval",        CMD_RETVAL },
85   { "rtfonly",       CMD_RTFONLY },
86   { "sa",            CMD_SA },
87   { "secreflist",    CMD_SECREFLIST },
88   { "section",       CMD_SECTION },
89   { "snippet",       CMD_SNIPPET },
90   { "subpage",       CMD_SUBPAGE },
91   { "subsection",    CMD_SUBSECTION },
92   { "subsubsection", CMD_SUBSUBSECTION },
93   { "paragraph",     CMD_PARAGRAPH },
94   { "see",           CMD_SA },
95   { "since",         CMD_SINCE },
96   { "skip",          CMD_SKIP },
97   { "skipline",      CMD_SKIPLINE },
98   { "xmlonly",       CMD_XMLONLY },
99   { "xrefitem",      CMD_XREFITEM },
100   { "throw",         CMD_EXCEPTION },
101   { "until",         CMD_UNTIL },
102   { "verbatim",      CMD_VERBATIM },
103   { "verbinclude",   CMD_VERBINCLUDE },
104   { "version",       CMD_VERSION },
105   { "warning",       CMD_WARNING },
106   { "throws",        CMD_EXCEPTION },
107   { "tparam",        CMD_TPARAM },
108   { "\\",            CMD_BSLASH },
109   { "@",             CMD_AT },
110   { "<",             CMD_LESS },
111   { ">",             CMD_GREATER },
112   { "&",             CMD_AMP },
113   { "$",             CMD_DOLLAR },
114   { "#",             CMD_HASH },
115   { "%",             CMD_PERCENT },
116   { "|",             CMD_PIPE },
117   { "::",            CMD_DCOLON },
118   { "\"",            CMD_QUOTE },
119   { "_internalref",  CMD_INTERNALREF },
120   { "dot",           CMD_DOT },
121   { "msc",           CMD_MSC },
122   { "enddot",        CMD_ENDDOT },
123   { "endmsc",        CMD_ENDMSC },
124   { "manonly",       CMD_MANONLY },
125   { "endmanonly",    CMD_ENDMANONLY },
126   { "includelineno", CMD_INCWITHLINES },
127   { "inheritdoc",    CMD_INHERITDOC },
128   { "mscfile",       CMD_MSCFILE },
129   { "rtfonly",       CMD_RTFONLY },
130   { "endrtfonly",    CMD_ENDRTFONLY },
131   { 0,               0 },
132 };
133
134 //----------------------------------------------------------------------------
135
136 CommandMap htmlTagMap[] =
137 {
138   { "strong",     HTML_BOLD },
139   { "center",     HTML_CENTER },
140   { "table",      HTML_TABLE },
141   { "caption",    HTML_CAPTION },
142   { "small",      HTML_SMALL },
143   { "code",       HTML_CODE },
144   { "dfn",        HTML_CODE },
145   { "var",        HTML_EMPHASIS },
146   { "img",        HTML_IMG },
147   { "pre",        HTML_PRE },
148   { "sub",        HTML_SUB },
149   { "sup",        HTML_SUP },
150   { "tr",         HTML_TR },
151   { "td",         HTML_TD },
152   { "th",         HTML_TH },
153   { "ol",         HTML_OL },
154   { "ul",         HTML_UL },
155   { "li",         HTML_LI },
156   { "tt",         XML_C /*HTML_CODE*/ },
157   { "kbd",        XML_C /*HTML_CODE*/ },
158   { "em",         HTML_EMPHASIS },
159   { "hr",         HTML_HR },
160   { "dl",         HTML_DL },
161   { "dt",         HTML_DT },
162   { "dd",         HTML_DD },
163   { "br",         HTML_BR },
164   { "i",          HTML_EMPHASIS },
165   { "a",          HTML_A },
166   { "b",          HTML_BOLD },
167   { "p",          HTML_P },
168   { "h1",         HTML_H1 },
169   { "h2",         HTML_H2 },
170   { "h3",         HTML_H3 },
171   { "h4",         HTML_H4 },
172   { "h5",         HTML_H5 },
173   { "h6",         HTML_H6 },
174   { "span",       HTML_SPAN },
175   { "div",        HTML_DIV },
176   { "blockquote", HTML_BLOCKQUOTE },
177
178   { "c",            XML_C },
179   // { "code",       XML_CODE },  <= ambiguous <code> is also a HTML tag
180   { "description",  XML_DESCRIPTION },
181   { "example",      XML_EXAMPLE },
182   { "exception",    XML_EXCEPTION },
183   { "include",      XML_INCLUDE },
184   { "item",         XML_ITEM },
185   { "list",         XML_LIST }, // type="table|bullet|number"
186   { "listheader",   XML_LISTHEADER },
187   { "para",         XML_PARA },
188   { "param",        XML_PARAM },
189   { "paramref",     XML_PARAMREF },
190   { "typeparam",    XML_TYPEPARAM },
191   { "typeparamref", XML_TYPEPARAMREF },
192   { "permission",   XML_PERMISSION },
193   { "remarks",      XML_REMARKS },
194   { "returns",      XML_RETURNS },
195   { "see",          XML_SEE },
196   { "seealso",      XML_SEEALSO },
197   { "summary",      XML_SUMMARY },
198   { "term",         XML_TERM },
199   { "value",        XML_VALUE },
200   { "inheritdoc",   XML_INHERITDOC },
201   { 0,              0 }
202 };
203
204 //----------------------------------------------------------------------------
205
206 Mapper *Mappers::cmdMapper     = new Mapper(cmdMap,TRUE);
207 Mapper *Mappers::htmlTagMapper = new Mapper(htmlTagMap,FALSE);
208
209 int Mapper::map(const char *n)
210 {
211   QCString name=n;
212   if (!m_cs) name=name.lower();
213   int *result;
214   return !name.isEmpty() && (result=m_map.find(name)) ? *result: 0;
215 }
216
217 Mapper::Mapper(const CommandMap *cm,bool caseSensitive) : m_map(89), m_cs(caseSensitive)
218 {
219   m_map.setAutoDelete(TRUE);
220   const CommandMap *p = cm;
221   while (p->cmdName)
222   {
223     m_map.insert(p->cmdName,new int(p->cmdId));
224     p++;
225   }
226 }
227
228 void Mappers::freeMappers()
229 {
230   delete cmdMapper;     cmdMapper     = 0;
231   delete htmlTagMapper; htmlTagMapper = 0;
232 }
233
234