summaryrefslogtreecommitdiff
path: root/scripts
authormickeyl <mickeyl>2004-04-03 13:45:37 (UTC)
committer mickeyl <mickeyl>2004-04-03 13:45:37 (UTC)
commita8e37033a05dd7771cc1e73f387004f31683049d (patch) (unidiff)
tree0791911c75cea495fd69b6ef13aef6430a8738ee /scripts
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 (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
@@ -1,72 +1,75 @@
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( '(.*)(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 ):
61 if s[i] == '"': 64 if s[i] == '"':
62 instring = not instring 65 instring = not instring
63 elif s[i] == "," and not instring: 66 elif s[i] == "," and not instring:
64 groups.append( group.strip() ) 67 groups.append( group.strip() )
65 group = "" 68 group = ""
66 i += 1 69 i += 1
67 continue 70 continue
68 group += s[i] 71 group += s[i]
69 i += 1 72 i += 1
70 continue 73 continue
71 74
72 groups.append( group.strip() ) 75 groups.append( group.strip() )
@@ -76,41 +79,41 @@ def transform( s ):
76 79
77 # damn. it gets complicated... 80 # damn. it gets complicated...
78 print >>sys.stderr, "<NOTE>: Comma's outside of strings = %d" % ( len( groups ) -1 ) 81 print >>sys.stderr, "<NOTE>: Comma's outside of strings = %d" % ( len( groups ) -1 )
79 82
80 formatstring, substitutions = groups[0], groups[1:] 83 formatstring, substitutions = groups[0], groups[1:]
81 result = "" 84 result = ""
82 85
83 # iterator over formatstring and substitute format directives (e.g. '%d') with the substitutions 86 # iterator over formatstring and substitute format directives (e.g. '%d') with the substitutions
84 subst = 0 87 subst = 0
85 i = 0 88 i = 0
86 indirective = False 89 indirective = False
87 while i < len( formatstring ): 90 while i < len( formatstring ):
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]
113 except: 116 except:
114 print >>sys.stderr, "Usage: %s <filename>\n" % sys.argv[0] 117 print >>sys.stderr, "Usage: %s <filename>\n" % sys.argv[0]
115 else: 118 else:
116 convert( fname ) 119 convert( fname )