[BACK]Return to checktab.awk CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / time

File: [cvs.NetBSD.org] / src / lib / libc / time / checktab.awk (download)

Revision 1.8, Fri Aug 15 11:04:07 2014 UTC (9 years, 8 months ago) by christos
Branch: MAIN
CVS Tags: prg-localcount2-base3, prg-localcount2-base2, prg-localcount2-base1, prg-localcount2-base, prg-localcount2, phil-wifi-base, phil-wifi-20200421, phil-wifi-20200411, phil-wifi-20200406, phil-wifi-20191119, phil-wifi-20190609, phil-wifi, pgoyette-localcount-base, pgoyette-localcount-20170426, pgoyette-localcount-20170320, pgoyette-localcount-20170107, pgoyette-localcount-20161104, pgoyette-localcount-20160806, pgoyette-localcount-20160726, pgoyette-localcount, pgoyette-compat-merge-20190127, pgoyette-compat-base, pgoyette-compat-20190127, pgoyette-compat-20190118, pgoyette-compat-1226, pgoyette-compat-1126, pgoyette-compat-1020, pgoyette-compat-0930, pgoyette-compat-0906, pgoyette-compat-0728, pgoyette-compat-0625, pgoyette-compat-0521, pgoyette-compat-0502, pgoyette-compat-0422, pgoyette-compat-0415, pgoyette-compat-0407, pgoyette-compat-0330, pgoyette-compat-0322, pgoyette-compat-0315, pgoyette-compat, perseant-stdc-iso10646-base, perseant-stdc-iso10646, netbsd-9-base, netbsd-9-3-RELEASE, netbsd-9-2-RELEASE, netbsd-9-1-RELEASE, netbsd-9-0-RELEASE, netbsd-9-0-RC2, netbsd-9-0-RC1, netbsd-9, netbsd-8-base, netbsd-8-2-RELEASE, netbsd-8-1-RELEASE, netbsd-8-1-RC1, netbsd-8-0-RELEASE, netbsd-8-0-RC2, netbsd-8-0-RC1, netbsd-8, netbsd-10-base, netbsd-10-0-RELEASE, netbsd-10-0-RC6, netbsd-10-0-RC5, netbsd-10-0-RC4, netbsd-10-0-RC3, netbsd-10-0-RC2, netbsd-10-0-RC1, netbsd-10, matt-nb8-mediatek-base, matt-nb8-mediatek, localcount-20160914, is-mlppp-base, is-mlppp, cjep_sun2x-base1, cjep_sun2x-base, cjep_sun2x, cjep_staticlib_x-base1, cjep_staticlib_x-base, cjep_staticlib_x, bouyer-socketcan-base1, bouyer-socketcan-base, bouyer-socketcan, HEAD
Changes since 1.7: +81 -33 lines

merge tzcode2014f via patch

#	$NetBSD: checktab.awk,v 1.8 2014/08/15 11:04:07 christos Exp $

# Check tz tables for consistency.

# Contributed by Paul Eggert.

