]> git.tdb.fi Git - ext/subsurface.git/commitdiff
Add some more parsing functions
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 31 Aug 2011 00:45:03 +0000 (17:45 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 31 Aug 2011 00:45:03 +0000 (17:45 -0700)
.. and fix the 'duration' parsing: it can be either in seconds, or in
mm:ss format.  Floating point doesn't make any sense.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
parse.c

diff --git a/parse.c b/parse.c
index 3ada58b46630e4f93d81508ff54df6db2fef5424..5c991fa8af8c9403c50a7725cbe7990a04b75c4b 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -421,12 +421,18 @@ static void temperature(char *buffer, void *_temperature)
 
 static void sampletime(char *buffer, void *_time)
 {
+       int i;
+       int min, sec;
        duration_t *time = _time;
-       union int_or_float val;
 
-       switch (integer_or_float(buffer, &val)) {
-       case INTEGER:
-               time->seconds = val.i;
+       i = sscanf(buffer, "%d:%d", &min, &sec);
+       switch (i) {
+       case 1:
+               sec = min;
+               min = 0;
+       /* fallthrough */
+       case 2:
+               time->seconds = sec + min*60;
                break;
        default:
                printf("Strange sample time reading %s\n", buffer);
@@ -434,6 +440,15 @@ static void sampletime(char *buffer, void *_time)
        free(buffer);
 }
 
+static void duration(char *buffer, void *_time)
+{
+       sampletime(buffer, _time);
+}
+
+static void ignore(char *buffer, void *_time)
+{
+}
+
 /* We're in samples - try to convert the random xml value to something useful */
 static void try_to_fill_sample(struct sample *sample, const char *name, char *buf)
 {
@@ -466,6 +481,34 @@ static void try_to_fill_dive(struct dive *dive, const char *name, char *buf)
                return;
        if (match("datetime", last, divedatetime, buf, &dive->when))
                return;
+       if (match("maxdepth", last, depth, buf, &dive->maxdepth))
+               return;
+       if (match("meandepth", last, depth, buf, &dive->meandepth))
+               return;
+       if (match("divetime", last, duration, buf, &dive->duration))
+               return;
+       if (match("divetimesec", last, duration, buf, &dive->duration))
+               return;
+       if (match("surfacetime", last, duration, buf, &dive->surfacetime))
+               return;
+       if (match("airtemp", last, temperature, buf, &dive->airtemp))
+               return;
+       if (match("watertemp", last, temperature, buf, &dive->watertemp))
+               return;
+       if (match("cylinderstartpressure", last, pressure, buf, &dive->beginning_pressure))
+               return;
+       if (match("cylinderendpressure", last, pressure, buf, &dive->end_pressure))
+               return;
+       if (match("divenumber", last, ignore, buf, NULL))
+               return;
+       if (match("diveseries", last, ignore, buf, NULL))
+               return;
+       if (match("number", last, ignore, buf, NULL))
+               return;
+       if (match("size", last, ignore, buf, NULL))
+               return;
+       if (match("fingerprint", last, ignore, buf, NULL))
+               return;
        nonmatch("dive", name, last, buf);
 }