summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dive.h1
-rw-r--r--gtk-gui.c34
-rw-r--r--save-xml.c34
3 files changed, 33 insertions, 36 deletions
diff --git a/dive.h b/dive.h
index b77a08468..1191ec6b6 100644
--- a/dive.h
+++ b/dive.h
@@ -530,7 +530,6 @@ extern void flush_divelist(struct dive *dive);
extern void set_dc_nickname(struct dive *dive);
extern const char *get_dc_nickname(const char *model, uint32_t deviceid);
extern void remember_dc(const char *model, uint32_t deviceid, const char *nickname, gboolean change_conf);
-extern void add_dc_to_string(char **dc_xml, struct divecomputer *dc);
#define DIVE_ERROR_PARSE 1
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;
-}
diff --git a/save-xml.c b/save-xml.c
index 88ae4e1e9..45caefe4c 100644
--- a/save-xml.c
+++ b/save-xml.c
@@ -443,6 +443,38 @@ static void save_dive(FILE *f, struct dive *dive)
fprintf(f, "</dive>\n");
}
+static char *add_dc_to_string(char *dc_xml, struct divecomputer *dc)
+{
+ char *pattern, *tmp;
+ const char *nickname;
+ int len;
+
+ /* we have no dc or no model or no deviceid information... nothing to do here */
+ if (!dc || !dc->model || !*dc->model || !dc->deviceid)
+ return dc_xml;
+
+ nickname = get_dc_nickname(dc->model, dc->deviceid);
+ /* We have no nickname, or it is the same as the model ID - nothing interesting */
+ if (!nickname || !*nickname || !strcmp(dc->model, nickname))
+ return dc_xml;
+
+ 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 dc_xml;
+ }
+
+ 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);
+ return tmp;
+}
+
#define VERSION 2
void save_dives(const char *filename)
@@ -464,7 +496,7 @@ void save_dives(const char *filename)
for_each_dive(i, dive) {
struct divecomputer *dc = &dive->dc;
while (dc) {
- add_dc_to_string(&dc_xml, dc);
+ dc_xml = add_dc_to_string(dc_xml, dc);
dc = dc->next;
}
}