ziguard.awk revision 331663
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  dst_type["vanguard.zi"] = 1
17  dst_type["main.zi"] = 1
18  dst_type["rearguard.zi"] = 1
19
20  # The command line should set OUTFILE to the name of the output file.
21  if (!dst_type[outfile]) exit 1
22  vanguard = outfile == "vanguard.zi"
23}
24
25/^Zone/ { zone = $2 }
26
27outfile != "main.zi" {
28  in_comment = /^#/
29
30  # If this line should differ due to Ireland using negative SAVE values,
31  # uncomment the desired version and comment out the undesired one.
32  Rule_Eire = /^#?Rule[\t ]+Eire[\t ]/
33  Zone_Dublin_post_1968 \
34    = (zone == "Europe/Dublin" && /^#?[\t ]+[01]:00[\t ]/ \
35       && (!$(in_comment + 4) || 1968 < $(in_comment + 4)))
36  if (Rule_Eire || Zone_Dublin_post_1968) {
37    if ((Rule_Eire \
38	 || (Zone_Dublin_post_1968 && $(in_comment + 3) == "IST/GMT"))	\
39	== vanguard) {
40      sub(/^#/, "")
41    } else if (/^[^#]/) {
42      sub(/^/, "#")
43    }
44  }
45}
46
47# If a Link line is followed by a Zone line for the same data, comment
48# out the Link line.  This can happen if backzone overrides a Link
49# with a Zone.
50/^Link/ {
51  linkline[$3] = NR
52}
53/^Zone/ {
54  sub(/^Link/, "#Link", line[linkline[$2]])
55}
56
57{ line[NR] = $0 }
58
59END {
60  for (i = 1; i <= NR; i++)
61    print line[i]
62}
63