-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New script for quick clang-format in place
Files changed: * Makefile: Add cfit.sh to scripts to install * cfit.sh: Created. Signed-off-by: Jeremy Bennett <[email protected]>
- Loading branch information
1 parent
0f26050
commit f309bfd
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |