File: check_guard

package info (click to toggle)
mp3fs 1.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, trixie
  • size: 888 kB
  • sloc: cpp: 1,884; ansic: 564; sh: 298; makefile: 82
file content (24 lines) | stat: -rwxr-xr-x 642 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
#!/bin/bash -e
# check_guard verifies that include guards are specified correctly.

. "${BASH_SOURCE%/*}/common.sh"

fix_guard () {
    file="$1"
    short_file="${file#$ROOT/src/}"
    want_guard=MP3FS_$(tr '[:lower:]/.' '[:upper:]_' <<< $short_file)_
    sed -e "0,/#ifndef / s/#ifndef .*/#ifndef $want_guard/" \
        -e "0,/#define / s/#define .*/#define $want_guard/" \
        -e "/#endif/,$ s,#endif.*,#endif  // $want_guard," \
        "$file"
}

check_guard_single () {
    file="$1"
    if [[ "$file" != *.h ]] ; then return 0 ; fi
    fix_guard "$file" | diff -u "$file" -
}

if in_main ; then
    driver check_guard_single :
fi