forked from mcu-dev/dev-apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclang_format.sh
27 lines (23 loc) · 876 Bytes
/
clang_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
#!/bin/bash
# Directories to process
directories=("apps")
# Log file
log_file="clang-format.log"
> "$log_file" # Clear the log file
# Loop through each directory
for dir in "${directories[@]}"; do
# Find all .c and .h files in the current directory, excluding the build folder
files=$(find "$dir" -type d -name "build" -prune -o -type f \( -name "*.c" -o -name "*.h" \) -print)
if [ -z "$files" ]; then
echo "No files found for formatting in $dir." | tee -a "$log_file"
else
for file in $files; do
echo "Formatting file: $file" | tee -a "$log_file"
if clang-format -i -style=llvm "$file" 2>&1 | tee -a "$log_file"; then
echo "Formatted file: $file" | tee -a "$log_file"
else
echo "Error formatting file: $file" | tee -a "$log_file"
fi
done
fi
done