File: check-eof

package info (click to toggle)
pbcopper 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 8,020 kB
  • sloc: ansic: 103,762; cpp: 47,286; python: 331; sh: 186; makefile: 22
file content (25 lines) | stat: -rwxr-xr-x 610 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env bash

readonly CHECK_DIRS=( include src tests/src )

# idea taken from https://unix.stackexchange.com/a/322884
wrong_files=()

readonly NEWLINE='
'
while IFS="" read -d $'\0' -r f ; do
    t=$(tail -c2 "${f}"; printf x)
    [[ ${t%x} =~ ${NEWLINE}$ ]] || wrong_files+=( "${f}" )
done < <(find ${CHECK_DIRS[*]} -type f \( \
    -name '*.c' -o \
    -name '*.cpp' -o \
    -name '*.h' \) -print0)

if (( ${#wrong_files[@]} )); then
    echo "The following files are missing a proper EOL marker at the end:"
    for i in "${wrong_files[@]}"; do
        echo "-- ${i}"
    done
    exit 1
fi
exit 0