Debian Codegraph @

codegen/rangetab.py

raw
1 def gen_range_tables(out, name, s_suffix, l_suffix, ranges):
2 numshort = 0
3 numlong = 0
4 sptr = "NULL"
5 lptr = "NULL"
6
7 for range in ranges:
8 (low, high) = range
9 if high < 0x10000:
10 if numshort == 0:
11 sptr = name + s_suffix
12 pline = "static const xmlChSRange %s[] = {" % sptr
13 else:
14 pline += ","
15 numshort += 1
16 else:
17 if numlong == 0:
18 if numshort > 0:
19 out.write(pline + "};\n")
20 lptr = name + l_suffix
21 pline = "static const xmlChLRange %s[] = {" % lptr
22 else:
23 pline += ","
24 numlong += 1
25 if len(pline) > 60:
26 out.write(pline + "\n")
27 pline = " "
28 elif pline[-1:] == ",":
29 pline += " "
30 pline += "{%s, %s}" % (hex(low), hex(high))
31
32 out.write(pline + "};\n")
33
34 return "{%s,%s,%s,%s}" % (numshort, numlong, sptr, lptr)