-rw-r--r-- | core/apps/qcop/main.cpp | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/core/apps/qcop/main.cpp b/core/apps/qcop/main.cpp new file mode 100644 index 0000000..73db0f6 --- a/dev/null +++ b/core/apps/qcop/main.cpp | |||
@@ -0,0 +1,85 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | #include <qpe/qcopenvelope_qws.h> | ||
22 | |||
23 | #include <qapplication.h> | ||
24 | #include <qstringlist.h> | ||
25 | #include <qdatastream.h> | ||
26 | #include <qtimer.h> | ||
27 | |||
28 | #include <stdlib.h> | ||
29 | #include <stdio.h> | ||
30 | |||
31 | static void usage() | ||
32 | { | ||
33 | fprintf( stderr, "Usage: qcop channel command [parameters]\n" ); | ||
34 | } | ||
35 | |||
36 | static void syntax( const QString &where, const QString &what ) | ||
37 | { | ||
38 | fprintf( stderr, "Syntax error in %s: %s\n", where.latin1(), what.latin1() ); | ||
39 | exit(1); | ||
40 | } | ||
41 | |||
42 | int main( int argc, char *argv[] ) | ||
43 | { | ||
44 | QApplication app( argc, argv ); | ||
45 | |||
46 | if ( argc < 3 ) { | ||
47 | usage(); | ||
48 | exit(1); | ||
49 | } | ||
50 | |||
51 | QString channel = argv[1]; | ||
52 | QString command = argv[2]; | ||
53 | command.stripWhiteSpace(); | ||
54 | |||
55 | int paren = command.find( "(" ); | ||
56 | if ( paren <= 0 ) | ||
57 | syntax( "command", command ); | ||
58 | |||
59 | QString params = command.mid( paren + 1 ); | ||
60 | if ( params[params.length()-1] != ')' ) | ||
61 | syntax( "command", command ); | ||
62 | |||
63 | params.truncate( params.length()-1 ); | ||
64 | QCopEnvelope env(channel.latin1(), command.latin1()); | ||
65 | |||
66 | int argIdx = 3; | ||
67 | |||
68 | QStringList paramList = QStringList::split( ",", params ); | ||
69 | QStringList::Iterator it; | ||
70 | for ( it = paramList.begin(); it != paramList.end(); ++it ) { | ||
71 | QString arg = argv[argIdx]; | ||
72 | if ( *it == "QString" ) { | ||
73 | env << arg; | ||
74 | } else if ( *it == "int" ) { | ||
75 | env << arg.toInt(); | ||
76 | } else { | ||
77 | syntax( "paramter type", *it ); | ||
78 | } | ||
79 | argIdx++; | ||
80 | } | ||
81 | |||
82 | QTimer::singleShot( 0, &app, SLOT(quit()) ); | ||
83 | return app.exec(); | ||
84 | } | ||
85 | |||