]> git.tdb.fi Git - ext/subsurface.git/blobdiff - parse-xml.c
Add weight system tracking
[ext/subsurface.git] / parse-xml.c
index 38be728da55ffd4c719d0c84080bb06df8199df6..34afdb9f690dc22fa83d6f08a94aaaddd13f1ce4 100644 (file)
@@ -76,6 +76,7 @@ struct units input_units;
  * technically the SI unit for pressure is Pascal, but
  * we default to bar (10^5 pascal), which people
  * actually use. Similarly, C instead of Kelvin.
+ * And kg instead of g.
  */
 const struct units SI_units = {
        .length = METERS,
@@ -105,12 +106,11 @@ static struct {
        const char *name;
 } event;
 static struct tm tm;
-static int cylinder_index;
+static int cylinder_index, ws_index;
 
 static enum import_source {
        UNKNOWN,
        LIBDIVECOMPUTER,
-       SUUNTO,
        UEMIS,
        DIVINGLOG,
        UDDF,
@@ -299,6 +299,27 @@ static void depth(char *buffer, void *_depth)
        free(buffer);
 }
 
+static void weight(char *buffer, void *_weight)
+{
+       weight_t *weight = _weight;
+       union int_or_float val;
+
+       switch (integer_or_float(buffer, &val)) {
+       case FLOAT:
+               switch (input_units.weight) {
+               case KG:
+                       weight->grams = val.fp * 1000 + 0.5;
+                       break;
+               case LBS:
+                       weight->grams = val.fp * 453.6 + 0.5;
+                       break;
+               }
+               break;
+       default:
+               printf("Strange depth reading %s\n", buffer);
+       }
+}
+
 static void temperature(char *buffer, void *_temperature)
 {
        temperature_t *temperature = _temperature;
@@ -644,26 +665,6 @@ static void try_to_fill_sample(struct sample *sample, const char *name, char *bu
        nonmatch("sample", name, buf);
 }
 
-/*
- * Crazy suunto xml. Look at how those o2/he things match up.
- */
-static int suunto_dive_match(struct dive **divep, const char *name, int len, char *buf)
-{
-       struct dive *dive = *divep;
-
-       return  MATCH(".o2pct", percent, &dive->cylinder[0].gasmix.o2) ||
-               MATCH(".hepct_0", percent, &dive->cylinder[0].gasmix.he) ||
-               MATCH(".o2pct_2", percent, &dive->cylinder[1].gasmix.o2) ||
-               MATCH(".hepct_1", percent, &dive->cylinder[1].gasmix.he) ||
-               MATCH(".o2pct_3", percent, &dive->cylinder[2].gasmix.o2) ||
-               MATCH(".hepct_2", percent, &dive->cylinder[2].gasmix.he) ||
-               MATCH(".o2pct_4", percent, &dive->cylinder[3].gasmix.o2) ||
-               MATCH(".hepct_3", percent, &dive->cylinder[3].gasmix.he) ||
-               MATCH(".cylindersize", cylindersize, &dive->cylinder[0].type.size) ||
-               MATCH(".cylinderworkpressure", pressure, &dive->cylinder[0].type.workingpressure) ||
-               0;
-}
-
 static const char *country, *city;
 
 static void divinglog_place(char *place, void *_location)
@@ -978,11 +979,6 @@ static void try_to_fill_dive(struct dive **divep, const char *name, char *buf)
        start_match("dive", name, buf);
 
        switch (import_source) {
-       case SUUNTO:
-               if (suunto_dive_match(divep, name, len, buf))
-                       return;
-               break;
-
        case UEMIS:
                if (uemis_dive_match(divep, name, len, buf))
                        return;
@@ -1050,7 +1046,8 @@ static void try_to_fill_dive(struct dive **divep, const char *name, char *buf)
                return;
        if (MATCH(".buddy", utf8_string, &dive->buddy))
                return;
-
+       if (MATCH(".rating", get_index, &dive->rating))
+               return;
        if (MATCH(".cylinder.size", cylindersize, &dive->cylinder[cylinder_index].type.size))
                return;
        if (MATCH(".cylinder.workpressure", pressure, &dive->cylinder[cylinder_index].type.workingpressure))
@@ -1061,7 +1058,12 @@ static void try_to_fill_dive(struct dive **divep, const char *name, char *buf)
                return;
        if (MATCH(".cylinder.end", pressure, &dive->cylinder[cylinder_index].end))
                return;
-
+       if (MATCH(".weightsystem.description", utf8_string, &dive->weightsystem[ws_index].description))
+               return;
+       if (MATCH(".weightsystem.weight", weight, &dive->weightsystem[ws_index].weight))
+               return;
+       if (MATCH("weight", weight, &dive->weightsystem[ws_index].weight))
+               return;
        if (MATCH(".o2", gasmix, &dive->cylinder[cylinder_index].gasmix.o2))
                return;
        if (MATCH(".n2", gasmix_nitrogen, &dive->cylinder[cylinder_index].gasmix))
@@ -1180,7 +1182,7 @@ static void sanitize_cylinder_type(cylinder_type_t *type)
        if (!type->size.mliter)
                return;
 
-       if (input_units.volume == CUFT || import_source == SUUNTO) {
+       if (input_units.volume == CUFT) {
                /* confusing - we don't really start from ml but millicuft !*/
                volume_of_air = cuft_to_l(type->size.mliter);
                atm = to_ATM(type->workingpressure);            /* working pressure in atm */
@@ -1210,6 +1212,7 @@ static void dive_end(void)
        record_dive(dive);
        dive = NULL;
        cylinder_index = 0;
+       ws_index = 0;
 }
 
 static void event_start(void)
@@ -1234,6 +1237,15 @@ static void cylinder_end(void)
        cylinder_index++;
 }
 
+static void ws_start(void)
+{
+}
+
+static void ws_end(void)
+{
+       ws_index++;
+}
+
 static void sample_start(void)
 {
        sample = prepare_sample(&dive);
@@ -1348,12 +1360,6 @@ static void visit(xmlNode *n)
        traverse(n->children);
 }
 
-static void suunto_importer(void)
-{
-       import_source = SUUNTO;
-       input_units = SI_units;
-}
-
 static void uemis_importer(void)
 {
        import_source = UEMIS;
@@ -1402,10 +1408,10 @@ static struct nesting {
        { "event", event_start, event_end },
        { "gasmix", cylinder_start, cylinder_end },
        { "cylinder", cylinder_start, cylinder_end },
+       { "weightsystem", ws_start, ws_end },
        { "P", sample_start, sample_end },
 
        /* Import type recognition */
-       { "SUUNTO", suunto_importer },
        { "Divinglog", DivingLog_importer },
        { "pre_dive", uemis_importer },
        { "dives", uemis_importer },
@@ -1536,6 +1542,7 @@ static struct xslt_files {
        const char *root;
        const char *file;
 } xslt_files[] = {
+       { "SUUNTO", "SuuntoSDM.xslt" },
        { "JDiveLog", "jdivelog2subsurface.xslt" },
        { NULL, }
 };