-
Notifications
You must be signed in to change notification settings - Fork 0
/
cfit.sh
executable file
·58 lines (45 loc) · 904 Bytes
/
cfit.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
#!/bin/bash
# Simple script to run clang-format
# Copyright (C) 2021 Embecosm Limited <www.embecosm.com>
# Contributor Jeremy Bennett <[email protected]>
# SPDX-License-Identifier: GPL-3.0-or-later
# Usage: cfit.sh MS|GNU|LLVM [file ...]
# If no files are specified, format all C and C++ source and headers in the
# directory.
if [ $# -lt 1 ]
then
echo "Usage: cfit.sh MS|LLVM [file ...]"
exit 1
fi
case $1
in
MS|Microsoft) style=Microsoft
;;
GNU) style=GNU
;;
LLVM) style=LLVM
;;
*) echo "Unknown style \"$1\""
exit 1
;;
esac
shift
if [ $# -lt 1 ]
then
files=$(ls -1 | grep '\(\.cpp$\)\|\(\.c$\)\|\(\.h$\)')
else
files=$*
fi
if [ "x${files}" != "x" ]
then
for f in ${files}
do
if [ ! -w ${f} ]
then
echo "${f} not writable: ignored"
else
echo ${f}
clang-format -i --style=${style} ${f}
fi
done
fi