dcop
main.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <qdom.h>
00024 #include <qfile.h>
00025 #include <qtextstream.h>
00026 #include <qstring.h>
00027
00028 #include <string.h>
00029 #include <stdlib.h>
00030 #include <stdio.h>
00031 #include <unistd.h>
00032 #include "main.h"
00033
00034
00035
00036 void usage()
00037 {
00038 fprintf( stderr, "Usage: dcopidl2cpp [ --no-skel | --no-stub ] [--c++-suffix <suffix>] file\n" );
00039 }
00040
00041 int main( int argc, char** argv )
00042 {
00043
00044 if ( *qVersion() == '1' ) {
00045 fprintf( stderr, "dcopidl2cpp appears to be linked to Qt 1 instead of Qt >= 2 ! Aborting.\n" );
00046 exit(1);
00047 }
00048 if ( argc < 2 ) {
00049 usage();
00050 return 1;
00051 }
00052 int argpos = 1;
00053 bool generate_skel = true;
00054 bool generate_stub = true;
00055
00056 QString suffix = "cpp";
00057
00058 while (argc > 2) {
00059
00060 if ( strcmp( argv[argpos], "--no-skel" ) == 0 )
00061 {
00062 generate_skel = false;
00063 for (int i = argpos; i < argc - 1; i++) argv[i] = argv[i+1];
00064 argc--;
00065 }
00066 else if ( strcmp( argv[argpos], "--no-stub" ) == 0 )
00067 {
00068 generate_stub = false;
00069 for (int i = argpos; i < argc - 1; i++) argv[i] = argv[i+1];
00070 argc--;
00071 }
00072 else if ( strcmp( argv[argpos], "--no-signals" ) == 0 )
00073 {
00074
00075
00076 for (int i = argpos; i < argc - 1; i++) argv[i] = argv[i+1];
00077 argc--;
00078 }
00079 else if ( strcmp( argv[argpos], "--c++-suffix" ) == 0)
00080 {
00081 if (argc - 1 < argpos) {
00082 usage();
00083 exit(1);
00084 }
00085 suffix = argv[argpos+1];
00086 for (int i = argpos; i < argc - 2; i++) argv[i] = argv[i+2];
00087 argc -= 2;
00088 } else {
00089 usage();
00090 exit(1);
00091 }
00092 }
00093
00094 QFile in( QFile::decodeName(argv[argpos]) );
00095 if ( !in.open( IO_ReadOnly ) )
00096 qFatal("Could not read %s", argv[argpos] );
00097
00098 QDomDocument doc;
00099 doc.setContent( &in );
00100
00101 QDomElement de = doc.documentElement();
00102 Q_ASSERT( de.tagName() == "DCOP-IDL" );
00103
00104 QString base( argv[argpos] );
00105 QString idl = base;
00106
00107 int pos = base.findRev( '.' );
00108 if ( pos != -1 )
00109 base = base.left( pos );
00110
00111 pos = idl.findRev('/');
00112 if ( pos != -1 )
00113 idl = idl.mid( pos+1 );
00114
00115 if ( generate_skel )
00116 generateSkel( idl, base + "_skel." + suffix, de );
00117
00118 if ( generate_stub ) {
00119 QString header = base;
00120 generateStub( idl, header + "_stub.h", de );
00121 pos = header.findRev('/');
00122 if ( pos != -1 )
00123 header = header.mid( pos+1 );
00124 generateStubImpl( idl, header + "_stub.h", base+".h", base + "_stub." + suffix, de);
00125 }
00126
00127 return 0;
00128 }