summaryrefslogtreecommitdiff
path: root/scripts/qdebug-odebug.py
authormickeyl <mickeyl>2004-04-02 12:28:51 (UTC)
committer mickeyl <mickeyl>2004-04-02 12:28:51 (UTC)
commitd3962d575f3fea442f9fb3e603f0a5f627ab4188 (patch) (unidiff)
tree5306c0ef2502a808e0f52e0f393d955ec7927770 /scripts/qdebug-odebug.py
parentbf7ec4adff3226b085421e0ea0b0699b748d3328 (diff)
downloadopie-d3962d575f3fea442f9fb3e603f0a5f627ab4188.zip
opie-d3962d575f3fea442f9fb3e603f0a5f627ab4188.tar.gz
opie-d3962d575f3fea442f9fb3e603f0a5f627ab4188.tar.bz2
this is a helper script for the qtdebug -> opiedebug conversion
it should catch most common usages - please try. Usage: qdebug-odebug.py <oldfilename.cpp> >newfilename.cpp
Diffstat (limited to 'scripts/qdebug-odebug.py') (more/less context) (ignore whitespace changes)
-rwxr-xr-xscripts/qdebug-odebug.py116
1 files changed, 116 insertions, 0 deletions
diff --git a/scripts/qdebug-odebug.py b/scripts/qdebug-odebug.py
new file mode 100755
index 0000000..cc1b7ca
--- a/dev/null
+++ b/scripts/qdebug-odebug.py
@@ -0,0 +1,116 @@
1#!/usr/bin/env python
2
3"""
4qdebug-odebug.py (C) 2004 Michael 'Mickey' Lauer <mickey@Vanille.de>
5This script helps to convert from the Qt debugging framework to the Opie debugging framework
6Though it will take care of the most common usages, it may not recognize uncommon ones, hence
7manual work may be needed after applying the script.
8"""
9
10import sys, sre
11
12qDebugExpression = sre.compile( '(.*)(qDebug)\(\s*(.*)\s*\);(.*)' )
13qWarningExpression = sre.compile( '(.*)(qWarning)\(\s*(.*)\s*\);(.*)' )
14qErrorExpression = sre.compile( '(.*)(qError)\(\s*(.*)\s*\);(.*)' )
15qFatalExpression = sre.compile( '(.*)(qFatal)\(\s*(.*)\s*\);(.*)' )
16
17debugTable = { "qDebug" : "odebug",
18 "qWarning" : "owarn",
19 "qError" : "oerr",
20 "qFatal" : "ofatal" }
21
22allExpressions = ( qDebugExpression, qWarningExpression, qErrorExpression, qFatalExpression )
23
24####################################################################################################
25
26def convert( fname ):
27 print >>sys.stderr, "<NOTE>: Dealing with %s..." % fname
28
29 for line in file( fname ):
30 match = False
31 for expr in allExpressions:
32 m = expr.match( line )
33 if m is None:
34 continue
35 else:
36 match = True
37 head, debug, content, tail = m.groups()
38 print >>sys.stderr, "<NOTE>: Groups = ", m.groups()
39 sys.stdout.write( head.strip() )
40 sys.stdout.write( debugTable[debug.strip()] )
41 sys.stdout.write( " << " )
42 sys.stdout.write( transform( content ).strip() )
43 sys.stdout.write( " << oendl; " )
44 sys.stdout.write( tail + "\n" )
45 continue
46 # nothing applies
47 if not match:
48 sys.stdout.write( line + "\n" )
49
50####################################################################################################
51
52def transform( s ):
53 print >>sys.stderr, "<NOTE>: Transforming '%s'..." % s
54
55 # check if there is one or more comma's outside of strings
56 groups = []
57 i = 0
58 instring = False
59 group = ""
60 while i < len( s ):
61 if s[i] == '"':
62 instring = not instring
63 elif s[i] == "," and not instring:
64 groups.append( group.strip() )
65 group = ""
66 i += 1
67 continue
68 group += s[i]
69 i += 1
70 continue
71
72 groups.append( group.strip() )
73
74 # check for easy case
75 if len( groups ) < 2: return s.replace( "%%", "%" )
76
77 # damn. it gets complicated...
78 print >>sys.stderr, "<NOTE>: Comma's outside of strings = %d" % ( len( groups ) -1 )
79
80 formatstring, substitutions = groups[0], groups[1:]
81 result = ""
82
83 # iterator over formatstring and substitute format directives (e.g. '%d') with the substitutions
84 subst = 0
85 i = 0
86 indirective = False
87 while i < len( formatstring ):
88 if formatstring[i] != "%":
89 result += formatstring[i]
90 i += 1
91 continue
92 else: # % in formatstring
93 indirective = True
94 i += 1
95 while i < len( formatstring ) and formatstring[i] not in "%dDiouxXfegEscpn":
96 i += 1
97 if formatstring[i] == "%":
98 result += "%"
99 else:
100 result += '" << %s << "' % substitutions[0]
101 del substitutions[0]
102 indirective = False
103 i += 1
104
105 print >>sys.stderr, "<NOTE>: Result seems to be '%s'" % result
106 return result.replace( "%%", "%" )
107
108####################################################################################################
109
110if __name__ == "__main__":
111 try:
112 fname = sys.argv[1]
113 except:
114 print >>sys.stderr, "Usage: %s <filename>\n" % sys.argv[0]
115 else:
116 convert( fname )