1 // goredo -- djb's redo implementation on pure Go
2 // Copyright (C) 2020-2024 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, version 3 of the License.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // Dependency DOT graph generation
26 type DotNodes struct {
31 func dotWalker(data map[DotNodes]bool, tgt *Tgt) (map[DotNodes]bool, error) {
32 raw, err := os.ReadFile(tgt.dep)
34 return nil, ErrLine(err)
36 _, raw, err = depHeadParse(raw)
38 return nil, ErrLine(err)
44 tgtH, _ := pathSplit(tgt.a)
46 typ, chunk, raw, err = chunkRead(raw)
48 return nil, ErrLine(err)
52 data[DotNodes{tgt.rel, NewTgt(path.Join(tgtH, string(chunk))).rel}] = true
53 case DepTypeIfchange, DepTypeIfchangeNonex:
54 if typ == DepTypeIfchangeNonex {
57 name = string(chunk[InodeLen+HashLen:])
59 dep = NewTgt(path.Join(tgtH, name))
63 data[DotNodes{tgt.rel, dep.rel}] = false
67 data, err = dotWalker(data, dep)
76 func dotPrint(tgts []*Tgt) error {
77 data := map[DotNodes]bool{}
79 for _, tgt := range tgts {
80 data, err = dotWalker(data, tgt)
85 fmt.Println(`digraph d {
88 splines=false // splines=ortho
89 node[shape=rectangle]`)
90 for nodes, nonexistent := range data {
91 fmt.Printf("\n\t\"%s\" -> \"%s\"", nodes.from, nodes.to)
93 fmt.Print(" [style=dotted]")