diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/dive.h | 2 | ||||
-rw-r--r-- | core/load-git.c | 11 | ||||
-rw-r--r-- | core/parse-xml.c | 22 | ||||
-rw-r--r-- | core/save-git.c | 6 | ||||
-rw-r--r-- | core/save-xml.c | 5 |
5 files changed, 42 insertions, 4 deletions
diff --git a/core/dive.h b/core/dive.h index 6fb1509b4..d336318d5 100644 --- a/core/dive.h +++ b/core/dive.h @@ -27,7 +27,7 @@ extern "C" { extern int last_xml_version; -enum dive_comp_type {OC, CCR, PSCR, FREEDIVE, NUM_DC_TYPE}; // Flags (Open-circuit and Closed-circuit-rebreather) for setting dive computer type +enum dive_comp_type {OC, CCR, PSCR, FREEDIVE, NUM_DC_TYPE, UNDEF_COMP_TYPE}; // Flags (Open-circuit and Closed-circuit-rebreather) for setting dive computer type enum cylinderuse {OC_GAS, DILUENT, OXYGEN, NOT_USED, NUM_GAS_USE}; // The different uses for cylinders extern const char *cylinderuse_text[]; diff --git a/core/load-git.c b/core/load-git.c index 4af7221c3..67a2dfa29 100644 --- a/core/load-git.c +++ b/core/load-git.c @@ -723,6 +723,15 @@ static void parse_dc_time(char *line, struct membuffer *str, void *_dc) static void parse_dc_watertemp(char *line, struct membuffer *str, void *_dc) { (void) str; struct divecomputer *dc = _dc; dc->watertemp = get_temperature(line); } + +int get_divemode(const char *divemodestring) { + for (int i = 0; i < NUM_DC_TYPE; i++) { + if (!strcmp(divemodestring, divemode_text[i])) + return i; + } + return 0; +} + static void parse_event_keyvalue(void *_event, const char *key, const char *value) { struct event *event = _event; @@ -736,6 +745,8 @@ static void parse_event_keyvalue(void *_event, const char *key, const char *valu event->value = val; } else if (!strcmp(key, "name")) { /* We get the name from the string handling */ + } else if (!strcmp(key,"divemode")) { + event->value = get_divemode(value); } else if (!strcmp(key, "cylinder")) { /* NOTE! We add one here as a marker that "yes, we got a cylinder index" */ event->gas.index = 1+get_index(value); diff --git a/core/parse-xml.c b/core/parse-xml.c index 47358865b..fa7572ac9 100644 --- a/core/parse-xml.c +++ b/core/parse-xml.c @@ -428,7 +428,7 @@ static void event_name(char *buffer, char *name) { int size = trimspace(buffer); if (size >= MAX_EVENT_NAME) - size = MAX_EVENT_NAME-1; + size = MAX_EVENT_NAME - 1; memcpy(name, buffer, size); name[size] = 0; } @@ -449,6 +449,24 @@ static void get_dc_type(char *buffer, enum dive_comp_type *dct) } } +/* For divemode_text[] (defined in dive.h) determine the index of + * the string contained in the xml divemode attribute and passed + * in buffer, below. Typical xml input would be: + * <event name='modechange' divemode='OC' /> */ +static void event_divemode(char *buffer, int *value) +{ + int size = trimspace(buffer); + if (size >= MAX_EVENT_NAME) + size = MAX_EVENT_NAME - 1; + buffer[size] = 0x0; + for (int i = 0; i < NUM_DC_TYPE; i++) { + if (!strcmp(buffer,divemode_text[i])) { + *value = i; + break; + } + } +} + #define MATCH(pattern, fn, dest) ({ \ /* Silly type compatibility test */ \ if (0) (fn)("test", dest); \ @@ -708,6 +726,8 @@ static void try_to_fill_event(const char *name, char *buf) return; if (MATCH("value", get_index, &cur_event.value)) return; + if (MATCH("divemode", event_divemode, &cur_event.value)) + return; if (MATCH("cylinder", get_index, &cur_event.gas.index)) { /* We add one to indicate that we got an actual cylinder index value */ cur_event.gas.index++; diff --git a/core/save-git.c b/core/save-git.c index 395490d83..c0f098d44 100644 --- a/core/save-git.c +++ b/core/save-git.c @@ -374,7 +374,11 @@ static void save_one_event(struct membuffer *b, struct dive *dive, struct event put_format(b, "event %d:%02d", FRACTION(ev->time.seconds, 60)); show_index(b, ev->type, "type=", ""); show_index(b, ev->flags, "flags=", ""); - show_index(b, ev->value, "value=", ""); + + if (!strcmp(ev->name,"modechange")) + show_utf8(b, "divemode=", divemode_text[ev->value], ""); + else + show_index(b, ev->value, "value=", ""); show_utf8(b, " name=", ev->name, ""); if (event_is_gaschange(ev)) { struct gasmix *mix = get_gasmix_from_event(dive, ev); diff --git a/core/save-xml.c b/core/save-xml.c index adf9ec2f1..90587163d 100644 --- a/core/save-xml.c +++ b/core/save-xml.c @@ -301,7 +301,10 @@ static void save_one_event(struct membuffer *b, struct dive *dive, struct event put_format(b, " <event time='%d:%02d min'", FRACTION(ev->time.seconds, 60)); show_index(b, ev->type, "type='", "'"); show_index(b, ev->flags, "flags='", "'"); - show_index(b, ev->value, "value='", "'"); + if (!strcmp(ev->name,"modechange")) + show_utf8(b, divemode_text[ev->value], "divemode='", "'",1); + else + show_index(b, ev->value, "value='", "'"); show_utf8(b, ev->name, " name='", "'", 1); if (event_is_gaschange(ev)) { struct gasmix *mix = get_gasmix_from_event(dive, ev); |