summaryrefslogtreecommitdiffstats
path: root/core/equipment.c
AgeCommit message (Collapse)Author
2020-05-06media: use table instead of linked list for mediaGravatar Berthold Stoeger
For consistency with equipment, use our table macros for pictures. Generally tables (arrays) are preferred over linked lists, because they allow random access. This is mostly copy & paste of the equipment code. Sadly, our table macros are quite messy and need some revamping. Therefore, the resulting code is likewise somewhat messy. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06cleanup: move copy_cylinders from dive.c to equipment.cGravatar Berthold Stoeger
Since this doesn't touch struct dive, dive.c is not an appropriate place for this function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-06cleanup: make remove_from_*_table equipment functions staticGravatar Berthold Stoeger
These functions were not used outside their translation unit. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01core: create fake cylinder at end of cylinder table (hack!)Gravatar Berthold Stoeger
When we had fixed-sized cylinder arrays, the planner used the last empty cylinder for "surface air". This was not recognized by the UI as a separate cylinder, because "empty cylinder" was the sentinel for the end of the table. The conversion to dynamically sized cylinder tables broke this code: everytime the surface segment is changed, a new dummy cylinder is added, which is visible in the UI. As a very temporary stop-gap fix, emulate the old code by creating a cylinder and then setting the end-of-table to before that cylinder. This means that we have to loosen the out-of-bound checks. That's all very scary and should be removed as soon as possible. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-05-01core: always keep an empty cylinder at the end of the cylinder arrayGravatar Berthold Stoeger
This will be temporarilly used by the planner to mark consumption of air at the surface. Do this by creating a new function add_cylinder, which replaces add_to_cylinder_table() and takes care of always adding a dummy cylinder at the end of the table. Make the original add_to_cylinder_table() local, so that it cannot be accessed anymore. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07undo: more fine-grained editing of cylinderGravatar Berthold Stoeger
Don't overwrite the full cylinder when editing a single field. Implement three "modes": editing of type, pressure and gasmix. Don't consider individual fields, because some of them are related. E.g. you can change the gasmix by setting the MOD. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: remove same_cylinderGravatar Berthold Stoeger
The last user was uses a more general function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cylinders: use preferences modpO2 preferences valueGravatar Berthold Stoeger
Use the user-editable MOD-pO2 preferences value when creating a default cylinder. It is not clear to me, when that even has a consequence, but it looks like the right thing to do. Reported-by: Robert C. Helling <helling@atdotde.de> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07cleanup: move fill_default_cylinder from planner.c to equipment.cGravatar Berthold Stoeger
Moreover, move the declaration from dive.h to equipment.h. The result is a) more consistent and b) more logical. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07core: add create_new_cylinder() functionGravatar Berthold Stoeger
Turn the code in CylindersModel that creates a new cylinder for addition into its own function to avoid code duplication. This will be used from the undo commands. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07core: introduce set_cylinder() functionGravatar Berthold Stoeger
We have a set_weightsystem() function. For symmetry, introduce a set_cylinder() function so that we can more-or-less copy&paste the weightsystem undo code for cylinder undo. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07core: make free_cylinder() globalGravatar Berthold Stoeger
The cylinder undo commands will keep a copy of a cylinder and therefore need the ability to free a cylinder object. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-04-07core: introduce clone_cylinder() functionGravatar Berthold Stoeger
We have a clone_weightsystem function. For symmetry, introduce a clone_cylinder() function so that we can more-or-less copy&paste the weightsystem undo code for cylinder undo. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-01-10code cleanup: introduce empty_cylinder constantGravatar Dirk Hohndel
This deals with the issue of initializing structs in C++. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-12-05Cleanup: set description to null in free_[weightsystem|cylinder]Gravatar Berthold Stoeger
Currently, the caller is responsible for not reusing a freed weightsystem / cylinder or resetting the description field to null. This is very unfriendly. Set the description field to null, because that allows us to call free_* repeatedly on the same object. Use the new behavior to make the weightsystem model code a bit cleaner. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-05Undo: make weight editing undoableGravatar Berthold Stoeger
Implement the EditWeight undo command. Since there is common code (storage of the old weight), this creates a common base class for RemoveWeight and EditWeight. The model calls directly into the undo command, which is somewhat unfortunate as it feels like a layering violation. It's the easy thing to do for now. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-05Cleanup: use free_weightsystem function instead of explicit freeGravatar Berthold Stoeger
Instead of freeing internal data of the weightsystem structure, call the free_weightsystem function (which has to be made extern at first). This makes things more future-proof, should the weightsystem struct ever be extended. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-12-05Undo: make weight-deletion an undoable actionGravatar Berthold Stoeger
This one is a bit more complicated than weight adding, because the multiple-dive case is not well defined. If multiple dives are selected, this implementation will search for weights that are identical to the weight deleted in the currently shown dive. The position of the weight in the list is ignored. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Cylinders: access cylinders with get_cylinder()Gravatar Berthold Stoeger
Instead of accessing the cylinder table directly, use the get_cylinder() function. This gives less unwieldy expressions. But more importantly, the function does bound checking. This is crucial for now as the code hasn't be properly audited since the change to arbitrarily sized cylinder tables. Accesses of invalid cylinder indexes may lead to silent data-corruption that is sometimes not even noticed by valgrind. Returning NULL instead of an invalid pointer will make debugging much easier. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Cleanup: return cylinder from add_empty_cylinder()Gravatar Berthold Stoeger
As a convenience, return the cylinder from add_empty_cylinder() to spare the caller from the nasty expression to fetch the last cylinder. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-11-09Core: remove MAX_CYLINDERS restrictionGravatar Berthold Stoeger
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>
2019-11-09Cleanup: move copy_cylinder_types() from dive.c to equipment.cGravatar Berthold Stoeger
Thus, future callers will not have to include the monster dive.h include if they just want to copy cylinders. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18Cleanup: remove unused weightsystem_none() functionGravatar Berthold Stoeger
This function was used to count the number of weightsystems used in a dive. Since the weightsysems are now collected in a dynamic table it became unused. Remove. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18Core: dynamically resize weight tableGravatar Berthold Stoeger
Replace the fixed-size weightsystem table by a dynamically relocated table. Reuse the table-macros used in other parts of the code. The table stores weightsystem entries, not pointers to weightsystems. Thus, ownership of the description string is taken when adding a weightsystem. An extra function adds a cloned weightsystem at the end of the table. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-07-18Core: Implement same_weightsystem() function to compare weightsGravatar Berthold Stoeger
This will be used later when joining and editing dives. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-07-18Cleanup: move cylinderuse_from_text() to equipment.cGravatar Berthold Stoeger
Since this function doesn't act on a dive and is only related to cylinders, move it to equipment.c and equipment.h. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19Cleanup: remove unused parameter used from find_best_gasmix_match()Gravatar Berthold Stoeger
The last direct user of the used parameter was removed in 16276faa45279817e363367550a6a37c179251f7, the last actual user in e2bbd0ceecff7193bb272430fbebfc4b02dd67c3. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19Cleanup: constify two equipment helper functionsGravatar Berthold Stoeger
add_cylinder_description() and add_weightsystem_description() don't modify their input parameter. constify them. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19Cleanup: move gas-functions to own translation unitGravatar Berthold Stoeger
But only functions that operate only on gases. Functions concerning cylinders or dives remain in dive.c or are moved to equipment.c Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19Cleanup: create equipment.h headerGravatar Berthold Stoeger
There is an equipment.c file, but no corresponding header. Move the corresponding functions into a newly created header. This does not improve compile time since, at least for now, equipment.h is included in dive.h. But it makes things more consistent. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-23Cleanup: user properly typed pointersGravatar Berthold Stoeger
A trivial cleanup: replace void by properly typed pointers in cylinder_none() and weightsystem_none(). Moreover, remove the unused function no_weightsystems(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-23Cleanup: pass gasmix by valueGravatar Berthold Stoeger
In a previous commit, the get_gasmix_* functions were changed to return by value. For consistency, also pass gasmix by value. Note that on common 64-bit platforms struct gasmix is the size of a pointer [2 * 32 bit vs. 64 bit] and therefore uses the same space on the stack. On 32-bit platforms, the stack use is probably doubled, but in return a dereference is avoided. Supporting arbitrary gas-mixes (H2, Ar, ...) will be such an invasive change that going back to pointers is probably the least of our worries. This commit is a step in const-ifying input parameters (passing by value is the ultimate way of signaling that the input parameter will not be changed [unless there are references to said parameter]). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-06-20equipment: use MAX_TANK_INFO in equipment.cGravatar Lubomir I. Ivanov
MAX_TANK_INFO is defined in dive.h but is not used in add_cylinder_description() or when allocating 'tank_info'. Use MAX_TANK_INFO instead of the literal 100. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2018-06-20equipment: sanitize 'ws_info' loop limitsGravatar Lubomir I. Ivanov
Instead of a constant or a macro for the maximum number of 'ws_info' elements the 100 literal was used. Define MAX_WS_INFO in dive.h and use it everywhere. Also clamp loops that iterate `ws_info' to MAX_WS_INFO. Prevents potential out-of-bounds reading, similarly to the previous commit about 'tank_info'. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2018-01-10Unused code: remove weightsystems_equal()Gravatar Jan Mulder
Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-11-27Code cleanup: Move index declarations into for loopGravatar Stefan Fuchs
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-11-27Add debug function dump_cylindersGravatar Stefan Fuchs
This function can be used to dump print all cylinder data. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-04-29Add SPDX header to remaining core filesGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-03-20Add 10l 200bar and 232bar cylinderGravatar Stefan Fuchs
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2017-03-12Only enable -Wmissing-field-initializers for ClangGravatar Lubomir I. Ivanov
The following pragma is Clang specific: It produces a warning: warning: ignoring #pragma clang diagnostic [-Wunknown-pragmas] Only enable it for Clang by checking the __clang__ macro. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-03-07In weights table 'weight' is redundant and no used for other types.Gravatar Martin Měřinský
2016-08-10Add HP117 to the cylinder listGravatar Brian Weber
Reported-by: Brian Weber Signed-off-by: weber311@gmail.com Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-04Make cylinder_nodata() take a const cylinder pointerGravatar Linus Torvalds
Some of the gas mix cleanups I'm doing are in code that uses const pointers, and wants to use this. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-04Move subsurface-core to core and qt-mobile to mobile-widgetsGravatar Dirk Hohndel
Having subsurface-core as a directory name really messes with autocomplete and is obviously redundant. Simmilarly, qt-mobile caused an autocomplete conflict and also was inconsistent with the desktop-widget name for the directory containing the "other" UI. And while cleaning up the resulting change in the path name for include files, I decided to clean up those even more to make them consistent overall. This could have been handled in more commits, but since this requires a make clean before the build, it seemed more sensible to do it all in one. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>