File: check_incpath

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 (30 lines) | stat: -rwxr-xr-x 800 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
26
27
28
29
30
#!/bin/bash -e
# check_incpath verifies that files are included with the correct path,
# specifically not relying on the behavior of searching the source directory
# first.

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

fix_incpath () {
    file="$1"
    srcpath="${file%/*}"
    basesrcpath="${srcpath#$ROOT/src/}"
    quote_includes=($(grep -Po '(?<=#include ").*(?=")' "$file"))
    sed_args=()
    for inc in "${quote_includes[@]}" ; do
        if [ -f "$srcpath/$inc" -a ! -f "$ROOT/src/$inc" ] ; then
            sed_args+=('-e')
            sed_args+=("/#include \"$inc\"/ s,$inc,$basesrcpath/$inc,")
        fi
    done
    sed -e '#' "${sed_args[@]}" "$file"
}

check_incpath_single () {
    file="$1"
    fix_incpath "$file" | diff -u "$file" -
}

if in_main ; then
    driver check_incpath_single :
fi