summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Garrett <jeff@jgarrett.org>2007-11-22 04:05:39 -0600
committerJeff Garrett <jeff@jgarrett.org>2007-11-22 04:05:39 -0600
commitfee3a2c05799588285e204c2067eba1dc786b55b (patch)
tree7dda11eff028302681ecc6c9a6c8380f977547ed
parent5ed820011bcafef38d412bc1bfffd4b4be11ec8b (diff)
Lazy initialization for road and search
-rw-r--r--src/main.c3
-rw-r--r--src/road.c20
-rw-r--r--src/search.c8
-rw-r--r--src/search.h1
-rw-r--r--src/search_city.c9
-rw-r--r--src/search_city.h1
-rw-r--r--src/search_coordinate.c9
-rw-r--r--src/search_coordinate.h1
-rw-r--r--src/search_road.c10
-rw-r--r--src/search_road.h1
10 files changed, 24 insertions, 39 deletions
diff --git a/src/main.c b/src/main.c
index 1108beb..d9b18f7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -187,9 +187,6 @@ gboolean main_init(void)
locationset_load_locationsets(); // needs glyph
- g_print("initializing search\n");
- search_init();
-
g_print("initialization complete\n");
return TRUE;
}
diff --git a/src/road.c b/src/road.c
index 8eb0497..cc56744 100644
--- a/src/road.c
+++ b/src/road.c
@@ -39,17 +39,15 @@ Purpose of road.c:
#define ROAD_SUFFIX_LIST_FILE_NAME ("road-suffix-list.txt")
#define ROAD_SUFFIX_LIST_MIN_WORDS (2)
-struct {
- GArray* pRoadNameSuffixArray; // an array of null-terminated vectors (an array of gchar* with the last being NULL)
-} g_Road = {0};
+static GArray *pRoadNameSuffixArray; // an array of null-terminated vectors (an array of gchar* with the last being NULL)
static void road_init()
{
gchar* pszPath = g_strdup_printf(PACKAGE_SOURCE_DIR"/data/%s", ROAD_SUFFIX_LIST_FILE_NAME);
- if(util_load_array_of_string_vectors(pszPath, &(g_Road.pRoadNameSuffixArray), ROAD_SUFFIX_LIST_MIN_WORDS) == FALSE) {
+ if(util_load_array_of_string_vectors(pszPath, &pRoadNameSuffixArray, ROAD_SUFFIX_LIST_MIN_WORDS) == FALSE) {
g_free(pszPath);
pszPath = g_strdup_printf(PACKAGE_DATA_DIR"/data/%s", ROAD_SUFFIX_LIST_FILE_NAME);
- if(util_load_array_of_string_vectors(pszPath, &(g_Road.pRoadNameSuffixArray), ROAD_SUFFIX_LIST_MIN_WORDS) == FALSE) {
+ if(util_load_array_of_string_vectors(pszPath, &pRoadNameSuffixArray, ROAD_SUFFIX_LIST_MIN_WORDS) == FALSE) {
g_error("Unable to load %s", ROAD_SUFFIX_LIST_FILE_NAME);
}
}
@@ -62,12 +60,12 @@ static void road_init()
const gchar* road_suffix_itoa(gint nSuffixID, ESuffixLength eSuffixLength)
{
- if (!g_Road)
+ if (!pRoadNameSuffixArray)
road_init();
- if(nSuffixID < g_Road.pRoadNameSuffixArray->len) {
+ if(nSuffixID < pRoadNameSuffixArray->len) {
//g_debug("looking up suffixID %d", nSuffixID);
- gchar** apszWords = g_array_index(g_Road.pRoadNameSuffixArray, gchar**, nSuffixID);
+ gchar** apszWords = g_array_index(pRoadNameSuffixArray, gchar**, nSuffixID);
g_assert(eSuffixLength == 0 || eSuffixLength == 1); // we know there are at least 2 words in the array (see call to util_load_name_list)
return apszWords[eSuffixLength];
}
@@ -78,15 +76,15 @@ const gchar* road_suffix_itoa(gint nSuffixID, ESuffixLength eSuffixLength)
gboolean road_suffix_atoi(const gchar* pszSuffix, gint* pReturnSuffixID)
{
- if (!g_Road)
+ if (!pRoadNameSuffixArray)
road_init();
g_assert(pszSuffix != NULL);
g_assert(pReturnSuffixID != NULL);
gint i;
- for(i=0 ; i<g_Road.pRoadNameSuffixArray->len ; i++) {
- gchar** apszWords = g_array_index(g_Road.pRoadNameSuffixArray, gchar**, i);
+ for(i=0 ; i<pRoadNameSuffixArray->len ; i++) {
+ gchar** apszWords = g_array_index(pRoadNameSuffixArray, gchar**, i);
// Does this list of words contain the string?
if(util_find_string_in_string_vector(pszSuffix, apszWords, NULL)) {
diff --git a/src/search.c b/src/search.c
index f33a754..3b7ce38 100644
--- a/src/search.c
+++ b/src/search.c
@@ -31,14 +31,6 @@
#include "search_city.h"
#include "search_coordinate.h"
-// functions
-
-void search_init()
-{
- search_road_init();
- search_city_init();
- search_coordinate_init();
-}
// functions common to all searches
diff --git a/src/search.h b/src/search.h
index 1cd4bc3..84e665d 100644
--- a/src/search.h
+++ b/src/search.h
@@ -37,7 +37,6 @@ typedef enum {
G_BEGIN_DECLS
-void search_init();
void search_clean_string(gchar* p);
void search_all(const gchar* pszSentence);
diff --git a/src/search_city.c b/src/search_city.c
index c7fc248..9e71348 100644
--- a/src/search_city.c
+++ b/src/search_city.c
@@ -34,10 +34,6 @@ void search_city_on_words(gchar** aWords, gint nWordCount);
static glyph_t* g_SearchResultTypeCityGlyph = NULL;
-void search_city_init()
-{
- g_SearchResultTypeCityGlyph = glyph_load_at_size("search-result-type-city", SEARCHWINDOW_SEARCH_RESULT_GLYPH_WIDTH, SEARCHWINDOW_SEARCH_RESULT_GLYPH_HEIGHT);
-}
void search_city_execute(const gchar* pszSentence)
{
@@ -59,6 +55,11 @@ void search_city_on_words(gchar** aWords, gint nWordCount)
gint nStateID = 0;
+ if (!g_SearchResultTypeCityGlyph)
+ g_SearchResultTypeCityGlyph = glyph_load_at_size("search-result-type-city",
+ SEARCHWINDOW_SEARCH_RESULT_GLYPH_WIDTH,
+ SEARCHWINDOW_SEARCH_RESULT_GLYPH_HEIGHT);
+
// index of first and last words of city name
gint iFirst = 0;
gint iLast = nWordCount-1;
diff --git a/src/search_city.h b/src/search_city.h
index 3015abd..505e282 100644
--- a/src/search_city.h
+++ b/src/search_city.h
@@ -26,7 +26,6 @@
G_BEGIN_DECLS
-void search_city_init();
void search_city_execute(const gchar* pszSentence);
G_END_DECLS
diff --git a/src/search_coordinate.c b/src/search_coordinate.c
index 18ee417..10bdc4d 100644
--- a/src/search_coordinate.c
+++ b/src/search_coordinate.c
@@ -46,10 +46,6 @@ static glyph_t* g_SearchResultTypeCoordinateGlyph = NULL;
//
// Public API
//
-void search_coordinate_init()
-{
- g_SearchResultTypeCoordinateGlyph = glyph_load_at_size("search-result-type-coordinate", SEARCHWINDOW_SEARCH_RESULT_GLYPH_WIDTH, SEARCHWINDOW_SEARCH_RESULT_GLYPH_HEIGHT);
-}
void search_coordinate_execute(const gchar* pszSentence)
{
@@ -82,6 +78,11 @@ void search_coordinate_execute(const gchar* pszSentence)
//
static void search_coordinate_add_result(const mappoint_t* pPoint)
{
+ if (!g_SearchResultTypeCoordinateGlyph)
+ g_SearchResultTypeCoordinateGlyph = glyph_load_at_size("search-result-type-coordinate",
+ SEARCHWINDOW_SEARCH_RESULT_GLYPH_WIDTH,
+ SEARCHWINDOW_SEARCH_RESULT_GLYPH_HEIGHT);
+
gchar* pszBuffer = g_strdup_printf(FORMAT_COORDINATE_RESULT, pPoint->fLatitude, pPoint->fLongitude);
searchwindow_add_result(SEARCH_RESULT_TYPE_COORDINATE, pszBuffer, g_SearchResultTypeCoordinateGlyph, pPoint, COORDINATE_RESULT_SUGGESTED_ZOOMLEVEL);
g_free(pszBuffer);
diff --git a/src/search_coordinate.h b/src/search_coordinate.h
index 952db06..5fb02a5 100644
--- a/src/search_coordinate.h
+++ b/src/search_coordinate.h
@@ -26,7 +26,6 @@
G_BEGIN_DECLS
-void search_coordinate_init();
void search_coordinate_execute(const gchar* pszSentence);
G_END_DECLS
diff --git a/src/search_road.c b/src/search_road.c
index ba4edc5..bc26850 100644
--- a/src/search_road.c
+++ b/src/search_road.c
@@ -60,11 +60,6 @@ typedef struct {
static glyph_t* g_SearchResultTypeRoadGlyph = NULL;
-void search_road_init()
-{
- g_SearchResultTypeRoadGlyph = glyph_load_at_size("search-result-type-road", SEARCHWINDOW_SEARCH_RESULT_GLYPH_WIDTH, SEARCHWINDOW_SEARCH_RESULT_GLYPH_HEIGHT);
-}
-
//#define ROAD_MIN_LENGTH_FOR_WILDCARD_SEARCH (4) wildcard search no longer used
@@ -487,6 +482,11 @@ void search_road_filter_result(
mappoint_t ptAddress = {0};
+ if (!g_SearchResultTypeRoadGlyph)
+ g_SearchResultTypeRoadGlyph = glyph_load_at_size("search-result-type-road",
+ SEARCHWINDOW_SEARCH_RESULT_GLYPH_WIDTH,
+ SEARCHWINDOW_SEARCH_RESULT_GLYPH_HEIGHT);
+
// pszStateNameLeft = "(st)";
// pszStateNameRight = "(st)";
diff --git a/src/search_road.h b/src/search_road.h
index 0f5597b..3ef0232 100644
--- a/src/search_road.h
+++ b/src/search_road.h
@@ -26,7 +26,6 @@
G_BEGIN_DECLS
-void search_road_init();
void search_road_execute(const gchar* pszSentence);
G_END_DECLS