1#!python 2 3# run from trunk/ and > errors.py 4 5import re 6 7errors = {} 8 9 10errors_h = open("headers/os/support/Errors.h", "r") 11 12bases = {} 13 14for line in errors_h: 15 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 = "" 30 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 36 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 42 43 m = re.match(r"\((?P<expr>.*)\)", expr) 44 if m: 45 # strip the parens 46 expr = m.group("expr") 47 #print expr 48 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) 56 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) 66 67 if value is None: 68 print "Value unknown for %s" % (define) 69 exit(1) 70 71 if re.match(r".*_BASE", define): 72 #print "base: %s=%s" % (define, value) 73 bases[define] = value 74 75 else: 76 #print "%s=%s :%s" % (define, expr, value) 77 errors[define] = {"expr": expr, "value": value, "str": ""} 78 79 80errors_h.close() 81 82#print bases 83#print errors 84#print errors['EILSEQ'] 85 86#exit(0) 87 88strerror_c = open("src/system/libroot/posix/string/strerror.c", "r") 89 90defines = [] 91 92for line in strerror_c: 93 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) 102 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" 117 118strerror_c.close() 119 120# Some fixup 121errors['B_OK']['str'] = "No Error" 122errors['B_NO_ERROR']['str'] = "No Error" 123errors['B_DONT_DO_THAT']['str'] = "Don't do that!" 124 125#print errors 126print "errors = {" 127for e in errors: 128 print "'%s': %s," % (e, errors[e]) 129print "}" 130