-
Notifications
You must be signed in to change notification settings - Fork 223
/
checklinks.awk
70 lines (64 loc) · 1.59 KB
/
checklinks.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
# Check links in tz tables.
# Contributed by Paul Eggert. This file is in the public domain.
BEGIN {
# Special marker indicating that the name is defined as a Zone.
# It is a newline so that it cannot match a valid name.
# It is not null so that its slot does not appear unset.
Zone = "\n"
}
/^Z/ {
if (defined[$2]) {
if (defined[$2] == Zone) {
printf "%s: Zone has duplicate definition\n", $2
} else {
printf "%s: Link with same name as Zone\n", $2
}
status = 1
}
defined[$2] = Zone
}
/^L/ {
if (defined[$3]) {
if (defined[$3] == Zone) {
printf "%s: Link with same name as Zone\n", $3
} else if (defined[$3] == $2) {
printf "%s: Link has duplicate definition\n", $3
} else {
printf "%s: Link to both %s and %s\n", $3, defined[$3], $2
}
status = 1
}
if (backcheck && FILENAME != backcheck && $3 != "GMT") {
printf "%s: Link should be in '%s'\n", $3, backcheck
status = 1
}
if ($4 == "#=") {
shortcut[$5] = $3
}
used[$2] = 1
defined[$3] = $2
}
END {
for (tz in used) {
if (defined[tz] != Zone) {
if (!defined[tz]) {
printf "%s: Link to nowhere\n", tz
status = 1
} else if (DATAFORM != "vanguard") {
printf "%s: Link to link\n", tz
status = 1
}
}
}
for (tz in shortcut) {
if (defined[shortcut[tz]] != defined[tz]) {
target = (!defined[tz] ? "absence" \
: defined[tz] == "\n" ? "zone" \
: defined[tz])
printf "%s: target %s disagrees with %s's target %s\n", \
tz, target, shortcut[tz], defined[shortcut[tz]]
status = 1
}
}
exit status
}