2c8effcbf4fe65d3c89a664f8e6afe0a0bafd8c4
[platform/upstream/doxygen.git] / src / cmdmapper.cpp
1 /******************************************************************************
2  *
3  * 
4  *
5  *
6  * Copyright (C) 1997-2015 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   { "latexinclude",  CMD_LATEXINCLUDE },
67   { "latexonly",     CMD_LATEXONLY },
68   { "li",            CMD_LI },
69   { "line",          CMD_LINE },
70   { "link",          CMD_LINK },
71   { "n",             CMD_LINEBREAK },
72   { "note",          CMD_NOTE },
73   { "p",             CMD_CODE },
74   { "par",           CMD_PAR },
75   { "param",         CMD_PARAM },
76   { "post",          CMD_POST },
77   { "pre",           CMD_PRE },
78   { "ref",           CMD_REF },
79   { "refitem",       CMD_SECREFITEM },
80   { "remark",        CMD_REMARK },
81   { "remarks",       CMD_REMARK },
82   { "result",        CMD_RETURN },
83   { "return",        CMD_RETURN },
84   { "returns",       CMD_RETURN },
85   { "retval",        CMD_RETVAL },
86   { "rtfonly",       CMD_RTFONLY },
87   { "sa",            CMD_SA },
88   { "secreflist",    CMD_SECREFLIST },
89   { "section",       CMD_SECTION },
90   { "snippet",       CMD_SNIPPET },
91   { "snippetdoc",    CMD_SNIPPETDOC },
92   { "snippetlineno", CMD_SNIPWITHLINES },
93   { "subpage",       CMD_SUBPAGE },
94   { "subsection",    CMD_SUBSECTION },
95   { "subsubsection", CMD_SUBSUBSECTION },
96   { "paragraph",     CMD_PARAGRAPH },
97   { "see",           CMD_SA },
98   { "since",         CMD_SINCE },
99   { "skip",          CMD_SKIP },
100   { "skipline",      CMD_SKIPLINE },
101   { "xmlonly",       CMD_XMLONLY },
102   { "xrefitem",      CMD_XREFITEM },
103   { "throw",         CMD_EXCEPTION },
104   { "until",         CMD_UNTIL },
105   { "verbatim",      CMD_VERBATIM },
106   { "verbinclude",   CMD_VERBINCLUDE },
107   { "version",       CMD_VERSION },
108   { "warning",       CMD_WARNING },
109   { "throws",        CMD_EXCEPTION },
110   { "tparam",        CMD_TPARAM },
111   { "\\",            CMD_BSLASH },
112   { "@",             CMD_AT },
113   { "<",             CMD_LESS },
114   { ">",             CMD_GREATER },
115   { "&",             CMD_AMP },
116   { "$",             CMD_DOLLAR },
117   { "#",             CMD_HASH },
118   { "%",             CMD_PERCENT },
119   { "|",             CMD_PIPE },
120   { ".",             CMD_PUNT },
121   { "+",             CMD_PLUS },
122   { "-",             CMD_MINUS },
123   { "::",            CMD_DCOLON },
124   { "\"",            CMD_QUOTE },
125   { "_internalref",  CMD_INTERNALREF },
126   { "dot",           CMD_DOT },
127   { "msc",           CMD_MSC },
128   { "startuml",      CMD_STARTUML },
129   { "enddot",        CMD_ENDDOT },
130   { "endmsc",        CMD_ENDMSC },
131   { "enduml",        CMD_ENDUML },
132   { "manonly",       CMD_MANONLY },
133   { "endmanonly",    CMD_ENDMANONLY },
134   { "includelineno", CMD_INCWITHLINES },
135   { "includedoc",    CMD_INCLUDEDOC },
136   { "inheritdoc",    CMD_INHERITDOC },
137   { "mscfile",       CMD_MSCFILE },
138   { "rtfonly",       CMD_RTFONLY },
139   { "endrtfonly",    CMD_ENDRTFONLY },
140   { "vhdlflow",      CMD_VHDLFLOW },
141   { "docbookonly",   CMD_DBONLY },
142   { "enddocbookonly",CMD_ENDDBONLY },
143   { "endinternal",   CMD_ENDINTERNAL },
144   { "parblock",      CMD_PARBLOCK },
145   { "endparblock",   CMD_ENDPARBLOCK },
146   { "diafile",       CMD_DIAFILE },
147   { "--",            CMD_NDASH },
148   { "---",           CMD_MDASH },
149   { "_setscope",     CMD_SETSCOPE },
150   { 0,               0 },
151 };
152
153 //----------------------------------------------------------------------------
154
155 CommandMap htmlTagMap[] =
156 {
157   { "strong",     HTML_BOLD },
158   { "center",     HTML_CENTER },
159   { "table",      HTML_TABLE },
160   { "caption",    HTML_CAPTION },
161   { "small",      HTML_SMALL },
162   { "code",       HTML_CODE },
163   { "dfn",        HTML_CODE },
164   { "var",        HTML_EMPHASIS },
165   { "img",        HTML_IMG },
166   { "pre",        HTML_PRE },
167   { "sub",        HTML_SUB },
168   { "sup",        HTML_SUP },
169   { "tr",         HTML_TR },
170   { "td",         HTML_TD },
171   { "th",         HTML_TH },
172   { "ol",         HTML_OL },
173   { "ul",         HTML_UL },
174   { "li",         HTML_LI },
175   { "tt",         XML_C /*HTML_CODE*/ },
176   { "kbd",        XML_C /*HTML_CODE*/ },
177   { "em",         HTML_EMPHASIS },
178   { "hr",         HTML_HR },
179   { "dl",         HTML_DL },
180   { "dt",         HTML_DT },
181   { "dd",         HTML_DD },
182   { "br",         HTML_BR },
183   { "i",          HTML_EMPHASIS },
184   { "a",          HTML_A },
185   { "b",          HTML_BOLD },
186   { "p",          HTML_P },
187   { "h1",         HTML_H1 },
188   { "h2",         HTML_H2 },
189   { "h3",         HTML_H3 },
190   { "h4",         HTML_H4 },
191   { "h5",         HTML_H5 },
192   { "h6",         HTML_H6 },
193   { "span",       HTML_SPAN },
194   { "div",        HTML_DIV },
195   { "blockquote", HTML_BLOCKQUOTE },
196
197   { "c",            XML_C },
198   // { "code",       XML_CODE },  <= ambiguous <code> is also a HTML tag
199   { "description",  XML_DESCRIPTION },
200   { "example",      XML_EXAMPLE },
201   { "exception",    XML_EXCEPTION },
202   { "include",      XML_INCLUDE },
203   { "item",         XML_ITEM },
204   { "list",         XML_LIST }, // type="table|bullet|number"
205   { "listheader",   XML_LISTHEADER },
206   { "para",         XML_PARA },
207   { "param",        XML_PARAM },
208   { "paramref",     XML_PARAMREF },
209   { "typeparam",    XML_TYPEPARAM },
210   { "typeparamref", XML_TYPEPARAMREF },
211   { "permission",   XML_PERMISSION },
212   { "remarks",      XML_REMARKS },
213   { "returns",      XML_RETURNS },
214   { "see",          XML_SEE },
215   { "seealso",      XML_SEEALSO },
216   { "summary",      XML_SUMMARY },
217   { "term",         XML_TERM },
218   { "value",        XML_VALUE },
219   { "inheritdoc",   XML_INHERITDOC },
220   { 0,              0 }
221 };
222
223 //----------------------------------------------------------------------------
224
225 Mapper *Mappers::cmdMapper     = new Mapper(cmdMap,TRUE);
226 Mapper *Mappers::htmlTagMapper = new Mapper(htmlTagMap,FALSE);
227
228 int Mapper::map(const char *n)
229 {
230   QCString name=n;
231   if (!m_cs) name=name.lower();
232   int *result;
233   return !name.isEmpty() && (result=m_map.find(name)) ? *result: 0;
234 }
235
236 QString Mapper::find(const int n)
237 {
238   QDictIterator<int> mapIterator(m_map);
239   for (int *curVal = mapIterator.toFirst();(curVal = mapIterator.current());++mapIterator)
240   {
241     if (*curVal == n || (*curVal == (n | SIMPLESECT_BIT))) return mapIterator.currentKey();
242   }
243   return NULL;
244 }
245
246 Mapper::Mapper(const CommandMap *cm,bool caseSensitive) : m_map(89), m_cs(caseSensitive)
247 {
248   m_map.setAutoDelete(TRUE);
249   const CommandMap *p = cm;
250   while (p->cmdName)
251   {
252     m_map.insert(p->cmdName,new int(p->cmdId));
253     p++;
254   }
255 }
256
257 void Mappers::freeMappers()
258 {
259   delete cmdMapper;     cmdMapper     = 0;
260   delete htmlTagMapper; htmlTagMapper = 0;
261 }
262
263