1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
#!/usr/bin/env python
import os, sys
dcopiface_header = """/* This file is part of the KDE project
* Copyright (C) 2005 Boudewijn Rempt <boud@valdyas.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef %(classname_upper)sIFACE_H
#define %(classname_upper)sIFACE_H
#include <dcopref.h>
#include <dcopobj.h>
#include <tqstring.h>
class %(classname)s;
class %(classname)sIface : virtual public DCOPObject
{
K_DCOP
public:
%(classname)sIface( %(classname)s * parent );
k_dcop:
private:
%(classname)s *m_parent;
};
#endif
"""
dcopiface_template = """/*
* This file is part of the KDE project
*
* Copyright (C) 2005 Boudewijn Rempt <boud@valdyas.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <tdeapplication.h>
#include "%(ifaceheader)s"
#include "%(classheader)s"
#include <dcopclient.h>
%(classname)sIface::%(classname)sIface( %(classname)s * parent )
: DCOPObject()
{
m_parent = parent;
}
"""
def parseHeader(headerfile, classname):
# parse the source class header to get a list of functions we're going to wrap
functions = []
if (headerfile.find("private:") > -1):
lines = headerfile[headerfile.find(classname):headerfile.find("private")].splitlines()
else:
lines = headerfile[headerfile.find(classname):headerfile.find("#endif")].splitlines()
i = 0
while i < len(lines):
line = lines[i].strip()
if (line.startswith("/") or
line.startswith("public:") or
line.startswith("*") or
line.startswith(classname) or
line.startswith("class") or
line.startswith("TQ_OBJECT") or
line.startswith("#") or
line.startswith("}") or
line.startswith("public Q_SLOTS:") or
line.find("~") != -1 or
len(line) == 0
):
i+=1
continue
if (line.startswith("protected")):
return functions
# by now we are reasonable sure that this is a function. We need to find the end of the function definition, and then
# if the return type is not primitive, replace it with dcopref.
function = line
complete = 0
# strip the inline implementation
if (line.find("{") > -1):
function = line[:line.find("{")]
if function.find("}") > -1:
function += line[line.find("}") + 1:]
complete = 1
else:
i += 1
# search for the missing } on the next lines
while i < len(lines):
if (lines[i].find("}") > -1):
function += lines[i][lines[i].find("}") + 1:]
complete = 1
i += 1
else:
complete = 1
if complete == 0:
i+=1
continue
if (function.endswith("= 0;")):
function = function[:-4] + ";"
print("\t", function)
i+=1
def createDCOP(header):
# Determine filenames and classnames
implementation = header[:-1] + "cc"
classname = ""
classname_upper ="_"
for part in header[:-2].split("_"):
classname = classname + part.capitalize()
classname_upper = classname_upper + part.upper() + "_"
ifaceheader = header[:-2] + "_iface.h"
ifaceimplementation = header[:-2] + "_iface.cpp"
ifaceclass = classname + "Iface"
#print "with: ", implementation, classname, classname_upper, ifaceheader, ifaceimplementation, ifaceclass
file(ifaceheader, "w+").write(dcopiface_header % { "classname_upper" : classname_upper,
"classname" : classname})
file(ifaceimplementation, "w+").write(dcopiface_template % {"ifaceheader" : ifaceheader,
"classheader" : header,
"classname" : classname })
functions = parseHeader(open(header).read(), classname)
def main(args):
for line in args[1:]:
print("Going to create a dcop interface for:", line[:-1])
createDCOP(line.strip())
if __name__=="__main__":
main(sys.argv)
|