def __init__(self, file_name, entropy_subset_length=5): #preprocess the file # print("Make sure to remove all the library includes") # subprocess.call("gcc -E -std=c99 -I/my_pycparser/utils/fake_libc_include " + # file_name + " -o preprocessed.c") self.ast = pycparser.parse_file(file_name, use_cpp=True) self.entropy_subset_length = entropy_subset_length self.current_entropy_subset_length = 0
print('Program Vocabulary: ', self.programVocabulary()) print('Program Volume: ', self.programVolume()) print('Program Difficulty: ', self.programDifficulty()) print('Program Level: ', self.programLevel()) print('Program Minimum Volume: ', self.programMinimumVolume()) print('Program Effort: ', self.programEffort()) print('Language Level: ', self.languageLevel()) print('Intelligence Content: ', self.intelligenceContent()) print('Programming Time: ', self.programmingTime()) if __name__ == "__main__": arguments = sys.argv[1:] count = len(arguments) if (count < 0): print("Insufficient arguments") ast = pycparser.parse_file("testp.c", use_cpp=True) main = ast.children()[-1] listOfOperators = parse_halstead(ast)[0] listOfOperands = parse_halstead(ast)[1] print('List of Operators : ', listOfOperators) print() print() print('List of Operands : ', listOfOperands) print() print("******Halstead Metrics******") hal_metric = HalsteadMetrics(listOfOperators, listOfOperands) hal_metric.showMetrics()