-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_eof.sh
More file actions
39 lines (34 loc) · 924 Bytes
/
check_eof.sh
File metadata and controls
39 lines (34 loc) · 924 Bytes
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
#!/bin/bash
FIX_MODE=0
if [ "$1" == "--fix" ]; then
FIX_MODE=1
echo "--- Checking and FIXING End-of-File Newlines ---"
else
echo "--- Checking End-of-File Newlines ---"
fi
ERROR=0
files=$(find . -type f \( -name "*.cpp" -o -name "*.c" -o -name "*.h" -o -name "*.asm" \))
for f in $files; do
# Skip build/tool directories
if [[ $f == *"./build"* ]]; then continue; fi
if [[ $f == *"./tools"* ]]; then continue; fi
if [[ -s "$f" && -n "$(tail -c 1 "$f")" ]]; then
if [ $FIX_MODE -eq 1 ]; then
# Append a newline
echo "" >> "$f"
echo "Fixed: $f"
else
echo "Missing Newline: $f"
ERROR=1
fi
fi
done
if [ $FIX_MODE -eq 0 ]; then
if [ $ERROR -eq 1 ]; then
echo "FAILED: Some files are missing the final newline."
exit 1
else
echo "All files look good."
exit 0
fi
fi