BEGIN {
	FS = "\t"

	if (!iso_table) iso_table = "iso3166.tab"
	if (!zone_table) zone_table = "zone1970.tab"
	if (!want_warnings) want_warnings = -1

	# A special (and we hope temporary) case.
	tztab["America/Montreal"] = 1

	# Some more special cases; these are zones that should probably
	# be turned into links.
	if (zone_table == "zone1970.tab") {
	  tztab["Africa/Addis_Ababa"] = 1
	  tztab["Africa/Asmara"] = 1
	  tztab["Africa/Bangui"] = 1
	  tztab["Africa/Blantyre"] = 1
	  tztab["Africa/Brazzaville"] = 1
	  tztab["Africa/Bujumbura"] = 1
	  tztab["Africa/Dar_es_Salaam"] = 1
	  tztab["Africa/Djibouti"] = 1
	  tztab["Africa/Douala"] = 1
	  tztab["Africa/Gaborone"] = 1
	  tztab["Africa/Harare"] = 1
	  tztab["Africa/Kampala"] = 1
	  tztab["Africa/Kigali"] = 1
	  tztab["Africa/Kinshasa"] = 1
	  tztab["Africa/Libreville"] = 1
	  tztab["Africa/Luanda"] = 1
	  tztab["Africa/Lubumbashi"] = 1
	  tztab["Africa/Lusaka"] = 1
	  tztab["Africa/Malabo"] = 1
	  tztab["Africa/Maseru"] = 1
	  tztab["Africa/Mbabane"] = 1
	  tztab["Africa/Mogadishu"] = 1
	  tztab["Africa/Niamey"] = 1
	  tztab["Africa/Porto-Novo"] = 1
	  tztab["America/Antigua"] = 1
	  tztab["America/Cayman"] = 1
	  tztab["Asia/Aden"] = 1
	  tztab["Asia/Bahrain"] = 1
	  tztab["Asia/Ho_Chi_Minh"] = 1
	  tztab["Asia/Kuwait"] = 1
	  tztab["Asia/Muscat"] = 1
	  tztab["Asia/Phnom_Penh"] = 1
	  tztab["Asia/Vientiane"] = 1
	  tztab["Indian/Antananarivo"] = 1
	  tztab["Indian/Comoro"] = 1
	  tztab["Indian/Mayotte"] = 1
	  tztab["Pacific/Midway"] = 1
	  tztab["Pacific/Saipan"] = 1
	}

	while (getline <iso_table) {
		iso_NR++
		if ($0 ~ /^#/) continue
		if (NF != 2) {
			printf "%s:%d: wrong number of columns\n", \
				iso_table, iso_NR >>"/dev/stderr"
			status = 1
		}
		cc = $1
		name = $2
		if (cc !~ /^[A-Z][A-Z]$/) {
			printf "%s:%d: invalid country code '%s'\n", \
				iso_table, iso_NR, cc >>"/dev/stderr"
			status = 1
		}
		if (cc <= cc0) {
			if (cc == cc0) {
				s = "duplicate";
			} else {
				s = "out of order";
			}

			printf "%s:%d: country code '%s' is %s\n", \
				iso_table, iso_NR, cc, s \
				>>"/dev/stderr"
			status = 1
		}
		cc0 = cc
		if (name2cc[name]) {
			printf "%s:%d: '%s' and '%s' have the sname name\n", \
				iso_table, iso_NR, name2cc[name], cc \
				>>"/dev/stderr"
			status = 1
		}
		name2cc[name] = cc
		cc2name[cc] = name
		cc2NR[cc] = iso_NR
	}

	cc0 = ""

	while (getline <zone_table) {
		zone_NR++
		if ($0 ~ /^#/) continue
		if (NF != 3 && NF != 4) {
			printf "%s:%d: wrong number of columns\n", \
				zone_table, zone_NR >>"/dev/stderr"
			status = 1
		}
		split($1, cca, /,/)
		cc = cca[1]
		coordinates = $2
		tz = $3
		comments = $4
		if (cc < cc0) {
			printf "%s:%d: country code '%s' is out of order\n", \
				zone_table, zone_NR, cc >>"/dev/stderr"
			status = 1
		}
		cc0 = cc
		tztab[tz] = 1
		tz2comments[tz] = comments
		tz2NR[tz] = zone_NR
		for (i in cca) {
		    cc = cca[i]
		    cctz = cc tz
		    cctztab[cctz] = 1
		    if (cc2name[cc]) {
			cc_used[cc]++
		    } else {
			printf "%s:%d: %s: unknown country code\n", \
				zone_table, zone_NR, cc >>"/dev/stderr"
			status = 1
		    }
		}
		if (coordinates !~ /^[-+][0-9][0-9][0-5][0-9][-+][01][0-9][0-9][0-5][0-9]$/ \
		    && 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]$/) {
			printf "%s:%d: %s: invalid coordinates\n", \
				zone_table, zone_NR, coordinates >>"/dev/stderr"
			status = 1
		}
	}

	for (cctz in cctztab) {
		cc = substr (cctz, 1, 2)
		tz = substr (cctz, 3)
		if (1 < cc_used[cc]) {
			comments_needed[tz] = cc
		}
	}
	for (cctz in cctztab) {
	  cc = substr (cctz, 1, 2)
	  tz = substr (cctz, 3)
	  if (!comments_needed[tz] && tz2comments[tz]) {
	    printf "%s:%d: unnecessary comment '%s'\n", \
		zone_table, tz2NR[tz], tz2comments[tz] \
		>>"/dev/stderr"
	    tz2comments[tz] = 0
	    status = 1
	  } else if (comments_needed[tz] && !tz2comments[tz]) {
	    printf "%s:%d: missing comment for %s\n", \
	      zone_table, tz2NR[tz], comments_needed[tz] \
	      >>"/dev/stderr"
	    status = 1
	  }
	}
	FS = " "
}

$1 ~ /^#/ { next }

{
	tz = rules = ""
	if ($1 == "Zone") {
		tz = $2
		ruleUsed[$4] = 1
	} else if ($1 == "Link" && zone_table == "zone.tab") {
		# Ignore Link commands if source and destination basenames
		# are identical, e.g. Europe/Istanbul versus Asia/Istanbul.
		src = $2
		dst = $3
		while ((i = index(src, "/"))) src = substr(src, i+1)
		while ((i = index(dst, "/"))) dst = substr(dst, i+1)
		if (src != dst) tz = $3
	} else if ($1 == "Rule") {
		ruleDefined[$2] = 1
	} else {
		ruleUsed[$2] = 1
	}
	if (tz && tz ~ /\//) {
		if (!tztab[tz]) {
			printf "%s: no data for '%s'\n", zone_table, tz \
				>>"/dev/stderr"
			status = 1
		}
		zoneSeen[tz] = 1
	}
}

END {
	for (tz in ruleDefined) {
		if (!ruleUsed[tz]) {
			printf "%s: Rule never used\n", tz
			status = 1
		}
	}
	for (tz in tztab) {
		if (!zoneSeen[tz]) {
			printf "%s:%d: no Zone table for '%s'\n", \
				zone_table, tz2NR[tz], tz >>"/dev/stderr"
			status = 1
		}
	}
	if (0 < want_warnings) {
		for (cc in cc2name) {
			if (!cc_used[cc]) {
				printf "%s:%d: warning: " \
					"no Zone entries for %s (%s)\n", \
					iso_table, cc2NR[cc], cc, cc2name[cc]
			}
		}
	}

	exit status
}