checklinks.awk 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Check links in tz tables.
  2. # Contributed by Paul Eggert. This file is in the public domain.
  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. /^Z/ {
  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. /^L/ {
  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. if (backcheck && FILENAME != backcheck && $3 != "GMT") {
  32. printf "%s: Link should be in '%s'\n", $3, backcheck
  33. status = 1
  34. }
  35. if ($4 == "#=") {
  36. shortcut[$5] = $3
  37. }
  38. used[$2] = 1
  39. defined[$3] = $2
  40. }
  41. END {
  42. for (tz in used) {
  43. if (defined[tz] != Zone) {
  44. if (!defined[tz]) {
  45. printf "%s: Link to nowhere\n", tz
  46. status = 1
  47. } else if (DATAFORM != "vanguard") {
  48. printf "%s: Link to link\n", tz
  49. status = 1
  50. }
  51. }
  52. }
  53. for (tz in shortcut) {
  54. if (defined[shortcut[tz]] != defined[tz]) {
  55. target = (!defined[tz] ? "absence" \
  56. : defined[tz] == "\n" ? "zone" \
  57. : defined[tz])
  58. printf "%s: target %s disagrees with %s's target %s\n", \
  59. tz, target, shortcut[tz], defined[shortcut[tz]]
  60. status = 1
  61. }
  62. }
  63. exit status
  64. }