|
From: Danny B. <dan...@us...> - 2008-08-17 08:43:50
|
Update of /cvsroot/roadmap/roadmap/src In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv6599 Modified Files: buildus_county.c Log Message: Add more verbose error messages, and one bounds check. Index: buildus_county.c =================================================================== RCS file: /cvsroot/roadmap/roadmap/src/buildus_county.c,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** buildus_county.c 27 Nov 2007 13:44:06 -0000 1.6 --- buildus_county.c 17 Aug 2008 08:43:41 -0000 1.7 *************** *** 1,4 **** ! /* buildus_county.c - Build a county table & index for RoadMap. ! * * LICENSE: * --- 1,3 ---- ! /* * LICENSE: * *************** *** 20,23 **** --- 19,27 ---- * along with RoadMap; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + /** + * @file + * @brief Build a county table & index for RoadMap. * * SYNOPSYS: *************** *** 49,52 **** --- 53,57 ---- #include "buildus_county.h" + #include "roadmap_dictionary.h" struct RoadMapCity { *************** *** 70,84 **** #define MAX_US_STATE 100 typedef struct { ! ! RoadMapString name; ! RoadMapString symbol; ! ! RoadMapArea edges; ! } BuildUsState; static BuildUsState State[MAX_US_STATE+1]; ! static int StateCode[MAX_US_STATE+1]; static int StateMaxCode = 0; --- 75,89 ---- #define MAX_US_STATE 100 + /** + * @brief + */ typedef struct { ! RoadMapString name; /**< */ ! RoadMapString symbol; /**< */ ! RoadMapArea edges; /**< */ } BuildUsState; static BuildUsState State[MAX_US_STATE+1]; ! static int StateCode[MAX_US_STATE+1]; static int StateMaxCode = 0; *************** *** 88,92 **** static void buildus_county_register (void); ! static void buildus_county_initialize (void) { --- 93,99 ---- static void buildus_county_register (void); ! /** ! * @brief ! */ static void buildus_county_initialize (void) { *************** *** 109,113 **** } ! int buildus_county_add (int fips, RoadMapString name, RoadMapString state_symbol) { --- 116,126 ---- } ! /** ! * @brief Add a county to the tables ! * @param fips the US standard number to indicate this county ! * @param name the name of this county ! * @param state_symbol the state in which this county is ! * @return the internal representation (index into table) of this county ! */ int buildus_county_add (int fips, RoadMapString name, RoadMapString state_symbol) { *************** *** 118,122 **** RoadMapCounty *this_county; - if (CountyByFips == NULL) buildus_county_initialize (); --- 131,134 ---- *************** *** 133,137 **** if (this_county->name != name) { ! buildmap_fatal (0, "non unique county FIPS code"); } return index; --- 145,154 ---- if (this_county->name != name) { ! static BuildMapDictionary county_dictionary; ! county_dictionary = buildmap_dictionary_open ("county"); ! buildmap_fatal (0, "non unique county FIPS code %d (%s, %s)", ! fips, ! buildmap_dictionary_get(county_dictionary, name), ! buildmap_dictionary_get(county_dictionary, this_county->name)); } return index; *************** *** 186,191 **** } else if (State[StateCode[fips]].symbol != state_symbol) { ! buildmap_fatal (0, "invalid state FIPS"); } --- 203,215 ---- } else if (State[StateCode[fips]].symbol != state_symbol) { + static BuildMapDictionary BuildMapStateDictionary; + BuildMapStateDictionary = buildmap_dictionary_open ("state"); ! buildmap_fatal (0, "invalid state FIPS (fips %d, state %s), not %s", ! fips, ! buildmap_dictionary_get(BuildMapStateDictionary, ! state_symbol), ! buildmap_dictionary_get(BuildMapStateDictionary, ! State[StateCode[fips]].symbol)); } *************** *** 193,197 **** } ! void buildus_county_add_state (RoadMapString name, RoadMapString symbol) { --- 217,225 ---- } ! /** ! * @brief Add a US state ! * @param name the name of this state ! * @param symbol the standard two-character symbol representing this state ! */ void buildus_county_add_state (RoadMapString name, RoadMapString symbol) { *************** *** 199,206 **** RoadMapArea area_reset = {0, 0, 0, 0}; - if (CountyByFips == NULL) buildus_county_initialize (); - /* Search if that state is not yet known. */ --- 227,232 ---- *************** *** 210,215 **** if (State[i].name != name) { ! buildmap_fatal (0, "state symbol conflict"); } return; --- 236,246 ---- if (State[i].name != name) { + static BuildMapDictionary state_dictionary; ! state_dictionary = buildmap_dictionary_open ("state"); ! buildmap_fatal (0, "state symbol conflict (%s %s %s)", ! buildmap_dictionary_get(state_dictionary, symbol), ! buildmap_dictionary_get(state_dictionary, State[i].name), ! buildmap_dictionary_get(state_dictionary, name)); } return; *************** *** 217,222 **** } - StateCount += 1; State[StateCount].name = name; State[StateCount].symbol = symbol; --- 248,257 ---- } + if (StateCount == MAX_US_STATE - 1) { + buildmap_fatal(0, "Cannot add more than %d states", MAX_US_STATE); + } + + StateCount += 1; State[StateCount].name = name; State[StateCount].symbol = symbol; *************** *** 225,229 **** } ! void buildus_county_add_city (int fips, RoadMapString city) { --- 260,268 ---- } ! /** ! * @brief ! * @param fips ! * @param city ! */ void buildus_county_add_city (int fips, RoadMapString city) { *************** *** 234,241 **** struct RoadMapCity *this_city; - if (CountyByFips == NULL) buildus_county_initialize (); - /* First retrieve the county. */ --- 273,278 ---- *************** *** 274,278 **** } ! void buildus_county_set_position (int fips, const RoadMapArea *bounding_box) { --- 311,319 ---- } ! /** ! * @brief ! * @param fips ! * @param bounding_box ! */ void buildus_county_set_position (int fips, const RoadMapArea *bounding_box) { *************** *** 324,328 **** } ! static int buildmap_county_compare (const void *r1, const void *r2) { --- 365,374 ---- } ! /** ! * @brief ! * @param r1 ! * @param r2 ! * @return ! */ static int buildmap_county_compare (const void *r1, const void *r2) { *************** *** 342,345 **** --- 388,397 ---- } + /** + * @brief + * @param r1 + * @param r2 + * @return + */ static int buildmap_county_compare_city (const void *r1, const void *r2) { *************** *** 369,372 **** --- 421,427 ---- } + /** + * @brief + */ static void buildus_county_sort (void) { *************** *** 412,416 **** } ! static void buildus_county_save (void) { --- 467,473 ---- } ! /** ! * @brief ! */ static void buildus_county_save (void) { *************** *** 560,564 **** } ! static buildmap_db_module BuildUsCountyModule = { "county", --- 617,623 ---- } ! /** ! * @brief ! */ static buildmap_db_module BuildUsCountyModule = { "county", *************** *** 569,573 **** }; ! static void buildus_county_register (void) { buildmap_db_register (&BuildUsCountyModule); --- 628,634 ---- }; ! /** ! * @brief ! */ static void buildus_county_register (void) { buildmap_db_register (&BuildUsCountyModule); |