xref: /freebsd/contrib/tzdata/checklinks.awk (revision 02e9120893770924227138ba49df1edb3896112a)
1# Check links in tz tables.
2
3# Contributed by Paul Eggert.  This file is in the public domain.
4
5BEGIN {
6    # Special marker indicating that the name is defined as a Zone.
7    # It is a newline so that it cannot match a valid name.
8    # It is not null so that its slot does not appear unset.
9    Zone = "\n"
10}
11
12/^Z/ {
13    if (defined[$2]) {
14	if (defined[$2] == Zone) {
15	    printf "%s: Zone has duplicate definition\n", $2
16	} else {
17	    printf "%s: Link with same name as Zone\n", $2
18	}
19	status = 1
20    }
21    defined[$2] = Zone
22}
23
24/^L/ {
25    if (defined[$3]) {
26	if (defined[$3] == Zone) {
27	    printf "%s: Link with same name as Zone\n", $3
28	} else if (defined[$3] == $2) {
29	    printf "%s: Link has duplicate definition\n", $3
30	} else {
31	    printf "%s: Link to both %s and %s\n", $3, defined[$3], $2
32	}
33	status = 1
34    }
35    if (backcheck && FILENAME != backcheck && $3 != "GMT") {
36      printf "%s: Link should be in '%s'\n", $3, backcheck
37      status = 1
38    }
39    if ($4 == "#=") {
40      shortcut[$5] = $3
41    }
42    used[$2] = 1
43    defined[$3] = $2
44}
45
46END {
47    for (tz in used) {
48	if (defined[tz] != Zone) {
49	  if (!defined[tz]) {
50	    printf "%s: Link to nowhere\n", tz
51	    status = 1
52	  } else if (DATAFORM != "vanguard") {
53	    printf "%s: Link to link\n", tz
54	    status = 1
55	  }
56	}
57    }
58    for (tz in shortcut) {
59      if (defined[shortcut[tz]] != defined[tz]) {
60	target = (!defined[tz] ? "absence" \
61		  : defined[tz] == "\n" ? "zone" \
62		  : defined[tz])
63	printf "%s: target %s disagrees with %s's target %s\n", \
64	  tz, target, shortcut[tz], defined[shortcut[tz]]
65	status = 1
66      }
67    }
68
69    exit status
70}
71