Update to project (Part 2.3) ( revised)

 This is now a much more clean version of the tool I am looking to create, as mentioned in the last blog I was having a hard time learning python and was hard coding a lot to get the result. I have worked on that and now am posting the code here:

import re

f = open("function.c", "r")

orgLine =""
name = ""
dataType = ""
topPart =""
bottomPart = ""
count = 0

for line in f:
    count = count + 1
    a = line.strip()
    if re.search("^void.", a):
        orgLine = a
        dataType = re.split("\s", a, 1)
        print(dataType[0])
        name = re.split("\(", dataType[1], 1)
        #print("Name of func is " + name[0])

        nextLine = f.readline()

        while not re.search(".{.?", nextLine):
            orgLine += nextLine.strip() + " "
            nextLine = f.readline()  
       
     
        l = re.split(".{.?", nextLine, 1)
        orgLine += l[0].strip()
        print(orgLine)
        #print("Prototype: " + orgLine)
        #print(orgLine)
        a = ""
        break

    topPart += a + "\n"

# will store the contents of file
content = ""

typeCount = 3
# suffix for each function
types = ["sve", "sve2", "arc_64"]

bustedUp = re.split("\(", orgLine, 1)
paramList = "(" + bustedUp[1]
lineToInsert = dataType[0] + " " + name[0] + paramList + "\n"
# get all lines under prototype of function
for line in f:
    bottomPart += line

output = open("header.c", "w")

for x in range(typeCount):
    lineToInsert = dataType[0] + " " + name[0] + "_" + types[x] +  paramList + "{"+ "\n"
    content += topPart + "\n" + lineToInsert + bottomPart
    content += "\n\n\n"

output.write(content)

Comments

Popular posts from this blog

SPO600 Lab1

SPO600(Project 3.2 FInal Post and thoughts on project and course)

SPO600(Project Part 2.1)