~ubuntu-branches/ubuntu/wily/tzdata/wily

« back to all changes in this revision

Viewing changes to checktab.awk

  • Committer: Package Import Robot
  • Author(s): Adam Conrad
  • Date: 2014-08-30 14:24:21 UTC
  • mfrom: (102.1.10 sid)
  • Revision ID: package-import@ubuntu.com-20140830142421-0er7x97qn8ag0gs0
Tags: 2014g-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Check tz tables for consistency.
 
2
 
 
3
# Contributed by Paul Eggert.
 
4
 
 
5
BEGIN {
 
6
        FS = "\t"
 
7
 
 
8
        if (!iso_table) iso_table = "iso3166.tab"
 
9
        if (!zone_table) zone_table = "zone1970.tab"
 
10
        if (!want_warnings) want_warnings = -1
 
11
 
 
12
        # A special (and we hope temporary) case.
 
13
        tztab["America/Montreal"] = 1
 
14
 
 
15
        # Some more special cases; these are zones that should probably
 
16
        # be turned into links.
 
17
        if (zone_table == "zone1970.tab") {
 
18
          tztab["Africa/Addis_Ababa"] = 1
 
19
          tztab["Africa/Asmara"] = 1
 
20
          tztab["Africa/Blantyre"] = 1
 
21
          tztab["Africa/Bujumbura"] = 1
 
22
          tztab["Africa/Dar_es_Salaam"] = 1
 
23
          tztab["Africa/Djibouti"] = 1
 
24
          tztab["Africa/Gaborone"] = 1
 
25
          tztab["Africa/Harare"] = 1
 
26
          tztab["Africa/Kampala"] = 1
 
27
          tztab["Africa/Kigali"] = 1
 
28
          tztab["Africa/Lubumbashi"] = 1
 
29
          tztab["Africa/Lusaka"] = 1
 
30
          tztab["Africa/Maseru"] = 1
 
31
          tztab["Africa/Mbabane"] = 1
 
32
          tztab["Africa/Mogadishu"] = 1
 
33
          tztab["America/Antigua"] = 1
 
34
          tztab["America/Cayman"] = 1
 
35
          tztab["Asia/Aden"] = 1
 
36
          tztab["Asia/Bahrain"] = 1
 
37
          tztab["Asia/Ho_Chi_Minh"] = 1
 
38
          tztab["Asia/Kuwait"] = 1
 
39
          tztab["Asia/Muscat"] = 1
 
40
          tztab["Asia/Phnom_Penh"] = 1
 
41
          tztab["Asia/Vientiane"] = 1
 
42
          tztab["Indian/Antananarivo"] = 1
 
43
          tztab["Indian/Comoro"] = 1
 
44
          tztab["Indian/Mayotte"] = 1
 
45
          tztab["Pacific/Midway"] = 1
 
46
          tztab["Pacific/Saipan"] = 1
 
47
        }
 
48
 
 
49
        while (getline <iso_table) {
 
50
                iso_NR++
 
51
                if ($0 ~ /^#/) continue
 
52
                if (NF != 2) {
 
53
                        printf "%s:%d: wrong number of columns\n", \
 
54
                                iso_table, iso_NR >>"/dev/stderr"
 
55
                        status = 1
 
56
                }
 
57
                cc = $1
 
58
                name = $2
 
59
                if (cc !~ /^[A-Z][A-Z]$/) {
 
60
                        printf "%s:%d: invalid country code '%s'\n", \
 
61
                                iso_table, iso_NR, cc >>"/dev/stderr"
 
62
                        status = 1
 
63
                }
 
64
                if (cc <= cc0) {
 
65
                        if (cc == cc0) {
 
66
                                s = "duplicate";
 
67
                        } else {
 
68
                                s = "out of order";
 
69
                        }
 
70
 
 
71
                        printf "%s:%d: country code '%s' is %s\n", \
 
72
                                iso_table, iso_NR, cc, s \
 
73
                                >>"/dev/stderr"
 
74
                        status = 1
 
75
                }
 
76
                cc0 = cc
 
77
                if (name2cc[name]) {
 
78
                        printf "%s:%d: '%s' and '%s' have the sname name\n", \
 
79
                                iso_table, iso_NR, name2cc[name], cc \
 
80
                                >>"/dev/stderr"
 
81
                        status = 1
 
82
                }
 
83
                name2cc[name] = cc
 
84
                cc2name[cc] = name
 
85
                cc2NR[cc] = iso_NR
 
86
        }
 
87
 
 
88
        cc0 = ""
 
89
 
 
90
        while (getline <zone_table) {
 
91
                zone_NR++
 
92
                if ($0 ~ /^#/) continue
 
93
                if (NF != 3 && NF != 4) {
 
94
                        printf "%s:%d: wrong number of columns\n", \
 
95
                                zone_table, zone_NR >>"/dev/stderr"
 
96
                        status = 1
 
97
                }
 
98
                split($1, cca, /,/)
 
99
                cc = cca[1]
 
100
                coordinates = $2
 
101
                tz = $3
 
102
                comments = $4
 
103
                if (cc < cc0) {
 
104
                        printf "%s:%d: country code '%s' is out of order\n", \
 
105
                                zone_table, zone_NR, cc >>"/dev/stderr"
 
106
                        status = 1
 
107
                }
 
108
                cc0 = cc
 
109
                tztab[tz] = 1
 
110
                tz2comments[tz] = comments
 
111
                tz2NR[tz] = zone_NR
 
112
                for (i in cca) {
 
113
                    cc = cca[i]
 
114
                    cctz = cc tz
 
115
                    cctztab[cctz] = 1
 
116
                    if (cc2name[cc]) {
 
117
                        cc_used[cc]++
 
118
                    } else {
 
119
                        printf "%s:%d: %s: unknown country code\n", \
 
120
                                zone_table, zone_NR, cc >>"/dev/stderr"
 
121
                        status = 1
 
122
                    }
 
123
                }
 
124
                if (coordinates !~ /^[-+][0-9][0-9][0-5][0-9][-+][01][0-9][0-9][0-5][0-9]$/ \
 
125
                    && coordinates !~ /^[-+][0-9][0-9][0-5][0-9][0-5][0-9][-+][01][0-9][0-9][0-5][0-9][0-5][0-9]$/) {
 
126
                        printf "%s:%d: %s: invalid coordinates\n", \
 
127
                                zone_table, zone_NR, coordinates >>"/dev/stderr"
 
128
                        status = 1
 
129
                }
 
130
        }
 
131
 
 
132
        for (cctz in cctztab) {
 
133
                cc = substr (cctz, 1, 2)
 
134
                tz = substr (cctz, 3)
 
135
                if (1 < cc_used[cc]) {
 
136
                        comments_needed[tz] = cc
 
137
                }
 
138
        }
 
139
        for (cctz in cctztab) {
 
140
          cc = substr (cctz, 1, 2)
 
141
          tz = substr (cctz, 3)
 
142
          if (!comments_needed[tz] && tz2comments[tz]) {
 
143
            printf "%s:%d: unnecessary comment '%s'\n", \
 
144
                zone_table, tz2NR[tz], tz2comments[tz] \
 
145
                >>"/dev/stderr"
 
146
            tz2comments[tz] = 0
 
147
            status = 1
 
148
          } else if (comments_needed[tz] && !tz2comments[tz]) {
 
149
            printf "%s:%d: missing comment for %s\n", \
 
150
              zone_table, tz2NR[tz], comments_needed[tz] \
 
151
              >>"/dev/stderr"
 
152
            status = 1
 
153
          }
 
154
        }
 
155
        FS = " "
 
156
}
 
157
 
 
158
$1 ~ /^#/ { next }
 
159
 
 
160
{
 
161
        tz = rules = ""
 
162
        if ($1 == "Zone") {
 
163
                tz = $2
 
164
                ruleUsed[$4] = 1
 
165
        } else if ($1 == "Link" && zone_table == "zone.tab") {
 
166
                # Ignore Link commands if source and destination basenames
 
167
                # are identical, e.g. Europe/Istanbul versus Asia/Istanbul.
 
168
                src = $2
 
169
                dst = $3
 
170
                while ((i = index(src, "/"))) src = substr(src, i+1)
 
171
                while ((i = index(dst, "/"))) dst = substr(dst, i+1)
 
172
                if (src != dst) tz = $3
 
173
        } else if ($1 == "Rule") {
 
174
                ruleDefined[$2] = 1
 
175
        } else {
 
176
                ruleUsed[$2] = 1
 
177
        }
 
178
        if (tz && tz ~ /\//) {
 
179
                if (!tztab[tz]) {
 
180
                        printf "%s: no data for '%s'\n", zone_table, tz \
 
181
                                >>"/dev/stderr"
 
182
                        status = 1
 
183
                }
 
184
                zoneSeen[tz] = 1
 
185
        }
 
186
}
 
187
 
 
188
END {
 
189
        for (tz in ruleDefined) {
 
190
                if (!ruleUsed[tz]) {
 
191
                        printf "%s: Rule never used\n", tz
 
192
                        status = 1
 
193
                }
 
194
        }
 
195
        for (tz in tztab) {
 
196
                if (!zoneSeen[tz]) {
 
197
                        printf "%s:%d: no Zone table for '%s'\n", \
 
198
                                zone_table, tz2NR[tz], tz >>"/dev/stderr"
 
199
                        status = 1
 
200
                }
 
201
        }
 
202
        if (0 < want_warnings) {
 
203
                for (cc in cc2name) {
 
204
                        if (!cc_used[cc]) {
 
205
                                printf "%s:%d: warning: " \
 
206
                                        "no Zone entries for %s (%s)\n", \
 
207
                                        iso_table, cc2NR[cc], cc, cc2name[cc]
 
208
                        }
 
209
                }
 
210
        }
 
211
 
 
212
        exit status
 
213
}