2 A command-line tool for removing unneeded data from a Doxygen tagfile.
3 The tool's main purpose is to trim the Qt library's tagfile to a manageable
4 size, but it may work with other tagfiles as well.
13 * Remove the Doxygen-generated "class", "namespace", or whatever prefix
14 * from a file name, and make it lowercase.
16 static void fixFilename(QDomElement
& node
, const QString
& compoundKind
)
18 QDomNode child
= node
.firstChild();
19 QString text
= child
.nodeValue();
20 if (text
.startsWith(compoundKind
))
22 int len
= compoundKind
.length();
23 text
= text
.mid(len
).toLower();
24 child
.setNodeValue(text
);
28 /*! Remove duplicate members from the compound. */
29 static void trimMembers(QDomElement
& compound
)
32 for (elem
= compound
.firstChildElement("member");
34 elem
= elem
.nextSiblingElement("member"))
36 QDomElement nameElem1
= elem
.firstChildElement("name");
38 QDomElement elem2
= elem
.nextSiblingElement("member");
39 while (!elem2
.isNull())
41 // If two members have a "name" tag with the same
42 // value, the second one of them gets removed.
43 QDomElement nameElem2
= elem2
.firstChildElement("name");
44 if (nameElem2
.text() == nameElem1
.text())
46 QDomElement old
= elem2
;
47 elem2
= elem2
.nextSiblingElement("member");
48 compound
.removeChild(old
);
51 elem2
= elem2
.nextSiblingElement("member");
56 /*! Remove unneeded nodes from a compound. */
57 static void trimCompound(QDomElement
& compound
)
59 QDomElement elem
= compound
.firstChildElement();
60 while (!elem
.isNull())
62 QString name
= elem
.tagName();
63 if (name
== "filename")
64 fixFilename(elem
, compound
.attribute("kind"));
65 else if (name
== "member"
66 && elem
.attribute("kind") == "enumeration")
68 QDomElement
tmp(elem
.firstChildElement("anchorfile"));
70 fixFilename(tmp
, compound
.attribute("kind"));
72 // The "arglist" tag is never used in class or
73 // namespace compounds.
74 tmp
= elem
.firstChildElement("arglist");
76 elem
.removeChild(tmp
);
78 else if (name
!= "name")
80 QDomElement old
= elem
;
81 elem
= elem
.nextSiblingElement();
82 compound
.removeChild(old
);
85 elem
= elem
.nextSiblingElement();
88 trimMembers(compound
);
91 /*! Trim out useless weight from the tagfile. */
92 static bool trimDoc(QDomDocument
& doc
)
94 QDomElement root
= doc
.documentElement();
95 if (root
.tagName() != "tagfile")
98 QDomElement compound
= root
.firstChildElement();
99 while (!compound
.isNull())
101 QString compoundKind
= compound
.attribute("kind");
102 if (compound
.tagName() != "compound"
103 || (compoundKind
!= "class" && compoundKind
!= "namespace"))
105 QDomElement old
= compound
;
106 compound
= compound
.nextSiblingElement();
107 root
.removeChild(old
);
111 trimCompound(compound
);
112 compound
= compound
.nextSiblingElement();
118 int main(int argc
, char* argv
[])
120 QCoreApplication
app(argc
, argv
);
121 QStringList args
= app
.arguments();
122 if (args
.size() <= 2)
124 qDebug() << "Usage: tagtrimmer SOURCE_FILE DEST_FILE";
129 if (!file
.open(QIODevice::ReadOnly
))
131 qWarning() << "Can't open file" << args
[1];
138 if (!doc
.setContent(&file
, &errorMsg
, &line
, &col
))
140 qWarning() << "Error in line" << line
<< "column" << col
;
141 qWarning() << errorMsg
;
148 qWarning() << "Couldn't trim the Doxytag file" << args
[1];
152 QFile
file2(args
[2]);
153 if (!file2
.open(QIODevice::WriteOnly
))
155 qWarning() << "Can't open file" << args
[2];
158 QTextStream
out(&file2
);