summaryrefslogtreecommitdiff
path: root/libopie2/tools
authormickeyl <mickeyl>2003-11-08 20:39:38 (UTC)
committer mickeyl <mickeyl>2003-11-08 20:39:38 (UTC)
commiteb26b0413c269b898a24deb30d5602ac0c142a56 (patch) (unidiff)
tree4e9b24ce6a9e8811eb9e62d8537b452921d4564d /libopie2/tools
parent33d86bb19d4e21b95504ba3b16789d08b4820313 (diff)
downloadopie-eb26b0413c269b898a24deb30d5602ac0c142a56.zip
opie-eb26b0413c269b898a24deb30d5602ac0c142a56.tar.gz
opie-eb26b0413c269b898a24deb30d5602ac0c142a56.tar.bz2
refactor the debug mapper and make it more secure
Diffstat (limited to 'libopie2/tools') (more/less context) (ignore whitespace changes)
-rwxr-xr-xlibopie2/tools/regen.py52
1 files changed, 41 insertions, 11 deletions
diff --git a/libopie2/tools/regen.py b/libopie2/tools/regen.py
index 2f7f418..9ad5352 100755
--- a/libopie2/tools/regen.py
+++ b/libopie2/tools/regen.py
@@ -11,54 +11,84 @@ result = os.popen( 'find /usr/include -name "*.h" |xargs grep -h SIOC|grep 0x' )
11try: 11try:
12 tablehfile = file( sys.argv[1]+".h", "w" ) 12 tablehfile = file( sys.argv[1]+".h", "w" )
13except: 13except:
14 tablehfile = sys.stdout 14 tablehfile = sys.stdout
15 15
16try: 16try:
17 tablecfile = file( sys.argv[1]+".cpp", "w" ) 17 tablecfile = file( sys.argv[1]+".cpp", "w" )
18except: 18except:
19 tablecfile = sys.stdout 19 tablecfile = sys.stdout
20 20
21print >>tablehfile,""" 21print >>tablehfile,"""
22/* 22/*
23 * ioctl table - generated by regen.py - (C) Michael 'Mickey' Lauer <mickey@vanille.de> 23 * debug value mapper - generated by regen.py - (C) Michael 'Mickey' Lauer <mickey@vanille.de>
24 */ 24 */
25 25
26#ifndef IOCTLMAP_H 26#ifndef DEBUGMAPPER_H
27#define IOCTLMAP_H 27#define DEBUGMAPPER_H
28 28
29#include <qstring.h> 29#include <qstring.h>
30#include <qintdict.h> 30#include <qintdict.h>
31 31
32typedef QIntDict<QString> IntStringMap; 32typedef QIntDict<QString> IntStringMap;
33 33
34IntStringMap* constructIoctlMap(); 34class DebugMapper
35{
36 public:
37 DebugMapper();
38 ~DebugMapper();
39
40 const QString& map( int value ) const;
41 private:
42 IntStringMap _map;
43};
35 44
36#endif 45#endif
37""" 46"""
38 47
39print >>tablecfile,""" 48print >>tablecfile,"""
40/* 49/*
41 * ioctl table - generated by regen.py - (C) Michael 'Mickey' Lauer <mickey@vanille.de> 50 * debug value mapper - generated by regen.py - (C) Michael 'Mickey' Lauer <mickey@vanille.de>
42 */ 51 */
43 52
44#include "%s" 53#include "%s"
45 54
46IntStringMap* constructIoctlMap() 55DebugMapper::DebugMapper()
47{ 56{
48\tIntStringMap* map = new IntStringMap(); 57 qDebug( "DebugMapper::DebugMapper()" );
49 58
50""" % (tablehfile.name) 59""" % (tablehfile.name)
51 60
52for line in result: 61for line in result:
53 l = line.split() 62 l = line.split()
54 if not l[0].startswith( "#define" ) or not l[2].startswith( "0x" ): 63 if not l[0].startswith( "#define" ) or not l[2].startswith( "0x" ):
55 print >>sys.stderr, "can't parse line: %s" % l 64 print >>sys.stderr, "can't parse line: %s" % l
56 continue 65 continue
57 #print >>tablecfile, "\tqDebug( \"adding %s = %s\" );" % ( l[2], l[1] ) 66 print >>tablecfile, " _map.insert( %s, new QString(\"%s\") );" % ( l[2], l[1] )
58 print >>tablecfile, "\tmap->insert( %s, new QString(\"%s\") );" % ( l[2], l[1] )
59 67
60 68
61print >>tablecfile,""" 69print >>tablecfile,"""
62\treturn map;
63}; 70};
64""" \ No newline at end of file 71
72
73DebugMapper::~DebugMapper()
74{
75 qDebug( "DebugMapper::~DebugMapper()" );
76}
77
78
79const QString& DebugMapper::map( int value ) const
80{
81 QString* result = _map[ value ];
82
83 if ( !result )
84 {
85 qDebug( "DebugMapper::map() - value not found." );
86 return QString::null;
87 }
88 else
89 {
90 return *result;
91 }
92}
93
94"""