You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
144 lines
5.2 KiB
144 lines
5.2 KiB
15 years ago
|
/****************************************************************************
|
||
|
|
||
|
Copyright (C) 2005 Lubos Lunak <l.lunak@kde.org>
|
||
|
|
||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||
|
copy of this software and associated documentation files (the "Software"),
|
||
|
to deal in the Software without restriction, including without limitation
|
||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||
|
and/or sell copies of the Software, and to permit persons to whom the
|
||
|
Software is furnished to do so, subject to the following conditions:
|
||
|
|
||
|
The above copyright notice and this permission notice shall be included in
|
||
|
all copies or substantial portions of the Software.
|
||
|
|
||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||
|
DEALINGS IN THE SOFTWARE.
|
||
|
|
||
|
****************************************************************************/
|
||
|
|
||
|
#undef QT_NO_CAST_ASCII
|
||
|
|
||
12 years ago
|
// See description in tdestartupconfig.cpp .
|
||
15 years ago
|
|
||
14 years ago
|
#include <tqfile.h>
|
||
13 years ago
|
#include <tqtextstream.h>
|
||
15 years ago
|
#include <kinstance.h>
|
||
|
#include <kstandarddirs.h>
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
15 years ago
|
#include <kdebug.h>
|
||
|
|
||
14 years ago
|
TQString get_entry( TQString* ll )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString& l = *ll;
|
||
15 years ago
|
l = l.stripWhiteSpace();
|
||
|
if( l.isEmpty())
|
||
14 years ago
|
return TQString::null;
|
||
|
TQString ret;
|
||
15 years ago
|
if( l[ 0 ] == '\'' )
|
||
|
{
|
||
|
unsigned int pos = 1;
|
||
|
while( pos < l.length() && l[ pos ] != '\'' )
|
||
|
ret += l[ pos++ ];
|
||
|
if( pos >= l.length())
|
||
|
{
|
||
14 years ago
|
*ll = TQString::null;
|
||
|
return TQString::null;
|
||
15 years ago
|
}
|
||
|
*ll = l.mid( pos + 1 );
|
||
|
return ret;
|
||
|
}
|
||
|
unsigned int pos = 0;
|
||
|
while( pos < l.length() && l[ pos ] != ' ' )
|
||
|
ret += l[ pos++ ];
|
||
|
*ll = l.mid( pos );
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
int main()
|
||
|
{
|
||
12 years ago
|
TDEInstance inst( "tdedostartupconfig" );
|
||
|
kdDebug() << "Running tdedostartupconfig." << endl;
|
||
14 years ago
|
TQString keysname = locateLocal( "config", "startupconfigkeys" );
|
||
|
TQFile keys( keysname );
|
||
15 years ago
|
if( !keys.open( IO_ReadOnly ))
|
||
|
return 3;
|
||
14 years ago
|
TQFile f1( locateLocal( "config", "startupconfig" ));
|
||
15 years ago
|
if( !f1.open( IO_WriteOnly ))
|
||
|
return 4;
|
||
14 years ago
|
TQFile f2( locateLocal( "config", "startupconfigfiles" ));
|
||
15 years ago
|
if( !f2.open( IO_WriteOnly ))
|
||
|
return 5;
|
||
14 years ago
|
TQTextStream startupconfig( &f1 );
|
||
|
TQTextStream startupconfigfiles( &f2 );
|
||
15 years ago
|
startupconfig << "#! /bin/sh\n";
|
||
|
for(;;)
|
||
|
{
|
||
14 years ago
|
TQString line;
|
||
15 years ago
|
if( keys.readLine( line, 1024 ) < 0 )
|
||
|
break;
|
||
|
line = line.stripWhiteSpace();
|
||
|
if( line.isEmpty())
|
||
|
break;
|
||
14 years ago
|
TQString tmp = line;
|
||
|
TQString file, group, key, def;
|
||
15 years ago
|
file = get_entry( &tmp );
|
||
|
group = get_entry( &tmp );
|
||
|
key = get_entry( &tmp );
|
||
|
def = get_entry( &tmp );
|
||
|
if( file.isEmpty() || group.isEmpty())
|
||
|
return 6;
|
||
|
if( group.left( 1 ) == "[" && group.right( 1 ) == "]" )
|
||
|
{ // whole config group
|
||
12 years ago
|
TDEConfig cfg( file );
|
||
15 years ago
|
group = group.mid( 1, group.length() - 2 );
|
||
14 years ago
|
TQMap< TQString, TQString > entries = cfg.entryMap( group );
|
||
15 years ago
|
startupconfig << "# " << line << "\n";
|
||
14 years ago
|
for( TQMap< TQString, TQString >::ConstIterator it = entries.begin();
|
||
15 years ago
|
it != entries.end();
|
||
|
++it )
|
||
|
{
|
||
14 years ago
|
TQString key = it.key();
|
||
|
TQString value = *it;
|
||
14 years ago
|
startupconfig << TQString(file.replace( ' ', '_' )).lower()
|
||
|
<< "_" << TQString(group.replace( ' ', '_' )).lower()
|
||
|
<< "_" << TQString(key.replace( ' ', '_' )).lower()
|
||
14 years ago
|
<< "=\"" << value.replace( "\"", "\\\"" ) << "\"\n";
|
||
15 years ago
|
}
|
||
|
}
|
||
|
else
|
||
|
{ // a single key
|
||
|
if( key.isEmpty())
|
||
|
return 7;
|
||
12 years ago
|
TDEConfig cfg( file );
|
||
15 years ago
|
cfg.setGroup( group );
|
||
14 years ago
|
TQString value = cfg.readEntry( key, def );
|
||
15 years ago
|
startupconfig << "# " << line << "\n";
|
||
14 years ago
|
startupconfig << TQString(file.replace( ' ', '_' )).lower()
|
||
|
<< "_" << TQString(group.replace( ' ', '_' )).lower()
|
||
|
<< "_" <<TQString( key.replace( ' ', '_' )).lower()
|
||
14 years ago
|
<< "=\"" << value.replace( "\"", "\\\"" ) << "\"\n";
|
||
15 years ago
|
}
|
||
|
startupconfigfiles << line << endl;
|
||
13 years ago
|
// use even currently non-existing paths in $TDEDIRS
|
||
12 years ago
|
TQStringList dirs = TQStringList::split( KPATH_SEPARATOR, TDEGlobal::dirs()->kfsstnd_prefixes());
|
||
14 years ago
|
for( TQStringList::ConstIterator it = dirs.begin();
|
||
15 years ago
|
it != dirs.end();
|
||
|
++it )
|
||
|
{
|
||
14 years ago
|
TQString cfg = *it + "share/config/" + file;
|
||
12 years ago
|
if( TDEStandardDirs::exists( cfg ))
|
||
15 years ago
|
startupconfigfiles << cfg << "\n";
|
||
|
else
|
||
|
startupconfigfiles << "!" << cfg << "\n";
|
||
|
}
|
||
|
startupconfigfiles << "*\n";
|
||
|
}
|
||
|
return 0;
|
||
|
}
|