-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex2dot.awk
executable file
·115 lines (100 loc) · 2.83 KB
/
index2dot.awk
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/gawk -f
#
# Turns the RFC index into a Graphviz .dot graph.
#
# Distributed under the terms of the GPL. See the file COPYING for
# details.
#
# $HeadURL$
# $Id$
BEGIN {
node_color["experimental"] = "crimson";
node_color["proposed standard"] = "orange";
node_color["draft standard"] = "yellow";
node_color["internet standard"] = "green";
node_color["standard"] = "green";
node_color["informational"] = "deepskyblue";
node_color["obsolete"] = "red";
node_color["unknown"] = "gray";
edge_attrs["update"] = " [label=\"Update\",color=blue]";
edge_attrs["obsolete"] = " [label=\"Obsolete\",color=red]";
in_rfc_list = 0;
}
# Beginning of RFC
/^[[:digit:]][[:digit:]][[:digit:]][[:digit:]]/ {
in_rfc_list = 1;
description = $0;
next;
}
# Description lines: concatenate the line to the description,
# collapsing runs of white space.
in_rfc_list {
description = description gensub(/ +/, " ", "g", $0);
}
# Empty line, end of RFC
/^$/ && in_rfc_list {
end_of_rfc(description);
description = "";
}
END {
end_of_rfc(description);
description = "";
}
function get_parenthesized_rfc_numbers(description, relation, array, left, right, rfcs, i)
{
if(left = index(description, "(" relation ))
{
right = index(substr(description, left), ")");
rfcs = substr(description,
left + length(relation) + 1,
right - length(relation) - 2);
gsub(/ |(RFC)/, "", rfcs);
}
split(rfcs, array, ",");
for(i in array)
{
if(!match(array[i], /^[[:digit:]][[:digit:]][[:digit:]][[:digit:]]$/))
array[i] = 0;
}
}
function get_status(description, left, right)
{
if(left = index(description, "(Status: "))
{
right = index(substr(description, left), ")");
status = substr(description,
left + 9,
right - 10);
return status;
}
else
{
return "UNKNOWN";
}
}
function end_of_rfc(description, number, color, label)
{
number = substr(description, 1, 4);
color = node_color[tolower(get_status(description))];
if(color == "")
{
color = node_color["unknown"];
}
label = number "\\n" substr(description, 6);
gsub(/ \((Format:|Obsoletes|Obsoleted by|Updates|Updated by|Also|Status:|DOI:) [^)]*\)/, "", label);
gsub(/ $/, "", label);
gsub(/\"/, "\\\"", label);
printf("node %s [color=%s,label=\"%s\"]\n", number, color, label);
get_parenthesized_rfc_numbers(description, "Updates", array);
for(updated in array)
{
if(array[updated] != 0)
print("edge " array[updated] " -> " number edge_attrs["update"]);
}
get_parenthesized_rfc_numbers(description, "Obsoletes", array);
for(obsoleted in array)
{
if(array[obsoleted] != 0)
print("edge " array[obsoleted] " -> " number edge_attrs["obsolete"]);
}
}