-rwxr-xr-x | libopie2/tools/regen.py | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/libopie2/tools/regen.py b/libopie2/tools/regen.py new file mode 100755 index 0000000..2f7f418 --- a/dev/null +++ b/libopie2/tools/regen.py | |||
@@ -0,0 +1,64 @@ | |||
1 | #!/usr/bin/env python | ||
2 | |||
3 | # | ||
4 | # regenerate ioctl_table.h | ||
5 | # | ||
6 | |||
7 | import sys | ||
8 | import os | ||
9 | result = os.popen( 'find /usr/include -name "*.h" |xargs grep -h SIOC|grep 0x' ).readlines() | ||
10 | |||
11 | try: | ||
12 | tablehfile = file( sys.argv[1]+".h", "w" ) | ||
13 | except: | ||
14 | tablehfile = sys.stdout | ||
15 | |||
16 | try: | ||
17 | tablecfile = file( sys.argv[1]+".cpp", "w" ) | ||
18 | except: | ||
19 | tablecfile = sys.stdout | ||
20 | |||
21 | print >>tablehfile,""" | ||
22 | /* | ||
23 | * ioctl table - generated by regen.py - (C) Michael 'Mickey' Lauer <mickey@vanille.de> | ||
24 | */ | ||
25 | |||
26 | #ifndef IOCTLMAP_H | ||
27 | #define IOCTLMAP_H | ||
28 | |||
29 | #include <qstring.h> | ||
30 | #include <qintdict.h> | ||
31 | |||
32 | typedef QIntDict<QString> IntStringMap; | ||
33 | |||
34 | IntStringMap* constructIoctlMap(); | ||
35 | |||
36 | #endif | ||
37 | """ | ||
38 | |||
39 | print >>tablecfile,""" | ||
40 | /* | ||
41 | * ioctl table - generated by regen.py - (C) Michael 'Mickey' Lauer <mickey@vanille.de> | ||
42 | */ | ||
43 | |||
44 | #include "%s" | ||
45 | |||
46 | IntStringMap* constructIoctlMap() | ||
47 | { | ||
48 | \tIntStringMap* map = new IntStringMap(); | ||
49 | |||
50 | """ % (tablehfile.name) | ||
51 | |||
52 | for line in result: | ||
53 | l = line.split() | ||
54 | if not l[0].startswith( "#define" ) or not l[2].startswith( "0x" ): | ||
55 | print >>sys.stderr, "can't parse line: %s" % l | ||
56 | continue | ||
57 | #print >>tablecfile, "\tqDebug( \"adding %s = %s\" );" % ( l[2], l[1] ) | ||
58 | print >>tablecfile, "\tmap->insert( %s, new QString(\"%s\") );" % ( l[2], l[1] ) | ||
59 | |||
60 | |||
61 | print >>tablecfile,""" | ||
62 | \treturn map; | ||
63 | }; | ||
64 | """ \ No newline at end of file | ||