-
Notifications
You must be signed in to change notification settings - Fork 0
/
coding_format.sh
executable file
·68 lines (61 loc) · 1.17 KB
/
coding_format.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
65
66
67
68
#!/bin/bash
formator='clang-format-3.8'
USAGE="USAGE:
`basename $0` <file|dir> \n
\n
"
check_valid_source_code()
{
file=$1
if [ "${file##*.}" = "c" ] \
|| [ "${file##*.}" = "C" ] \
|| [ "${file##*.}" = "cc" ] \
|| [ "${file##*.}" = "cpp" ] \
|| [ "${file##*.}" = "CPP" ] \
|| [ "${file##*.}" = "c++" ] \
|| [ "${file##*.}" = "cp" ] \
|| [ "${file##*.}" = "cxx" ] \
|| [ "${file##*.}" = "c++" ] \
|| [ "${file##*.}" = "h" ] \
|| [ "${file##*.}" = "H" ] \
|| [ "${file##*.}" = "hh" ] \
|| [ "${file##*.}" = "hpp" ];
then
return 1
else
return 0
fi
}
format_file()
{
check_valid_source_code $1
if [ $? -eq 0 ]; then
##echo "Skip Invalid file: $1"
return -1
fi
echo "Formating file $1"
$formator -style=file -i $1
return 0
}
check_parameter()
{
if [ $# -lt 1 ]; then
echo -e $USAGE
exit 1
fi
}
parse_main()
{
if [ -d $1 ]; then
# for dir:
all_files=`find $1`
for file in $all_files
do
format_file $file
done
elif [ -f $1 ]; then
format_file $1
fi
}
check_parameter $*
parse_main $*