From: Linus Torvalds Date: Tue, 27 Sep 2011 17:46:42 +0000 (-0700) Subject: Merge branch 'otu-tracking-v2' of git://github.com/dirkhh/subsurface X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=2a8f7ab78f8d00b699b683b122ad2cf0ddc094b6;hp=-c;p=ext%2Fsubsurface.git Merge branch 'otu-tracking-v2' of git://github.com/dirkhh/subsurface * 'otu-tracking-v2' of git://github.com/dirkhh/subsurface: Make OTU column invisible by default Add OTU to divelist Calculate OTUs for every dive Fix up trivial conflicts in dive.h (due to dive event handling also adding a field to the dive structure) --- 2a8f7ab78f8d00b699b683b122ad2cf0ddc094b6 diff --combined dive.h index b121892,5cb3241..42d91d6 --- a/dive.h +++ b/dive.h @@@ -134,6 -134,11 +134,11 @@@ static inline int to_PSI(pressure_t pre return pressure.mbar * 0.0145037738 + 0.5; } + static inline double to_ATM(pressure_t pressure) + { + return pressure.mbar / 1013.25; + } + struct sample { duration_t time; depth_t depth; @@@ -142,21 -147,6 +147,21 @@@ int cylinderindex; }; +/* + * Events are currently pretty meaningless. This is + * just based on the random data that libdivecomputer + * gives us. I'm not sure what a real "architected" + * event model would actually look like, but right + * now you can associate a list of events with a dive, + * and we'll do something about it. + */ +struct event { + struct event *next; + duration_t time; + int type, flags, value; + char name[]; +}; + #define MAX_CYLINDERS (8) struct dive { @@@ -171,7 -161,7 +176,8 @@@ depth_t visibility; temperature_t airtemp, watertemp; cylinder_t cylinder[MAX_CYLINDERS]; + int otu; + struct event *events; int samples, alloc_samples; struct sample sample[]; }; @@@ -243,8 -233,6 +249,8 @@@ extern struct dive *try_to_merge(struc extern void renumber_dives(int nr); +extern void add_event(struct dive *dive, int time, int type, int flags, int value, const char *name); + /* UI related protopypes */ extern void init_ui(int argc, char **argv); diff --combined parse-xml.c index 50f83f6,8f916b0..6eafb0d --- a/parse-xml.c +++ b/parse-xml.c @@@ -92,14 -92,8 +92,14 @@@ const struct units IMPERIAL_units = */ static struct dive *dive; static struct sample *sample; +static struct { + int active; + duration_t time; + int type, flags, value; + const char *name; +} event; static struct tm tm; -static int event_index, cylinder_index; +static int cylinder_index; static enum import_source { UNKNOWN, @@@ -564,32 -558,6 +564,32 @@@ static int uddf_fill_sample(struct samp 0; } +static void eventtime(char *buffer, void *_duration) +{ + duration_t *duration = _duration; + sampletime(buffer, duration); + if (sample) + duration->seconds += sample->time.seconds; +} + +static void try_to_fill_event(const char *name, char *buf) +{ + int len = strlen(name); + + start_match("event", name, buf); + if (MATCH(".event", utf8_string, &event.name)) + return; + if (MATCH(".name", utf8_string, &event.name)) + return; + if (MATCH(".time", eventtime, &event.time)) + return; + if (MATCH(".type", get_index, &event.type)) + return; + if (MATCH(".flags", get_index, &event.flags)) + return; + nonmatch("event", name, buf); +} + /* 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) { @@@ -1083,7 -1051,7 +1083,7 @@@ static void match_standard_cylinder(cyl return; cuft = type->size.mliter / 28317.0; - cuft *= type->workingpressure.mbar / 1013.25; + cuft *= to_ATM(type->workingpressure); psi = type->workingpressure.mbar / 68.95; switch (psi) { @@@ -1138,7 -1106,7 +1138,7 @@@ static void sanitize_cylinder_type(cyli if (input_units.volume == CUFT || import_source == SUUNTO) { volume_of_air = type->size.mliter * 28.317; /* milli-cu ft to milliliter */ - atm = type->workingpressure.mbar / 1013.25; /* working pressure in atm */ + atm = to_ATM(type->workingpressure); /* working pressure in atm */ volume = volume_of_air / atm; /* milliliters at 1 atm: "true size" */ type->size.mliter = volume + 0.5; } @@@ -1169,15 -1137,11 +1169,15 @@@ static void dive_end(void static void event_start(void) { + memset(&event, 0, sizeof(event)); + event.active = 1; } static void event_end(void) { - event_index++; + if (event.name && strcmp(event.name, "surface") != 0) + add_event(dive, event.time.seconds, event.type, event.flags, event.value, event.name); + event.active = 0; } static void cylinder_start(void) @@@ -1192,6 -1156,7 +1192,6 @@@ static void cylinder_end(void static void sample_start(void) { sample = prepare_sample(&dive); - event_index = 0; } static void sample_end(void) @@@ -1211,10 -1176,6 +1211,10 @@@ static void entry(const char *name, in return; memcpy(buf, raw, size); buf[size] = 0; + if (event.active) { + try_to_fill_event(name, buf); + return; + } if (sample) { try_to_fill_sample(sample, name, buf); return;