aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/import-cobalt.c3
-rw-r--r--core/import-divinglog.c3
-rw-r--r--core/import-shearwater.c6
-rw-r--r--core/import-suunto.c6
-rw-r--r--core/parse-xml.c12
-rw-r--r--core/parse.c3
-rw-r--r--core/parse.h2
7 files changed, 15 insertions, 20 deletions
diff --git a/core/import-cobalt.c b/core/import-cobalt.c
index 967f7df51..28f6968a3 100644
--- a/core/import-cobalt.c
+++ b/core/import-cobalt.c
@@ -39,8 +39,7 @@ static int cobalt_cylinders(void *param, int columns, char **data, char **column
struct parser_state *state = (struct parser_state *)param;
cylinder_t *cyl;
- cylinder_start(state);
- cyl = &state->cur_dive->cylinders.cylinders[state->cur_dive->cylinders.nr - 1];
+ cyl = cylinder_start(state);
if (data[0])
cyl->gasmix.o2.permille = atoi(data[0]) * 10;
if (data[1])
diff --git a/core/import-divinglog.c b/core/import-divinglog.c
index cd122c40a..5b9e4be3b 100644
--- a/core/import-divinglog.c
+++ b/core/import-divinglog.c
@@ -26,8 +26,7 @@ static int divinglog_cylinder(void *param, int columns, char **data, char **colu
if (data[7] && atoi(data[7]) > 0)
dbl = 2;
- cylinder_start(state);
- cyl = &state->cur_dive->cylinders.cylinders[state->cur_dive->cylinders.nr - 1];
+ cyl = cylinder_start(state);
/*
* Assuming that we have to double the cylinder size, if double
diff --git a/core/import-shearwater.c b/core/import-shearwater.c
index cd5815c6e..1c1e68eb4 100644
--- a/core/import-shearwater.c
+++ b/core/import-shearwater.c
@@ -28,8 +28,7 @@ static int shearwater_cylinders(void *param, int columns, char **data, char **co
if (o2 == 990 && he == 0)
o2 = 1000;
- cylinder_start(state);
- cyl = &state->cur_dive->cylinders.cylinders[state->cur_dive->cylinders.nr - 1];
+ cyl = cylinder_start(state);
cyl->gasmix.o2.permille = o2;
cyl->gasmix.he.permille = he;
cylinder_end(state);
@@ -70,8 +69,7 @@ static int shearwater_changes(void *param, int columns, char **data, char **colu
}
if (!found) {
// Cylinder not found, creating a new one
- cylinder_start(state);
- cyl = &state->cur_dive->cylinders.cylinders[state->cur_dive->cylinders.nr - 1];
+ cyl = cylinder_start(state);
cyl->gasmix.o2.permille = o2;
cyl->gasmix.he.permille = he;
cylinder_end(state);
diff --git a/core/import-suunto.c b/core/import-suunto.c
index 408128cb7..d34c01442 100644
--- a/core/import-suunto.c
+++ b/core/import-suunto.c
@@ -218,8 +218,7 @@ static int dm4_dive(void *param, int columns, char **data, char **column)
/*
* TODO: handle multiple cylinders
*/
- cylinder_start(state);
- cyl = &state->cur_dive->cylinders.cylinders[state->cur_dive->cylinders.nr - 1];
+ cyl = cylinder_start(state);
if (data[22] && atoi(data[22]) > 0)
cyl->start.mbar = atoi(data[22]);
else if (data[10] && atoi(data[10]) > 0)
@@ -328,8 +327,7 @@ static int dm5_cylinders(void *param, int columns, char **data, char **column)
struct parser_state *state = (struct parser_state *)param;
cylinder_t *cyl;
- cylinder_start(state);
- cyl = &state->cur_dive->cylinders.cylinders[state->cur_dive->cylinders.nr - 1];
+ cyl = cylinder_start(state);
if (data[7] && atoi(data[7]) > 0 && atoi(data[7]) < 350000)
cyl->start.mbar = atoi(data[7]);
if (data[8] && atoi(data[8]) > 0 && atoi(data[8]) < 350000)
diff --git a/core/parse-xml.c b/core/parse-xml.c
index 02363bde6..0f297bf9a 100644
--- a/core/parse-xml.c
+++ b/core/parse-xml.c
@@ -1560,13 +1560,14 @@ static void uddf_importer(struct parser_state *state)
state->xml_parsing_units.temperature = KELVIN;
}
+typedef void (*parser_func)(struct parser_state *);
/*
* I'm sure this could be done as some fancy DTD rules.
* It's just not worth the headache.
*/
static struct nesting {
const char *name;
- void (*start)(struct parser_state *), (*end)(struct parser_state *);
+ parser_func start, end;
} nesting[] = {
{ "divecomputerid", dc_settings_start, dc_settings_end },
{ "settings", settings_start, settings_end },
@@ -1579,9 +1580,9 @@ static struct nesting {
{ "SAMPLE", sample_start, sample_end },
{ "reading", sample_start, sample_end },
{ "event", event_start, event_end },
- { "mix", cylinder_start, cylinder_end },
- { "gasmix", cylinder_start, cylinder_end },
- { "cylinder", cylinder_start, cylinder_end },
+ { "mix", (parser_func)cylinder_start, (parser_func)cylinder_end },
+ { "gasmix", (parser_func)cylinder_start, (parser_func)cylinder_end },
+ { "cylinder", (parser_func)cylinder_start, (parser_func)cylinder_end },
{ "weightsystem", ws_start, ws_end },
{ "divecomputer", divecomputer_start, divecomputer_end },
{ "P", sample_start, sample_end },
@@ -1910,8 +1911,7 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *tabl
}
}
if (!found) {
- cylinder_start(&state);
- cylinder_t *cyl = &state.cur_dive->cylinders.cylinders[state.cur_dive->cylinders.nr - 1];
+ cyl = cylinder_start(&state);
cyl->gasmix.o2.permille = ptr[6] * 10;
cyl->gasmix.he.permille = ptr[7] * 10;
cylinder_end(&state);
diff --git a/core/parse.c b/core/parse.c
index dd8c612e8..8a07ba818 100644
--- a/core/parse.c
+++ b/core/parse.c
@@ -287,9 +287,10 @@ void picture_end(struct parser_state *state)
state->cur_picture = NULL;
}
-void cylinder_start(struct parser_state *state)
+cylinder_t *cylinder_start(struct parser_state *state)
{
add_empty_cylinder(&state->cur_dive->cylinders);
+ return &state->cur_dive->cylinders.cylinders[state->cur_dive->cylinders.nr - 1];
}
void cylinder_end(struct parser_state *state)
diff --git a/core/parse.h b/core/parse.h
index a36ca0e61..23b9d5af4 100644
--- a/core/parse.h
+++ b/core/parse.h
@@ -101,7 +101,7 @@ void trip_start(struct parser_state *state);
void trip_end(struct parser_state *state);
void picture_start(struct parser_state *state);
void picture_end(struct parser_state *state);
-void cylinder_start(struct parser_state *state);
+cylinder_t *cylinder_start(struct parser_state *state);
void cylinder_end(struct parser_state *state);
void ws_start(struct parser_state *state);
void ws_end(struct parser_state *state);