ziguard.awk 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. # Convert tzdata source into vanguard or rearguard form.
  2. # Contributed by Paul Eggert. This file is in the public domain.
  3. # This is not a general-purpose converter; it is designed for current tzdata.
  4. # It just converts from current source to main, vanguard, and rearguard forms.
  5. # Although it might be nice for it to be idempotent, or to be useful
  6. # for converting back and forth between vanguard and rearguard formats,
  7. # it does not do these nonessential tasks now.
  8. #
  9. # Although main and vanguard forms are currently equivalent,
  10. # this need not always be the case.
  11. #
  12. # When converting to vanguard form, the output can use negative SAVE
  13. # values.
  14. #
  15. # When converting to rearguard form, the output uses only nonnegative
  16. # SAVE values. The idea is for the output data to simulate the behavior
  17. # of the input data as best it can within the constraints of the
  18. # rearguard format.
  19. BEGIN {
  20. dataform_type["vanguard"] = 1
  21. dataform_type["main"] = 1
  22. dataform_type["rearguard"] = 1
  23. # The command line should set DATAFORM.
  24. if (!dataform_type[DATAFORM]) exit 1
  25. vanguard = DATAFORM == "vanguard"
  26. }
  27. /^Zone/ { zone = $2 }
  28. DATAFORM != "main" {
  29. in_comment = /^#/
  30. uncomment = comment_out = 0
  31. # If this line should differ due to Czechoslovakia using negative SAVE values,
  32. # uncomment the desired version and comment out the undesired one.
  33. if (zone == "Europe/Prague" && /^#?[\t ]+[01]:00[\t ]/ && /1947 Feb 23/) {
  34. if (($(in_comment + 2) != "-") == vanguard) {
  35. uncomment = in_comment
  36. } else {
  37. comment_out = !in_comment
  38. }
  39. }
  40. # If this line should differ due to Ireland using negative SAVE values,
  41. # uncomment the desired version and comment out the undesired one.
  42. Rule_Eire = /^#?Rule[\t ]+Eire[\t ]/
  43. Zone_Dublin_post_1968 \
  44. = (zone == "Europe/Dublin" && /^#?[\t ]+[01]:00[\t ]/ \
  45. && (!$(in_comment + 4) || 1968 < $(in_comment + 4)))
  46. if (Rule_Eire || Zone_Dublin_post_1968) {
  47. if ((Rule_Eire \
  48. || (Zone_Dublin_post_1968 && $(in_comment + 3) == "IST/GMT")) \
  49. == vanguard) {
  50. uncomment = in_comment
  51. } else {
  52. comment_out = !in_comment
  53. }
  54. }
  55. # If this line should differ due to Namibia using negative SAVE values,
  56. # uncomment the desired version and comment out the undesired one.
  57. Rule_Namibia = /^#?Rule[\t ]+Namibia[\t ]/
  58. Zone_using_Namibia_rule \
  59. = (zone == "Africa/Windhoek" && /^#?[\t ]+[12]:00[\t ]/ \
  60. && ($(in_comment + 2) == "Namibia" \
  61. || ($(in_comment + 2) == "-" && $(in_comment + 3) == "CAT" \
  62. && ((1994 <= $(in_comment + 4) && $(in_comment + 4) <= 2017) \
  63. || in_comment + 3 == NF))))
  64. if (Rule_Namibia || Zone_using_Namibia_rule) {
  65. if ((Rule_Namibia \
  66. ? ($(in_comment + 9) ~ /^-/ \
  67. || ($(in_comment + 9) == 0 && $(in_comment + 10) == "CAT")) \
  68. : $(in_comment + 1) == "2:00" && $(in_comment + 2) == "Namibia") \
  69. == vanguard) {
  70. uncomment = in_comment
  71. } else {
  72. comment_out = !in_comment
  73. }
  74. }
  75. if (uncomment) {
  76. sub(/^#/, "")
  77. }
  78. if (comment_out) {
  79. sub(/^/, "#")
  80. }
  81. # In rearguard format, change the Japan rule line with "Sat>=8 25:00"
  82. # to "Sun>=9 1:00", to cater to zic before 2007 and to older Java.
  83. if (!vanguard && $1 == "Rule" && $7 == "Sat>=8" && $8 == "25:00") {
  84. sub(/Sat>=8/, "Sun>=9")
  85. sub(/25:00/, " 1:00")
  86. }
  87. # In rearguard format, change the Morocco lines with negative SAVE values
  88. # to use positive SAVE values.
  89. if (!vanguard && $1 == "Rule" && $2 == "Morocco" && $4 == 2018 \
  90. && $6 == "Oct") {
  91. sub(/\t2018\t/, "\t2017\t")
  92. }
  93. if (!vanguard && $1 == "Rule" && $2 == "Morocco" && 2019 <= $3) {
  94. if ($9 == "0") {
  95. sub(/\t0\t/, "\t1:00\t")
  96. } else {
  97. sub(/\t-1:00\t/, "\t0\t")
  98. }
  99. }
  100. if (!vanguard && $1 == "1:00" && $2 == "Morocco" && $3 == "+01/+00") {
  101. sub(/1:00\tMorocco\t\+01\/\+00$/, "0:00\tMorocco\t+00/+01")
  102. }
  103. }
  104. # If a Link line is followed by a Link or Zone line for the same data, comment
  105. # out the Link line. This can happen if backzone overrides a Link
  106. # with a Zone or a different Link.
  107. /^Zone/ {
  108. sub(/^Link/, "#Link", line[linkline[$2]])
  109. }
  110. /^Link/ {
  111. sub(/^Link/, "#Link", line[linkline[$3]])
  112. linkline[$3] = NR
  113. }
  114. { line[NR] = $0 }
  115. END {
  116. for (i = 1; i <= NR; i++)
  117. print line[i]
  118. }