forked from libusual/libusual
-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_modules.sh
executable file
·56 lines (47 loc) · 952 Bytes
/
find_modules.sh
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
53
54
55
56
#! /bin/sh
set -e
top="$1"
# sanity check
test -n "$top" || {
echo "usage: $0 USUAL_DIR SRC ..." >&2
exit 1
}
test -f "$top/usual/base.h" || {
echo "usage: $0 USUAL_DIR SRC ..." >&2
exit 1
}
shift
test -n "$1" || exit 0
test -n "$AWK" || AWK=awk
# return uniq module names, exclude already found ones
grep_usual() {
excl='excl["config"]=1'
for m in $m_done; do
excl="$excl;excl[\"$m\"]=1"
done
prog='
BEGIN { '"$excl"' }
/^#include[ \t]*[<"]usual\// {
p1 = index($0, "/");
p2 = index($0, ".");
m = substr($0, p1+1, p2-p1-1);
if (!excl[m]) print m;
}'
$AWK "$prog" "$@" | sort -u
}
# return module filename globs
make_pats() {
for m in "$@"; do
echo "$top/usual/$m*.[ch]"
done
}
# loop over grep until all mods are found
m_done=""
m_tocheck=`grep_usual "$@"`
while test -n "$m_tocheck"; do
m_done="$m_done $m_tocheck"
pats=`make_pats $m_tocheck`
m_tocheck=`grep_usual $pats`
done
# done
echo $m_done