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