-
Notifications
You must be signed in to change notification settings - Fork 0
/
CheckMisraC.py
53 lines (40 loc) · 1.6 KB
/
CheckMisraC.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
def parse_cppcheck_output(file_path):
mandatory_errors = []
optimized_output = []
mandatory_keywords = ["Major", "Critical", "Mandatory"]
with open(file_path, 'r') as file:
lines = file.readlines()
for line in lines:
# Check if the line contains a mandatory violation
if any(keyword in line for keyword in mandatory_keywords):
mandatory_errors.append(line)
optimized_output.append(line)
return mandatory_errors, optimized_output
def main():
# Define ANSI escape code for red
red = '\033[31m'
reset = '\033[0m'
green = '\033[32m'
# Update this to the full path of MisraCkOut.txt if necessary
input_file = r'.\MisraCkOut.txt'
if not os.path.isfile(input_file):
print(f"File not found: {input_file}")
return 1 # Return error code
mandatory_errors, optimized_output = parse_cppcheck_output(input_file)
# Write the optimized output to a new file
optimized_output_file = r'.\MisraC_Check\OptimizedMisraCkOut.txt'
with open(optimized_output_file, 'w') as file:
for line in optimized_output:
file.write(line)
# Print errors if there are mandatory violations
if mandatory_errors:
print("Mandatory violations found:")
for error in mandatory_errors:
print(error.strip())
print(f"{red}\n Error: Mandatory violations detected !!! \n{reset}")
return 1 # Return error code
print(f"{green}\n No mandatory violations found. \n{reset}")
return 0 # Return success code
if __name__ == "__main__":
exit(main())