-
Notifications
You must be signed in to change notification settings - Fork 0
/
columns_check.sh
executable file
·64 lines (56 loc) · 1.26 KB
/
columns_check.sh
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
#! /bin/sh
# idea : check for spaces after a "for", "if", or "while"
# idea : check for spaces at the end of lines
alias lines="python ~/afs/Shell-Scripts/lines_number.py"
alias fw="python ~/afs/Shell-Scripts/cs-for-while.py"
alias spaces="python ~/afs/Shell-Scripts/cs-ending-spaces.py"
GREEN="\033[92m"
GRAY="\033[90m"
RED="\033[91m"
ENDC="\033[0m"
BLUE="\033[34m"
BOLD="\033[1m"
echo -e "$BOLD $GREEN CODING STYLE CHECK $ENDC"
if [ $# -ne 1 ]; then
echo -e "\tUsage : cs FILE
Usage : cs FOLDER (recursively)"
exit 1
fi
read_lines() {
pos=1
while IFS= read -r line
do
nb=${#line}
if [ $nb -eq 80 ]; then
echo -e $1 : $BOLD $GRAY WARNING $ENDC line $pos is 80 columns long
fi
if [ $nb -gt 80 ]; then
echo -e $1 : $BOLD $RED ERROR $ENDC line $pos is $nb columns long
fi
pos=$(($pos+1))
done < $1
}
recurse() {
for i in "$1"/*;do
if [ -d "$i" ];then
recurse "$i"
elif [ -f "$i" ]; then
ext="${i##*.}"
if [ "$ext" = "cc" ] || [ "$ext" = "c" ] || [ "$ext" = "hh" ] ||
[ "$ext" = "h" ] || [ "$ext" = "hxx" ]; then
read_lines $i
spaces $i
fw $i
lines $i
fi
fi
done
}
if [ -d $1 ]; then
recurse $1
else
read_lines $1
spaces $1
fw $1
lines $1
fi