summaryrefslogtreecommitdiff
path: root/libopie2/tools/regen.py
blob: 9ad5352da097a97bf8f8673a87053e5634e8d824 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python

#
# regenerate ioctl_table.h
#

import sys
import os
result = os.popen( 'find /usr/include -name "*.h" |xargs grep -h SIOC|grep 0x' ).readlines()

try:
    tablehfile = file( sys.argv[1]+".h", "w" )
except:
    tablehfile = sys.stdout

try:
    tablecfile = file( sys.argv[1]+".cpp", "w" )
except:
    tablecfile = sys.stdout

print >>tablehfile,"""
/*
 * debug value mapper - generated by regen.py - (C) Michael 'Mickey' Lauer <mickey@vanille.de>
 */

#ifndef DEBUGMAPPER_H
#define DEBUGMAPPER_H

#include <qstring.h>
#include <qintdict.h>

typedef QIntDict<QString> IntStringMap;

class DebugMapper
{
  public:
    DebugMapper();
    ~DebugMapper();

    const QString& map( int value ) const;
  private:
    IntStringMap _map;
};

#endif
"""

print >>tablecfile,"""
/*
 * debug value mapper - generated by regen.py - (C) Michael 'Mickey' Lauer <mickey@vanille.de>
 */

#include "%s"

DebugMapper::DebugMapper()
{
    qDebug( "DebugMapper::DebugMapper()" );

""" % (tablehfile.name)

for line in result:
    l = line.split()
    if not l[0].startswith( "#define" ) or not l[2].startswith( "0x" ):
        print >>sys.stderr, "can't parse line: %s" % l
        continue
    print >>tablecfile, "    _map.insert( %s, new QString(\"%s\") );" % ( l[2], l[1] )


print >>tablecfile,"""
};


DebugMapper::~DebugMapper()
{
    qDebug( "DebugMapper::~DebugMapper()" );
}


const QString& DebugMapper::map( int value ) const
{
    QString* result = _map[ value ];

    if ( !result )
    {
        qDebug( "DebugMapper::map() - value not found." );
        return QString::null;
    }
    else
    {
        return *result;
    }
}

"""