xref: /minix3/share/misc/nanpa.awk (revision 5737b690dc0057f1cf4d1bfc3a46686ab250b0be)
1*5737b690SBen Gras# $NetBSD: nanpa.awk,v 1.2 2003/03/13 02:55:01 jhawk Exp $
2*5737b690SBen Gras#
3*5737b690SBen Gras# todo:
4*5737b690SBen Gras#	parse "http://docs.nanpa.com/cgi-bin/npa_reports/nanpa?
5*5737b690SBen Gras#	    function=list_npa_introduced" to produce parenthetical
6*5737b690SBen Gras#	    notes about what area codes are overlayed by others
7*5737b690SBen Gras#	    (or split from).
8*5737b690SBen Gras#
9*5737b690SBen Grasfunction parse(file, ispipe, isplanning,	i, planinit, t)
10*5737b690SBen Gras{
11*5737b690SBen Gras	planinit = 0;
12*5737b690SBen Gras	while((ispipe?(file | getline):(getline < file)) > 0) {
13*5737b690SBen Gras		sub(/#.*/, "");
14*5737b690SBen Gras		if (length($0)==0) continue;
15*5737b690SBen Gras		if (isplanning) {
16*5737b690SBen Gras			split($0, f);
17*5737b690SBen Gras			if (!planinit && f[2]=="NEW NPA") {
18*5737b690SBen Gras				planinit=1;
19*5737b690SBen Gras				for (i=1; i<=NF; i++)
20*5737b690SBen Gras					fnames[$i]=i-1;
21*5737b690SBen Gras			} else if (planinit && length(f[fnames["NEW NPA"]])>1) {
22*5737b690SBen Gras				t = f[fnames["LOCATION"]] FS;
23*5737b690SBen Gras				if (f[fnames["OVERLAY?"]]=="Yes")
24*5737b690SBen Gras				  t = t "Overlay of " f[fnames["OLD NPA"]];
25*5737b690SBen Gras				else if (f[fnames["OLD NPA"]])
26*5737b690SBen Gras				  t = t "Split of " f[fnames["OLD NPA"]];
27*5737b690SBen Gras				if (f[fnames["STATUS"]])
28*5737b690SBen Gras					t = t " (" f[fnames["STATUS"]] ")";
29*5737b690SBen Gras				if (length(f[fnames["IN SERVICE DATE"]]) > 1)
30*5737b690SBen Gras					t = t " effective " \
31*5737b690SBen Gras					    f[fnames["IN SERVICE DATE"]];
32*5737b690SBen Gras				data[f[fnames["NEW NPA"]] "*"] = t;
33*5737b690SBen Gras			}
34*5737b690SBen Gras		} else {
35*5737b690SBen Gras			# digits only
36*5737b690SBen Gras			match($0, /^[0-9]/);
37*5737b690SBen Gras			if (RSTART==0) continue;
38*5737b690SBen Gras			i=index($0, FS);
39*5737b690SBen Gras			data[substr($0, 1, i-1)]=substr($0,i+1);
40*5737b690SBen Gras		}
41*5737b690SBen Gras	}
42*5737b690SBen Gras	close(file);
43*5737b690SBen Gras}
44*5737b690SBen Gras
45*5737b690SBen GrasBEGIN{
46*5737b690SBen Gras	FS=":"
47*5737b690SBen Gras	print "# $""NetBSD: $";
48*5737b690SBen Gras	print "# Generated from http://www.nanpa.com/area_codes/index.html";
49*5737b690SBen Gras	print "# (with local exceptions)";
50*5737b690SBen Gras	print "# ";
51*5737b690SBen Gras	print "# format:";
52*5737b690SBen Gras	print "#   Area Code : Description : Detail : State/Province Abbrev.";
53*5737b690SBen Gras	print "#   (3rd and 4th fields optional)";
54*5737b690SBen Gras	print "#   A * in the Area Code field indicates a future area code."
55*5737b690SBen Gras	print "# ";
56*5737b690SBen Gras	parse("ftp -o - " \
57*5737b690SBen Gras	    "http://docs.nanpa.com/cgi-bin/npa_reports/nanpa\\?" \
58*5737b690SBen Gras	    "function=list_npa_geo_number | sed -f nanpa.sed", 1, 0);
59*5737b690SBen Gras	parse("ftp -o - " \
60*5737b690SBen Gras	    "http://docs.nanpa.com/cgi-bin/npa_reports/nanpa\\?" \
61*5737b690SBen Gras	    "function=list_npa_non_geo | sed -f nanpa.sed", 1, 0);
62*5737b690SBen Gras	parse("ftp -o - " \
63*5737b690SBen Gras	    "http://docs.nanpa.com/cgi-bin/npa_reports/nanpa\\?" \
64*5737b690SBen Gras	    "function=list_npa_not_in_service | sed -f nanpa.sed", 1, 1);
65*5737b690SBen Gras	parse("na.phone.add", 0, 0);
66*5737b690SBen Gras	sort="sort -n";
67*5737b690SBen Gras	for (i in data)
68*5737b690SBen Gras		print i FS data[i] | sort
69*5737b690SBen Gras	close(sort);
70*5737b690SBen Gras}
71