1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
/***************************************************************************
* Copyright (C) 2003 by Jonas B. Jacobi *
* j.jacobi@gmx.de *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "doxydoc.h"
#include <list>
#include <qstring.h>
#include <qstringlist.h>
#include <qdom.h>
#include <qdir.h>
#include <qfile.h>
#include <qregexp.h>
void DoxyDoc::formatType( QString& str )
{
str.replace( QRegExp( " " ), "" );
}
DoxyDoc::DoxyDoc( const QStringList& dir )
{
for ( uint i = 0; i < dir.count(); ++i )
m_dirs.push_back( QDir( *( dir.at( i ) ) ) );
}
//crappy implementation, change later
QString DoxyDoc::functionDescription( const QString& tmpscope, const QString& name,
const QString& tmptype, const QString& tmparguments )
{
QString scope = tmpscope;
bool foundfile = false;
//produce doxygen conform filenames
QString filename = "/class" + scope.replace( QRegExp( "_" ), "__" ).replace( QRegExp( "::" ), "_1_1" ) + ".xml";
//search for file in all directories
for ( std::list<QDir>::const_iterator ci = m_dirs.begin(); !foundfile && ci != m_dirs.end(); ++ci )
{
if ( QFile::exists( ci->path() + filename ) )
{
if ( m_file.name() != ci->path() + filename )
{
m_file.close();
m_file.setName( ci->path() + filename );
if ( !m_file.open( IO_ReadOnly ) )
{
m_file.setName( "" );
return "";
}
QDomDocument m_doc;
m_doc.setContent( m_file.readAll() );
m_file.close();
m_list = m_doc.elementsByTagName( "memberdef" );
foundfile = true;
}
else //file is already opened
foundfile = true;
}
}
if ( !foundfile )
return QString::null;
QString type = tmptype;
formatType( type );
for ( uint i = 0; i < m_list.count(); ++i )
{
QDomElement elem = m_list.item( i ).toElement();
if ( elem.elementsByTagName( "name" ).item( 0 ).toElement().text() == name &&
elem.elementsByTagName( "type" ).item( 0 ).toElement().text() == tmptype )
{
QDomNodeList paramnodes = elem.elementsByTagName( "param" );
QString nodearguments = "", arguments = tmparguments;
for ( unsigned int j = 0; j < paramnodes.count(); ++j )
nodearguments += paramnodes.item( j ).childNodes().item( 0 ).toElement().text() + ",";
if ( nodearguments != "" )
{
nodearguments = nodearguments.left( nodearguments.length() - 1 );
formatType( nodearguments );
}
formatType( arguments );
if ( arguments == nodearguments )
{
QString brief = "";
QDomNode briefnode = elem.elementsByTagName( "briefdescription" ).item( 0 );
if ( briefnode.hasChildNodes() )
brief = briefnode.firstChild().toElement().text();
QString detailstr = "", paramstr = "";
QDomNode detail = elem.elementsByTagName( "detaileddescription" ).item( 0 );
if ( detail.hasChildNodes() )
detail = detail.firstChild();
QDomNode descnode = detail.firstChild();
while ( !descnode.isNull() )
{
if ( descnode.nodeName() == "parameterlist" )
{
int tmpcount = descnode.childNodes().count();
for ( int k = 0; k < tmpcount; ++k )
{
//add parametername
paramstr += "<li><i>" + descnode.childNodes().item( k++ ).toElement().text() + "</i>\t";
//add parameterdescription
paramstr += descnode.childNodes().item( k ).toElement().text() + "</li>";
}
}
else
if ( descnode.nodeName() == "simplesect" )
{}
else
{
if ( descnode.isText() )
detailstr += descnode.toText().data();
else
detailstr += descnode.toElement().text();
}
descnode = descnode.nextSibling();
}
QString description = "";
if ( brief != "" )
description += brief + "<p>";
if ( detailstr != "" )
description += detailstr + "<p>";
if ( paramstr != "" )
description += "<b>Parameterlist:</b><p>" + paramstr;
if ( description == "" )
return QString::null;
else
return description;
}
}
}
return QString::null;
}
//kate: indent-mode csands; tab-width 4; space-indent off;
|