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