|
@@ -0,0 +1,66 @@
|
|
1
|
+#!/usr/bin/env python
|
|
2
|
+import sys
|
|
3
|
+import re
|
|
4
|
+
|
|
5
|
+pxenv_status_files = ('../../src/include/errno.h', )
|
|
6
|
+errfile_files = ('../../src/include/gpxe/errfile.h',
|
|
7
|
+ '../../src/arch/i386/include/bits/errfile.h')
|
|
8
|
+posix_errno_files = ('../../src/include/errno.h', )
|
|
9
|
+
|
|
10
|
+PXENV_STATUS_RE = re.compile(r'^#define\s+(PXENV_STATUS_[^\s]+)\s+(.+)$')
|
|
11
|
+ERRFILE_RE = re.compile(r'^#define\s+(ERRFILE_[^\s]+)\s+(.+)$')
|
|
12
|
+POSIX_ERRNO_RE = re.compile(r'^#define\s+(E[A-Z]+)\s+.*(0x[0-9a-f]+).*$')
|
|
13
|
+
|
|
14
|
+def err(msg):
|
|
15
|
+ sys.stderr.write('%s: %s\n' % (sys.argv[0], msg))
|
|
16
|
+ sys.exit(1)
|
|
17
|
+
|
|
18
|
+def load_header_file(filename, regexp):
|
|
19
|
+ defines = {}
|
|
20
|
+ for line in open(filename, 'r'):
|
|
21
|
+ m = regexp.match(line)
|
|
22
|
+ if m:
|
|
23
|
+ key, val = m.groups()
|
|
24
|
+ defines[key] = val
|
|
25
|
+ return defines
|
|
26
|
+
|
|
27
|
+def evaluate(defines, expr):
|
|
28
|
+ pyexpr = ''
|
|
29
|
+ for token in expr.split():
|
|
30
|
+ if token in '()':
|
|
31
|
+ pass
|
|
32
|
+ elif token.startswith('/*') or token.startswith('//'):
|
|
33
|
+ break
|
|
34
|
+ elif token.startswith('0x') or token == '|':
|
|
35
|
+ pyexpr += token
|
|
36
|
+ else:
|
|
37
|
+ if token in defines:
|
|
38
|
+ pyexpr += '0x%x' % defines[token]
|
|
39
|
+ else:
|
|
40
|
+ return -1
|
|
41
|
+ if not re.match(r'^[0-9a-zA-Z_|]+$', pyexpr):
|
|
42
|
+ err('invalid expression')
|
|
43
|
+ return eval(pyexpr)
|
|
44
|
+
|
|
45
|
+def build(filenames, regexp):
|
|
46
|
+ unevaluated = {}
|
|
47
|
+ for filename in filenames:
|
|
48
|
+ unevaluated.update(load_header_file(filename, regexp))
|
|
49
|
+
|
|
50
|
+ evaluated = {}
|
|
51
|
+ changed = True
|
|
52
|
+ while changed:
|
|
53
|
+ changed = False
|
|
54
|
+ for key in list(unevaluated.keys()):
|
|
55
|
+ val = evaluate(evaluated, unevaluated[key])
|
|
56
|
+ if val != -1:
|
|
57
|
+ del unevaluated[key]
|
|
58
|
+ evaluated[key] = val
|
|
59
|
+ changed = True
|
|
60
|
+ if unevaluated:
|
|
61
|
+ err('unable to evaluate all #defines')
|
|
62
|
+ return evaluated
|
|
63
|
+
|
|
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))
|