diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2014-03-09 13:13:48 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-03-09 19:36:35 -0700 |
commit | 7991e36c563271eca16863fb46f70440686c304b (patch) | |
tree | fcdcafcce6bf3bdffe90a56f19e9b21d6ffb2293 /load-git.c | |
parent | 5fcb36f5a83a0eb1a45553f8d1c6d1e0e2fb41af (diff) | |
download | subsurface-7991e36c563271eca16863fb46f70440686c304b.tar.gz |
Parse basic dive computer sample data
This doesn't yet parse the (less common) "key=value" type sample data,
so it's not complete, but the framework for that is in place too.
With this, we now parse all the basics, and the most noticeable missing
part is the cylinder and weigthsystem data. Lack of cylinder data in
particular means that SAC-rates etc don't get calculated, but other than
that it looks almost complete - you don't miss the missing event and
sample details unless you look for them.
I'll get the missing pieces done too, but this basic sample parsing was
visually a big step.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'load-git.c')
-rw-r--r-- | load-git.c | 92 |
1 files changed, 91 insertions, 1 deletions
diff --git a/load-git.c b/load-git.c index 6024cdf3c..be4d7649e 100644 --- a/load-git.c +++ b/load-git.c @@ -211,9 +211,99 @@ report_error("Unmatched action '%s'", line); return -1; } -/* FIXME! Samples not parsed */ +static void parse_sample_keyvalue(struct sample *sample, const char *key, const char *value) +{ + /* FIXME! Sample key-value pairs not parsed */ +} + +/* Parse key=val parts of the samples */ +static char *parse_sample_entry(struct sample *sample, char *line) +{ + char *key = line, *val, c; + + while ((c = *line) != 0) { + if (isspace(c) || c == '=') + break; + line++; + } + + if (c == '=') + *line++ = 0; + val = line; + + while ((c = *line) != 0) { + if (isspace(c)) + break; + line++; + } + if (c) + *line++ = 0; + + parse_sample_keyvalue(sample, key, val); + return line; +} + +static char *parse_sample_unit(struct sample *sample, double val, char *unit) +{ + char *end = unit, c; + + /* Skip over the unit */ + while ((c = *end) != 0) { + if (isspace(c)) { + *end++ = 0; + break; + } + end++; + } + + /* The units are "°C", "m" or "bar", so let's just look at the first character */ + switch (*unit) { + case 'm': + sample->depth.mm = rint(1000*val); + break; + case 'b': + sample->cylinderpressure.mbar = rint(1000*val); + break; + default: + sample->temperature.mkelvin = C_to_mkelvin(val); + break; + } + + return end; +} + static void sample_parser(char *line, struct divecomputer *dc) { + int m,s; + struct sample *sample = prepare_sample(dc); + + m = strtol(line, &line, 10); + if (*line == ':') + s = strtol(line+1, &line, 10); + sample->time.seconds = m*60+s; + + for (;;) { + char c; + + while (isspace(c = *line)) + line++; + if (!c) + break; + /* Less common sample entries have a name */ + if (c >= 'a' && c <= 'z') { + line = parse_sample_entry(sample, line); + } else { + const char *end; + double val = ascii_strtod(line, &end); + if (end == line) { + report_error("Odd sample data: %s", line); + break; + } + line = (char *)end; + line = parse_sample_unit(sample, val, line); + } + } + finish_sample(dc); } static void parse_dc_airtemp(char *line, struct membuffer *str, void *_dc) |