From 32e2d97a117f0b60564e05d9d641aa74ac2da939 Mon Sep 17 00:00:00 2001 From: Kaj-Michael Lang Date: Mon, 5 May 2008 15:39:52 +0300 Subject: [PATCH] Move and rename repo string parser. --- src/config-gconf.c | 57 +--------------------------------------- src/map-repo.c | 8 +++--- src/map-tile-repo.c | 63 +++++++++++++++++++++++++++++++++++++++++++++ src/map-tile-repo.h | 1 + 4 files changed, 68 insertions(+), 61 deletions(-) diff --git a/src/config-gconf.c b/src/config-gconf.c index 1fc3b83..2966e95 100644 --- a/src/config-gconf.c +++ b/src/config-gconf.c @@ -118,61 +118,6 @@ g_slist_free(temp_list); return TRUE; } -RepoData * -config_parse_repo(gchar * str) -{ - /* Parse each part of a repo, delimited by newline characters: - * 1. name - * 2. url - * 3. cache_dir - * 4. dl_zoom_steps - * 5. view_zoom_steps - */ -gchar *token, *error_check; -RepoData *rd; - -rd=map_tile_repo_new(); - -/* Parse name. */ -token = strsep(&str, "\n\t"); -if (token) - rd->name = g_strdup(token); - -/* Parse URL format. */ -token = strsep(&str, "\n\t"); -if (token) - rd->url = g_strdup(token); - -/* Parse cache dir. */ -token = strsep(&str, "\n\t"); -if (token) - rd->cache_dir = gnome_vfs_expand_initial_tilde(token); - -/* Parse download zoom steps. */ -token = strsep(&str, "\n\t"); -if (!token || !*token || !(rd->dl_zoom_steps = atoi(token))) - rd->dl_zoom_steps = 1; - -/* Parse view zoom steps. */ -token = strsep(&str, "\n\t"); -if (!token || !*token || !(rd->view_zoom_steps = atoi(token))) - rd->view_zoom_steps = 1; - -/* Parse double-size. */ -token = strsep(&str, "\n\t"); -if (token) - rd->double_size = atoi(token); /* Default is zero (FALSE) */ - -/* Parse next-able. */ -token = strsep(&str, "\n\t"); -if (!token || !*token - || (rd->nextable = strtol(token, &error_check, 10), token == str)) - rd->nextable = TRUE; - -map_tile_repo_set_type(rd); -return rd; -} - static void config_default_repo(void) { @@ -220,7 +165,7 @@ curr_repo_index = gconf_client_get_int(gconf_client, GCONF_KEY_CURRREPO, NULL); list = gconf_client_get_list(gconf_client, GCONF_KEY_REPOSITORIES, GCONF_VALUE_STRING, NULL); for (curr = list; curr != NULL; curr = curr->next) { - RepoData *rd = config_parse_repo(curr->data); + RepoData *rd = map_tile_repo_new_from_string(curr->data); _repo_list = g_list_append(_repo_list, rd); if (!curr_repo_index--) repo_set_curr(rd); diff --git a/src/map-repo.c b/src/map-repo.c index e7c69ae..237052f 100644 --- a/src/map-repo.c +++ b/src/map-repo.c @@ -366,18 +366,16 @@ if (GTK_RESPONSE_OK == gtk_dialog_run(GTK_DIALOG(confirm))) { /* Get repo config file from www.gnuite.com. */ if (GNOME_VFS_OK != (vfs_result = gnome_vfs_read_entire_file(MAP_REPO_LIST_URL, &size, &bytes))) { - popup_error(rmi->dialog, - _("An error occurred while retrieving the repositories. " - "The web service may be temporarily down.")); + popup_error(rmi->dialog, _("An error occurred while retrieving the repositories. The web service may be temporarily down.")); g_printerr("Error while download repositories: %s\n", gnome_vfs_result_to_string(vfs_result)); } else { - /* Parse each line as a reposotory. */ + /* Parse each line as a repository. */ for (head = bytes; head && *head; head = tail) { RepoData *rd; RepoEditInfo *rei; tail = strchr(head, '\n'); *tail++ = '\0'; - rd = config_parse_repo(head); + rd = map_tile_repo_new_from_string(head); rei = repoman_dialog_add_repo(rmi, g_strdup(rd->name)); /* Initialize fields with data from the RepoData object. */ gtk_entry_set_text(GTK_ENTRY(rei->txt_url), rd->url); diff --git a/src/map-tile-repo.c b/src/map-tile-repo.c index d7d60e0..5442612 100644 --- a/src/map-tile-repo.c +++ b/src/map-tile-repo.c @@ -32,9 +32,72 @@ map_tile_repo_new(void) return g_new0(RepoData, 1); } +RepoData * +map_tile_repo_new_from_string(gchar *str) +{ +gchar *token, *error_check; +RepoData *rd; + +/* Parse each part of a repo, delimited by newline characters: + * 1. name + * 2. url + * 3. cache_dir + * 4. dl_zoom_steps + * 5. view_zoom_steps + */ + +rd=map_tile_repo_new(); + +/* Parse name. */ +token = strsep(&str, "\n\t"); +if (token) + rd->name = g_strdup(token); + +/* Parse URL format. */ +token = strsep(&str, "\n\t"); +if (token) + rd->url = g_strdup(token); + +/* Parse cache dir. */ +token = strsep(&str, "\n\t"); +if (token) + rd->cache_dir = gnome_vfs_expand_initial_tilde(token); + +/* Parse download zoom steps. */ +token = strsep(&str, "\n\t"); +if (!token || !*token || !(rd->dl_zoom_steps = atoi(token))) + rd->dl_zoom_steps = 1; + +/* Parse view zoom steps. */ +token = strsep(&str, "\n\t"); +if (!token || !*token || !(rd->view_zoom_steps = atoi(token))) + rd->view_zoom_steps = 1; + +/* Parse double-size. */ +token = strsep(&str, "\n\t"); +if (token) + rd->double_size = atoi(token); /* Default is zero (FALSE) */ + +/* Parse next-able. */ +token = strsep(&str, "\n\t"); +if (!token || !*token || (rd->nextable = strtol(token, &error_check, 10), token == str)) + rd->nextable = TRUE; + +map_tile_repo_set_type(rd); +return rd; +} + + void map_tile_repo_free(RepoData *rd) { +if (rd->name) + g_free(rd->name); +if (rd->url) + g_free(rd->url); +if (rd->cache_dir) + g_free(rd->cache_dir); + g_free(rd); } diff --git a/src/map-tile-repo.h b/src/map-tile-repo.h index 3e7c191..57e1f0c 100644 --- a/src/map-tile-repo.h +++ b/src/map-tile-repo.h @@ -29,6 +29,7 @@ struct _RepoData { }; RepoData *map_tile_repo_new(void); +RepoData *map_tile_repo_new_from_string(gchar *str); void map_tile_repo_free(RepoData *rd); void map_tile_repo_set_type(RepoData *rd); -- 2.39.5