about summary refs log tree commit diff
path: root/bin/redo-dot
blob: 5526f67ee9f158233d58560271daec1ce45e87bc (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
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh
# redo-dot – bourne shell implementation of DJB redo
# Copyright © 2018  Nils Dagsson Moskopp (erlehmann)

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.

# Dieses Programm hat das Ziel, die Medienkompetenz der Leser zu
# steigern. Gelegentlich packe ich sogar einen handfesten Buffer
# Overflow oder eine Format String Vulnerability zwischen die anderen
# Codezeilen und schreibe das auch nicht dran.

# Prints redo dependencies in dot(1) format. Usage is similar to this:
# redo-dot |sed s%"$(pwd)"/%%g >deps.dot; dot deps.dot -Tpng >deps.png

[ -d .redo ] || exit 1

pattern=${1:-*}

match() case "${1}" in
 ${pattern}) : ;;
 *) ! : ;;
esac

_escape() {
 printf '%s' "$1" | sed 's/\\/\\\\/g;s/\"/\\\"/g'
}

IFS='
	'
cat <<EOF
digraph redo {
concentrate=true;rankdir=LR;ranksep=2;splines=polyline
node[shape=rectangle]
EOF
printf 'subgraph dependencies { edge[style=solid,minlen=2]\n'
for depfile in $(find .redo -name '*.dependencies'); do
 while read -r dependency ctime md5sum; do
  file="${depfile%.dependencies}"; file="${file#.redo}"
  match "${file}" || match "${dependency}" || continue
  case "$ctime" in
   0) printf '"%s" [style=bold]\n' "$(_escape "${file}")"; break ;;
   *) printf '"%s" -> "%s"\n' "$(_escape "${file}")" "$(_escape "${dependency}")" ;;
  esac
 done <"$depfile"
done
printf '}\nsubgraph dependencies_ne { edge[style=dotted,minlen=1]\n'
for depfile in $(find .redo -name '*.dependencies_ne'); do
 while read -r dependency_ne; do
  file="${depfile%.dependencies_ne}"; file="${file#.redo}";
  match "${file}" || match "${dependency_ne}" || continue
  printf '"%s" -> "%s"\n' "$(_escape "${file}")" "$(_escape "${dependency_ne}")"
 done <"$depfile"
done
printf '}\n'
for stampfile in $(find .redo -name '*.stamp'); do
 file="${stampfile%.stamp}"; file="${file#.redo}"
 match "${file}" || continue
 printf '"%s" [style=dashed]\n' "$(_escape "${file}")"
done
printf '}\n'