Check supported DF_1_XXX bits
[glibc.git] / timezone / checktab.awk
blobc88b12f1baf60a60c645689a5bbcf094faffa497
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 while (getline <iso_table) {
13 iso_NR++
14 if ($0 ~ /^#/) continue
15 if (NF != 2) {
16 printf "%s:%d: wrong number of columns\n", \
17 iso_table, iso_NR >>"/dev/stderr"
18 status = 1
20 cc = $1
21 name = $2
22 if (cc !~ /^[A-Z][A-Z]$/) {
23 printf "%s:%d: invalid country code `%s'\n", \
24 iso_table, iso_NR, cc >>"/dev/stderr"
25 status = 1
27 if (cc <= cc0) {
28 if (cc == cc0) {
29 s = "duplicate";
30 } else {
31 s = "out of order";
34 printf "%s:%d: country code `%s' is %s\n", \
35 iso_table, iso_NR, cc, s \
36 >>"/dev/stderr"
37 status = 1
39 cc0 = cc
40 if (name2cc[name]) {
41 printf "%s:%d: `%s' and `%s' have the sname name\n", \
42 iso_table, iso_NR, name2cc[name], cc \
43 >>"/dev/stderr"
44 status = 1
46 name2cc[name] = cc
47 cc2name[cc] = name
48 cc2NR[cc] = iso_NR
51 zone_table = "zone.tab"
52 cc0 = ""
54 while (getline <zone_table) {
55 zone_NR++
56 if ($0 ~ /^#/) continue
57 if (NF != 3 && NF != 4) {
58 printf "%s:%d: wrong number of columns\n", \
59 zone_table, zone_NR >>"/dev/stderr"
60 status = 1
62 cc = $1
63 coordinates = $2
64 tz = $3
65 comments = $4
66 if (cc < cc0) {
67 printf "%s:%d: country code `%s' is out of order\n", \
68 zone_table, zone_NR, cc >>"/dev/stderr"
69 status = 1
71 cc0 = cc
72 if (tz2cc[tz]) {
73 printf "%s:%d: %s: duplicate TZ column\n", \
74 zone_table, zone_NR, tz >>"/dev/stderr"
75 status = 1
77 tz2cc[tz] = cc
78 tz2comments[tz] = 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 (tz in tz2cc) {
96 if (cc_used[tz2cc[tz]] == 1) {
97 if (tz2comments[tz]) {
98 printf "%s:%d: unnecessary comment `%s'\n", \
99 zone_table, tz2NR[tz], tz2comments[tz] \
100 >>"/dev/stderr"
101 status = 1
103 } else {
104 if (!tz2comments[tz]) {
105 printf "%s:%d: missing comment\n", \
106 zone_table, tz2NR[tz] >>"/dev/stderr"
107 status = 1
112 FS = " "
116 tz = ""
117 if ($1 == "Zone") tz = $2
118 if ($1 == "Link") {
119 # Ignore Link commands if source and destination basenames
120 # are identical, e.g. Europe/Istanbul versus Asia/Istanbul.
121 src = $2
122 dst = $3
123 while ((i = index(src, "/"))) src = substr(src, i+1)
124 while ((i = index(dst, "/"))) dst = substr(dst, i+1)
125 if (src != dst) tz = $3
127 if (tz && tz ~ /\//) {
128 if (!tz2cc[tz]) {
129 printf "%s: no data for `%s'\n", zone_table, tz \
130 >>"/dev/stderr"
131 status = 1
133 zoneSeen[tz] = 1
137 END {
138 for (tz in tz2cc) {
139 if (!zoneSeen[tz]) {
140 printf "%s:%d: no Zone table for `%s'\n", \
141 zone_table, tz2NR[tz], tz >>"/dev/stderr"
142 status = 1
146 if (0 < want_warnings) {
147 for (cc in cc2name) {
148 if (!cc_used[cc]) {
149 printf "%s:%d: warning: " \
150 "no Zone entries for %s (%s)\n", \
151 iso_table, cc2NR[cc], cc, cc2name[cc]
156 exit status