author | mickeyl <mickeyl> | 2004-04-26 12:25:42 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2004-04-26 12:25:42 (UTC) |
commit | a26e4da56923553a2f9e4da4db3b92bdb75479c8 (patch) (unidiff) | |
tree | e936f193364176109edc0ae4cc05678a2549ca78 /scripts | |
parent | caf74b437544a95410bbd030045e15e4dcaa91f0 (diff) | |
download | opie-a26e4da56923553a2f9e4da4db3b92bdb75479c8.zip opie-a26e4da56923553a2f9e4da4db3b92bdb75479c8.tar.gz opie-a26e4da56923553a2f9e4da4db3b92bdb75479c8.tar.bz2 |
update
-rwxr-xr-x | scripts/qdebug-odebug.py | 21 |
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,119 +1,124 @@ | |||
1 | #!/usr/bin/env python | 1 | #!/usr/bin/env python |
2 | 2 | ||
3 | """ | 3 | """ |
4 | qdebug-odebug.py (C) 2004 Michael 'Mickey' Lauer <mickey@Vanille.de> | 4 | qdebug-odebug.py (C) 2004 Michael 'Mickey' Lauer <mickey@Vanille.de> |
5 | This script helps to convert from the Qt debugging framework to the Opie debugging framework | 5 | This script helps to convert from the Qt debugging framework to the Opie debugging framework |
6 | Though it will take care of the most common usages, it may not recognize uncommon ones, hence | 6 | Though it will take care of the most common usages, it may not recognize uncommon ones, hence |
7 | manual work may be needed after applying the script. | 7 | manual work may be needed after applying the script. |
8 | """ | 8 | """ |
9 | 9 | ||
10 | import sys, sre | 10 | import sys, sre |
11 | 11 | ||
12 | qDebugExpression = sre.compile( '(.*)(qDebug)\(\s*(.*)\s*\);(.*)' ) | 12 | qDebugExpression = sre.compile( '(?P<head>.*)(?P<statement>qDebug)\(\s*(?P<content>.*)\s*\);(?P<tail>.*)' ) |
13 | qWarningExpression = sre.compile( '(.*)(qWarning)\(\s*(.*)\s*\);(.*)' ) | 13 | qWarningExpression = sre.compile( '(?P<head>.*)(?P<statement>qWarning)\(\s*(?P<content>.*)\s*\);(?P<tail>.*)' ) |
14 | qErrorExpression = sre.compile( '(.*)(qError)\(\s*(.*)\s*\);(.*)' ) | 14 | qErrorExpression = sre.compile( '(?P<head>.*)(?P<statement>qError)\(\s*(?P<content>.*)\s*\);(?P<tail>.*)' ) |
15 | qFatalExpression = sre.compile( '(.*)(qFatal)\(\s*(.*)\s*\);(.*)' ) | 15 | qFatalExpression = sre.compile( '(?P<head>.*)(?P<statement>qFatal)\(\s*(?P<content>.*)\s*\);(?P<tail>.*)' ) |
16 | printfExpression = sre.compile( '(.*)(printf)\(\s*(.*)\s*\);(.*)' ) | 16 | #printfExpression = sre.compile( '(?P<head>.*)(?![s\.])(?P<statement>printf)\(\s*(?P<content>.*)\s*\);(?P<tail>.*)' ) |
17 | 17 | ||
18 | debugTable = { "qDebug" : "odebug", | 18 | debugTable = { "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 | ||
24 | allExpressions = ( qDebugExpression, qWarningExpression, qErrorExpression, qFatalExpression, printfExpression ) | 24 | allExpressions = ( qDebugExpression, qWarningExpression, qErrorExpression, qFatalExpression ) #, printfExpression ) |
25 | 25 | ||
26 | #################################################################################################### | 26 | #################################################################################################### |
27 | 27 | ||
28 | def convert( fname ): | 28 | def 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 | ||
55 | def transform( s ): | 60 | def transform( s ): |
56 | print >>sys.stderr, "<NOTE>: Transforming '%s'..." % s | 61 | print >>sys.stderr, "<NOTE>: Transforming '%s'..." % s |
57 | 62 | ||
58 | # check if there is one or more comma's outside of strings | 63 | # check if there is one or more comma's outside of strings |
59 | groups = [] | 64 | groups = [] |
60 | i = 0 | 65 | i = 0 |
61 | instring = False | 66 | instring = False |
62 | group = "" | 67 | group = "" |
63 | while i < len( s ): | 68 | while i < len( s ): |
64 | if s[i] == '"': | 69 | if s[i] == '"': |
65 | instring = not instring | 70 | instring = not instring |
66 | elif s[i] == "," and not instring: | 71 | elif s[i] == "," and not instring: |
67 | groups.append( group.strip() ) | 72 | groups.append( group.strip() ) |
68 | group = "" | 73 | group = "" |
69 | i += 1 | 74 | i += 1 |
70 | continue | 75 | continue |
71 | group += s[i] | 76 | group += s[i] |
72 | i += 1 | 77 | i += 1 |
73 | continue | 78 | continue |
74 | 79 | ||
75 | groups.append( group.strip() ) | 80 | groups.append( group.strip() ) |
76 | 81 | ||
77 | # check for easy case | 82 | # check for easy case |
78 | if len( groups ) < 2: return s.replace( "%%", "%" ) | 83 | if len( groups ) < 2: return s.replace( "%%", "%" ) |
79 | 84 | ||
80 | # damn. it gets complicated... | 85 | # damn. it gets complicated... |
81 | print >>sys.stderr, "<NOTE>: Comma's outside of strings = %d" % ( len( groups ) -1 ) | 86 | print >>sys.stderr, "<NOTE>: Comma's outside of strings = %d" % ( len( groups ) -1 ) |
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 | ||
113 | if __name__ == "__main__": | 118 | if __name__ == "__main__": |
114 | try: | 119 | try: |
115 | fname = sys.argv[1] | 120 | fname = sys.argv[1] |
116 | except: | 121 | except: |
117 | print >>sys.stderr, "Usage: %s <filename>\n" % sys.argv[0] | 122 | print >>sys.stderr, "Usage: %s <filename>\n" % sys.argv[0] |
118 | else: | 123 | else: |
119 | convert( fname ) | 124 | convert( fname ) |