exec/protocol.sh
author František Kučera <franta-hg@frantovo.cz>
Sun, 05 Jan 2020 16:28:53 +0100
branchv_0
changeset 0 4d5b3eda7be1
permissions -rwxr-xr-x
exec: protocol design draft
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
#!/bin/bash
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     3
read_nullbyte() { for v in "$@"; do export "$v"; read -r -d '' "$v"; done }
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     4
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     5
# Warning: this script is unsafe and certain characters (which are perfectly legal in CSV values) might cause invalid DOT (GraphViz) streams. (you have been warned)
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     6
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     7
nodes() {
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     8
	cat messages.csv \
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     9
		| relpipe-in-csv \
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
		| relpipe-tr-cut '.*' 'message|sender' \
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
		| relpipe-tr-sed '.*' 'sender' 'executor' 'coral' \
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
		| relpipe-tr-sed '.*' 'sender' 'process'  'gold2' \
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
		| relpipe-out-nullbyte \
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    14
		| while read_nullbyte message color; do echo "$message[style=\"filled,rounded\", fillcolor=$color];"; done
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
	echo;
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    16
}
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    17
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    18
edges() {
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    19
	cat protocol.csv \
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    20
		| relpipe-in-csv \
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    21
		| relpipe-out-nullbyte \
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    22
		| while read_nullbyte from to label; do echo "$from -> $to [label=\"  $label\"];"; done
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    23
}
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    24
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    25
header() {
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    26
	echo "digraph G {
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    27
#rankdir=LR;
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    28
node[shape=box, style=rounded, fontname=Ubuntu];
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    29
start[shape=doublecircle];
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    30
end[shape=doublecircle];
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
";
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
}
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    33
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    34
footer() {
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    35
	echo "}";
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
}
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
4d5b3eda7be1 exec: protocol design draft
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    38
( header; nodes; edges; footer ) | dot -Tpdf > protocol.pdf