mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Read and write divemode changes (xml and git)
This provides for reading of divemode change events from dive logs and for writing them to dive logs. This applies to xml and git divelogs. Divemode change events have the following structure: event->name = "modechange" event->value = integer corresponding to enum dive_comp_type (dive.c), reflecting the type of divemode change (OC, CCR, PSCR, etc). In the dive log file, the event value is written as a string that corresponds to each of the enum values, e.g. <event name='modechange' divemode='OC' /> This xml is also read from the dive log file and translated to an appropriate value of event->value. The file diveeventitem.cpp was udated to reflect this new way of dealing with divemode change events. Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
This commit is contained in:
parent
5f95c226ef
commit
b9174332d5
6 changed files with 48 additions and 7 deletions
|
@ -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++;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue