[cairo-commit] roadster/src Makefile.am, 1.27, 1.28 import_tiger.c, 1.27, 1.28 tiger.c, NONE, 1.1 tiger.h, NONE, 1.1

Jeff Garrett commit at pdx.freedesktop.org
Tue Oct 30 01:14:56 PDT 2007


Committed by: jgarrett

Update of /cvs/cairo/roadster/src
In directory kemper:/tmp/cvs-serv20775/src

Modified Files:
	Makefile.am import_tiger.c 
Added Files:
	tiger.c tiger.h 
Log Message:
2007-10-30 Jeff Garrett <jeff at jgarrett.org>

	* data/Makefile.am:
	* data/tiger-states.txt: Add list of TIGER states
	* src/Makefile.am
	* src/import_tiger.c
	* src/tiger.c
	* src/tiger.h: Use list of TIGER states instead of hard-coded array


Index: Makefile.am
===================================================================
RCS file: /cvs/cairo/roadster/src/Makefile.am,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- Makefile.am	26 Oct 2005 02:52:09 -0000	1.27
+++ Makefile.am	30 Oct 2007 08:14:53 -0000	1.28
@@ -53,7 +53,8 @@
 	road.c\
 	animator.c\
 	tooltipwindow.c\
-	test_poly.c
+	test_poly.c\
+	tiger.c
 
 roadster_LDADD = \
 	$(GNOME_LIBS) \

Index: import_tiger.c
===================================================================
RCS file: /cvs/cairo/roadster/src/import_tiger.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -d -r1.27 -r1.28
--- import_tiger.c	30 Oct 2007 05:25:11 -0000	1.27
+++ import_tiger.c	30 Oct 2007 08:14:53 -0000	1.28
@@ -31,6 +31,7 @@
 #include "import_tiger.h"
 #include "importwindow.h"
 #include "road.h"
+#include "tiger.h"
 
 #ifdef USE_GNOME_VFS
 #include <gnome-vfs-2.0/libgnomevfs/gnome-vfs.h>
@@ -55,13 +56,6 @@
 #define ROWS_PER_PULSE						(18000)		// call import_progress_pulse() after this many rows parsed
 #define CALLBACKS_PER_PULSE					(30)		// call " after this many iterations over hash tables (writing to DB)
 
