This repository was archived by the owner on Jul 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnormChecker
More file actions
executable file
·146 lines (125 loc) · 3.9 KB
/
normChecker
File metadata and controls
executable file
·146 lines (125 loc) · 3.9 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
GRAY='\033[0;37m'
NC='\033[0m' # No Color
HEADER_REGEXP='^/\*\036\*\* EPITECH PROJECT, (20(1[7-9]|[2-9]\d)|2[1-9]\d{2}|[3-9]\d{3})\036\*\* [^\036]+\036\*\* File description:\036\*\* [^\036]+\036\*/\036\036'
FORBIDEN_FUNCTIONS=( " printf" " dprintf" " fprintf" " vprintf" " sprintf" " snprintf" " vprintf" " vfprintf" " vsprintf" " vsnprintf" " asprintf" " scranf" " memcpy" " memset" " memmove" " strcat" " strchar" " strcpy" " atoi" " strlen" " strstr" " strncat" " strncpy" " strcasestr" " strncasestr" " strcmp" " strncmp" " strtok" " strnlen" " strdup" " realloc" " reallocarray" )
header_format()
{
local file=$1
if !(head -n 7 $file | tr '\n' '\036' | grep -qP "$HEADER_REGEXP") 2> /dev/null; then
echo -ne "${RED}Major\t${NC}: "
echo -ne "$file" | sed 's/^..//'
echo -e ": $line: Missing or corrupted header"
fi
}
line_length()
{
local file=$1
local line=1
while read tmp; do
local length=${#tmp}
if (( $length > 80 )); then
echo -ne "${RED}Major\t${NC}: "
echo -ne "$file" | sed 's/^..//'
echo -e ": $line: Too long line ($length > 80)"
fi
((line++))
done < $file
}
trailing_spaces()
{
local file=$1
local line=1
while IFS= read -r tmp; do
echo -e "$tmp" | grep " $" > /dev/null
if (($? == 0)); then
echo -ne "${GRAY}Implicit${NC}: "
echo -n "$file" | sed 's/^..//'
echo -e ": $line: Trailing space"
fi
((line++))
done < $file
}
useless_files()
{
local extentions=( ".*.swp" "*.o" "*~" "*.gch" ".vscode*" )
for extention in ${extentions[@]}; do
local tmp=$(find -type f -name $extention)
local length=${#tmp}
if (( length != 0 )); then
for i in $tmp; do
echo -ne "${RED}Major\t${NC}: "
echo -n "$i" | sed 's/^.\{2\}//'
echo -e ": Useless file"
done
fi
done
}
functions_separator()
{
local file=$1
local line=1
while IFS= read -r tmp; do
if [[ ${tmp::1} == "}" ]]; then
local next_line=$(sed "$((line + 1))q;d" $file)
if (( ${#next_line} != 0 )); then
echo -ne "${GREEN}Minor\t${NC}: "
echo -n "$file" | sed 's/^..//'
echo -e ": $((line + 1)): Missing empty line between functions"
fi
fi
((line++))
done < $file
}
identation()
{
local file=$1
local line=1
while IFS= read -r tmp; do
local trimed_str=$(echo -e $tmp | sed "s/^[ \t]*//")
local removed_spaces=$(( ${#tmp} - ${#trimed_str} ))
if (( removed_spaces % 4 != 0 )); then
echo -ne "${GREEN}Minor\t${NC}: "
echo -n "$file" | sed 's/^..//'
echo -e ": $((line)): Bad indentation"
fi
((line++))
done < $file
}
forbiden_functions()
{
local file=$1
local line=1
while IFS= read -r tmp; do
for function in $FORBIDEN_FUNCTIONS; do
if (echo $tmp | grep -qP $function 2> /dev/null); then
echo -ne "${RED}Major\t${NC}: "
echo -ne "$file" | sed 's/^..//'
echo -e ": $line: Use of forbidden function ($function)"
fi
done
((line++))
done < $file
}
count_functions()
{
local file=$1
local tmp=$(cat $file | grep "^{" | wc -l)
if (( tmp > 5 )); then
echo -ne "${RED}Major\t${NC}: "
echo -ne "$file" | sed 's/^..//'
echo -e ": Too much function in this file ($tmp > 5)"
fi
}
files=$(find -type f -name "*.c")
for file in $files; do
line_length $file # Major
trailing_spaces $file # Implicit
forbiden_functions $file # Major
functions_separator $file # Minor
count_functions $file # Major
header_format $file
done
useless_files $files # Major