+static int buffer_value(char *buffer)
+{
+ int val = atoi(buffer);
+ free(buffer);
+ return val;
+}
+
+static void uemis_length_unit(char *buffer, void *_unused)
+{
+ units.length = buffer_value(buffer) ? FEET : METERS;
+}
+
+static void uemis_volume_unit(char *buffer, void *_unused)
+{
+ units.volume = buffer_value(buffer) ? CUFT : LITER;
+}
+
+static void uemis_pressure_unit(char *buffer, void *_unused)
+{
+#if 0
+ units.pressure = buffer_value(buffer) ? PSI : BAR;
+#endif
+}
+
+static void uemis_temperature_unit(char *buffer, void *_unused)
+{
+ units.temperature = buffer_value(buffer) ? FAHRENHEIT : CELSIUS;
+}
+
+static void uemis_weight_unit(char *buffer, void *_unused)
+{
+ units.weight = buffer_value(buffer) ? LBS : KG;
+}
+
+static void uemis_time_unit(char *buffer, void *_unused)
+{
+}
+
+static void uemis_date_unit(char *buffer, void *_unused)
+{
+}
+
+/* Modified julian day, yay! */
+static void uemis_date_time(char *buffer, void *_when)
+{
+ time_t *when = _when;
+ union int_or_float val;
+
+ switch (integer_or_float(buffer, &val)) {
+ case FLOAT:
+ *when = (val.fp - 40587.5) * 86400;
+ break;
+ default:
+ fprintf(stderr, "Strange julian date: %s", buffer);
+ }
+ free(buffer);
+}
+
+/*
+ * Uemis doesn't know time zones. You need to do them as
+ * minutes, not hours.
+ *
+ * But that's ok, we don't track timezones yet either. We
+ * just turn everything into "localtime expressed as UTC".
+ */
+static void uemis_time_zone(char *buffer, void *_when)
+{
+ time_t *when = _when;
+ signed char tz = atoi(buffer);
+
+ *when += tz * 3600;
+}
+
+static int uemis_dive_match(struct dive *dive, const char *name, int len, char *buf)
+{
+ return MATCH(".units.length", uemis_length_unit, &units) ||
+ MATCH(".units.volume", uemis_volume_unit, &units) ||
+ MATCH(".units.pressure", uemis_pressure_unit, &units) ||
+ MATCH(".units.temperature", uemis_temperature_unit, &units) ||
+ MATCH(".units.weight", uemis_weight_unit, &units) ||
+ MATCH(".units.time", uemis_time_unit, &units) ||
+ MATCH(".units.date", uemis_date_unit, &units) ||
+ MATCH(".date_time", uemis_date_time, &dive->when) ||
+ MATCH(".time_zone", uemis_time_zone, &dive->when) ||
+ MATCH(".ambient.temperature", decicelsius, &dive->airtemp) ||
+ 0;
+}
+