summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-08-30 17:45:03 -0700
committerGravatar Linus Torvalds <torvalds@linux-foundation.org>2011-08-30 17:45:03 -0700
commitfc38f4f0c4dba1b7339edbe7ef01b53cbcc78f15 (patch)
tree4cb0c1cdc97fc2d886940bad270a37f7b572ea0c
parent048a5a2b32c0638708ca4779007f9e33226d54f4 (diff)
downloadsubsurface-fc38f4f0c4dba1b7339edbe7ef01b53cbcc78f15.tar.gz
Add some more parsing functions
.. 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>
-rw-r--r--parse.c51
1 files changed, 47 insertions, 4 deletions
diff --git a/parse.c b/parse.c
index 3ada58b46..5c991fa8a 100644
--- 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);
}