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-divinglog.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-divinglog.c')
-rw-r--r-- | core/import-divinglog.c | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/core/import-divinglog.c b/core/import-divinglog.c index 98d2effbb..cd122c40a 100644 --- a/core/import-divinglog.c +++ b/core/import-divinglog.c @@ -18,22 +18,16 @@ static int divinglog_cylinder(void *param, int columns, char **data, char **colu UNUSED(columns); UNUSED(column); struct parser_state *state = (struct parser_state *)param; + cylinder_t *cyl; short dbl = 1; //char get_cylinder_template[] = "select TankID,TankSize,PresS,PresE,PresW,O2,He,DblTank from Tank where LogID = %d"; - /* - * Divinglog might have more cylinders than what we support. So - * better to ignore those. - */ - - if (state->cur_cylinder_index >= MAX_CYLINDERS) - return 0; - if (data[7] && atoi(data[7]) > 0) dbl = 2; cylinder_start(state); + cyl = &state->cur_dive->cylinders.cylinders[state->cur_dive->cylinders.nr - 1]; /* * Assuming that we have to double the cylinder size, if double @@ -41,18 +35,18 @@ static int divinglog_cylinder(void *param, int columns, char **data, char **colu */ if (data[1] && atoi(data[1]) > 0) - state->cur_dive->cylinder[state->cur_cylinder_index].type.size.mliter = atol(data[1]) * 1000 * dbl; + cyl->type.size.mliter = atol(data[1]) * 1000 * dbl; if (data[2] && atoi(data[2]) > 0) - state->cur_dive->cylinder[state->cur_cylinder_index].start.mbar = atol(data[2]) * 1000; + cyl->start.mbar = atol(data[2]) * 1000; if (data[3] && atoi(data[3]) > 0) - state->cur_dive->cylinder[state->cur_cylinder_index].end.mbar = atol(data[3]) * 1000; + cyl->end.mbar = atol(data[3]) * 1000; if (data[4] && atoi(data[4]) > 0) - state->cur_dive->cylinder[state->cur_cylinder_index].type.workingpressure.mbar = atol(data[4]) * 1000; + cyl->type.workingpressure.mbar = atol(data[4]) * 1000; if (data[5] && atoi(data[5]) > 0) - state->cur_dive->cylinder[state->cur_cylinder_index].gasmix.o2.permille = atol(data[5]) * 10; + cyl->gasmix.o2.permille = atol(data[5]) * 10; if (data[6] && atoi(data[6]) > 0) - state->cur_dive->cylinder[state->cur_cylinder_index].gasmix.he.permille = atol(data[6]) * 10; + cyl->gasmix.he.permille = atol(data[6]) * 10; cylinder_end(state); @@ -136,8 +130,8 @@ static int divinglog_profile(void *param, int columns, char **data, char **colum state->cur_sample->temperature.mkelvin = C_to_mkelvin(temp / 10.0f); state->cur_sample->pressure[0].mbar = pressure * 100; state->cur_sample->rbt.seconds = rbt; - if (oldcyl != tank) { - struct gasmix mix = state->cur_dive->cylinder[tank].gasmix; + if (oldcyl != tank && tank >= 0 && tank < state->cur_dive->cylinders.nr) { + struct gasmix mix = state->cur_dive->cylinders.cylinders[tank].gasmix; int o2 = get_o2(mix); int he = get_he(mix); |