control_systems_torbox 0.2.1

Control systems toolbox
Documentation
import re


with open("SLICOT-Reference/src/AB08ND.c", "r") as c_file:
    c_code = c_file.read()

# remove new lines
c_code = c_code.replace("\n", " ")
# remove everything inside function: i.e.: {...}
c_code = re.sub(r"\{.*?\bLast", "{ /* Last ", c_code, flags=re.DOTALL)


# get function signature
pattern = r'\w+\s\w+_\('

# Find all function signatures and extract the return type
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)

# remove before function signature
pattern = r'^.*?\w+\s\w+_\('
c_code = re.sub(pattern, function_signature, c_code, flags=re.MULTILINE)

# change to void if return is int
if return_type == "int":
    c_code = re.sub(r'\bint\b', 'void', c_code)
    

# remove all added fntlen arguments for strings
c_code = re.sub(r',\s+ftnlen\s\w+', '', c_code)

# change back to normal c types
c_code = re.sub(r'\binteger\b', 'int', c_code)
c_code = re.sub(r'\bdoublereal\b', 'double', c_code)

print(c_code)



# remove all before line with function name
# c_code = re.sub(r".*?AB08ND\(.*?\)", "", c_code, flags=re.DOTALL) 
# print(c_code)