-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph-templates
executable file
·84 lines (76 loc) · 1.76 KB
/
graph-templates
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
# Decides whether a full path is a template or build script, and processes it.
categorize() {
if [[ $1 =~ .*/([^/]+)-[[:digit:]]+\.template ]]
then
extract_templates "$1" "${BASH_REMATCH[1]}" 'style=solid'
else
extract_templates "$1" \
"$(makepkg-expanded -p "$1" \
-r 'makepkg --printsrcinfo -p "$1"' \
| grep -Po '(?<=pkgbase = ).*')" \
'style=bold'
fi
}
extract_templates() {
echo " \"$2\"${3:+ [$3]};"
grep -Po '(?<=template (input|start); name=).*(?=;|$)' $1 \
| sed "s/.*/ \"$2\" -> \"\0\";/"
}
process_defaults() {
while read -rd $''
do
process $REPLY
done < <( find -regextype posix-egrep \
\( -name 'PKGBUILD' -o -regex '.*-[[:digit:]]+\.template' \) \
-print0 )
}
suppress_defaults() {
process_defaults() {
:
}
}
# Proxy method to categorize, preventing the
# processing of defaults on first execution.
process() {
suppress_defaults
process() {
categorize "$@" &
}
process "$@"
}
echo 'digraph templates {'
echo " node [style=dashed];"
while [ $OPTIND -le $# ]
do
if getopts 'hl:z:' argument
then
case $argument in
h) {
suppress_defaults
echo "usage: $0 [options | files ...]"
echo 'display template inclusion relation in graphiz dot format'
echo ' -h only shows this help text'
echo ' -l <file> read file list from file'
echo ' -z <file> read zero delimited file list'
} >&2 ;;
l)
while read -r
do
process $REPLY
done < <(cat "$OPTARG") ;;
z)
while read -rd $''
do
process $REPLY
done < "$OPTARG" ;;
\?) exit 1 ;;
esac
else
process "${!OPTIND}"
let OPTIND++
fi
done
process_defaults
wait
echo '}'