-typedef struct {
-	gchar* pszCode;
-	gchar* pszName;
-} state_t;
-
-extern state_t g_aStates[79];
-
 gint g_nStateID = 0;		// this is set during import process
 
 typedef enum {
@@ -1276,9 +1270,12 @@
 	// did we read all files?
 	if(bSuccess) {
 		gint nStateID = (nTigerSetNumber / 1000);	// int division (eg. turn 25017 into 25)
-		if(nStateID < G_N_ELEMENTS(g_aStates)) {
+		GHashTable *states = tiger_get_states();
+		struct tiger_state *st;
+		if ((st = g_hash_table_lookup(states, &nStateID)))
+		{
 			gint nCountryID = 1;	// USA is #1 *gag*
-			db_insert_state(g_aStates[nStateID].pszName, g_aStates[nStateID].pszCode, nCountryID, &g_nStateID);
+			db_insert_state(st->name, st->abbrev, nCountryID, &g_nStateID);
 		}
 
 		g_assert(G_N_ELEMENTS(apszExtensions) == 7);
@@ -1428,73 +1425,3 @@
 	g_print("\n");
 }
 #endif
-
-state_t g_aStates[79] = {
-			{"", 	""},	// NOTE: these are in the proper order to line up with the TIGER data's FIPS code.  don't mess with them. :)
-/* 1 */		{"AL", 	"Alabama"},
-/* 2 */		{"AK", 	"Alaska"},
-/* 3 */		{"", 	""},	// unused
-/* 4 */		{"AZ", 	"Arizona"},
-/* 5 */		{"AR", 	"Arkansas"},
-/* 6 */		{"CA", 	"California"},
-/* 7 */		{"", 	""},
-/* 8 */		{"CO", 	"Colorado"},
-/* 9 */		{"CT", 	"Connecticut"},
-/* 10 */	{"DE", 	"Delaware"},
-/* 11 */	{"DC", 	"District of Columbia"},
-/* 12 */	{"FL", 	"Florida"},
-/* 13 */	{"GA", 	"Georgia"},
-/* 14 */	{"", 	""},
-/* 15 */	{"HI", 	"Hawaii"},
-/* 16 */	{"ID", 	"Idaho"},
-/* 17 */	{"IL", 	"Illinois"},
-/* 18 */	{"IN", 	"Indiana"},
-/* 19 */	{"IA", 	"Iowa"},
-/* 20 */	{"KS", 	"Kansas"},
-/* 21 */	{"KY", 	"Kentucky"},
-/* 22 */	{"LA", 	"Louisiana"},
-/* 23 */	{"ME", 	"Maine"},
-/* 24 */	{"MD", 	"Maryland"},
-/* 25 */	{"MA", 	"Massachusetts"},
-/* 26 */	{"MI", 	"Michigan"},
-/* 27 */	{"MN", 	"Minnesota"},
-/* 28 */	{"MS", 	"Mississippi"},
-/* 29 */	{"MO", 	"Missouri"},
-/* 30 */	{"MT", 	"Montana"},
-/* 31 */	{"NE", 	"Nebraska"},
-/* 32 */	{"NV", 	"Nevade"},
-/* 33 */	{"NH", 	"New Hampshire"},
-/* 34 */	{"NJ", 	"New Jersey"},
-/* 35 */	{"NM", 	"New Mexico"},
-/* 36 */	{"NY", 	"New York"},
-/* 37 */	{"NC", 	"North Carolina"},
-/* 38 */	{"ND", 	"North Dakota"},
-/* 39 */	{"OH", 	"Ohio"},
-/* 40 */	{"OK", 	"Oklahoma"},
-/* 41 */	{"OR", 	"Oregon"},
-/* 42 */	{"PA", 	"Pennsylvania"},
-/* 43 */	{"", 	""},
-/* 44 */	{"RI", 	"Rhode Island"},
-/* 45 */	{"SC", 	"South Carolina"},
-/* 46 */	{"SD", 	"South Dakota"},
-/* 47 */	{"TN", 	"Tennessee"},
-/* 48 */	{"TX", 	"Texas"},
-/* 49 */	{"UT", 	"Utah"},
-/* 50 */	{"VT", 	"Vermont"},
-/* 51 */	{"VA", 	"Virginia"},
-/* 52 */	{"", 	""},
-/* 53 */	{"WA", 	"Washington"},
-/* 54 */	{"WV", 	"West Virginia"},
-/* 55 */	{"WI", 	"Wisconsin"},
-/* 56 */	{"WY", 	"Wyoming"},
-/* 57-59 */	{"", 	""},{"", 	""},{"", 	""},
-/* 60 */	{"AS", 	"American Samoa"},
-/* 61-65 */	{"", 	""},{"", 	""},{"", 	""},{"", 	""},{"", 	""},
-/* 66 */	{"GU", 	"Guam"},
-/* 67-68 */	{"", 	""}, {"", 	""},
-/* 69 */	{"MP", 	"Northern Mariana Islands"},
-/* 70-71 */	{"", 	""},{"", 	""},
-/* 72 */	{"PR", 	"Puerto Rico"},
-/* 73-77 */	{"", 	""},{"", 	""},{"", 	""},{"", 	""},{"", 	""},
-/* 78 */	{"VI", 	"Virgin Islands"},
-};

--- NEW FILE: tiger.c ---
/*
 * tiger.c
 * TIGER helper functions
 *
 * Copyright 2007 Jeff Garrett <jeff at jgarrett.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#include <glib.h>
#include "config.h"
#include "tiger.h"


#define TIGER_STATES_FILE	DATADIR "/tiger-states.txt"

GHashTable *state_list;


GHashTable *tiger_get_states()
{
	gchar *contents, **lines, **iter, **tokens;
	struct tiger_state *st;
	gint *fips_code;

	if (state_list)
		return state_list;

	if (!g_file_get_contents(TIGER_STATES_FILE, &contents, NULL, NULL))
	{
		g_warning("Cannot read TIGER states file %s\n", TIGER_STATES_FILE);
		return NULL;
	}

	state_list = g_hash_table_new(g_int_hash, g_int_equal);

	/* The data file of TIGER states is tab-delimited with fields
	 * for the state FIPS code, the abbreviation, and the state name.
	 */
	lines = g_strsplit(contents, "\n", 0);
	for (iter = lines; iter && **iter; iter++)
	{
		st = g_new0(struct tiger_state, 1);
		fips_code = g_new0(gint, 1);

		tokens = g_strsplit(*iter, "\t", 0);
		*fips_code = g_ascii_strtoull(tokens[0], NULL, 10);
		st->abbrev = g_strdup(tokens[1]);
		st->name   = g_strdup(tokens[2]);

		g_hash_table_insert(state_list, fips_code, st);

		g_strfreev(tokens);
	}
	g_strfreev(lines);
	g_free(contents);

	return state_list;
}

--- NEW FILE: tiger.h ---
/*
 * tiger.h
 * TIGER helper functions
 *
 * Copyright 2007 Jeff Garrett <jeff at jgarrett.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef __TIGER_H
#define __TIGER_H

#include <glib.h>


struct tiger_state {
	gchar *name;
	gchar *abbrev;
};


GHashTable *tiger_get_states();

#endif



More information about the cairo-commit mailing list