summaryrefslogtreecommitdiffstats
path: root/gtk-gui.c
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2012-12-28 08:38:47 -0800
committerGravatar Dirk Hohndel <dirk@hohndel.org>2012-12-28 09:04:59 -0800
commit3b136f23ee4f3ddee1c157dfee2ff84fe6fa130e (patch)
treeee026605d81a3278a55c38fcd04d45c375f20f08 /gtk-gui.c
parentfc1bb0a32cc2b665fdac804c487232ff6ab8341a (diff)
downloadsubsurface-3b136f23ee4f3ddee1c157dfee2ff84fe6fa130e.tar.gz
Make add_dc_to_string() skip redundant entries
There is no point writing out divecomputer nicknames that do not exist (or that match the dive computer model), so don't. Also, make the function to do this static to save-xml.c, which is the only user (I initially didn't _find_ the function to create the XML string because it was illogically hidden in gtk-gui.c), and change the calling convention to be more direct (pass in a string and return a result, rather than modify a "pointer to string"). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'gtk-gui.c')
-rw-r--r--gtk-gui.c34
1 files changed, 0 insertions, 34 deletions
diff --git a/gtk-gui.c b/gtk-gui.c
index 974cfe29d..60a1f18d3 100644
--- a/gtk-gui.c
+++ b/gtk-gui.c
@@ -2281,37 +2281,3 @@ void set_dc_nickname(struct dive *dive)
dc = dc->next;
}
}
-
-void add_dc_to_string(char **dc_xml, struct divecomputer *dc)
-{
- char *pattern, *tmp;
- const char *nickname;
- int len;
-
- if (!dc || !dc->model || !*dc->model || !dc->deviceid)
- /* we have no dc or no model or no deviceid information... nothing to do here */
- return;
- len = sizeof(" model='' deviceid=''") + strlen(dc->model) + 8;
- pattern = malloc(len);
- snprintf(pattern, len, " model='%s' deviceid='%08x'", dc->model, dc->deviceid);
- if (*dc_xml && strstr(*dc_xml, pattern)) {
- /* already have that one */
- free(pattern);
- return;
- }
- nickname = get_dc_nickname(dc->model, dc->deviceid);
- if (!nickname || !*nickname || !strcmp(dc->model, nickname)) {
- /* we still want to store this entry as it explicitly tells us
- * "no nickname needed, use model" */
- len += strlen(*dc_xml) + sizeof("<divecomputerid/>\n");
- tmp = malloc(len);
- snprintf(tmp, len, "%s<divecomputerid%s/>\n", *dc_xml, pattern);
- } else {
- len += strlen(*dc_xml) + strlen(nickname) + sizeof("<divecomputerid nickname=''/>\n");
- tmp = malloc(len);
- snprintf(tmp, len, "%s<divecomputerid%s nickname='%s'/>\n", *dc_xml, pattern, nickname);
- }
- free(pattern);
- free(*dc_xml);
- *dc_xml = tmp;
-}