Warning, /sdk/kompare/tests/cvsdiff/edm.diff is written in an unsupported language. File is not indexed.

0001 Index: client/dcop.cpp
0002 ===================================================================
0003 RCS file: /home/kde/kdelibs/dcop/client/dcop.cpp,v
0004 retrieving revision 1.26
0005 diff -e -r1.26 dcop.cpp
0006 343a
0007 
0008 // vim: set ts=8 sts=4 sw=4 noet:
0009 
0010 .
0011 340a
0012 }
0013 
0014 
0015 int main( int argc, char** argv )
0016 {
0017     bool readStdin = false;
0018     int numOptions = 0;
0019     QString user;
0020     Session session = DefaultSession;
0021     QString sessionName;
0022     
0023     // Scan for command-line options first
0024     for( int pos = 1 ; pos <= argc - 1 ; pos++ )
0025     {
0026         if( strcmp( argv[ pos ], "--help" ) == 0 )
0027             showHelp( 0 );
0028         else if( strcmp( argv[ pos ], "--pipe" ) == 0 )
0029         {
0030             readStdin = true;
0031             numOptions++;
0032         }
0033         else if( strcmp( argv[ pos ], "--user" ) == 0 )
0034         {
0035             if( pos <= argc - 2 )
0036             {
0037                 user = QString::fromLocal8Bit( argv[ pos + 1] );
0038                 numOptions +=2;
0039                 pos++;
0040             }
0041             else
0042             {
0043                 cerr << "Missing username for '--user' option!" << endl << endl;
0044                 showHelp( -1 );
0045             }
0046         }
0047         else if( strcmp( argv[ pos ], "--all-users" ) == 0 )
0048         {
0049             user = "*";
0050             numOptions ++;
0051         }
0052         else if( strcmp( argv[ pos ], "--list-sessions" ) == 0 )
0053         {
0054             session = QuerySessions;
0055             numOptions ++;
0056         }
0057         else if( strcmp( argv[ pos ], "--all-sessions" ) == 0 )
0058         {
0059             session = AllSessions;
0060             numOptions ++;
0061         }
0062         else if( argv[ pos ][ 0 ] == '-' )
0063         {
0064             cerr << "Unknown command-line option '" << argv[ pos ]
0065                  << "'." << endl << endl;
0066             showHelp( -1 );
0067         }
0068         else
0069             break;      // End of options
0070     }
0071 
0072     argc -= numOptions;
0073 
0074     QCStringList args;
0075     for( int i = numOptions; i < argc + numOptions - 1; i++ )
0076         args.append( argv[ i + 1 ] );
0077     
0078     if( readStdin && args.count() < 3 )
0079     {
0080         cerr << "--pipe option only supported for function calls!" << endl << endl;
0081         showHelp( -1 );
0082     }
0083     
0084     if( user == "*" && args.count() < 3 && session != QuerySessions )
0085     {
0086         cerr << "ERROR: The --all-users option is only supported for function calls!" << endl << endl;
0087         showHelp( -1 );
0088     }
0089     
0090     if( session == QuerySessions && !args.isEmpty() )
0091     {
0092         cerr << "ERROR: The --list-sessions option cannot be used for actual DCOP calls!" << endl << endl;
0093         showHelp( -1 );
0094     }
0095     
0096     if( session == QuerySessions && user.isEmpty() )
0097     {
0098         cerr << "ERROR: The --list-sessions option can only be used with the --user or" << endl
0099              << "--all-users options!" << endl << endl;
0100         showHelp( -1 );
0101     }
0102     
0103     if( session != DefaultSession && session != QuerySessions &&
0104         args.count() < 3 )
0105     {
0106         cerr << "ERROR: The --session and --all-sessions options are only supported for function" << endl
0107              << "calls!" << endl << endl;
0108         showHelp( -1 );
0109     }
0110     
0111     UserList users;
0112     if( user == "*" )
0113         users = userList();
0114     else if( !user.isEmpty() )
0115         users[ user ] = userList()[ user ];
0116 
0117     runDCOP( args, users, session, sessionName, readStdin );
0118 .
0119 339a
0120         if( users.count() > 1 || ( users.count() == 1 &&
0121             ( getenv( "ICEAUTHORITY" ) == 0 || getenv( "DISPLAY" ) == 0 ) ) )
0122         {
0123             // Check for ICE authority file and if the file can be read by us
0124             QString home = it.data();
0125             QString iceFile = it.data() + "/.ICEauthority";
0126             QFileInfo fi( iceFile );
0127             if( iceFile.isEmpty() )
0128             {
0129                 cerr << "WARNING: Cannot determine home directory for user "
0130                      << it.key() << "!" << endl
0131                      << "Please check permissions or set the $ICEAUTHORITY variable manually before" << endl
0132                      << "calling dcop." << endl;
0133             }
0134             else if( fi.exists() )
0135             {
0136                 if( fi.isReadable() )
0137                 {
0138                     char *envStr = strdup( ( "ICEAUTHORITY=" + iceFile ).ascii() );
0139                     putenv( envStr );
0140                     //cerr << "ice: " << envStr << endl;
0141                 }
0142                 else
0143                 {
0144                     cerr << "WARNING: ICE authority file " << iceFile
0145                          << "is not readable by you!" << endl
0146                          << "Please check permissions or set the $ICEAUTHORITY variable manually before" << endl
0147                          << "calling dcop." << endl;
0148                 }
0149             }
0150             else
0151             {
0152                 if( users.count() > 1 )
0153                     continue;
0154                 else
0155                 {
0156                     cerr << "WARNING: Cannot find ICE authority file "
0157                          << iceFile << "!" << endl
0158                          << "Please check permissions or set the $ICEAUTHORITY"
0159                          << " variable manually before" << endl
0160                          << "calling dcop." << endl;
0161                 }
0162             }
0163         }
0164 
0165         // Main loop
0166         // If users is an empty list we're calling for the currently logged
0167         // in user. In this case we don't have a session, but still want
0168         // to iterate the loop once.
0169         QStringList::Iterator sIt = sessions.begin();
0170         for( ; sIt != sessions.end() || users.isEmpty(); sIt++ )
0171         {
0172             if( !presetDCOPServer && !users.isEmpty() )
0173             {
0174                 QString dcopFile = it.data() + "/" + *sIt;
0175                 QFile f( dcopFile );
0176                 if( !f.open( IO_ReadOnly ) )
0177                 {
0178                     cerr << "Can't open " << dcopFile << " for reading!" << endl;
0179                     exit( -1 );
0180                 }
0181 
0182                 QStringList l( QStringList::split( '\n', f.readAll() ) );
0183                 dcopServer = l.first();
0184 
0185                 if( dcopServer.isEmpty() )
0186                 {
0187                     cerr << "WARNING: Unable to determine DCOP server for session "
0188                          << *sIt << "!" << endl
0189                          << "Please check permissions or set the $DCOPSERVER variable manually before" << endl
0190                          << "calling dcop." << endl;
0191                     exit( -1 );
0192                 }
0193             }
0194             
0195             delete client;
0196             client = new DCOPClient;
0197             if( !dcopServer.isEmpty() )
0198                 client->setServerAddress( dcopServer.ascii() );
0199             bool success = client->attach();
0200             if( !success )
0201             {
0202                 cerr << "ERROR: Couldn't attach to DCOP server!" << endl;
0203                 continue;
0204             }
0205             dcop = client;
0206 
0207             switch ( args.count() )
0208             {
0209             case 0:
0210                 queryApplications("");
0211                 break;
0212             case 1:
0213                 if (endsWith(app, '*'))
0214                    queryApplications(app);
0215                 else
0216                    queryObjects( app, "" );
0217                 break;
0218             case 2:
0219                 if (endsWith(objid, '*'))
0220                    queryObjects(app, objid);
0221                 else
0222                    queryFunctions( app, objid );
0223                 break;
0224             case 3:
0225             default:
0226                 if( readStdin )
0227                 {
0228                     QCStringList::Iterator replaceArg = args.end();
0229                    
0230                     QCStringList::Iterator it;
0231                     for( it = args.begin(); it != args.end(); it++ )
0232                         if( *it == "%1" )
0233                             replaceArg = it;
0234                     
0235                     // Read from stdin until EOF and call function for each line read
0236                     char *buf = new char[ 1000 ];
0237                     while ( !feof( stdin ) )
0238                     {
0239                         fgets( buf, 1000, stdin );
0240                 
0241                         if( replaceArg != args.end() )
0242                             *replaceArg = buf;
0243 
0244                         callFunction( app, objid, function, params );
0245                     }
0246                 }
0247                 else
0248                 {
0249                     // Just call function
0250 //                  cout << "call " << app << ", " << objid << ", " << function << ", (params)" << endl;
0251                     callFunction( app, objid, function, params );
0252                 }
0253                 break;
0254             }
0255             // Another sIt++ would make the loop infinite...
0256             if( users.isEmpty() )
0257                 break;
0258         }
0259         
0260         // Another it++ would make the loop infinite...
0261         if( it == users.end() )
0262             break;
0263 .
0264 308,338c
0265         if( !args.isEmpty() )
0266             app = args[ 0 ];
0267         if( args.count() > 1 )
0268             objid = args[ 1 ];
0269         if( args.count() > 2 )
0270             function = args[ 2 ];
0271         if( args.count() > 3)
0272         {
0273             params = args;
0274             params.remove( params.begin() );
0275             params.remove( params.begin() );
0276             params.remove( params.begin() );
0277         }
0278     }
0279 
0280     bool firstRun = true;
0281     UserList::Iterator it;
0282     QStringList sessions;
0283     bool presetDCOPServer = false;
0284 //    char *dcopStr = 0L;
0285     QString dcopServer;
0286     
0287     for( it = users.begin(); it != users.end() || firstRun; it++ )
0288     {
0289         firstRun = false;
0290 
0291         //cout << "Iterating '" << it.key() << "'" << endl;
0292 
0293         if( session == QuerySessions )
0294         {
0295             QStringList sessions = dcopSessionList( it.key(), it.data() );
0296             if( sessions.isEmpty() )
0297             {
0298                 cout << "No active sessions";
0299                 if( !( *it ).isEmpty() )
0300                     cout << " for user " << *it;
0301                 cout << endl;
0302             }
0303             else
0304             {
0305                 cout << "Active sessions ";
0306                 if( !( *it ).isEmpty() )
0307                     cout << "for user " << *it << " ";
0308                 cout << ":" << endl;
0309                 
0310                 QStringList::Iterator sIt;
0311                 for( sIt = sessions.begin(); sIt != sessions.end(); sIt++ )
0312                     cout << "  " << *sIt << endl;
0313 
0314                 cout << endl;
0315             }
0316             continue;
0317         }
0318 
0319         if( getenv( "DCOPSERVER" ) )
0320         {
0321             sessions.append( getenv( "DCOPSERVER" ) );
0322             presetDCOPServer = true;
0323         }
0324 
0325         if( users.count() > 1 || ( users.count() == 1 &&
0326             ( getenv( "DCOPSERVER" ) == 0 /*&& getenv( "DISPLAY" ) == 0*/ ) ) )
0327         {
0328             sessions = dcopSessionList( it.key(), it.data() );
0329             if( sessions.isEmpty() )
0330             {
0331                 if( users.count() > 1 )
0332                     continue;
0333                 else
0334                 {
0335                     cerr << "ERROR: No active KDE sessions!" << endl
0336                          << "If you are sure there is one, please set the $DCOPSERVER variable manually" << endl
0337                          << "before calling dcop." << endl;
0338                     exit( -1 );
0339                 }
0340             }
0341             else if( sessions.count() > 1 && session != AllSessions )
0342             {
0343                 cerr << "ERROR: Multiple available KDE sessions!" << endl
0344                      << "Please specify the correct session to use with --session or use the" << endl
0345                      << "--all-sessions option to broadcast to all sessions." << endl;
0346                 exit( -1 );
0347             }
0348         }
0349 .
0350 289,304c
0351         // WARNING: This part (until the closing '}') could very
0352         // well be broken now. As I don't know how to trigger and test
0353         // dcoprefs this code is *not* tested. It compiles and it looks
0354         // ok to me, but that's all I can say - Martijn (2001/12/24)
0355         int delimPos = args[ 0 ].findRev( ',' );
0356         if( delimPos == -1 )
0357         {
0358             cerr << "Error: '" << args[ 0 ]
0359                  << "' is not a valid DCOP reference." << endl;
0360             exit( -1 );
0361         }
0362         args[ 0 ][ delimPos ] = 0;
0363         app = args[ 0 ].mid( 8 );
0364         delimPos++;
0365         args[ 0 ][ args[ 0 ].length() - 1 ] = 0;
0366         objid = args[ 0 ].mid( delimPos );
0367         if( args.count() > 1 )
0368             function = args[ 1 ];
0369         if( args.count() > 2 )
0370         {
0371             params = args;
0372             params.remove( params.begin() );
0373             params.remove( params.begin() );
0374         }
0375 .
0376 286,287c
0377     QCStringList params;
0378     DCOPClient *client = 0L;
0379     if ( !args.isEmpty() && args[ 0 ].find( "DCOPRef(" ) == 0 )
0380 .
0381 282a
0382 /**
0383  * Do the actual DCOP call
0384  */
0385 void runDCOP( QCStringList args, UserList users, Session session,
0386               const QString sessionName, bool readStdin )
0387 {
0388 .
0389 279,281c
0390     return result;
0391 }
0392 
0393 /**
0394  * Return a list of available DCOP sessions for the specified user
0395  * An empty list means no sessions are available, or an error occurred.
0396  */
0397 QStringList dcopSessionList( const QString &user, const QString &home )
0398 {
0399     if( home.isEmpty() )
0400     {
0401         cerr << "WARNING: Cannot determine home directory for user "
0402              << user << "!" << endl
0403              << "Please check permissions or set the $DCOPSERVER variable manually before" << endl
0404              << "calling dcop." << endl;
0405         return QStringList();
0406     }
0407 
0408     QStringList result;
0409     QFileInfo dirInfo( home );
0410     if( !dirInfo.exists() || !dirInfo.isReadable() )
0411         return result;
0412 
0413     QDir d( home );
0414     d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks );
0415     d.setNameFilter( ".DCOPserver*" );
0416 
0417     const QFileInfoList *list = d.entryInfoList();
0418     if( !list )
0419         return result;
0420 
0421     QFileInfoListIterator it( *list );
0422     QFileInfo *fi;
0423 
0424     while ( ( fi = it.current() ) != 0 )
0425     {
0426         if( fi->isReadable() )
0427             result.append( fi->fileName() );
0428         ++it;
0429     }
0430     return result;
0431 }
0432 .
0433 274,276c
0434     QStringList l( QStringList::split( '\n', f.readAll() ) );
0435 
0436     for( QStringList::ConstIterator it( l.begin() ); it != l.end(); ++it )
0437     {
0438         QStringList userInfo( QStringList::split( ':', *it, true ) );
0439         result[ userInfo[ 0 ] ] = userInfo[ 5 ];
0440 .
0441 272a
0442     UserList result;
0443     
0444     QFile f( "/etc/passwd" );
0445 
0446     if( !f.open( IO_ReadOnly ) )
0447     {
0448         cerr << "Can't open /etc/passwd for reading!" << endl;
0449         return result;
0450     }
0451 .
0452 270,271c
0453 /**
0454  * Return a list of all users and their home directories.
0455  * Returns an empty list if /etc/passwd cannot be read for some reason.
0456  */
0457 static UserList userList()
0458 .
0459 268a
0460 /**
0461  * Show command-line help and exit
0462  */
0463 void showHelp( int exitCode = 0 )
0464 {
0465     cout << "Usage: dcop [options] [application [object [function [arg1] [arg2] ... ] ] ]" << endl
0466          << "" << endl
0467          << "Console DCOP client" << endl
0468          << "" << endl
0469          << "Generic options:" << endl
0470          << "  --help          Show help about options" << endl
0471          << "" << endl
0472          << "Options:" << endl
0473          << "  --pipe          Call DCOP for each line read from stdin" << endl
0474          << "  --user <user>   Connect to the given user's DCOP server. This option will" << endl
0475          << "                  ignore the values of the environment vars $DCOPSERVER and" << endl
0476          << "                  $ICEAUTHORITY, even if they are set." << endl
0477          << "                  If the user has more than one open session, you must also" << endl
0478          << "                  use one of the --list-sessions, --session or --als-sessions" << endl
0479          << "                  command-line options." << endl
0480          << "  --all-users     Send the same DCOP call to all users with a running DCOP" << endl
0481          << "                  server. Only failed calls to existing DCOP servers will"
0482          << "                  generate an error message. If no DCOP server is available" << endl
0483          << "                  at all, no error will be generated." << endl;
0484     
0485     exit( exitCode );
0486 }
0487 .
0488 246,250c
0489     uint i = 0;
0490     for( QStringList::Iterator it = types.begin(); it != types.end(); ++it )
0491         marshall( arg, args, i, *it );
0492 
0493     if ( i != args.count() )
0494     {
0495 .
0496 164c
0497 //            exit(1);
0498             return;
0499 .
0500 156,157c
0501                 uint a = (*it).contains(',');
0502                 if ( ( a == 0 && args.isEmpty() ) || ( a > 0 && a + 1 == args.count() ) )
0503 .
0504 139c
0505         if ( !ok && args.isEmpty() )
0506 .
0507 123d
0508 121c
0509 void callFunction( const char* app, const char* obj, const char* func, const QCStringList args )
0510 .
0511 35a
0512 static QTextStream cout( stdout, IO_WriteOnly );
0513 static QTextStream cerr( stderr, IO_WriteOnly );
0514 
0515 /**
0516  * Session to send call to
0517  * DefaultSession - current session. Current KDE session when called without
0518  *                  --user or --all-users option. Otherwise this value ignores
0519  *                  all users with more than one active session.
0520  * AllSessions    - Send to all sessions found. requires --user or --all-users.
0521  * QuerySessions  - Don't call DCOP, return a list of available sessions.
0522  * CustomSession  - Use the specified session
0523  */
0524 enum Session { DefaultSession = 0, AllSessions, QuerySessions, CustomSession };
0525 
0526 .
0527 33a
0528 typedef QMap<QString, QString> UserList;
0529 
0530 .
0531 28,30c
0532 #include "../kdatastream.h"
0533 .
0534 25c
0535 #include <qdir.h>
0536 #include <qfile.h>
0537 #include <qfileinfo.h>
0538 #include <qmap.h>
0539 #include <qstringlist.h>
0540 #include <qtextstream.h>
0541 #include <qvariant.h>
0542 
0543 // putenv() is not available on all platforms, so make sure the emulation
0544 // wrapper is available in those cases by loading config.h!
0545 #include <config.h>
0546 
0547 .
0548 23c
0549 #include <ctype.h>
0550 #include <stdio.h>
0551 #include <stdlib.h>
0552 
0553 .
0554 Index: client/dcopfind.cpp
0555 ===================================================================
0556 RCS file: /home/kde/kdelibs/dcop/client/dcopfind.cpp,v
0557 retrieving revision 1.2
0558 diff -e -r1.2 dcopfind.cpp
0559 224c
0560     QCStringList params;
0561     for( int i = 0; i < argc; i++ )
0562             params.append( args[ i ] );
0563     
0564     findObject( app, objid, function, params );
0565 .
0566 133c
0567     if ( (uint) i != args.count() ) {
0568 .
0569 131c
0570         marshall(arg, args, i, *it);
0571 .
0572 121c
0573     if ( types.count() != args.count() ) {
0574 .
0575 39c
0576 bool findObject( const char* app, const char* obj, const char* func, QCStringList args )
0577 .
0578 Index: client/marshall.cpp
0579 ===================================================================
0580 RCS file: /home/kde/kdelibs/dcop/client/marshall.cpp,v
0581 retrieving revision 1.3
0582 diff -e -r1.3 marshall.cpp
0583 347a
0584         QByteArray dummy_data;
0585         QDataStream dummy_arg(dummy_data, IO_WriteOnly);
0586 
0587         uint j = i;
0588         uint count = 0;
0589         // Parse list to get the count
0590         while (true) {
0591             if( j > args.count() )
0592             {
0593                 qWarning("List end-delimiter '%s' not found.", delim.latin1());
0594                 exit(1);
0595             }
0596             if( QString::fromLocal8Bit( args[ j ] ) == delim )
0597                 break;
0598             marshall( dummy_arg, args, j, type );
0599             count++;
0600         }
0601         arg << (Q_UINT32) count;
0602         // Parse the list for real
0603         while (true) {
0604             if( i > args.count() )
0605             {
0606                 qWarning("List end-delimiter '%s' not found.", delim.latin1());
0607                 exit(1);
0608             }
0609             if( QString::fromLocal8Bit( args[ i ] ) == delim )
0610                 break;
0611             marshall( arg, args, i, type );
0612         }
0613     } else {
0614         qWarning( "cannot handle datatype '%s'", type.latin1() );
0615         exit(1);
0616     }
0617     i++;
0618 .
0619 319,346c
0620     if ( type == "int" )
0621         arg << s.toInt();
0622     else if ( type == "uint" )
0623         arg << s.toUInt();
0624     else if ( type == "unsigned" )
0625         arg << s.toUInt();
0626     else if ( type == "unsigned int" )
0627         arg << s.toUInt();
0628     else if ( type == "long" )
0629         arg << s.toLong();
0630     else if ( type == "long int" )
0631         arg << s.toLong();
0632     else if ( type == "unsigned long" )
0633         arg << s.toULong();
0634     else if ( type == "unsigned long int" )
0635         arg << s.toULong();
0636     else if ( type == "float" )
0637         arg << s.toFloat();
0638     else if ( type == "double" )
0639         arg << s.toDouble();
0640     else if ( type == "bool" )
0641         arg << mkBool( s );
0642     else if ( type == "QString" )
0643         arg << s;
0644     else if ( type == "QCString" )
0645         arg << QCString( args[ i ] );
0646     else if ( type == "QColor" )
0647         arg << mkColor( s );
0648     else if ( type == "QPoint" )
0649         arg << mkPoint( s );
0650     else if ( type == "QSize" )
0651         arg << mkSize( s );
0652     else if ( type == "QRect" )
0653         arg << mkRect( s );
0654     else if ( type == "QVariant" ) {
0655         if ( s == "true" || s == "false" )
0656             arg << QVariant( mkBool( s ), 42 );
0657         else if ( s.left( 4 ) == "int(" )
0658             arg << QVariant( s.mid(4, s.length()-5).toInt() );
0659         else if ( s.left( 7 ) == "QPoint(" )
0660             arg << QVariant( mkPoint( s.mid(7, s.length()-8) ) );
0661         else if ( s.left( 6 ) == "QSize(" )
0662             arg << QVariant( mkSize( s.mid(6, s.length()-7) ) );
0663         else if ( s.left( 6 ) == "QRect(" )
0664             arg << QVariant( mkRect( s.mid(6, s.length()-7) ) );
0665         else if ( s.left( 7 ) == "QColor(" )
0666             arg << QVariant( mkColor( s.mid(7, s.length()-8) ) );
0667         else
0668             arg << QVariant( s );
0669     } else if ( type.startsWith("QValueList<")) {
0670         type = type.mid(11, type.length() - 12);
0671         QStringList list;
0672         QString delim = s;
0673         if (delim == "[")
0674            delim = "]";
0675         if (delim == "(")
0676            delim = ")";
0677 .
0678 247,317c
0679     if (type == "QStringList")
0680        type = "QValueList<QString>";
0681     if (type == "QCStringList")
0682        type = "QValueList<QCString>";
0683     if( i > args.count() )
0684     {
0685         qWarning("Not enough arguments.");
0686         exit(1);
0687     }       
0688     QString s = QString::fromLocal8Bit( args[ i ] );
0689 .
0690 245c
0691 void marshall( QDataStream &arg, QCStringList args, uint &i, QString type )
0692 .