summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-04-03 13:45:37 (UTC)
committer mickeyl <mickeyl>2004-04-03 13:45:37 (UTC)
commita8e37033a05dd7771cc1e73f387004f31683049d (patch) (unidiff)
tree0791911c75cea495fd69b6ef13aef6430a8738ee
parente995afe17ead003dd0b4bc12604d7f8cb5cd4493 (diff)
downloadopie-a8e37033a05dd7771cc1e73f387004f31683049d.zip
opie-a8e37033a05dd7771cc1e73f387004f31683049d.tar.gz
opie-a8e37033a05dd7771cc1e73f387004f31683049d.tar.bz2
small fixes and add 'printf' to the number of substituted constructs
the script seems to work good, i converted the whole 'noncore' which will be commited in a few hours. basically the only amount of handwork after applying the script is adding #include <opie2/odebug.h> and using namespace Opie::Core - if it's not already there.
Diffstat (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
@@ -8,49 +8,52 @@ manual 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 = []
@@ -92,17 +95,17 @@ def transform( s ):
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####################################################################################################