diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2014-11-16 23:11:18 +0000 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2014-11-16 23:20:39 +0000 |
commit | 23304f69c04f13ba87f32e8574a75c08212a3608 (patch) | |
tree | 7925373ac99b32cb1306cd885b43ffe3f084f8ab | |
parent | 202c5cbfeb6888b05ae4b14b4f563666bc6ca763 (diff) | |
download | subsurface-23304f69c04f13ba87f32e8574a75c08212a3608.tar.gz |
Load and save the dc type for CCR dives
Oddly we already had code to load this from XML, but nothing else.
This makes the load from XML work like the rest of our code and adds the
save to XML plus the load and save for the git format.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r-- | dive.c | 1 | ||||
-rw-r--r-- | dive.h | 3 | ||||
-rw-r--r-- | load-git.c | 14 | ||||
-rw-r--r-- | parse-xml.c | 61 | ||||
-rw-r--r-- | save-git.c | 2 | ||||
-rw-r--r-- | save-xml.c | 5 |
6 files changed, 56 insertions, 30 deletions
@@ -27,6 +27,7 @@ static const char *default_tags[] = { }; const char *cylinderuse_text[] = { "OC-gas", "diluent", "oxygen" }; +const char *dctype_text[] = { "OC", "CCR", "PSCR" }; int event_is_gaschange(struct event *ev) @@ -47,10 +47,11 @@ extern "C" { #include <stdbool.h> #endif -enum dive_comp_type {OC, CCR, PSCR}; // Flags (Open-circuit and Closed-circuit-rebreather) for setting dive computer type +enum dive_comp_type {OC, CCR, PSCR, NUM_DC_TYPE}; // Flags (Open-circuit and Closed-circuit-rebreather) for setting dive computer type enum cylinderuse {OC_GAS, DILUENT, OXYGEN, NUM_GAS_USE}; // The different uses for cylinders extern const char *cylinderuse_text[]; +extern const char *dctype_text[]; struct gasmix { fraction_t o2; diff --git a/load-git.c b/load-git.c index 9cf6baf6c..54d349bd0 100644 --- a/load-git.c +++ b/load-git.c @@ -130,6 +130,15 @@ static duration_t get_duration(const char *line) return d; } +static enum dive_comp_type get_dctype(const char *line) +{ + for (enum dive_comp_type i = 0; i < NUM_DC_TYPE; i++) { + if (strcmp(line, dctype_text[i]) == 0) + return i; + } + return 0; +} + static int get_index(const char *line) { return atoi(line); } static int get_hex(const char *line) @@ -500,6 +509,9 @@ static void parse_dc_diveid(char *line, struct membuffer *str, void *_dc) static void parse_dc_duration(char *line, struct membuffer *str, void *_dc) { struct divecomputer *dc = _dc; dc->duration = get_duration(line); } +static void parse_dc_dctype(char *line, struct membuffer *str, void *_dc) +{ struct divecomputer *dc = _dc; dc->dctype = get_dctype(line); } + static void parse_dc_maxdepth(char *line, struct membuffer *str, void *_dc) { struct divecomputer *dc = _dc; dc->maxdepth = get_depth(line); } @@ -732,7 +744,7 @@ static void parse_picture_gps(char *line, struct membuffer *str, void *_pic) struct keyword_action dc_action[] = { #undef D #define D(x) { #x, parse_dc_ ## x } - D(airtemp), D(date), D(deviceid), D(diveid), D(duration), + D(airtemp), D(date), D(dctype), D(deviceid), D(diveid), D(duration), D(event), D(keyvalue), D(maxdepth), D(meandepth), D(model), D(salinity), D(surfacepressure), D(surfacetime), D(time), D(watertemp), }; diff --git a/parse-xml.c b/parse-xml.c index 70ac63ee2..c8feac1c8 100644 --- a/parse-xml.c +++ b/parse-xml.c @@ -29,6 +29,25 @@ static xmlDoc *test_xslt_transforms(xmlDoc *doc, const char **params); struct dive_table dive_table; struct dive_table *target_table = NULL; +/* Trim a character string by removing leading and trailing white space characters. + * Parameter: a pointer to a null-terminated character string (buffer); + * Return value: length of the trimmed string, excluding the terminal 0x0 byte + * The original pointer (buffer) remains valid after this function has been called + * and points to the trimmed string */ +int trimspace(char *buffer) { + int i, size, start, end; + size = strlen(buffer); + for(start = 0; isspace(buffer[start]); start++) + if (start >= size) return 0; // Find 1st character following leading whitespace + for(end = size - 1; isspace(buffer[end]); end--) // Find last character before trailing whitespace + if (end <= 0) return 0; + for(i = start; i <= end; i++) // Move the nonspace characters to the start of the string + buffer[i-start] = buffer[i]; + size = end - start + 1; + buffer[size] = 0x0; // then terminate the string + return size; // return string length +} + /* * Add a dive into the dive_table array */ @@ -319,10 +338,12 @@ static void pressure(char *buffer, pressure_t *pressure) static void cylinder_use(char *buffer, enum cylinderuse *cyl_use) { - for (enum cylinderuse i = 0; i < NUM_GAS_USE; i++) { - if (same_string(buffer, cylinderuse_text[i])) { - *cyl_use = i; - return; + if (trimspace(buffer)) { + for (enum cylinderuse i = 0; i < NUM_GAS_USE; i++) { + if (same_string(buffer, cylinderuse_text[i])) { + *cyl_use = i; + return; + } } } } @@ -522,26 +543,6 @@ static void cylindersize(char *buffer, volume_t *volume) } } -/* Trim a character string by removing leading and trailing white space characters. - * Parameter: a pointer to a null-terminated character string (buffer); - * Return value: length of the trimmed string, excluding the terminal 0x0 byte - * The original pointer (buffer) remains valid after this function has been called - * and points to the trimmed string */ -int trimspace(char *buffer) { - int i, size, start, end; - size = strlen(buffer); - for(start = 0; isspace(buffer[start]); start++) - if (start >= size) return 0; // Find 1st character following leading whitespace - for(end = size - 1; isspace(buffer[end]); end--) // Find last character before trailing whitespace - if (end <= 0) return 0; - for(i = start; i <= end; i++) // Move the nonspace characters to the start of the string - buffer[i-start] = buffer[i]; - size = end - start + 1; - buffer[size] = 0x0; // then terminate the string - return size; // return string length -} - - static void utf8_string(char *buffer, void *_res) { char **res = _res; @@ -561,11 +562,15 @@ static void event_name(char *buffer, char *name) } /* Extract the dive computer type from the xml text buffer */ -static void get_dc_type(char *buffer, enum dive_comp_type *i) +static void get_dc_type(char *buffer, enum dive_comp_type *dct) { - if((trimspace(buffer)) && (strcmp(buffer,"CCR") == 0)) - *i = CCR; // if the xml string = "CCR", set dc-type to CCR -} // otherwise the default dc-type is used (OC) + if (trimspace(buffer)) { + for (enum dive_comp_type i = 0; i < NUM_DC_TYPE; i++) { + if (strcmp(buffer, dctype_text[i]) == 0) + *dct = i; + } + } +} #define MATCH(pattern, fn, dest) ({ \ /* Silly type compatibility test */ \ diff --git a/save-git.c b/save-git.c index 68fc52637..288917a29 100644 --- a/save-git.c +++ b/save-git.c @@ -339,6 +339,8 @@ static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer show_date(b, dc->when); if (dc->duration.seconds && dc->duration.seconds != dive->dc.duration.seconds) put_duration(b, dc->duration, "duration ", "min\n"); + if (dc->dctype != OC) + put_format(b, "dctype %s\n", dctype_text[dc->dctype]); save_depths(b, dc); save_temperatures(b, dc); diff --git a/save-xml.c b/save-xml.c index 31ad436bc..736e6a4db 100644 --- a/save-xml.c +++ b/save-xml.c @@ -351,6 +351,11 @@ static void save_dc(struct membuffer *b, struct dive *dive, struct divecomputer show_date(b, dc->when); if (dc->duration.seconds && dc->duration.seconds != dive->dc.duration.seconds) put_duration(b, dc->duration, " duration='", " min'"); + if (dc->dctype != OC) { + for (enum dive_comp_type i = 0; i < NUM_DC_TYPE; i++) + if (dc->dctype == i) + show_utf8(b, dctype_text[i], " dctype='", "'", 1); + } put_format(b, ">\n"); save_depths(b, dc); save_temperatures(b, dc); |