summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-04-26 12:25:42 (UTC)
committer mickeyl <mickeyl>2004-04-26 12:25:42 (UTC)
commita26e4da56923553a2f9e4da4db3b92bdb75479c8 (patch) (unidiff)
treee936f193364176109edc0ae4cc05678a2549ca78
parentcaf74b437544a95410bbd030045e15e4dcaa91f0 (diff)
downloadopie-a26e4da56923553a2f9e4da4db3b92bdb75479c8.zip
opie-a26e4da56923553a2f9e4da4db3b92bdb75479c8.tar.gz
opie-a26e4da56923553a2f9e4da4db3b92bdb75479c8.tar.bz2
update
Diffstat (more/less context) (ignore whitespace changes)
-rwxr-xr-xscripts/qdebug-odebug.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/scripts/qdebug-odebug.py b/scripts/qdebug-odebug.py
index 636c1b2..7a417e1 100755
--- a/scripts/qdebug-odebug.py
+++ b/scripts/qdebug-odebug.py
@@ -1,55 +1,60 @@
1#!/usr/bin/env python 1#!/usr/bin/env python
2 2
3""" 3"""
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( '(?P<head>.*)(?P<statement>qDebug)\(\s*(?P<content>.*)\s*\);(?P<tail>.*)' )
13qWarningExpression = sre.compile( '(.*)(qWarning)\(\s*(.*)\s*\);(.*)' ) 13qWarningExpression = sre.compile( '(?P<head>.*)(?P<statement>qWarning)\(\s*(?P<content>.*)\s*\);(?P<tail>.*)' )
14qErrorExpression = sre.compile( '(.*)(qError)\(\s*(.*)\s*\);(.*)' ) 14qErrorExpression = sre.compile( '(?P<head>.*)(?P<statement>qError)\(\s*(?P<content>.*)\s*\);(?P<tail>.*)' )
15qFatalExpression = sre.compile( '(.*)(qFatal)\(\s*(.*)\s*\);(.*)' ) 15qFatalExpression = sre.compile( '(?P<head>.*)(?P<statement>qFatal)\(\s*(?P<content>.*)\s*\);(?P<tail>.*)' )
16printfExpression = sre.compile( '(.*)(printf)\(\s*(.*)\s*\);(.*)' ) 16#printfExpression = sre.compile( '(?P<head>.*)(?![s\.])(?P<statement>printf)\(\s*(?P<content>.*)\s*\);(?P<tail>.*)' )
17 17
18debugTable = { "qDebug" : "odebug", 18debugTable = { "qDebug" : "odebug",
19 "qWarning" : "owarn", 19 "qWarning" : "owarn",
20 "qError" : "oerr", 20 "qError" : "oerr",
21 "qFatal" : "ofatal", 21 "qFatal" : "ofatal",
22 "printf" : "odebug" } 22 "printf" : "odebug" }
23 23
24allExpressions = ( qDebugExpression, qWarningExpression, qErrorExpression, qFatalExpression, printfExpression ) 24allExpressions = ( qDebugExpression, qWarningExpression, qErrorExpression, qFatalExpression ) #, printfExpression )
25 25
26#################################################################################################### 26####################################################################################################
27 27
28def convert( fname ): 28def convert( fname ):
29 print >>sys.stderr, "<NOTE>: Dealing with %s..." % fname 29 print >>sys.stderr, "<NOTE>: Dealing with %s..." % fname
30 30
31 for line in file( fname ): 31 for line in file( fname ):
32 match = False 32 match = False
33 for expr in allExpressions: 33 for expr in allExpressions:
34 m = expr.match( line ) 34 m = expr.match( line )
35 if m is None: 35 if m is None:
36 continue 36 continue
37 else: 37 else:
38 match = True 38 match = True
39 head, debug, content, tail = m.groups() 39
40 head = m.groupdict()["head"]
41 debug = m.groupdict()["statement"]
42 content = m.groupdict()["content"]
43 tail = m.groupdict()["tail"]
44
40 print >>sys.stderr, "<NOTE>: Groups = ", m.groups() 45 print >>sys.stderr, "<NOTE>: Groups = ", m.groups()
41 sys.stdout.write( head ) # don't strip() here, because we want to keep indentation 46 sys.stdout.write( head ) # don't strip() here, because we want to keep indentation
42 sys.stdout.write( debugTable[debug.strip()] ) 47 sys.stdout.write( debugTable[debug.strip()] )
43 sys.stdout.write( " << " ) 48 sys.stdout.write( " << " )
44 sys.stdout.write( transform( content ).strip() ) 49 sys.stdout.write( transform( content ).strip() )
45 sys.stdout.write( " << oendl; " ) 50 sys.stdout.write( " << oendl; " )
46 sys.stdout.write( tail ) 51 sys.stdout.write( tail )
47 if not tail.endswith( "\n" ): sys.stdout.write( "\n" ) 52 if not tail.endswith( "\n" ): sys.stdout.write( "\n" )
48 continue 53 continue
49 # nothing applies 54 # nothing applies
50 if not match: 55 if not match:
51 sys.stdout.write( line ) 56 sys.stdout.write( line )
52 57
53#################################################################################################### 58####################################################################################################
54 59
55def transform( s ): 60def transform( s ):
@@ -82,33 +87,33 @@ def transform( s ):
82 87
83 formatstring, substitutions = groups[0], groups[1:] 88 formatstring, substitutions = groups[0], groups[1:]
84 result = "" 89 result = ""
85 90
86 # iterator over formatstring and substitute format directives (e.g. '%d') with the substitutions 91 # iterator over formatstring and substitute format directives (e.g. '%d') with the substitutions
87 subst = 0 92 subst = 0
88 i = 0 93 i = 0
89 indirective = False 94 indirective = False
90 while i < len( formatstring ): 95 while i < len( formatstring ):
91 if formatstring[i] != "%": 96 if formatstring[i] != "%":
92 result += formatstring[i] 97 result += formatstring[i]
93 i += 1 98 i += 1
94 continue 99 continue
95 else: # % in formatstring 100 else: # % in formatstring
96 indirective = True 101 indirective = True
97 i += 1 102 i += 1
98 while i < len( formatstring ) and formatstring[i] not in "%dDiouxXfegEscpn": 103 while i < len( formatstring ) and formatstring[i] not in "%dDiouxXfFegEscpn":
99 i += 1 104 i += 1
100 if formatstring[i] == "%": 105 if formatstring[i] == "%":
101 result += "%" 106 result += "%"
102 else: 107 else:
103 result += '" << %s << "' % substitutions[0].replace( "(const char*)", "" ).replace( ".latin1()", "" ) 108 result += '" << %s << "' % substitutions[0].replace( "(const char*)", "" ).replace( ".latin1()", "" )
104 del substitutions[0] 109 del substitutions[0]
105 indirective = False 110 indirective = False
106 i += 1 111 i += 1
107 112
108 print >>sys.stderr, "<NOTE>: Result seems to be '%s'" % result 113 print >>sys.stderr, "<NOTE>: Result seems to be '%s'" % result
109 return result.replace( "%%", "%" ) 114 return result.replace( "%%", "%" )
110 115
111#################################################################################################### 116####################################################################################################
112 117
113if __name__ == "__main__": 118if __name__ == "__main__":
114 try: 119 try: