in scripts/gen_wrappers.py [0:0]
def get_const_from_define(full_src_lines):
define_code = []
seen = set()
for line in full_src_lines:
define = "#define"
if line.find(define) > -1:
line = line[len(define):].strip()
last_len = 100000
while last_len != len(line):
last_len = len(line)
line = line.replace(" ", " ")
line = line.replace("\t", " ")
comment = ""
if line.find("//") > -1:
line, comment = line.split("//")
line, comment = line.strip(), comment.strip()
if line.find(" ") > -1:
var, val = line.split(" ")
try:
# In C/C++ numbers can have an 'f' suffix, specifying a single-precision number.
# That is not supported by the Python floating point parser, therefore we need to strip that bit.
if val[-1] == 'f':
val = val[:-1]
val = float(val)
varname = var[2:]
if varname in seen:
print("Already seen {name}, skipping".format(name=varname))
continue
seen.add(varname)
new_line = varname + " = " + str(val)
new_line += " " * (35 - len(new_line))
new_line += " # " + comment
define_code.append(new_line)
except Exception:
traceback.print_exc()
print("Couldn't parse line: %s" % line)
return define_code