--===============1583820205==
Content-Type: multipart/signed;
boundary="nextPart2936771.xueaifJiia";
protocol="application/pgp-signature";
micalg=pgp-sha1
Content-Transfer-Encoding: 7bit

--nextPart2936771.xueaifJiia
Content-Type: multipart/mixed;
boundary="Boundary-01=_ZNtHE5kjQsPS5si"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

--Boundary-01=_ZNtHE5kjQsPS5si
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Hi,

as the usage of KConfigXT is recommended for KDE4 apps a tool which helps t=
o=20
convert your current config would be cool. I wrote once KConfigXTraKtor,=20
which parses your source files and creates the XML file for you. It tries t=
o=20
guess the key type and group name, but this desn't work well. It's a very=20
basic tool, but I think it helps a bit.
Also, it's written in C++. I would prefer a tool, which I don't have to=20
compile first. As I'm not very good in any script language, I attach the=20
small file. So, if someone volunteers to port and improve it, it would be=20
great.

Regards,
Stefan

--Boundary-01=_ZNtHE5kjQsPS5si
Content-Type: text/x-c++src;
charset="us-ascii";
name="main.cpp"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename="main.cpp"

/************************************************** *************************
* Copyright (C) 2004 by Stefan Nikolaus *
* stefan.nikolaus@stuco.uni-oldenburg.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. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
************************************************** *************************/


#include
#include
#include

#include
#include
#include
#include

#include
using namespace std;

static const KCmdLineOptions options[] =
{
{ "r", I18N_NOOP("recursive parsing"), 0 },
{ "+directory", I18N_NOOP("Input directory"), 0 },
{ "+file", I18N_NOOP("Output kcfg XML file"), 0 },
KCmdLineLastOption
};

class Entry
{
public:
Entry()
{
type = "String";
};

bool operator==(const Entry& e) const { return(e.key == key); };
QString key;
QString type;
QString group;
QStringList files;
};

class Group
{
public:
Group()
{
name = QString::null;
entries.setAutoDelete(true);
};
Group( QString& gname )
{
name = gname;
entries.setAutoDelete(true);
};

bool operator==(const Group& e) const { return(e.name == name); };
QString name;
QPtrList entries;
};


