Fix -Wundef warnings for _IO_JUMPS_OFFSET.
[glibc.git] / timezone / checktab.awk
blobfec4f628e5a1b473c87e3eab192f305d9cf7bdfb
1 # Check tz tables for consistency.
3 # Contributed by Paul Eggert.
5 BEGIN {
6 FS = "\t"
8 if (!iso_table) iso_table = "iso3166.tab"
9 if (!zone_table) zone_table = "zone.tab"
10 if (!want_warnings) want_warnings = -1
12 # A special (and we hope temporary) case.
13 tztab["America/Montreal"] = 1
15 while (getline <iso_table) {
16 iso_NR++
17 if ($0 ~ /^#/) continue
18 if (NF != 2) {
19 printf "%s:%d: wrong number of columns\n", \
20 iso_table, iso_NR >>"/dev/stderr"
21 status = 1
23 cc = $1
24 name = $2
25 if (cc !~ /^[A-Z][A-Z]$/) {
26 printf "%s:%d: invalid country code `%s'\n", \
27 iso_table, iso_NR, cc >>"/dev/stderr"
28 status = 1
30 if (cc <= cc0) {
31 if (cc == cc0) {
32 s = "duplicate";
33 } else {
34 s = "out of order";
37 printf "%s:%d: country code `%s' is %s\n", \
38 iso_table, iso_NR, cc, s \
39 >>"/dev/stderr"
40 status = 1
42 cc0 = cc
43 if (name2cc[name]) {
44 printf "%s:%d: `%s' and `%s' have the sname name\n", \
45 iso_table, iso_NR, name2cc[name], cc \
46 >>"/dev/stderr"
47 status = 1
49 name2cc[name] = cc
50 cc2name[cc] = name
51 cc2NR[cc] = iso_NR
54 zone_table = "zone.tab"
55 cc0 = ""
57 while (getline <zone_table) {
58 zone_NR++
59 if ($0 ~ /^#/) continue
60 if (NF != 3 && NF != 4) {
61 printf "%s:%d: wrong number of columns\n", \
62 zone_table, zone_NR >>"/dev/stderr"
63 status = 1
65 cc = $1
66 coordinates = $2
67 tz = $3
68 comments = $4
69 if (cc < cc0) {
70 printf "%s:%d: country code `%s' is out of order\n", \
71 zone_table, zone_NR, cc >>"/dev/stderr"
72 status = 1
74 cc0 = cc
75 cctz = cc tz
76 cctztab[cctz] = 1
77 tztab[tz] = 1
78 tz2comments[cctz] = comments
79 tz2NR[tz] = zone_NR
80 if (cc2name[cc]) {
81 cc_used[cc]++
82 } else {
83 printf "%s:%d: %s: unknown country code\n", \
84 zone_table, zone_NR, cc >>"/dev/stderr"
85 status = 1
87 if (coordinates !~ /^[-+][0-9][0-9][0-5][0-9][-+][01][0-9][0-9][0-5][0-9]$/ \
88 && 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]$/) {
89 printf "%s:%d: %s: invalid coordinates\n", \
90 zone_table, zone_NR, coordinates >>"/dev/stderr"
91 status = 1
95 for (cctz in cctztab) {
96 cc = substr (cctz, 1, 2)
97 tz = substr (cctz, 3)
98 if (cc_used[cc] == 1) {
99 if (tz2comments[cctz]) {
100 printf "%s:%d: unnecessary comment `%s'\n", \
101 zone_table, tz2NR[tz], \
102 tz2comments[cctz] \
103 >>"/dev/stderr"
104 status = 1
106 } else {
107 if (!tz2comments[cctz]) {
108 printf "%s:%d: missing comment\n", \
109 zone_table, tz2NR[tz] >>"/dev/stderr"
110 status = 1
115 FS = " "
119 tz = ""
120 if ($1 == "Zone") tz = $2
121 if ($1 == "Link") {
122 # Ignore Link commands if source and destination basenames
123 # are identical, e.g. Europe/Istanbul versus Asia/Istanbul.
124 src = $2
125 dst = $3
126 while ((i = index(src, "/"))) src = substr(src, i+1)
127 while ((i = index(dst, "/"))) dst = substr(dst, i+1)
128 if (src != dst) tz = $3
130 if (tz && tz ~ /\//) {
131 if (!tztab[tz]) {
132 printf "%s: no data for `%s'\n", zone_table, tz \
133 >>"/dev/stderr"
134 status = 1
136 zoneSeen[tz] = 1
140 END {
141 for (tz in tz2cc) {
142 if (!zoneSeen[tz]) {
143 printf "%s:%d: no Zone table for `%s'\n", \
144 zone_table, tz2NR[tz], tz >>"/dev/stderr"
145 status = 1
149 if (0 < want_warnings) {
150 for (cc in cc2name) {
151 if (!cc_used[cc]) {
152 printf "%s:%d: warning: " \
153 "no Zone entries for %s (%s)\n", \
154 iso_table, cc2NR[cc], cc, cc2name[cc]
159 exit status