Skip to content

Commit

Permalink
New script for quick clang-format in place
Browse files Browse the repository at this point in the history
Files changed:

	* Makefile: Add cfit.sh to scripts to install
	* cfit.sh: Created.

Signed-off-by: Jeremy Bennett <[email protected]>
  • Loading branch information
jeremybennett committed Mar 30, 2021
1 parent 0f26050 commit f309bfd
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ C_PROGS = rcmd-dump

SHELL_SCRIPTS = camera-off.sh \
camera-on.sh \
cfit.sh \
compress-pdf.sh \
reverse-csv.sh \
syslog-all.sh \
Expand Down
58 changes: 58 additions & 0 deletions cfit.sh
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

0 comments on commit f309bfd

Please sign in to comment.