[net.sources] Mods to recent "areacode" program

evp@lewey.AIT.COM (Ed Post) (12/12/86)

A few weeks ago, ken@rochester.UUCP posted a little areacode program.  It was
pointed out by some that "grep" on the areacode data works just as well in
the unix environment, as well as allowing searches for areacodes by
geographic keys as well.  However, most microcomputers don't supply grep
utilities.  I've updated the areacode program to provide the
ability to "grep" for items if the parameter isn't a valid areacode.

The code includes the corrections ken mailed, plus the addition of
Arkansas that appeared later from wendt@megaron.UUCP.  This has been
compiled by the Lattice compiler for an IBM-PC, and also on a 4.3bsd
machine.

			-Ed

#! /bin/sh
# This is a shell archive, meaning:
# 1.  Remove everything above the #! /bin/sh line.
# 2.  Save the resulting test in a file
# 3.  Execute the file with /bin/sh (not csh) to create the files:
#
#		areacode.c
#
# Created by evp (Ed Post) on Thu Dec 11 14:13:12 PST 1986
#
if test -f 'areacode.c'
then
	echo shar: will not over-write existing file 'areacode.c'
else
echo extracting 'areacode.c'
sed 's/^X//' >areacode.c <<'SHAR_EOF'
X#include	<stdio.h>
X#include	<ctype.h>
X
X/*
X
X	areacode.c
X	Translated from AREACODE.MAC.
X	Ken Yap (ken@rochester.arpa, ..!rochester!ken).
X
X	Compile: cc -O -o areacode areacode.c
X	Run: areacode nnn nnn ...
X
X	AREACODE.C Ver 1.4 as of November 25, 1986
X
X	Ver. 1.4 searches the text of the areacode list when a
X	non-numeric argument is found. This modification by
X	Ed Post (...hplabs!lewey!evp) 11/25/86.
X
X	Ver. 1.3 added LA suburbs area code 818, added periods to
X	messages (why not?), deleted double entry for area code 809,
X	removed ungrammatical comma from ASCII string at MSG2: and
X	added a space before the `$' in MSG2: so the first space in
X	messages could be removed, providing an extra space for text
X	without changing the SCAN3: routine's 58-character bias.
X	This version provided for M80/L80 devotees courtesy of Irv
X	Hoff's XLATE5.COM to prevent undue anxiety trying to find a
X	copy of ASM.COM.  It has not been tested, so bug fixes from
X	Z80-land are more than welcome. - Bruce Morgen
X
X	Ver. 1.2 added 718 area code for New York City, and fixed bug
X	   in area code 604-804 Harry Kaemmerer
X
X	Ver. 1.1 update of area codes for new U.S. areas, Mexico, &
X	Eastern Canada. Harvey G. Lord, Storrs, CT 06268
X
X	Ver. 1.0 - January 2, 1981 by Kelly Smith
X
X	AREACODE is used to display the region and state, specified
X	by the user...very handy, when someone leaves a area code
X	number on a CBBS, but no city or state reference. Simple
X	enough to use, just type AREACODE nnn<cr> (where 'nnn' is a
X	three digit area  code), and in return, you get a
X	geographical region by city(s), and state. Sorry if your
X	particular city is not represented, and feel free to add it
X	as required...
X*/
X
X/*
X**	These must be in sorted order because binary search is used
X*/
X
Xchar *areacode[]	= {
X"011the International Access Code",
X"170Northwest Mexico",
X"190Mexico City, Mexico",
X"201Hackensack, Morristown, and Newark, New Jersey",
X"202Washington, District of Columbia",
X"203all regions, Connecticut",
X"204Manitoba, Canada",
X"205all regions, Alabama",
X"206Seattle, Tacoma, and Vancouver, Washington",
X"207all regions, Maine",
X"208all regions, Idaho",
X"209Fresno and Stockton, California",
X"212New York City (Manhattan and Bronx) New York",
X"213Los Angeles, California",
X"214Dallas, Texas",
X"215Allentown, Chester, and Philadelphia, Pennsylvania",
X"216Akron, Cleveland, Massillon, and Youngstown, Ohio",
X"217Casey and Springfield, Illinois",
X"218Duluth, Minnesota",
X"219Gary, Hammond, Michigan City, and South Bend, Indiana",
X"301all regions, Maryland",
X"302all regions, Delaware",
X"303all regions, Colorado",
X"304all regions, West Virginia",
X"305Fort Lauderdale, Key West, Miami and Florida",
X"306Saskatchewan, Canada",
X"307all regions, Wyoming",
X"308North Platte and Scottsbluff, Nebraska",
X"309Peoria, Illinois",
X"312Aurora, Chicago, Elgin, and Highland Park, Illinois",
X"313Detroit, Adrian, and Ann Arbor, Michigan",
X"314Saint Louis, Missouri",
X"315Syracuse and Utica, New York",
X"316Dodge City and Wichita, Kansas",
X"317Indianapolis and Kokomo, Indiana",
X"318Lake Charles and Shreveport, Louisiana",
X"319Dubuque, Iowa",
X"401all regions, Rhode Island",
X"402Lincoln and Omaha, Nebraska",
X"403Alberta, Canada",
X"404Atlanta and Rome, Georgia",
X"405Oklahoma City, Oklahoma",
X"406all regions, Montana",
X"408San Jose and Sunnyvale, California",
X"409Galveston, Texas",
X"412Pittsburgh, Indiana, and Rochester, Pennsylvania",
X"413Springfield, Massachusetts",
X"414Green Bay, Milwaukee, and Racine, Wisconsin",
X"415Oakland and San Francisco, California",
X"416Toronto and Ontario, Canada",
X"417Joplin and Springfield, Missouri",
X"418Quebec, Quebec, Canada",
X"419Toldeo, Ohio",
X"501all regions, Arkansas",
X"502Louisville, Paducah, and Shelbyville, Kentucky",
X"503all regions, Oregon",
X"504Baton Rouge and New Orleans, Louisiana",
X"505all regions, New Mexico",
X"506New Brunswick, Canada",
X"507Albert Lea and Rochester, Minnesota",
X"509Pullman, Spokane, and Walla Walla, Washington",
X"512Austin, Corpus Christi, and San Antonio, Texas",
X"513Cincinnati and Dayton, Ohio",
X"514Montreal, Canada",
X"515Des Moines and Mason City, Iowa",
X"516Hempstead, New York",
X"517Lansing and Saginaw, Michigan",
X"518Albany, Greenwich, and Schenectady, New York",
X"519London, Ontario, Canada",
X"525the Country and City code for Mexico City, Mexico",
X"601all regions, Mississippi",
X"602all regions, Arizona",
X"603all regions, New Hampshire",
X"604British Columbia, Canada",
X"605all regions, South Dakota",
X"606Ashland and Winchester, Kentucky",
X"607Elmira, Ithaca, and Stamford, New York",
X"608Beloit and Madison, Wisconsin",
X"609Atlantic City, Camden, and Trenton, New Jersey",
X"612Minneapolis and Saint Paul, Minnesota",
X"613Ottawa, Ontario, Canada",
X"614Columbus, Marietta, and Newark, Ohio",
X"615Chattanooga and Nashville, Tennessee",
X"616Battle Creek, Cadillac, and Grand Rapids, Michigan",
X"617Boston, Framingham, and New Bedford, Massachusetts",
X"618Alton, Mount Vernon, and Centralia, Illinois",
X"619San Diego and the Imperial Valley, California",
X"701all regions, North Dakota",
X"702all regions, Nevada",
X"703Fredericksburg, Roanoke, and Winchester, Virginia",
X"704Charlotte and Salisbury, North Carolina",
X"705North Bay, Ontario, Canada",
X"707Eureka, Napa, and Santa Rosa, California",
X"709Newfoundland, Canada",
X"712Council Bluffs, Iowa",
X"713Houston, Texas",
X"714Orange and Palm Springs, California",
X"715Eau Claire and Wausau, Wisconsin",
X"716Buffalo, Niagara Falls, and Rochester, New York",
X"717Harrisburg, Scranton, and Wilkes-Barre, Pennsylvania",
X"718New York City (Queens, Brooklyn and Staten Island) NY",
X"801all regions, Utah",
X"802all regions, Vermont",
X"803all regions, South Carolina",
X"804Charlottesville, Norfolk, and Richmond, Virginia",
X"805Bakersfield, Ventura, and Simi Valley, California",
X"806Amarillo, Texas",
X"807Thunder Bay, Ontario, Canada",
X"808all regions, Hawaii",
X"809Bahamas, Bermuda, Puerto Rico, and the Virgin Islands",
X"812Evansville, Indiana",
X"813Avon Park, Fort Myers, and Winter Haven, Florida",
X"814Altoona, Erie, and Punxsutawney, Pennsylvania",
X"815La Salle, Joliet, and Rockford, Illinois",
X"816Kansas City and Saint Joseph, Missouri",
X"817Fort Worth, Temple, and Waco, Texas",
X"818the suburban area near Los Angeles, California",
X"819Malartic and Western Quebec, Canada",
X"901Memphis, Tennesee",
X"902Prince Edward Island and Nova Scotia, Canada",
X"904Jacksonville, Florida",
X"906Sault Ste. Marie, Michigan",
X"907all regions, Alaska",
X"912Waycross and Savannah, Georgia",
X"913Ottawa and Topeka, Kansas",
X"914Monroe, Mount Vernon, and Poughkeepsie, New York",
X"915El Paso, Texas",
X"916Sacramento and South Tahoe, California",
X"918Muskogee and Tulsa, Oklahoma",
X"919Greenville, Raleigh, and Williamston, North Carolina"
X};
X
X/* Lattice compiler uses this definition -- it's useful here */
X#undef tolower
X#define tolower(c) (isupper(c)?((c)+'a'-'A'):(c))
X
Xint scan(code)
Xchar *code;
X{
X	register int	i;
X	int		found;
X	int		isin();
X	char *p;
X
X	found = 0;
X	for (i = 0; i < sizeof(areacode) / sizeof(areacode[0]); i++) {
X		if (isin(code,areacode[i])) {
X			p = areacode[i];
X			printf("%c%c%c - %s.\n",p[0],p[1],p[2],p+3);
X			found++;
X		}
X	}
X	return (found);
X}
X
Xint umatch(pat,str)
Xchar *pat,*str;
X{
X	for (; *pat; pat++,str++) {
X		if (tolower(*pat) != tolower(*str)) return (0);
X	}
X	return (1);
X}
X
Xint isin(p,s)
Xchar *p, *s;
X{
X	char c;
X	int umatch();
X
X	c = tolower(*p);
X	for (; *s; s++) {
X		if (c == tolower(*s) && umatch(p,s)) {
X			return (1);
X		}
X	}
X	return (0);
X}
X
Xchar *where(code)
Xchar		*code;
X{
X	register int	i, high, low, mid;
X	int		strncmp();
X
X	low = 0; high = sizeof(areacode) / sizeof(areacode[0]) - 1;
X	while (low <= high)
X	{
X		mid = (low + high) / 2;
X		i = strncmp(code, areacode[mid], 3);
X		if (i < 0)
X			high = mid - 1;
X		else if (i > 0)
X			low = mid + 1;
X		else
X			return (areacode[mid] + 3);
X	}
X	return ("not a valid area code");
X}
X
Xarea(code)
Xchar		*code;
X{
X	char		*where();
X	int		scan();
X
X	if (!isdigit(code[0]) || !isdigit(code[1]) || !isdigit(code[2])
X	    || code[3] != '\0') {
X		printf("Scanning for '%s' in area code list.\n", code);
X		if (scan(code)) {
X			printf("done.\n");
X		} else {
X			printf("No entries for '%s'.\n",code);
X		}
X	} else {
X		printf("Area code %s is %s.\n", code, where(code));
X	}
X}
X
Xmain(argc, argv)
X	int		argc;
X	char		*argv[];
X{
X	if (argc < 2)
X	{
X		printf("Usage: areacode nnn nnn ...\n");
X		exit(1);
X	}
X
X	for (--argc, ++argv; argc > 0; --argc, ++argv)
X		area(*argv);
X}
SHAR_EOF
if test 8402 -ne  ` wc -c < areacode.c `
then
	echo shar: error transmitting 'areacode.c' -- should have been 8402 characters
fi
fi
# end of shell archive
exit 0
-- 
Ed Post -- hplabs!lewey!evp
American Information Technology    (408)252-8713