|
@@ -1,4 +1,19 @@
|
1
|
1
|
#!/usr/bin/env python
|
|
2
|
+# Copyright (C) 2008 Stefan Hajnoczi <stefanha@gmail.com>.
|
|
3
|
+#
|
|
4
|
+# This program is free software; you can redistribute it and/or
|
|
5
|
+# modify it under the terms of the GNU General Public License as
|
|
6
|
+# published by the Free Software Foundation; either version 2 of the
|
|
7
|
+# License, or any later version.
|
|
8
|
+#
|
|
9
|
+# This program is distributed in the hope that it will be useful, but
|
|
10
|
+# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
+# General Public License for more details.
|
|
13
|
+#
|
|
14
|
+# You should have received a copy of the GNU General Public License
|
|
15
|
+# along with this program; if not, write to the Free Software
|
|
16
|
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2
|
17
|
import sys
|
3
|
18
|
import re
|
4
|
19
|
|
|
@@ -15,6 +30,15 @@ def err(msg):
|
15
|
30
|
sys.stderr.write('%s: %s\n' % (sys.argv[0], msg))
|
16
|
31
|
sys.exit(1)
|
17
|
32
|
|
|
33
|
+def to_pxenv_status(errno):
|
|
34
|
+ return errno & 0xff
|
|
35
|
+
|
|
36
|
+def to_errfile(errno):
|
|
37
|
+ return (errno >> 13) & 0x7ff
|
|
38
|
+
|
|
39
|
+def to_posix_errno(errno):
|
|
40
|
+ return (errno >> 24) & 0x7f
|
|
41
|
+
|
18
|
42
|
def load_header_file(filename, regexp):
|
19
|
43
|
defines = {}
|
20
|
44
|
for line in open(filename, 'r'):
|
|
@@ -42,7 +66,7 @@ def evaluate(defines, expr):
|
42
|
66
|
err('invalid expression')
|
43
|
67
|
return eval(pyexpr)
|
44
|
68
|
|
45
|
|
-def build(filenames, regexp):
|
|
69
|
+def build(filenames, regexp, selector):
|
46
|
70
|
unevaluated = {}
|
47
|
71
|
for filename in filenames:
|
48
|
72
|
unevaluated.update(load_header_file(filename, regexp))
|
|
@@ -59,8 +83,12 @@ def build(filenames, regexp):
|
59
|
83
|
changed = True
|
60
|
84
|
if unevaluated:
|
61
|
85
|
err('unable to evaluate all #defines')
|
62
|
|
- return evaluated
|
63
|
86
|
|
64
|
|
-print 'pxenv_status =', repr(build(pxenv_status_files, PXENV_STATUS_RE))
|
65
|
|
-print 'errfile =', repr(build(errfile_files, ERRFILE_RE))
|
66
|
|
-print 'posix_errno =', repr(build(posix_errno_files, POSIX_ERRNO_RE))
|
|
87
|
+ lookup = {}
|
|
88
|
+ for key, val in evaluated.iteritems():
|
|
89
|
+ lookup[selector(val)] = key
|
|
90
|
+ return lookup
|
|
91
|
+
|
|
92
|
+print 'pxenv_status =', repr(build(pxenv_status_files, PXENV_STATUS_RE, to_pxenv_status))
|
|
93
|
+print 'errfile =', repr(build(errfile_files, ERRFILE_RE, to_errfile))
|
|
94
|
+print 'posix_errno =', repr(build(posix_errno_files, POSIX_ERRNO_RE, to_posix_errno))
|