docs/ikteam: Delete most files.
[haiku.git] / 3rdparty / mmu_man / irc / Haiku / gen_err_list.py
bloba06457848ec8570c21398f5b8f9250849bebad47
1 #!python
3 # run from trunk/ and > errors.py
5 import re
7 errors = {}
10 errors_h = open("headers/os/support/Errors.h", "r")
12 bases = {}
14 for line in errors_h:
16 match = re.match(r'#\s?define\s+(?P<define>\w+)\s+(?P<expr>.+)', line)
17 if match:
18 define = match.groupdict().get("define")
19 expr = match.groupdict().get("expr")
20 value = None
21 #print "==== %s ==== %s" % (define, expr)
22 if expr == "INT_MIN":
23 value = 0x80000000
24 if expr == "(-1)":
25 value = -1
26 expr = ""
27 if expr == "((int)0)":
28 value = 0
29 expr = ""
31 m = re.match(r"B_TO_POSIX_ERROR\((?P<expr>.*)\)", expr)
32 if m:
33 # strip the macro
34 expr = m.group("expr")
35 #print expr
37 m = re.match(r"B_FROM_POSIX_ERROR\((?P<expr>.*)\)", expr)
38 if m:
39 # strip the macro
40 expr = m.group("expr")
41 #print expr
43 m = re.match(r"\((?P<expr>.*)\)", expr)
44 if m:
45 # strip the parens
46 expr = m.group("expr")
47 #print expr
49 m = re.match(r"(?P<expr>\w+)$", expr)
50 if m:
51 # strip the macro
52 token = m.group("expr")
53 if token in errors:
54 value = errors[token]["value"]
55 #print "%s -> %s = %s" % (define, token, value)
57 m = re.match(r"(?P<base>.*_BASE)\s*\+\s*(?P<offset>\w+)$", expr)
58 if m:
59 base = m.group("base")
60 if base not in bases:
61 raise "error"
62 b = bases[base]
63 o = int(m.group("offset"), 0)
64 value = b + o
65 #print "value: %x + %x = %x = %d" % (b, o, value, value)
67 if value is None:
68 print "Value unknown for %s" % (define)
69 exit(1)
71 if re.match(r".*_BASE", define):
72 #print "base: %s=%s" % (define, value)
73 bases[define] = value
75 else:
76 #print "%s=%s :%s" % (define, expr, value)
77 errors[define] = {"expr": expr, "value": value, "str": ""}
80 errors_h.close()
82 #print bases
83 #print errors
84 #print errors['EILSEQ']
86 #exit(0)
88 strerror_c = open("src/system/libroot/posix/string/strerror.c", "r")
90 defines = []
92 for line in strerror_c:
94 match = re.match(r'\t*case (?P<define>\w+):', line)
95 if match:
96 define = match.groupdict().get("define")
97 defines.append(define)
98 match = re.match(r'\t*//\s+(?P<define>\w+):*$', line)
99 if match:
100 define = match.groupdict().get("define")
101 defines.append(define)
103 match = re.match(r'\t*return "(?P<str>.+)";', line)
104 if match:
105 str = match.groupdict().get("str")
106 #print defines
107 for d in defines:
108 #print d
109 if errors[d]:
110 #print errors[d]#['str']
111 errors[d]['str'] = str
112 else:
113 print "not found: %s" % (d)
114 exit(1)
115 defines = []
116 #errors[define] = "plop"
118 strerror_c.close()
120 # Some fixup
121 errors['B_OK']['str'] = "No Error"
122 errors['B_NO_ERROR']['str'] = "No Error"
123 errors['B_DONT_DO_THAT']['str'] = "Don't do that!"
125 #print errors
126 print "errors = {"
127 for e in errors:
128 print "'%s': %s," % (e, errors[e])
129 print "}"