Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
att
GitHub Repository: att/ast
Path: blob/master/src/cmd/mam/mamdot.sh
1808 views
1
########################################################################
2
# #
3
# This software is part of the ast package #
4
# Copyright (c) 1989-2011 AT&T Intellectual Property #
5
# and is licensed under the #
6
# Eclipse Public License, Version 1.0 #
7
# by AT&T Intellectual Property #
8
# #
9
# A copy of the License is available at #
10
# http://www.eclipse.org/org/documents/epl-v10.html #
11
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
12
# #
13
# Information and Software Systems Research #
14
# AT&T Research #
15
# Florham Park NJ #
16
# #
17
# Glenn Fowler <[email protected]> #
18
# #
19
########################################################################
20
: convert MAM dependency info to dot input
21
COMMAND=mamdot
22
case `(getopts '[-][123:xyz]' opt --xyz; echo 0$opt) 2>/dev/null` in
23
0123) ARGV0="-a $COMMAND"
24
USAGE=$'
25
[-?
26
@(#)$Id: mamdot (AT&T Labs Research) 1997-02-16 $
27
]
28
'$USAGE_LICENSE$'
29
[+NAME?mamdot - make abstract machine to dot dependency graph conversion filter]
30
[+DESCRIPTION?\bmamdot\b reads MAM (Make Abstract Machine) target and
31
prerequisite file descriptions from the standard input and writes a
32
\bdot\b(1) description of the dependency graph on the standard output.
33
Mamfiles are generated by the \b--mam\b option of \bnmake\b(1) and
34
\bgmake\b(1).]
35
[i:ignore?Dependency names matching the shell \apattern\a are
36
ignored.]:[pattern]
37
[+SEE ALSO?\bdot\b(1), \bgmake\b(1), \bnmake\b(1)]
38
'
39
;;
40
*) ARGV0=""
41
USAGE="i:[pattern]"
42
;;
43
esac
44
45
usage()
46
{
47
OPTIND=0
48
getopts $ARGV0 "$USAGE" OPT '-?'
49
exit 2
50
}
51
52
integer level=0
53
typeset -A pwd top
54
typeset ignore= tree="@(make|done|prev)"
55
56
while getopts $ARGV0 "$USAGE" OPT
57
do case $OPT in
58
i) [[ $ignore ]] && ignore="$ignore|"
59
ignore=$ignore$OPTARG
60
;;
61
*) usage
62
;;
63
esac
64
done
65
[[ $ignore ]] && ignore="@($ignore)"
66
67
list[0]=all
68
top[0]=1
69
print "digraph mam {"
70
print "rankdir = LR"
71
print "node [ shape = box ]"
72
while read -r label op arg arg2 arg3 args
73
do [[ $label == [[:digit:]]* ]] || {
74
arg3=$args
75
arg2=$arg
76
arg=$op
77
op=$label
78
label=0
79
}
80
rule=$arg
81
[[ ${top[$label]} || $arg == */* || $op != $tree ]] || {
82
arg=$label::$arg
83
[[ $op == make ]] && print "\"$arg\" [ label = \"$rule\" ]"
84
}
85
case $op in
86
make) [[ $rule == $ignore ]] || list[level]=${list[level]}$'\n'\"$arg\"
87
level=level+1
88
list[level]=
89
;;
90
prev) [[ $rule == $ignore ]] || list[level]=${list[level]}$'\n'\"$arg\"
91
;;
92
done) [[ $rule == $ignore || ! ${list[level]} ]] ||
93
print "\"$arg\" -> {${list[level]} }"
94
level=level-1
95
;;
96
info) case $arg in
97
pwd) [[ $arg3 == "." ]] && top[$label]=1 ;;
98
esac
99
;;
100
esac
101
done
102
print "}"
103
104