1# Convert tzdata source into vanguard or rearguard form. 2 3# Contributed by Paul Eggert. This file is in the public domain. 4 5# This is not a general-purpose converter; it is designed for current tzdata. 6# 7# When converting to vanguard form, the output can use negative SAVE 8# values. 9# 10# When converting to rearguard form, the output uses only nonnegative 11# SAVE values. The idea is for the output data to simulate the behavior 12# of the input data as best it can within the constraints of the 13# rearguard format. 14 15BEGIN { 16 dataform_type["vanguard"] = 1 17 dataform_type["main"] = 1 18 dataform_type["rearguard"] = 1 19 20 # The command line should set DATAFORM. 21 if (!dataform_type[DATAFORM]) exit 1 22 vanguard = DATAFORM == "vanguard" 23} 24 25/^Zone/ { zone = $2 } 26 27DATAFORM != "main" { 28 in_comment = /^#/ 29 uncomment = comment_out = 0 30 31 # If the 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" && /1947 Feb 23/) { 34 if (($(in_comment + 2) != "-") == vanguard) { 35 uncomment = in_comment 36 } else { 37 comment_out = !in_comment 38 } 39 } 40 41 # If this line should differ due to Ireland using negative SAVE values, 42 # uncomment the desired version and comment out the undesired one. 43 Rule_Eire = /^#?Rule[\t ]+Eire[\t ]/ 44 Zone_Dublin_post_1968 \ 45 = (zone == "Europe/Dublin" && /^#?[\t ]+[01]:00[\t ]/ \ 46 && (!$(in_comment + 4) || 1968 < $(in_comment + 4))) 47 if (Rule_Eire || Zone_Dublin_post_1968) { 48 if ((Rule_Eire \ 49 || (Zone_Dublin_post_1968 && $(in_comment + 3) == "IST/GMT")) \ 50 == vanguard) { 51 uncomment = in_comment 52 } else { 53 comment_out = !in_comment 54 } 55 } 56 57 # If this line should differ due to Namibia using Rule SAVE suffixes, 58 # uncomment the desired version and comment out the undesired one. 59 Rule_Namibia = /^#?Rule[\t ]+Namibia[\t ]/ 60 Zone_using_Namibia_rule \ 61 = (zone == "Africa/Windhoek" \ 62 && ($(in_comment + 2) == "Namibia" \ 63 || (1994 <= $(in_comment + 4) && $(in_comment + 4) <= 2017) \ 64 || in_comment + 3 == NF)) 65 if (Rule_Namibia || Zone_using_Namibia_rule) { 66 if ((Rule_Namibia \ 67 ? ($(in_comment + 9) ~ /^-/ \ 68 || ($(in_comment + 9) == 0 && $(in_comment + 10) == "CAT")) \ 69 : $(in_comment + 1) == "2:00" && $(in_comment + 2) == "Namibia") \ 70 == vanguard) { 71 uncomment = in_comment 72 } else { 73 comment_out = !in_comment 74 } 75 } 76 77 if (uncomment) { 78 sub(/^#/, "") 79 } 80 if (comment_out) { 81 sub(/^/, "#") 82 } 83} 84 85# If a Link line is followed by a Zone line for the same data, comment 86# out the Link line. This can happen if backzone overrides a Link 87# with a Zone. 88/^Link/ { 89 linkline[$3] = NR 90} 91/^Zone/ { 92 sub(/^Link/, "#Link", line[linkline[$2]]) 93} 94 95{ line[NR] = $0 } 96 97END { 98 for (i = 1; i <= NR; i++) 99 print line[i] 100} 101