diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-08-04 18:44:57 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-11-09 19:19:04 +0100 |
commit | 7c9f46acd202121e67557bb634961ef17a9f6c1f (patch) | |
tree | f21b6ff42a930cc97c31db9f20c03f1613e70291 /core/import-shearwater.c | |
parent | cd4f66014f7b5269dff9e088c9d7d38241c03156 (diff) | |
download | subsurface-7c9f46acd202121e67557bb634961ef17a9f6c1f.tar.gz |
Core: remove MAX_CYLINDERS restriction
Instead of using fixed size arrays, use a new cylinder_table structure.
The code copies the weightsystem code, but is significantly more complex
because cylinders are such an integral part of the core.
Two functions to access the cylinders were added:
get_cylinder() and get_or_create_cylinder()
The former does a simple array access and supposes that the cylinder
exists. The latter is used by the parser(s) and if a cylinder with
the given id does not exist, cylinders up to that id are generated.
One point will make C programmers cringe: the cylinder structure is
passed by value. This is due to the way the table-macros work. A
refactoring of the table macros is planned. It has to be noted that
the size of a cylinder_t is 64 bytes, i.e. 8 long words on a 64-bit
architecture, so passing on the stack is probably not even significantly
slower than passing as reference.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core/import-shearwater.c')
-rw-r--r-- | core/import-shearwater.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/core/import-shearwater.c b/core/import-shearwater.c index 4bed8ff18..cd5815c6e 100644 --- a/core/import-shearwater.c +++ b/core/import-shearwater.c @@ -18,6 +18,7 @@ static int shearwater_cylinders(void *param, int columns, char **data, char **co UNUSED(columns); UNUSED(column); struct parser_state *state = (struct parser_state *)param; + cylinder_t *cyl; int o2 = lrint(strtod_flags(data[0], NULL, 0) * 1000); int he = lrint(strtod_flags(data[1], NULL, 0) * 1000); @@ -28,8 +29,9 @@ static int shearwater_cylinders(void *param, int columns, char **data, char **co o2 = 1000; cylinder_start(state); - state->cur_dive->cylinder[state->cur_cylinder_index].gasmix.o2.permille = o2; - state->cur_dive->cylinder[state->cur_cylinder_index].gasmix.he.permille = he; + cyl = &state->cur_dive->cylinders.cylinders[state->cur_dive->cylinders.nr - 1]; + cyl->gasmix.o2.permille = o2; + cyl->gasmix.he.permille = he; cylinder_end(state); return 0; @@ -40,6 +42,7 @@ static int shearwater_changes(void *param, int columns, char **data, char **colu UNUSED(columns); UNUSED(column); struct parser_state *state = (struct parser_state *)param; + cylinder_t *cyl; if (columns != 3) { return 1; @@ -58,8 +61,9 @@ static int shearwater_changes(void *param, int columns, char **data, char **colu // Find the cylinder index int i; bool found = false; - for (i = 0; i < state->cur_cylinder_index; ++i) { - if (state->cur_dive->cylinder[i].gasmix.o2.permille == o2 && state->cur_dive->cylinder[i].gasmix.he.permille == he) { + for (i = 0; i < state->cur_dive->cylinders.nr; ++i) { + const cylinder_t *cyl = &state->cur_dive->cylinders.cylinders[i]; + if (cyl->gasmix.o2.permille == o2 && cyl->gasmix.he.permille == he) { found = true; break; } @@ -67,13 +71,13 @@ static int shearwater_changes(void *param, int columns, char **data, char **colu if (!found) { // Cylinder not found, creating a new one cylinder_start(state); - state->cur_dive->cylinder[state->cur_cylinder_index].gasmix.o2.permille = o2; - state->cur_dive->cylinder[state->cur_cylinder_index].gasmix.he.permille = he; + cyl = &state->cur_dive->cylinders.cylinders[state->cur_dive->cylinders.nr - 1]; + cyl->gasmix.o2.permille = o2; + cyl->gasmix.he.permille = he; cylinder_end(state); - i = state->cur_cylinder_index; } - add_gas_switch_event(state->cur_dive, get_dc(state), state->sample_rate ? atoi(data[0]) / state->sample_rate * 10 : atoi(data[0]), i); + add_gas_switch_event(state->cur_dive, get_dc(state), state->sample_rate ? atoi(data[0]) / state->sample_rate * 10 : atoi(data[0]), state->cur_dive->cylinders.nr - 1); return 0; } |