File: check-eof

package info (click to toggle)
pbbam 1.6.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 13,812 kB
  • sloc: cpp: 57,023; xml: 2,749; ansic: 869; python: 534; sh: 277; makefile: 187
file content (25 lines) | stat: -rwxr-xr-x 616 bytes parent folder | download
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 tools )

# 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