checklinks.awk 978 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Check links in tz tables.
  2. # Contributed by Paul Eggert.
  3. BEGIN {
  4. # Special marker indicating that the name is defined as a Zone.
  5. # It is a newline so that it cannot match a valid name.
  6. # It is not null so that its slot does not appear unset.
  7. Zone = "\n"
  8. }
  9. /^Zone/ {
  10. if (defined[$2]) {
  11. if (defined[$2] == Zone) {
  12. printf "%s: Zone has duplicate definition\n", $2
  13. } else {
  14. printf "%s: Link with same name as Zone\n", $2
  15. }
  16. status = 1
  17. }
  18. defined[$2] = Zone
  19. }
  20. /^Link/ {
  21. if (defined[$3]) {
  22. if (defined[$3] == Zone) {
  23. printf "%s: Link with same name as Zone\n", $3
  24. } else if (defined[$3] == $2) {
  25. printf "%s: Link has duplicate definition\n", $3
  26. } else {
  27. printf "%s: Link to both %s and %s\n", $3, defined[$3], $2
  28. }
  29. status = 1
  30. }
  31. used[$2] = 1
  32. defined[$3] = $2
  33. }
  34. END {
  35. for (tz in used) {
  36. if (defined[tz] != Zone) {
  37. printf "%s: Link to non-zone\n", tz
  38. status = 1
  39. }
  40. }
  41. exit status
  42. }