summaryrefslogtreecommitdiff
path: root/scripts
Unidiff
Diffstat (limited to 'scripts') (more/less context) (ignore whitespace changes)
-rwxr-xr-xscripts/qdebug-odebug.py15
1 files changed, 9 insertions, 6 deletions
diff --git a/scripts/qdebug-odebug.py b/scripts/qdebug-odebug.py
index cc1b7ca..636c1b2 100755
--- a/scripts/qdebug-odebug.py
+++ b/scripts/qdebug-odebug.py
@@ -4,57 +4,60 @@
4qdebug-odebug.py (C) 2004 Michael 'Mickey' Lauer <mickey@Vanille.de> 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 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 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. 7manual work may be needed after applying the script.
8""" 8"""
9 9
10import sys, sre 10import sys, sre
11 11
12qDebugExpression = sre.compile( '(.*)(qDebug)\(\s*(.*)\s*\);(.*)' ) 12qDebugExpression = sre.compile( '(.*)(qDebug)\(\s*(.*)\s*\);(.*)' )
13qWarningExpression = sre.compile( '(.*)(qWarning)\(\s*(.*)\s*\);(.*)' ) 13qWarningExpression = sre.compile( '(.*)(qWarning)\(\s*(.*)\s*\);(.*)' )
14qErrorExpression = sre.compile( '(.*)(qError)\(\s*(.*)\s*\);(.*)' ) 14qErrorExpression = sre.compile( '(.*)(qError)\(\s*(.*)\s*\);(.*)' )
15qFatalExpression = sre.compile( '(.*)(qFatal)\(\s*(.*)\s*\);(.*)' ) 15qFatalExpression = sre.compile( '(.*)(qFatal)\(\s*(.*)\s*\);(.*)' )
16printfExpression = sre.compile( '(.*)(printf)\(\s*(.*)\s*\);(.*)' )
16 17
17debugTable = { "qDebug" : "odebug", 18debugTable = { "qDebug" : "odebug",
18 "qWarning" : "owarn", 19 "qWarning" : "owarn",
19 "qError" : "oerr", 20 "qError" : "oerr",
20 "qFatal" : "ofatal" } 21 "qFatal" : "ofatal",
22 "printf" : "odebug" }
21 23
22allExpressions = ( qDebugExpression, qWarningExpression, qErrorExpression, qFatalExpression ) 24allExpressions = ( qDebugExpression, qWarningExpression, qErrorExpression, qFatalExpression, printfExpression )
23 25
24#################################################################################################### 26####################################################################################################
25 27
26def convert( fname ): 28def convert( fname ):
27 print >>sys.stderr, "<NOTE>: Dealing with %s..." % fname 29 print >>sys.stderr, "<NOTE>: Dealing with %s..." % fname
28 30
29 for line in file( fname ): 31 for line in file( fname ):
30 match = False 32 match = False
31 for expr in allExpressions: 33 for expr in allExpressions:
32 m = expr.match( line ) 34 m = expr.match( line )
33 if m is None: 35 if m is None:
34 continue 36 continue
35 else: 37 else:
36 match = True 38 match = True
37 head, debug, content, tail = m.groups() 39 head, debug, content, tail = m.groups()
38 print >>sys.stderr, "<NOTE>: Groups = ", m.groups() 40 print >>sys.stderr, "<NOTE>: Groups = ", m.groups()
39 sys.stdout.write( head.strip() ) 41 sys.stdout.write( head ) # don't strip() here, because we want to keep indentation
40 sys.stdout.write( debugTable[debug.strip()] ) 42 sys.stdout.write( debugTable[debug.strip()] )
41 sys.stdout.write( " << " ) 43 sys.stdout.write( " << " )
42 sys.stdout.write( transform( content ).strip() ) 44 sys.stdout.write( transform( content ).strip() )
43 sys.stdout.write( " << oendl; " ) 45 sys.stdout.write( " << oendl; " )
44 sys.stdout.write( tail + "\n" ) 46 sys.stdout.write( tail )
47 if not tail.endswith( "\n" ): sys.stdout.write( "\n" )
45 continue 48 continue
46 # nothing applies 49 # nothing applies
47 if not match: 50 if not match:
48 sys.stdout.write( line + "\n" ) 51 sys.stdout.write( line )
49 52
50#################################################################################################### 53####################################################################################################
51 54
52def transform( s ): 55def transform( s ):
53 print >>sys.stderr, "<NOTE>: Transforming '%s'..." % s 56 print >>sys.stderr, "<NOTE>: Transforming '%s'..." % s
54 57
55 # check if there is one or more comma's outside of strings 58 # check if there is one or more comma's outside of strings
56 groups = [] 59 groups = []
57 i = 0 60 i = 0
58 instring = False 61 instring = False
59 group = "" 62 group = ""
60 while i < len( s ): 63 while i < len( s ):
@@ -88,25 +91,25 @@ def transform( s ):
88 if formatstring[i] != "%": 91 if formatstring[i] != "%":
89 result += formatstring[i] 92 result += formatstring[i]
90 i += 1 93 i += 1
91 continue 94 continue
92 else: # % in formatstring 95 else: # % in formatstring
93 indirective = True 96 indirective = True
94 i += 1 97 i += 1
95 while i < len( formatstring ) and formatstring[i] not in "%dDiouxXfegEscpn": 98 while i < len( formatstring ) and formatstring[i] not in "%dDiouxXfegEscpn":
96 i += 1 99 i += 1
97 if formatstring[i] == "%": 100 if formatstring[i] == "%":
98 result += "%" 101 result += "%"
99 else: 102 else:
100 result += '" << %s << "' % substitutions[0] 103 result += '" << %s << "' % substitutions[0].replace( "(const char*)", "" ).replace( ".latin1()", "" )
101 del substitutions[0] 104 del substitutions[0]
102 indirective = False 105 indirective = False
103 i += 1 106 i += 1
104 107
105 print >>sys.stderr, "<NOTE>: Result seems to be '%s'" % result 108 print >>sys.stderr, "<NOTE>: Result seems to be '%s'" % result
106 return result.replace( "%%", "%" ) 109 return result.replace( "%%", "%" )
107 110
108#################################################################################################### 111####################################################################################################
109 112
110if __name__ == "__main__": 113if __name__ == "__main__":
111 try: 114 try:
112 fname = sys.argv[1] 115 fname = sys.argv[1]