summaryrefslogtreecommitdiff
path: root/tools/notsd-find-includes
blob: 6dfb406fa3697ea427bc05ed4e1e67744da77a60 (plain)
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
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env bash

phase=phase0

phase0() {
        phase=phase0
        local line="$1"
        case "$line" in
                '#include'*|'typedef '*';')
                        phase1 "$line"
                        ;;
                *)
                        ;;
        esac
}

phase1() {
        phase=phase1
        local line="$1"
        case "$line" in
                '')
                        ;;
                '#include'*)
                        ;;
                'typedef '*';')
                        ;;
                *)
                        phase2 "$line"
                        ;;
        esac
}

phase2() {
        phase=phase2
        local line="$1"
        printf '%s\n' "$line"
        cat
}

main() {
        current_file="$1"
        set -o pipefail
        {
                IFS=''
                while read -r line; do
                        "$phase" "$line"
                        IFS=''
                done
        } < "$current_file" | grep '^#include' | ifne printf '%s\n' "$current_file"
}

main "$@"