17cef702dSapb# Check links in tz tables.
27cef702dSapb
333a9650fSchristos# Contributed by Paul Eggert.  This file is in the public domain.
47cef702dSapb
533a9650fSchristosBEGIN {
633a9650fSchristos    # Special marker indicating that the name is defined as a Zone.
733a9650fSchristos    # It is a newline so that it cannot match a valid name.
833a9650fSchristos    # It is not null so that its slot does not appear unset.
933a9650fSchristos    Zone = "\n"
1033a9650fSchristos}
1133a9650fSchristos
12f2ef9bbcSkre/^Z/ {
1333a9650fSchristos    if (defined[$2]) {
1433a9650fSchristos	if (defined[$2] == Zone) {
1533a9650fSchristos	    printf "%s: Zone has duplicate definition\n", $2
1633a9650fSchristos	} else {
1733a9650fSchristos	    printf "%s: Link with same name as Zone\n", $2
1833a9650fSchristos	}
1933a9650fSchristos	status = 1
2033a9650fSchristos    }
2133a9650fSchristos    defined[$2] = Zone
2233a9650fSchristos}
2333a9650fSchristos
24f2ef9bbcSkre/^L/ {
2533a9650fSchristos    if (defined[$3]) {
2633a9650fSchristos	if (defined[$3] == Zone) {
2733a9650fSchristos	    printf "%s: Link with same name as Zone\n", $3
2833a9650fSchristos	} else if (defined[$3] == $2) {
2933a9650fSchristos	    printf "%s: Link has duplicate definition\n", $3
3033a9650fSchristos	} else {
3133a9650fSchristos	    printf "%s: Link to both %s and %s\n", $3, defined[$3], $2
3233a9650fSchristos	}
3333a9650fSchristos	status = 1
3433a9650fSchristos    }
35*eef857c5Skre    if (backcheck && FILENAME != backcheck && $3 != "GMT") {
36*eef857c5Skre      printf "%s: Link should be in '%s'\n", $3, backcheck
37*eef857c5Skre      status = 1
38*eef857c5Skre    }
39*eef857c5Skre    if ($4 == "#=") {
40*eef857c5Skre      shortcut[$5] = $3
41*eef857c5Skre    }
4233a9650fSchristos    used[$2] = 1
4333a9650fSchristos    defined[$3] = $2
4433a9650fSchristos}
457cef702dSapb
467cef702dSapbEND {
477cef702dSapb    for (tz in used) {
4833a9650fSchristos	if (defined[tz] != Zone) {
49*eef857c5Skre	  if (!defined[tz]) {
50*eef857c5Skre	    printf "%s: Link to nowhere\n", tz
51*eef857c5Skre	    status = 1
52*eef857c5Skre	  } else if (DATAFORM != "vanguard") {
53*eef857c5Skre	    printf "%s: Link to link\n", tz
54*eef857c5Skre	    status = 1
55*eef857c5Skre	  }
56*eef857c5Skre	}
57*eef857c5Skre    }
58*eef857c5Skre    for (tz in shortcut) {
59*eef857c5Skre      if (defined[shortcut[tz]] != defined[tz]) {
60*eef857c5Skre	target = (!defined[tz] ? "absence" \
61*eef857c5Skre		  : defined[tz] == "\n" ? "zone" \
62*eef857c5Skre		  : defined[tz])
63*eef857c5Skre	printf "%s: target %s disagrees with %s's target %s\n", \
64*eef857c5Skre	  tz, target, shortcut[tz], defined[shortcut[tz]]
657cef702dSapb	status = 1
667cef702dSapb      }
677cef702dSapb    }
687cef702dSapb
697cef702dSapb    exit status
707cef702dSapb}
71