3
# Convert the MTC exit codes into a disjoint union type. Each line in the file looks like:
5
# errdef, MTC_EXIT_SUCCESS, 0, 0, "",
8
# cat ../xha.hg/include/mtcerrno.def | ./scripts/mtcerrno-to-ocaml.py > ocaml/xapi/xha_errno.ml
15
line = file.readline()
18
if line.startswith("errdef, MTC_EXIT"):
19
bits = line.split(",")
20
name = bits[1].strip()
21
code = bits[2].strip()
22
desc = bits[4].strip()
23
this = { "name": name, "code": code, "desc": desc }
28
return ctor[0].upper() + ctor[1:].lower()
30
def make_datatype(all):
33
print "| %s" % ctor_name(x)
36
print "let to_string : code -> string = function"
38
print "| %s -> \"%s\"" % (ctor_name(x), x['name'])
40
def to_description_string(all):
41
print "let to_description_string : code -> string = function"
43
print "| %s -> %s" % (ctor_name(x), x['desc'])
46
print "let of_int : int -> code = function"
48
print "| %s -> %s" % (x['code'], ctor_name(x))
49
print "| x -> failwith (Printf.sprintf \"Unrecognised MTC exit code: %d\" x)"
51
if __name__ == "__main__":
52
all = parse(sys.stdin)
53
print "(* Autogenerated by %s -- do not edit *)" % (sys.argv[0])
56
to_description_string(all)