int main( int argc, char **argv )
{
KAboutData aboutData( "kconfig_xtraktor",
I18N_NOOP("KConfig XtraKtor"),
"0.1.1",
I18N_NOOP("Extracts configuration entries out of C++ source files."),
KAboutData::License_LGPL );
aboutData.addAuthor( "Stefan Nikolaus", 0, "stefan.nikolaus@stuco.uni-oldenburg.de" );

KCmdLineArgs::init( argc, argv, &aboutData );
KCmdLineArgs::addCmdLineOptions( options );

KInstance app( &aboutData );

KCmdLineArgs *args = KCmdLineArgs:arsedArgs();

if ( args->count() < 2 ) {
kdError() << "Too few arguments." << endl;
return 1;
}
if ( args->count() > 2 ) {
kdError() << "Too many arguments." << endl;
return 1;
}

QString dirname = args->url( 0 ).path();
QString outputFilename = args->url( 1 ).path();

int counter = 0;
bool recursive = args->isSet("r");
Entry *entry;
Group *group = new Group();
QDir dir( dirname );
QString unknownKeys = "\n";
QPtrList entries;
QPtrList groups;
QStringList files = dir.entryList( "*.cpp *.cc", QDir::Files );
QStringList subdirs = dir.entryList( QDir:irs );

groups.setAutoDelete( true );
groups.append( group ); // for unknown groups

if ( recursive )
{
for ( QStringList::Iterator itdir = subdirs.begin(); itdir != subdirs.end(); ++itdir )
{
if ( (*itdir == ".") || (*itdir =="..") )
continue;
QDir subdir(dir.path() + "/" + *itdir);
QStringList subfiles = subdir.entryList( "*.cpp *.cc" );

for ( QStringList::Iterator itf = subfiles.begin(); itf != subfiles.end(); ++itf )
{
files.append( QString( "%1/%2" ).arg(subdir.path()).arg(*itf) );
}
}
}

for ( QStringList::Iterator it = files.begin(); it != files.end(); ++it )
{
QString filename = dir.filePath( *it );
QString line, leftStr, rightStr, entryName;
QFile file( filename );

cout << "processing file: " << *it;

if ( file.open( IO_ReadOnly ) )
{
QTextStream stream( &file );
int i = 1;
while ( !stream.atEnd() )
{
line = stream.readLine();

QRegExp rx("setGroup");
if ( rx.search( line ) > -1 )
{
QString groupName = line.section("\"",1,1);

bool found = false;
for( group = groups.first(); group; group = groups.next() )
{
if ( group->name == groupName )
{
found = true;
break;
}
}
if ( !found )
{
group = new Group(groupName);
groups.append( group );
group = groups.last();
}
}
else
{
QRegExp rx("^\\}");
if( rx.search(line) > -1 )
{
group = groups.first(); // unknown group
}

if ( line.contains( QRegExp( "(read|write)[a-zA-Z]*Entry\\(" ) ) )
{
int index = line.find("Entry(");

leftStr = line.left( index );
rightStr = line.right( line.length() - index - 6 );

index = rightStr.find("\"");
if ( index > -1 )
{
entryName = rightStr.right( rightStr.length() - index -1 );
index = entryName.find("\"");
if ( index > -1 )
entryName = entryName.left( index );
else
entryName = rightStr;

bool found = false;
for( entry = group->entries.first(); entry; entry = group->entries.next() )
{
if ( entry->key == entryName )
{
found = true;
break;
}
}
if ( !found )
{
entry = new Entry();
entry->key = entryName;
group->entries.append( entry );
entry = group->entries.last();
counter++;
}

entry->files += QString("%1:%2").arg(*it).arg(i);
entry->files += line;

if ( leftStr.find("read") > -1 )
{
if ( leftStr.endsWith("Bool") )
entry->type = "Bool";
else if ( leftStr.endsWith("List") )
entry->type = "StringList";
else if ( leftStr.endsWith("Num") )
entry->type = "Int";
else if ( leftStr.endsWith("UnsignedNum") )
entry->type = "UInt";
else if ( leftStr.endsWith("IntList") )
entry->type = "IntList";
else if ( leftStr.endsWith("Path") )
entry->type = "Path";
else if ( leftStr.endsWith("PathList") )
entry->type = "PathList";
else if ( leftStr.endsWith("Size") )
entry->type = "Size";
else if ( leftStr.endsWith("Font") )
entry->type = "Font";
else if ( leftStr.endsWith("Rect") )
entry->type = "Rect";
else if ( leftStr.endsWith("Color") )
entry->type = "Color";
else if ( leftStr.endsWith("Point") )
entry->type = "Point";
else if ( leftStr.endsWith("DateTime") )
entry->type = "DateTime";
}
}
else
{
unknownKeys += QString("\n").arg(*it).arg(i);
unknownKeys += QString("\n");
}
}
}
i++;
}
file.close();
cout << ": done" << endl;
}
else
{
cout << ": failed" << endl;
}
}

QFile outfile( outputFilename );
if ( !outfile.open( IO_WriteOnly ) ) {
kdError() << "Can't open '" << outputFilename << "for writing."
<< endl;
return 1;
}

QTextStream kcfg( &outfile );

kcfg << "" << endl;
kcfg << " kcfg << " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" << endl;
kcfg << " xsi:schemaLocation=\"http://www.kde.org/standards/kcfg/1.0" << endl;
kcfg << " http://www.kde.org/standards/kcfg/1.0/kcfg.xsd\" >" << endl;
kcfg << " " << endl;
kcfg << " " << endl;
kcfg << endl;

for ( group = groups.first(); group ; group = groups.next() )
{
kcfg << " name << "\">" << endl;

for ( entry = group->entries.first(); entry ; entry = group->entries.next() )
{
kcfg << " kcfg << "key=\"" << entry->key.latin1() << "\" ";
kcfg << "type=\"" << entry->type << "\">" << endl;
kcfg << " " << endl;
kcfg << " " << endl;
kcfg << " " << endl;
for ( QStringList::Iterator it3 = entry->files.begin(); it3 != entry->files.end(); ++it3 )
{
kcfg << QString(" ").arg( *it3 ) << endl;
}
kcfg << "
" << endl;
}

kcfg << "
" << endl;
}
kcfg << endl;
kcfg << unknownKeys << endl;
kcfg << "
" << endl;

outfile.close();

cout << "Entries found: " << counter << endl;
}

--Boundary-01=_ZNtHE5kjQsPS5si--

--nextPart2936771.xueaifJiia
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (GNU/Linux)

iD8DBQBEHtNcpfDn2DABIpcRAmO4AJ9pdcCN5GiPwC/CqCX5M1idcgDXcwCfQr12
sA9nv7XHID5xPJVz0vjvahw=
=bEz9
-----END PGP SIGNATURE-----

--nextPart2936771.xueaifJiia--

--===============1583820205==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline


>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<


--===============1583820205==--