Warning, /sdk/kompare/tests/cvsdiff/unifiedm.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 -u -r1.26 dcop.cpp
0006 --- client/dcop.cpp     2001/10/31 01:17:39     1.26
0007 +++ client/dcop.cpp     2002/01/16 18:06:14
0008 @@ -20,19 +20,47 @@
0009  
0010  ******************************************************************/
0011  
0012 -#include <qvariant.h>
0013 +#include <ctype.h>
0014 +#include <stdio.h>
0015 +#include <stdlib.h>
0016 +
0017  #include <qcolor.h>
0018 -#include "../kdatastream.h"
0019 +#include <qdir.h>
0020 +#include <qfile.h>
0021 +#include <qfileinfo.h>
0022 +#include <qmap.h>
0023 +#include <qstringlist.h>
0024 +#include <qtextstream.h>
0025 +#include <qvariant.h>
0026 +
0027 +// putenv() is not available on all platforms, so make sure the emulation
0028 +// wrapper is available in those cases by loading config.h!
0029 +#include <config.h>
0030 +
0031  #include "../dcopclient.h"
0032  #include "../dcopref.h"
0033 -#include <stdlib.h>
0034 -#include <stdio.h>
0035 -#include <ctype.h>
0036 +#include "../kdatastream.h"
0037  
0038  #include "marshall.cpp"
0039  
0040 +typedef QMap<QString, QString> UserList;
0041 +
0042  static DCOPClient* dcop = 0;
0043  
0044 +static QTextStream cout( stdout, IO_WriteOnly );
0045 +static QTextStream cerr( stderr, IO_WriteOnly );
0046 +
0047 +/**
0048 + * Session to send call to
0049 + * DefaultSession - current session. Current KDE session when called without
0050 + *                  --user or --all-users option. Otherwise this value ignores
0051 + *                  all users with more than one active session.
0052 + * AllSessions    - Send to all sessions found. requires --user or --all-users.
0053 + * QuerySessions  - Don't call DCOP, return a list of available sessions.
0054 + * CustomSession  - Use the specified session
0055 + */
0056 +enum Session { DefaultSession = 0, AllSessions, QuerySessions, CustomSession };
0057 +
0058  bool startsWith(const QCString &id, const char *str, int n)
0059  {
0060    return !n || (strncmp(id.data(), str, n) == 0);
0061 @@ -118,9 +146,8 @@
0062      }
0063  }
0064  
0065 -void callFunction( const char* app, const char* obj, const char* func, int argc, char** args )
0066 +void callFunction( const char* app, const char* obj, const char* func, const QCStringList args )
0067  {
0068 -
0069      QString f = func; // Qt is better with unicode strings, so use one.
0070      int left = f.find( '(' );
0071      int right = f.find( ')' );
0072 @@ -136,7 +163,7 @@
0073         bool ok = false;
0074         QCStringList funcs = dcop->remoteFunctions( app, obj, &ok );
0075         QCString realfunc;
0076 -       if ( !ok && argc == 0 )
0077 +       if ( !ok && args.isEmpty() )
0078             goto doit;
0079         if ( !ok )
0080          {
0081 @@ -153,15 +180,16 @@
0082  
0083             if ( l > 0 && (*it).mid( s, l - s ) == func ) {
0084                 realfunc = (*it).mid( s );
0085 -               int a = (*it).contains(',');
0086 -               if ( ( a == 0 && argc == 0) || ( a > 0 && a + 1 == argc ) )
0087 +               uint a = (*it).contains(',');
0088 +               if ( ( a == 0 && args.isEmpty() ) || ( a > 0 && a + 1 == args.count() ) )
0089                     break;
0090             }
0091         }
0092         if ( realfunc.isEmpty() )
0093         {
0094             qWarning("no such function");
0095 -            exit(1);
0096 +//            exit(1);
0097 +           return;
0098         }
0099         f = realfunc;
0100         left = f.find( '(' );
0101 @@ -243,11 +271,12 @@
0102      QCString replyType;
0103      QDataStream arg(data, IO_WriteOnly);
0104  
0105 -    int i = 0;
0106 -    for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) {
0107 -        marshall(arg, argc, args, i, *it);
0108 -    }
0109 -    if ( i != argc ) {
0110 +    uint i = 0;
0111 +    for( QStringList::Iterator it = types.begin(); it != types.end(); ++it )
0112 +        marshall( arg, args, i, *it );
0113 +
0114 +    if ( i != args.count() )
0115 +    {
0116         qWarning( "arguments do not match" );
0117         exit(1);
0118      }
0119 @@ -265,79 +294,480 @@
0120          }
0121      }
0122  }
0123 -
0124  
0125 +/**
0126 + * Show command-line help and exit
0127 + */
0128 +void showHelp( int exitCode = 0 )
0129 +{
0130 +    cout << "Usage: dcop [options] [application [object [function [arg1] [arg2] ... ] ] ]" << endl
0131 +        << "" << endl
0132 +        << "Console DCOP client" << endl
0133 +        << "" << endl
0134 +        << "Generic options:" << endl
0135 +        << "  --help          Show help about options" << endl
0136 +        << "" << endl
0137 +        << "Options:" << endl
0138 +        << "  --pipe          Call DCOP for each line read from stdin" << endl
0139 +        << "  --user <user>   Connect to the given user's DCOP server. This option will" << endl
0140 +        << "                  ignore the values of the environment vars $DCOPSERVER and" << endl
0141 +        << "                  $ICEAUTHORITY, even if they are set." << endl
0142 +        << "                  If the user has more than one open session, you must also" << endl
0143 +        << "                  use one of the --list-sessions, --session or --als-sessions" << endl
0144 +        << "                  command-line options." << endl
0145 +        << "  --all-users     Send the same DCOP call to all users with a running DCOP" << endl
0146 +        << "                  server. Only failed calls to existing DCOP servers will"
0147 +        << "                  generate an error message. If no DCOP server is available" << endl
0148 +        << "                  at all, no error will be generated." << endl;
0149 +    
0150 +    exit( exitCode );
0151 +}
0152  
0153 -int main( int argc, char** argv )
0154 +/**
0155 + * Return a list of all users and their home directories.
0156 + * Returns an empty list if /etc/passwd cannot be read for some reason.
0157 + */
0158 +static UserList userList()
0159  {
0160 +    UserList result;
0161 +    
0162 +    QFile f( "/etc/passwd" );
0163 +
0164 +    if( !f.open( IO_ReadOnly ) )
0165 +    {
0166 +       cerr << "Can't open /etc/passwd for reading!" << endl;
0167 +       return result;
0168 +    }
0169  
0170 -    if ( argc > 1 && argv[1][0] == '-' ) {
0171 -       fprintf( stderr, "Usage: dcop [ application [object [function [arg1] [arg2] [arg3] ... ] ] ] \n" );
0172 -       exit(0);
0173 +    QStringList l( QStringList::split( '\n', f.readAll() ) );
0174 +
0175 +    for( QStringList::ConstIterator it( l.begin() ); it != l.end(); ++it )
0176 +    {
0177 +       QStringList userInfo( QStringList::split( ':', *it, true ) );
0178 +       result[ userInfo[ 0 ] ] = userInfo[ 5 ];
0179      }
0180  
0181 -    DCOPClient client;
0182 -    client.attach();
0183 -    dcop = &client;
0184 +    return result;
0185 +}
0186 +
0187 +/**
0188 + * Return a list of available DCOP sessions for the specified user
0189 + * An empty list means no sessions are available, or an error occurred.
0190 + */
0191 +QStringList dcopSessionList( const QString &user, const QString &home )
0192 +{
0193 +    if( home.isEmpty() )
0194 +    {
0195 +       cerr << "WARNING: Cannot determine home directory for user "
0196 +            << user << "!" << endl
0197 +            << "Please check permissions or set the $DCOPSERVER variable manually before" << endl
0198 +            << "calling dcop." << endl;
0199 +       return QStringList();
0200 +    }
0201 +
0202 +    QStringList result;
0203 +    QFileInfo dirInfo( home );
0204 +    if( !dirInfo.exists() || !dirInfo.isReadable() )
0205 +       return result;
0206 +
0207 +    QDir d( home );
0208 +    d.setFilter( QDir::Files | QDir::Hidden | QDir::NoSymLinks );
0209 +    d.setNameFilter( ".DCOPserver*" );
0210 +
0211 +    const QFileInfoList *list = d.entryInfoList();
0212 +    if( !list )
0213 +       return result;
0214 +
0215 +    QFileInfoListIterator it( *list );
0216 +    QFileInfo *fi;
0217 +
0218 +    while ( ( fi = it.current() ) != 0 )
0219 +    {
0220 +       if( fi->isReadable() )
0221 +           result.append( fi->fileName() );
0222 +       ++it;
0223 +    }
0224 +    return result;
0225 +}
0226  
0227 +/**
0228 + * Do the actual DCOP call
0229 + */
0230 +void runDCOP( QCStringList args, UserList users, Session session,
0231 +              const QString sessionName, bool readStdin )
0232 +{
0233      QCString app;
0234      QCString objid;
0235      QCString function;
0236 -    char **args = 0;
0237 -    if ((argc > 1) && (strncmp(argv[1], "DCOPRef(", 8)) == 0)
0238 +    QCStringList params;
0239 +    DCOPClient *client = 0L;
0240 +    if ( !args.isEmpty() && args[ 0 ].find( "DCOPRef(" ) == 0 )
0241      {
0242 -       char *delim = strchr(argv[1], ',');
0243 -       if (!delim)
0244 -       {
0245 -          fprintf(stderr, "Error: '%s' is not a valid DCOP reference.\n", argv[1]);
0246 -          return 1;
0247 -       }
0248 -       *delim = 0;
0249 -       app = argv[1] + 8;
0250 -       delim++;
0251 -       delim[strlen(delim)-1] = 0;
0252 -       objid = delim;
0253 -       if (argc > 2)
0254 -          function = argv[2];
0255 -       if (argc > 3)
0256 -          args = &argv[3];
0257 -       argc++;
0258 +       // WARNING: This part (until the closing '}') could very
0259 +       // well be broken now. As I don't know how to trigger and test
0260 +       // dcoprefs this code is *not* tested. It compiles and it looks
0261 +       // ok to me, but that's all I can say - Martijn (2001/12/24)
0262 +       int delimPos = args[ 0 ].findRev( ',' );
0263 +       if( delimPos == -1 )
0264 +        {
0265 +           cerr << "Error: '" << args[ 0 ]
0266 +                << "' is not a valid DCOP reference." << endl;
0267 +           exit( -1 );
0268 +        }
0269 +        args[ 0 ][ delimPos ] = 0;
0270 +        app = args[ 0 ].mid( 8 );
0271 +        delimPos++;
0272 +        args[ 0 ][ args[ 0 ].length() - 1 ] = 0;
0273 +        objid = args[ 0 ].mid( delimPos );
0274 +        if( args.count() > 1 )
0275 +           function = args[ 1 ];
0276 +       if( args.count() > 2 )
0277 +       {
0278 +           params = args;
0279 +           params.remove( params.begin() );
0280 +           params.remove( params.begin() );
0281 +       }
0282      }
0283      else
0284      {
0285 -       if (argc > 1)
0286 -          app = argv[1];
0287 -       if (argc > 2)
0288 -          objid = argv[2];
0289 -       if (argc > 3)
0290 -          function = argv[3];
0291 -       if (argc > 4)
0292 -          args = &argv[4];
0293 -    }
0294 -
0295 -    switch ( argc ) {
0296 -    case 0:
0297 -    case 1:
0298 -       queryApplications("");
0299 -       break;
0300 -    case 2:
0301 -        if (endsWith(app, '*'))
0302 -           queryApplications(app);
0303 -        else
0304 -           queryObjects( app, "" );
0305 -       break;
0306 -    case 3:
0307 -        if (endsWith(objid, '*'))
0308 -           queryObjects(app, objid);
0309 -        else
0310 -           queryFunctions( app, objid );
0311 -       break;
0312 -    case 4:
0313 -    default:
0314 -       callFunction( app, objid, function, argc - 4, args );
0315 -       break;
0316 +        if( !args.isEmpty() )
0317 +           app = args[ 0 ];
0318 +        if( args.count() > 1 )
0319 +           objid = args[ 1 ];
0320 +        if( args.count() > 2 )
0321 +           function = args[ 2 ];
0322 +        if( args.count() > 3)
0323 +       {
0324 +           params = args;
0325 +           params.remove( params.begin() );
0326 +           params.remove( params.begin() );
0327 +           params.remove( params.begin() );
0328 +       }
0329 +    }
0330 +
0331 +    bool firstRun = true;
0332 +    UserList::Iterator it;
0333 +    QStringList sessions;
0334 +    bool presetDCOPServer = false;
0335 +//    char *dcopStr = 0L;
0336 +    QString dcopServer;
0337 +    
0338 +    for( it = users.begin(); it != users.end() || firstRun; it++ )
0339 +    {
0340 +       firstRun = false;
0341 +
0342 +       //cout << "Iterating '" << it.key() << "'" << endl;
0343 +
0344 +       if( session == QuerySessions )
0345 +       {
0346 +           QStringList sessions = dcopSessionList( it.key(), it.data() );
0347 +           if( sessions.isEmpty() )
0348 +           {
0349 +               cout << "No active sessions";
0350 +               if( !( *it ).isEmpty() )
0351 +                   cout << " for user " << *it;
0352 +               cout << endl;
0353 +           }
0354 +           else
0355 +           {
0356 +               cout << "Active sessions ";
0357 +               if( !( *it ).isEmpty() )
0358 +                   cout << "for user " << *it << " ";
0359 +               cout << ":" << endl;
0360 +               
0361 +               QStringList::Iterator sIt;
0362 +               for( sIt = sessions.begin(); sIt != sessions.end(); sIt++ )
0363 +                   cout << "  " << *sIt << endl;
0364 +
0365 +               cout << endl;
0366 +           }
0367 +           continue;
0368 +       }
0369 +
0370 +       if( getenv( "DCOPSERVER" ) )
0371 +       {
0372 +           sessions.append( getenv( "DCOPSERVER" ) );
0373 +           presetDCOPServer = true;
0374 +       }
0375 +
0376 +       if( users.count() > 1 || ( users.count() == 1 &&
0377 +           ( getenv( "DCOPSERVER" ) == 0 /*&& getenv( "DISPLAY" ) == 0*/ ) ) )
0378 +       {
0379 +           sessions = dcopSessionList( it.key(), it.data() );
0380 +           if( sessions.isEmpty() )
0381 +           {
0382 +               if( users.count() > 1 )
0383 +                   continue;
0384 +               else
0385 +               {
0386 +                   cerr << "ERROR: No active KDE sessions!" << endl
0387 +                        << "If you are sure there is one, please set the $DCOPSERVER variable manually" << endl
0388 +                        << "before calling dcop." << endl;
0389 +                   exit( -1 );
0390 +               }
0391 +           }
0392 +           else if( sessions.count() > 1 && session != AllSessions )
0393 +           {
0394 +               cerr << "ERROR: Multiple available KDE sessions!" << endl
0395 +                    << "Please specify the correct session to use with --session or use the" << endl
0396 +                    << "--all-sessions option to broadcast to all sessions." << endl;
0397 +               exit( -1 );
0398 +           }
0399 +       }
0400  
0401 +       if( users.count() > 1 || ( users.count() == 1 &&
0402 +           ( getenv( "ICEAUTHORITY" ) == 0 || getenv( "DISPLAY" ) == 0 ) ) )
0403 +       {
0404 +           // Check for ICE authority file and if the file can be read by us
0405 +           QString home = it.data();
0406 +           QString iceFile = it.data() + "/.ICEauthority";
0407 +           QFileInfo fi( iceFile );
0408 +           if( iceFile.isEmpty() )
0409 +           {
0410 +               cerr << "WARNING: Cannot determine home directory for user "
0411 +                    << it.key() << "!" << endl
0412 +                    << "Please check permissions or set the $ICEAUTHORITY variable manually before" << endl
0413 +                    << "calling dcop." << endl;
0414 +           }
0415 +           else if( fi.exists() )
0416 +           {
0417 +               if( fi.isReadable() )
0418 +               {
0419 +                   char *envStr = strdup( ( "ICEAUTHORITY=" + iceFile ).ascii() );
0420 +                   putenv( envStr );
0421 +                   //cerr << "ice: " << envStr << endl;
0422 +               }
0423 +               else
0424 +               {
0425 +                   cerr << "WARNING: ICE authority file " << iceFile
0426 +                        << "is not readable by you!" << endl
0427 +                        << "Please check permissions or set the $ICEAUTHORITY variable manually before" << endl
0428 +                        << "calling dcop." << endl;
0429 +               }
0430 +           }
0431 +           else
0432 +           {
0433 +               if( users.count() > 1 )
0434 +                   continue;
0435 +               else
0436 +               {
0437 +                   cerr << "WARNING: Cannot find ICE authority file "
0438 +                        << iceFile << "!" << endl
0439 +                        << "Please check permissions or set the $ICEAUTHORITY"
0440 +                        << " variable manually before" << endl
0441 +                        << "calling dcop." << endl;
0442 +               }
0443 +           }
0444 +       }
0445 +
0446 +       // Main loop
0447 +       // If users is an empty list we're calling for the currently logged
0448 +       // in user. In this case we don't have a session, but still want
0449 +       // to iterate the loop once.
0450 +       QStringList::Iterator sIt = sessions.begin();
0451 +       for( ; sIt != sessions.end() || users.isEmpty(); sIt++ )
0452 +       {
0453 +           if( !presetDCOPServer && !users.isEmpty() )
0454 +           {
0455 +               QString dcopFile = it.data() + "/" + *sIt;
0456 +               QFile f( dcopFile );
0457 +               if( !f.open( IO_ReadOnly ) )
0458 +               {
0459 +                   cerr << "Can't open " << dcopFile << " for reading!" << endl;
0460 +                   exit( -1 );
0461 +               }
0462 +
0463 +               QStringList l( QStringList::split( '\n', f.readAll() ) );
0464 +               dcopServer = l.first();
0465 +
0466 +               if( dcopServer.isEmpty() )
0467 +               {
0468 +                   cerr << "WARNING: Unable to determine DCOP server for session "
0469 +                        << *sIt << "!" << endl
0470 +                        << "Please check permissions or set the $DCOPSERVER variable manually before" << endl
0471 +                        << "calling dcop." << endl;
0472 +                   exit( -1 );
0473 +               }
0474 +           }
0475 +           
0476 +           delete client;
0477 +           client = new DCOPClient;
0478 +           if( !dcopServer.isEmpty() )
0479 +               client->setServerAddress( dcopServer.ascii() );
0480 +           bool success = client->attach();
0481 +           if( !success )
0482 +           {
0483 +               cerr << "ERROR: Couldn't attach to DCOP server!" << endl;
0484 +               continue;
0485 +           }
0486 +           dcop = client;
0487 +
0488 +           switch ( args.count() )
0489 +           {
0490 +           case 0:
0491 +               queryApplications("");
0492 +               break;
0493 +           case 1:
0494 +               if (endsWith(app, '*'))
0495 +                  queryApplications(app);
0496 +               else
0497 +                  queryObjects( app, "" );
0498 +               break;
0499 +           case 2:
0500 +               if (endsWith(objid, '*'))
0501 +                  queryObjects(app, objid);
0502 +               else
0503 +                  queryFunctions( app, objid );
0504 +               break;
0505 +           case 3:
0506 +           default:
0507 +               if( readStdin )
0508 +               {
0509 +                   QCStringList::Iterator replaceArg = args.end();
0510 +                  
0511 +                   QCStringList::Iterator it;
0512 +                   for( it = args.begin(); it != args.end(); it++ )
0513 +                       if( *it == "%1" )
0514 +                           replaceArg = it;
0515 +                   
0516 +                   // Read from stdin until EOF and call function for each line read
0517 +                   char *buf = new char[ 1000 ];
0518 +                   while ( !feof( stdin ) )
0519 +                   {
0520 +                       fgets( buf, 1000, stdin );
0521 +               
0522 +                       if( replaceArg != args.end() )
0523 +                           *replaceArg = buf;
0524 +
0525 +                       callFunction( app, objid, function, params );
0526 +                   }
0527 +               }
0528 +               else
0529 +               {
0530 +                   // Just call function
0531 +//                 cout << "call " << app << ", " << objid << ", " << function << ", (params)" << endl;
0532 +                   callFunction( app, objid, function, params );
0533 +               }
0534 +               break;
0535 +           }
0536 +           // Another sIt++ would make the loop infinite...
0537 +           if( users.isEmpty() )
0538 +               break;
0539 +       }
0540 +       
0541 +       // Another it++ would make the loop infinite...
0542 +       if( it == users.end() )
0543 +           break;
0544      }
0545 +}
0546 +
0547  
0548 +int main( int argc, char** argv )
0549 +{
0550 +    bool readStdin = false;
0551 +    int numOptions = 0;
0552 +    QString user;
0553 +    Session session = DefaultSession;
0554 +    QString sessionName;
0555 +    
0556 +    // Scan for command-line options first
0557 +    for( int pos = 1 ; pos <= argc - 1 ; pos++ )
0558 +    {
0559 +       if( strcmp( argv[ pos ], "--help" ) == 0 )
0560 +           showHelp( 0 );
0561 +       else if( strcmp( argv[ pos ], "--pipe" ) == 0 )
0562 +       {
0563 +           readStdin = true;
0564 +           numOptions++;
0565 +       }
0566 +       else if( strcmp( argv[ pos ], "--user" ) == 0 )
0567 +       {
0568 +           if( pos <= argc - 2 )
0569 +           {
0570 +               user = QString::fromLocal8Bit( argv[ pos + 1] );
0571 +               numOptions +=2;
0572 +               pos++;
0573 +           }
0574 +           else
0575 +           {
0576 +               cerr << "Missing username for '--user' option!" << endl << endl;
0577 +               showHelp( -1 );
0578 +           }
0579 +       }
0580 +       else if( strcmp( argv[ pos ], "--all-users" ) == 0 )
0581 +       {
0582 +           user = "*";
0583 +           numOptions ++;
0584 +       }
0585 +       else if( strcmp( argv[ pos ], "--list-sessions" ) == 0 )
0586 +       {
0587 +           session = QuerySessions;
0588 +           numOptions ++;
0589 +       }
0590 +       else if( strcmp( argv[ pos ], "--all-sessions" ) == 0 )
0591 +       {
0592 +           session = AllSessions;
0593 +           numOptions ++;
0594 +       }
0595 +       else if( argv[ pos ][ 0 ] == '-' )
0596 +       {
0597 +           cerr << "Unknown command-line option '" << argv[ pos ]
0598 +                << "'." << endl << endl;
0599 +           showHelp( -1 );
0600 +       }
0601 +       else
0602 +           break;      // End of options
0603 +    }
0604 +
0605 +    argc -= numOptions;
0606 +
0607 +    QCStringList args;
0608 +    for( int i = numOptions; i < argc + numOptions - 1; i++ )
0609 +       args.append( argv[ i + 1 ] );
0610 +    
0611 +    if( readStdin && args.count() < 3 )
0612 +    {
0613 +       cerr << "--pipe option only supported for function calls!" << endl << endl;
0614 +       showHelp( -1 );
0615 +    }
0616 +    
0617 +    if( user == "*" && args.count() < 3 && session != QuerySessions )
0618 +    {
0619 +       cerr << "ERROR: The --all-users option is only supported for function calls!" << endl << endl;
0620 +       showHelp( -1 );
0621 +    }
0622 +    
0623 +    if( session == QuerySessions && !args.isEmpty() )
0624 +    {
0625 +       cerr << "ERROR: The --list-sessions option cannot be used for actual DCOP calls!" << endl << endl;
0626 +       showHelp( -1 );
0627 +    }
0628 +    
0629 +    if( session == QuerySessions && user.isEmpty() )
0630 +    {
0631 +       cerr << "ERROR: The --list-sessions option can only be used with the --user or" << endl
0632 +            << "--all-users options!" << endl << endl;
0633 +       showHelp( -1 );
0634 +    }
0635 +    
0636 +    if( session != DefaultSession && session != QuerySessions &&
0637 +        args.count() < 3 )
0638 +    {
0639 +       cerr << "ERROR: The --session and --all-sessions options are only supported for function" << endl
0640 +            << "calls!" << endl << endl;
0641 +       showHelp( -1 );
0642 +    }
0643 +    
0644 +    UserList users;
0645 +    if( user == "*" )
0646 +       users = userList();
0647 +    else if( !user.isEmpty() )
0648 +       users[ user ] = userList()[ user ];
0649 +
0650 +    runDCOP( args, users, session, sessionName, readStdin );
0651 +
0652      return 0;
0653  }
0654 +
0655 +// vim: set ts=8 sts=4 sw=4 noet:
0656 +
0657 Index: client/dcopfind.cpp
0658 ===================================================================
0659 RCS file: /home/kde/kdelibs/dcop/client/dcopfind.cpp,v
0660 retrieving revision 1.2
0661 diff -u -r1.2 dcopfind.cpp
0662 --- client/dcopfind.cpp 2001/10/31 01:17:39     1.2
0663 +++ client/dcopfind.cpp 2002/01/16 18:06:14
0664 @@ -36,7 +36,7 @@
0665  static bool bAppIdOnly = 0;
0666  static bool bLaunchApp = 0;
0667  
0668 -bool findObject( const char* app, const char* obj, const char* func, int argc, char** args )
0669 +bool findObject( const char* app, const char* obj, const char* func, QCStringList args )
0670  {
0671      QString f = func; // Qt is better with unicode strings, so use one.
0672      int left = f.find( '(' );
0673 @@ -118,7 +118,7 @@
0674         f = fc;
0675      }
0676  
0677 -    if ( (int) types.count() != argc ) {
0678 +    if ( types.count() != args.count() ) {
0679         qWarning( "arguments do not match" );
0680         exit(1);
0681      }
0682 @@ -128,9 +128,9 @@
0683  
0684      int i = 0;
0685      for ( QStringList::Iterator it = types.begin(); it != types.end(); ++it ) {
0686 -        marshall(arg, argc, args, i, *it);
0687 +        marshall(arg, args, i, *it);
0688      }
0689 -    if ( (int) i != argc ) {
0690 +    if ( (uint) i != args.count() ) {
0691         qWarning( "arguments do not match" );
0692         exit(1);
0693      }
0694 @@ -221,7 +221,11 @@
0695         argc = 0;
0696      }
0697  
0698 -    findObject( app, objid, function, argc, args );
0699 +    QCStringList params;
0700 +    for( int i = 0; i < argc; i++ )
0701 +           params.append( args[ i ] );
0702 +    
0703 +    findObject( app, objid, function, params );
0704  
0705      return 0;
0706  }
0707 Index: client/marshall.cpp
0708 ===================================================================
0709 RCS file: /home/kde/kdelibs/dcop/client/marshall.cpp,v
0710 retrieving revision 1.3
0711 diff -u -r1.3 marshall.cpp
0712 --- client/marshall.cpp 2001/10/31 01:17:39     1.3
0713 +++ client/marshall.cpp 2002/01/16 18:06:14
0714 @@ -242,108 +242,110 @@
0715  
0716  }
0717  
0718 -void  marshall(QDataStream &arg, int argc, char **argv, int &i, QString type)
0719 +void marshall( QDataStream &arg, QCStringList args, uint &i, QString type )
0720  {
0721 -       if (type == "QStringList")
0722 -           type = "QValueList<QString>";
0723 -       if (type == "QCStringList")
0724 -           type = "QValueList<QCString>";
0725 -       if (i >= argc)
0726 -       {
0727 -           qWarning("Not enough arguments.");
0728 -            exit(1);
0729 -        }       
0730 -        QString s = QString::fromLocal8Bit(argv[i]);
0731 - 
0732 -       if ( type == "int" )
0733 -           arg << s.toInt();
0734 -       else if ( type == "uint" )
0735 -           arg << s.toUInt();
0736 -       else if ( type == "unsigned" )
0737 -           arg << s.toUInt();
0738 -       else if ( type == "unsigned int" )
0739 -           arg << s.toUInt();
0740 -       else if ( type == "long" )
0741 -           arg << s.toLong();
0742 -       else if ( type == "long int" )
0743 -           arg << s.toLong();
0744 -       else if ( type == "unsigned long" )
0745 -           arg << s.toULong();
0746 -       else if ( type == "unsigned long int" )
0747 -           arg << s.toULong();
0748 -       else if ( type == "float" )
0749 -           arg << s.toFloat();
0750 -       else if ( type == "double" )
0751 -           arg << s.toDouble();
0752 -       else if ( type == "bool" )
0753 -           arg << mkBool( s );
0754 -       else if ( type == "QString" )
0755 -           arg << s;
0756 -       else if ( type == "QCString" )
0757 -           arg << QCString( argv[i] );
0758 -       else if ( type == "QColor" )
0759 -           arg << mkColor( s );
0760 -       else if ( type == "QPoint" )
0761 -           arg << mkPoint( s );
0762 -       else if ( type == "QSize" )
0763 -           arg << mkSize( s );
0764 -       else if ( type == "QRect" )
0765 -           arg << mkRect( s );
0766 -       else if ( type == "QVariant" ) {
0767 -           if ( s == "true" || s == "false" )
0768 -               arg << QVariant( mkBool( s ), 42 );
0769 -           else if ( s.left( 4 ) == "int(" )
0770 -               arg << QVariant( s.mid(4, s.length()-5).toInt() );
0771 -           else if ( s.left( 7 ) == "QPoint(" )
0772 -               arg << QVariant( mkPoint( s.mid(7, s.length()-8) ) );
0773 -           else if ( s.left( 6 ) == "QSize(" )
0774 -               arg << QVariant( mkSize( s.mid(6, s.length()-7) ) );
0775 -           else if ( s.left( 6 ) == "QRect(" )
0776 -               arg << QVariant( mkRect( s.mid(6, s.length()-7) ) );
0777 -           else if ( s.left( 7 ) == "QColor(" )
0778 -               arg << QVariant( mkColor( s.mid(7, s.length()-8) ) );
0779 -           else
0780 -               arg << QVariant( s );
0781 -       } else if ( type.startsWith("QValueList<")) {
0782 -            type = type.mid(11, type.length() - 12);
0783 -            QStringList list;
0784 -           QString delim = s;
0785 -            if (delim == "[")
0786 -               delim = "]";
0787 -            if (delim == "(")
0788 -               delim = ")";
0789 -            i++;
0790 -           QByteArray dummy_data;
0791 -            QDataStream dummy_arg(dummy_data, IO_WriteOnly);
0792 +    if (type == "QStringList")
0793 +       type = "QValueList<QString>";
0794 +    if (type == "QCStringList")
0795 +       type = "QValueList<QCString>";
0796 +    if( i > args.count() )
0797 +    {
0798 +       qWarning("Not enough arguments.");
0799 +       exit(1);
0800 +    }       
0801 +    QString s = QString::fromLocal8Bit( args[ i ] );
0802  
0803 -            int j = i;
0804 -            int count = 0;
0805 -            // Parse list to get the count
0806 -            while (true) {
0807 -               if (j >= argc)
0808 -               {
0809 -                   qWarning("List end-delimiter '%s' not found.", delim.latin1());
0810 -                   exit(1);
0811 -               }
0812 -                if (argv[j] == delim) break;
0813 -                marshall(dummy_arg, argc, argv, j, type);
0814 -                count++;
0815 -            }
0816 -            arg << (Q_UINT32) count;
0817 -            // Parse the list for real
0818 -            while (true) {
0819 -               if (i >= argc)
0820 -               {
0821 -                   qWarning("List end-delimiter '%s' not found.", delim.latin1());
0822 -                   exit(1);
0823 -               }
0824 -                if (argv[i] == delim) break;
0825 -                marshall(arg, argc, argv, i, type);
0826 -            }
0827 -       } else {
0828 -           qWarning( "cannot handle datatype '%s'", type.latin1() );
0829 -           exit(1);
0830 -       }
0831 +    if ( type == "int" )
0832 +       arg << s.toInt();
0833 +    else if ( type == "uint" )
0834 +       arg << s.toUInt();
0835 +    else if ( type == "unsigned" )
0836 +       arg << s.toUInt();
0837 +    else if ( type == "unsigned int" )
0838 +       arg << s.toUInt();
0839 +    else if ( type == "long" )
0840 +       arg << s.toLong();
0841 +    else if ( type == "long int" )
0842 +       arg << s.toLong();
0843 +    else if ( type == "unsigned long" )
0844 +       arg << s.toULong();
0845 +    else if ( type == "unsigned long int" )
0846 +       arg << s.toULong();
0847 +    else if ( type == "float" )
0848 +       arg << s.toFloat();
0849 +    else if ( type == "double" )
0850 +       arg << s.toDouble();
0851 +    else if ( type == "bool" )
0852 +       arg << mkBool( s );
0853 +    else if ( type == "QString" )
0854 +       arg << s;
0855 +    else if ( type == "QCString" )
0856 +       arg << QCString( args[ i ] );
0857 +    else if ( type == "QColor" )
0858 +       arg << mkColor( s );
0859 +    else if ( type == "QPoint" )
0860 +       arg << mkPoint( s );
0861 +    else if ( type == "QSize" )
0862 +       arg << mkSize( s );
0863 +    else if ( type == "QRect" )
0864 +       arg << mkRect( s );
0865 +    else if ( type == "QVariant" ) {
0866 +       if ( s == "true" || s == "false" )
0867 +           arg << QVariant( mkBool( s ), 42 );
0868 +       else if ( s.left( 4 ) == "int(" )
0869 +           arg << QVariant( s.mid(4, s.length()-5).toInt() );
0870 +       else if ( s.left( 7 ) == "QPoint(" )
0871 +           arg << QVariant( mkPoint( s.mid(7, s.length()-8) ) );
0872 +       else if ( s.left( 6 ) == "QSize(" )
0873 +           arg << QVariant( mkSize( s.mid(6, s.length()-7) ) );
0874 +       else if ( s.left( 6 ) == "QRect(" )
0875 +           arg << QVariant( mkRect( s.mid(6, s.length()-7) ) );
0876 +       else if ( s.left( 7 ) == "QColor(" )
0877 +           arg << QVariant( mkColor( s.mid(7, s.length()-8) ) );
0878 +       else
0879 +           arg << QVariant( s );
0880 +    } else if ( type.startsWith("QValueList<")) {
0881 +       type = type.mid(11, type.length() - 12);
0882 +       QStringList list;
0883 +       QString delim = s;
0884 +       if (delim == "[")
0885 +          delim = "]";
0886 +       if (delim == "(")
0887 +          delim = ")";
0888         i++;
0889 +       QByteArray dummy_data;
0890 +       QDataStream dummy_arg(dummy_data, IO_WriteOnly);
0891 +
0892 +       uint j = i;
0893 +       uint count = 0;
0894 +       // Parse list to get the count
0895 +       while (true) {
0896 +           if( j > args.count() )
0897 +           {
0898 +               qWarning("List end-delimiter '%s' not found.", delim.latin1());
0899 +               exit(1);
0900 +           }
0901 +           if( QString::fromLocal8Bit( args[ j ] ) == delim )
0902 +               break;
0903 +           marshall( dummy_arg, args, j, type );
0904 +           count++;
0905 +       }
0906 +       arg << (Q_UINT32) count;
0907 +       // Parse the list for real
0908 +       while (true) {
0909 +           if( i > args.count() )
0910 +           {
0911 +               qWarning("List end-delimiter '%s' not found.", delim.latin1());
0912 +               exit(1);
0913 +           }
0914 +           if( QString::fromLocal8Bit( args[ i ] ) == delim )
0915 +               break;
0916 +           marshall( arg, args, i, type );
0917 +       }
0918 +    } else {
0919 +       qWarning( "cannot handle datatype '%s'", type.latin1() );
0920 +       exit(1);
0921 +    }
0922 +    i++;
0923  }
0924