+ show_milli(f, pre, pressure.mbar, " bar", post);
+}
+
+/*
+ * We're outputting utf8 in xml.
+ * We need to quote the characters <, >, &.
+ *
+ * Technically I don't think we'd necessarily need to quote the control
+ * characters, but at least libxml2 doesn't like them. It doesn't even
+ * allow them quoted. So we just skip them and replace them with '?'.
+ *
+ * Nothing else (and if we ever do this using attributes, we'd need to
+ * quote the quotes we use too).
+ */
+static void quote(FILE *f, const char *text)
+{
+ const char *p = text;
+
+ for (;;) {
+ const char *escape;
+
+ switch (*p++) {
+ default:
+ continue;
+ case 0:
+ escape = NULL;
+ break;
+ case 1 ... 8:
+ case 11: case 12:
+ case 14 ... 31:
+ escape = "?";
+ break;
+ case '<':
+ escape = "<";
+ break;
+ case '>':
+ escape = ">";
+ break;
+ case '&':
+ escape = "&";
+ break;
+ }
+ fwrite(text, (p - text - 1), 1, f);
+ if (!escape)
+ break;
+ fputs(escape, f);
+ text = p;
+ }
+}
+
+static void show_utf8(FILE *f, const char *text, const char *pre, const char *post)
+{
+ int len;
+
+ if (!text)
+ return;
+ while (isspace(*text))
+ text++;
+ len = strlen(text);
+ if (!len)
+ return;
+ while (len && isspace(text[len-1]))
+ len--;
+ /* FIXME! Quoting! */
+ fputs(pre, f);
+ quote(f, text);
+ fputs(post, f);
+}
+
+static void save_depths(FILE *f, struct dive *dive)
+{
+ /* What's the point of this dive entry again? */
+ if (!dive->maxdepth.mm && !dive->meandepth.mm)
+ return;
+
+ fputs(" <depth", f);
+ show_depth(f, dive->maxdepth, " max='", "'");
+ show_depth(f, dive->meandepth, " mean='", "'");
+ fputs(" />\n", f);
+}
+
+static void save_temperatures(FILE *f, struct dive *dive)
+{
+ if (!dive->airtemp.mkelvin && !dive->watertemp.mkelvin)
+ return;
+ fputs(" <temperature", f);
+ show_temperature(f, dive->airtemp, " air='", "'");
+ show_temperature(f, dive->watertemp, " water='", "'");
+ fputs(" />\n", f);