import re
with open("SLICOT-Reference/src/AB08ND.c", "r") as c_file:
c_code = c_file.read()
c_code = c_code.replace("\n", " ")
c_code = re.sub(r"\{.*?\bLast", "{ /* Last ", c_code, flags=re.DOTALL)
pattern = r'\w+\s\w+_\('
matches = re.findall(pattern, c_code, flags=re.MULTILINE)
assert(len(matches) == 1), "More than one function found or none found"
function_signature = matches[0]
return_type = function_signature.split()[0]
print(matches)
pattern = r'^.*?\w+\s\w+_\('
c_code = re.sub(pattern, function_signature, c_code, flags=re.MULTILINE)
if return_type == "int":
c_code = re.sub(r'\bint\b', 'void', c_code)
c_code = re.sub(r',\s+ftnlen\s\w+', '', c_code)
c_code = re.sub(r'\binteger\b', 'int', c_code)
c_code = re.sub(r'\bdoublereal\b', 'double', c_code)
print(c_code)