Commit graph

66 commits

Author SHA1 Message Date
Dirk Hohndel
8e212c0858 Fedora Rawhide builds fail without stdlib include
Implicit declarations of malloc, free, atoi, and others are considered an
error now.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2023-12-04 12:55:10 -08:00
Michael Keller
b9b47092c1 Desktop: Fix bug in diveplan for CCR dives with multiple segments.
Fixes a bug reported in
https://groups.google.com/g/subsurface-divelog/c/8N3cTz2Zv5E:
When planning a CCR dive with multiple segments, the textual dive plan
was showing a non-existent gas change with bogus data.  The first part
of the fix is uncluttering of the message printed: Since this change is
_after_ the current diveplanpoint the data needs to come from `nextdp`
and not `dp`.  The second part is that the message is not printed any
more if the current and the following segments have been manually added:
According to comments in the code the change should only be printed on
the segment _before_ the change if this segment is an ascent segment
that is followed by a manually entered segment.

Signed-off-by: Michael Keller <github@ike.ch>
2023-03-01 15:35:55 +01:00
Berthold Stoeger
642d9c80b3 planner: pass in_planner argument to decoMode()
To remove reliance on global state, pass an "in_planner" argument
to decoMode(). Thus, calls to in_planner() can be removed.

This is a more-or-less automated change. Ultimately it would
probably be better to pass the current deco-mode to the affected
functions instead of calling decoMode() with an in_planner
parameter.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2021-02-17 07:26:55 -08:00
Berthold Stoeger
794066b236 Cylinders: access cylinders with get_cylinder()
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-09 19:19:04 +01:00
Berthold Stoeger
7c9f46acd2 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>
2019-11-09 19:19:04 +01:00
Robert C. Helling
a3a3913e1e Planner: Don't accumulate rounding errors in stop durations
When displaying segment or stop times in the planner notes, we always
round to the next full minute. This can mean for example that we
round down more often than rounding up with the result that the sum
of the segment times does not match the total runtime and can for example
lead to stops that are shown with 0min duration.

With this patch, we increase the reference time of the last display only
by the duration time actually shown. This way, the rounding errors don't
accumulate but having rounded down previously makes rounding up the next
time more propable.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-11-03 04:05:29 -08:00
Linus Torvalds
a9b1fbdcc5 Don't expose 'detach_buffer()' to membuffer users
The native buffer of a membuffer is not NUL-terminated, so when you want
to detach it and use it as a C string, you had to first do
'mb_cstring()' that adds the proper termination/

This was all documented in the header files, and all but two users did
it correctly.

But there were those two users, and the exported interface was
unnecessarily hard to use.  We do want the "just detach the raw buffer"
internally in the membuffer code, but let's not make the exported
interface be that hard to use.

So this switches the exported interface to be 'detach_cstring()', which
does that 'mb_cstring()' for you, and avoids the possibility that you'd
use a non-terminated memory buffer as a C string.

The old 'detach_buffer()' is now purely the internal membuffer
implementation, and not used by others.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2019-10-27 12:42:54 -07:00
Anton Lundin
0e7fe1b852 Cleanup and correct plannernotes html
This balances the tags to a equal amount of start and end tags in the
planner notes html.

This also breaks it up with new-lines, so its a bit easier on the eyes,
and gives a validator the chance to point out on which line a error is.

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2019-09-11 17:21:50 +01:00
Anton Lundin
9935343ba1 Add debug capability to planner notes
The output it spits out can be copy-pasted into a html validator like:
https://validator.w3.org/nu/#textarea

Signed-off-by: Anton Lundin <glance@acc.umu.se>
2019-09-11 17:21:50 +01:00
Robert C. Helling
00c902d66c Show correct notes entry when switching on stops
When gas switching only on stops is selected, the notes
showed an extra line at the not realized stop depth. This
eliminates it. It also makes sure there are no 0 second
spurious entries. And gas switching takes more than zero
time (otherwise we would have to print a line of zero
duration for at the gas switch depth).

Reported-by: tormento <turment@gmail.com>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-09-11 14:55:33 +01:00
Berthold Stoeger
ee365b7341 Plan: introduce function that returns disclaimer
The setting of the disclaimer variable was removed inadvertently
some time ago, which removed the disclaimer from the printed plan.
Instead, introduce a function that returns the disclaimer with
the current deco mode. Use that function to generate the dive
notes and for printing.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-10 21:31:21 +02:00
Berthold Stoeger
4706b0f11a Planner: remove planner disclaimer from old notes
There used to be code to remove the old planner notes when replanning
a dive. It used a global variable and seemed rather brittle. Moreover,
the place that set the global variable was inadvertently removed.
Therefore has been effectively dead code.

Reimplement the functionality, but be more robust by considering
that the deco-type may have changed: Split the translated disclaimer
string in two parts, before and after the "%s" place-holder.
Search for these two parts. Remove the disclaimer and everything
after the disclaimer.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-10 21:31:21 +02:00
Robert C. Helling
4767349111 Update deco disclaimer
Our disclaimer is no longer "new". It is still true that people
should not blindly follow it.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-05-29 15:04:33 +03:00
willemferguson
a969d1dd45 Implement height-to-pressure functions in planner
The units.h file has two functions to convert atm pressure to mbar
and also to convert mbar to atm pressure. Implement these two
functions in the planner.

Signed-off-by: willemferguson <willemferguson@zoology.up.ac.za>
2019-05-17 09:46:05 +02:00
Robert C. Helling
aa86d47e47 Don't show surface gas in gas use list
Skip gas use calculation for the gas that was used in
the surface segment added by the planner in the end.

Reported-by: philippe@philmassart.net
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-04-16 02:00:35 +12:00
Robert C. Helling
5e494ce761 Show a bit of surface degassing in the planner
to display the deco parameters at the surface,
in particular tissue saturation and heat map.

Suggeted-by: Matthias Heinrichs <info@heinrichsweikamp.com>
Signed-off-by: Robert C. Helling <helling@atdotde.de>
2019-03-29 06:51:12 -07:00
Berthold Stoeger
31f1af07c2 Planner: fix display of "overlapping dives" message
1) Add a missing <div>

2) More importantly: recognize html content via <div>-tags instead of
   <table>-tags.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-12 14:17:55 -07:00
Berthold Stoeger
6e4a253896 Profile: fix SAC calculation for air dives
Commit f5b11daffd changed gasmix
arguments and return values to be passed by value instead of
using pointers.

Notably, get_gasmix() is fed a default-value and returns a
new value. In the old code, NULL was passed in in a first
loop iteration and non-NULL was always returned in the first
iteration. Thus, an equality comparison of passed-in an
returned gasmix would always fail in the first loop iteration.

The new code passed in air as default. Now if air was also
returned, then the matching gases were not calculated in
calculate_sac(). To revert to the old behavior, pass in
an invalid gasmix.

Moreover, give names to the invalid and air gasmixes.

Reported-by: tormento <turment@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-09-10 14:23:59 -07:00
Berthold Stoeger
605e1e19ed Cleanup: const-ify functions taking pointers to events
This is another entry in the series to make more things
"const-clean" with the ultimate goal of merge_dive() take
const pointers.

This concerns functions taking pointers to events and
the fallout from making these const.

The somewhat debatable part of this commit might be
that get_next_event() is split in a two distinct
(const and non-const) versions with different names,
since C doesn't allow overloading. The linker should
recognize that these functions are identical and remove
one of them.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-08-23 05:16:38 -07:00
Berthold Stoeger
360f07e453 Cleanup: pass gasmix by value
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-08-23 05:16:38 -07:00
Stefan Fuchs
24c915e97c In planner notes don't show dive mode for first data point
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-07-13 11:26:28 -07:00
Stefan Fuchs
9883b9f10e Add three missing translations for divemode_text_ui in plannernotes.c
Added three missing translations which were forgotten here:
fcf6b819d9

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-07-13 11:26:28 -07:00
Robert C. Helling
4157365c96 Make planner notes divemode aware...
... and fix a problem with setpoint changes shown in the wrong line

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-06-24 09:35:55 +02:00
Berthold Stoeger
10cabcdb69 Plannernotes: '\0'-terminate ICD-buffer
When creating the ICD-notes the membuffer was not '\0'-terminated,
leading to output of stale data.

Reported-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-05-18 15:11:04 +03:00
Robert C. Helling
969dfee9ec Rename enum dive_comp_type to divemode_t
...as the usuage is not anymore about a computer but
a momentary dive mode. Rename the end indicator as well.

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-05-14 23:47:00 +03:00
Willem Ferguson
cad4eb39c4 Implement get_divemode() to find the divemode at a particular time
Replaced a rather cumbersome function that that did the above. Upon
the suggestion of Robert Helling who proposed a much shorter way,
this new function replaced the previous ones. This necessitated
changes to divelist.c, profile.c and plannernotes.c, as well as
dive.c/h.

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-05-14 23:47:00 +03:00
Willem Ferguson
0e08c0870a Simplify the bailout detection functions.
Function peek_next_divemodechange() is redundant if get_next_divemodechange()
has one additional parameter. Calls to get_next_divemodechange() were
updated in divelist.c, plannernotes.c and profile.c.

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-05-14 23:47:00 +03:00
Willem Ferguson
cf377beb2e Incorporate bailout events in CCR & PSCR gas calculations.
This is a first step to interpret bailout events.
1) The event structures have a new attribute: divemode.
   Currently interpreted dive modes are OC, CCR, PSCR.
2) When doing fill_pressures(), the calculation is aware
   of divemode. When divemode is OC (==bailout), then
   the appropriate calculations of gas pressures are done.
3) Two new functions get_next_divemodechange() and
   get_divemode_at_time() are created to find divemode
   changes in the events linked list and to determine
   the dive mode at any point during the dive.
4) fill_pressures gets a small amendment to facilitate
   the correct calculations, depending on divemode.
The cases where fill_pressures() is used *outside the planner*
are changed. The result is that, for dives with bailout, the
correct gas pressures are shown on the dive profile. The
deco for bailout dives is not yet correct. This is the
next step.

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-05-14 23:47:00 +03:00
Berthold Stoeger
71d1e78db2 Cleanup: Fix memory leak in plannernotes.c
dive->notes was overwritten without free()ing the old buffer.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-11 14:01:51 +03:00
Berthold Stoeger
a4834e198d Cleanup: fix "unsave" snprintf()s in plannernotes.c
The planner notes were constructed using a sequence of
  len += snprintf(buf, buflen - len, ...);
calls. This will fail once len > buflen, because the second parameter
of snprintf is unsigned. Note that snprintf returns the number of
bytes that would have been written if it weren't truncated.

Fix this by using membuffer with put_format()/put_string() and
asprintf_loc().

Fixes #1155.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-11 14:01:51 +03:00
Berthold Stoeger
f7b2355ced Cleanup: unconstify results of two functions
get_dive_date_c_string() and get_current_date() return copied strings.
Make this explicit by returning non-const pointers.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-11 14:01:51 +03:00
Berthold Stoeger
44bcc5a307 Cleanup: make local functions in core/plannernotes.c of static linkage
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-11 14:01:51 +03:00
Berthold Stoeger
5afe1a53d8 Cleanup: Move *_loc formatting functions into new format.cpp file
qthelper.cpp is already quite voluminous. Move the recently
introduced localized versions of (v)snprintf() and put_format()
into their own translation unit.

Moreover, adopt C-style semantics for asprintf_loc(). This function
will be used to remove fixed-size buffers in core/plannernotes.c.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-04-09 11:29:43 -07:00
Berthold Stoeger
18c034ea37 Localization: implement *_loc() functions in plannernotes.c
Replace snprintf() and put_format() by snprintf_loc() and
put_format_loc(), respectively to localize formatting of
integers and floats.

Acked-by: Stefan Fuchs <sfuchs@gmx.de>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-03-05 16:23:55 +01:00
Berthold Stoeger
cd5e17cf79 Cleanup: Unify qthelper.h and qthelperfromc.h
Since all qt-helpers are defined in qthelper.cpp, there seems to be
no reason to have two include files. By unifying the two files,
duplication and inconsistencies are removed. The C++-only part is
simply compiled away with #ifdefs.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-02-26 19:06:02 +02:00
Stefan Fuchs
d9c0df0142 Correctly suppress display of ICD table if prefs.show_icd is false
Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-25 02:04:30 +02:00
Stefan Fuchs
f08e24d65b Exit add_plan_to_notes() in plannernotes.c always via label finished
Replace an early "return" in add_plan_to_notes() with a "goto finished;"
This was the initial idea of doing it plus it fixes a potential memory
leak (missing free for icdbuffer).

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-02-22 21:48:46 +02:00
Robert C. Helling
818ab36b24 Indicate direction of transition in verbatim plan
Replace "Transition to" by "Ascent to" or "Descend to"

Signed-off-by: Robert C. Helling <helling@atdotde.de>
2018-02-20 14:29:31 +01:00
Willem Ferguson
5416fc7afb Print icd data only when it is really needed
Reduce the impact and visibility of icd calculations by writing
the data to the planner output only in cases where gas switches
involve:

1) ascent
2) helium is used as part of breathing gas
3) gas switch results in an increase in partial pressure of nitrogen.

Coding change:

1) The code for writing the header of the icd table as well as
   the inclusion of the data in the planner output is made
   conditional on the above three requirements. This involves
   moving the code that writes the table header into the
   function that writes an icd data item to buffer.
2) Manipulation of a boolean variable that controls writing
   of the table header to buffer and that also determines
   whether any icd results should be inluded in the planner
   results.
3) Reorganise comments so that there are not multiple tabs between
   the code and the start of a comment.

Correct type and insert braces where important

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-02-02 13:14:09 +01:00
Willem Ferguson
b9ac89574e Planner: print icd information at 0.1 resolution
The gas fractions (in %) are now printed at a resolution of 0.1%
and not at 0.01% as previously.

The string in the info box that provides icd data is reformatted
so that the info-box is as narrow as possible.

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-24 22:03:42 +01:00
Stefan Fuchs
c866b82f35 Planner notes min gas: Remove incorrect line wrap inside printf string
With old code the tabs at the start of the second line were incorrectly
added to the string.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-01-21 09:56:35 +01:00
Stefan Fuchs
81e9b230ca Planner notes ICD: Format HTML with DIV, do table title differently
In the planner notes format the HTML for different sections with
div tags.

Put the table title for the ICD table outside the table because then the
alignment looks a little bit nicer.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-01-21 09:56:35 +01:00
Stefan Fuchs
d3bcf02bbc Planner notes ICD: Coding style change only
Avoid the need for a char array for the "old_gas_name" by passing
two pointers to the gasmixes to the add_icd_entry function and
calling helper function gasname() there twice.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-01-21 09:56:35 +01:00
Stefan Fuchs
e408e32ed6 Planner notes ICD: Print correct runtime for gaschange
If a gaschange happens at the beginning of a segment, currently the
wrong runtime (end of segment time) is printed in the ICD table.

This is corrected here.

Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
2018-01-21 09:56:35 +01:00
Willem Ferguson
f2fe389abd Move function isobaric_counterdiffusion()
Move the above function from plannernotes.c to dive.c so that
it is available to be called from the dive log part of the
software, and not only from the planner. The following was done:

1) Edit the comment above the code to make it more accurate
2) Move the structure icd_data to dive.h
3) Create an external reference in dive.h for the above function
4) Copy the body of isobaric_counterdiffusion() to dive.c

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-20 10:10:09 +01:00
Willem Ferguson
f072f78c29 Implement ICD calculations in planner output
This patch implements the calculation and printing of icd parameters
in the dive planner output. It does:
1) icd parameters are calculated following the rule-of-fifths for
   OC trimix dives. For each gas change on the ascent that involves
   helium, the change in gas composition as well as the change in
   partial pressures are shown. If rule-of-fifths is exceeded, a
   warning message is prinetd.
2) An independent function is provided that in principle enables
   calculation of icd paramaters outside of the context of the
   dive planner.

Further updates to icd calculations

These changes respond to #1047. Code style conventions have been
improved. The ICD table is now also printed when the planner is
set to verbatim mode. The code that created the html icd results
has been moved to a function. This does not make the code more
efficient (many parameters passed) but it makes the code more clean.

Free a new dynamic variable (old_gas_name)

Stylistic changes to new code in plannernotes.c

Changes in comments to explain some of the changes I made.
Preparation of comments and functioning of isobaric_counterdiffusion()
and its dependent data structure for possible transfer to dive.c
and dive.h after finalisation and merging of the present PR.
Smaller stylistic changes to conform to our coding rules.

The several comments and suggestions during github review
(@atdotde, @leolit123, @sfuchs79) are incorporated.

Fixed up mis-aligned comments and text descriptions by replacing
tab characters with space characters, thereby hard-forcing
alignment of indented lines of text.

Remove parameter *dive from function isobaric_counterdiffusion().

Improve a few constructs to conform to our style rules.

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-19 19:43:16 +02:00
Willem Ferguson
082def8162 Fix indentations for plannernotes.c
The last 2 commits have now been squashed.
S Fuchs's comment on line 315 has been fixed

Signed-off-by: Willem Ferguson <willemferguson@zoology.up.ac.za>
2018-01-11 21:47:04 +01:00
Rick Walsh
34236e3c84 Planner notes: don't omit deco stops with rapid ascent rates
This fixes a bug where if the user entered very high ascent (or less commonly
descent) rates such that the time to ascend (or descend) from one level to the
next was less than 10s, that leg would be skipped in the dive plan notes.

Reported-by: Alexander Maier <maieralex@me.com>
Signed-off-by: Rick Walsh <rickmwalsh@gmail.com>
2017-12-28 19:11:31 -08:00
Dirk Hohndel
424e757094 Cleanup: avoid memory leak
Coverity CID 208308

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26 15:57:44 -08:00
Berthold Stoeger
a748e7f239 Unify float calulations: use double
Internal floating point (FP) calculations should be performed using double
unless there is a very good reason. This avoids headaches with conversions.
Indeed, the vast majority of FP calculations were already done using double.
This patch adapts most remaining calculations. Not converted where things
that were based on binary representations and variables which weren't used
anyway.

An analysis of all instances follows:

core/plannernotes.c, l.404:

This was a comparison between two floats. On the left side, first an integer
was cast to float then multiplied with and integer and divided by a constant
double. The right hand side was an integer cast to a float. Simply divide by
1000.0 first to convert to double and continue with calculations. On the right
hand side, remove the cast, because the integer will be implicitely cast to
double for comparison. This conversion actually emits less instructions,
because no conversion to double and back is performed.

core/planner.c, l.613:

Same analysis as previous case.

subsurface-desktop-main.cpp, l.155:

A local variable representing the version OpenGL version. Turn this into
integer logic. Not only does this avoid dreaded FP rounding issues, it also
works correctly for minor version > 10 (not that such a thing is to be
expected anytime soon).

abstractpreferenceswidget.[h/cpp]:

A widget where the position is described as a float. Turn into double.

desktop-widgets/divelogexportdialog.cpp, l.313:

total_weight is described as float. Use double arithmetics instead. This
instance fixes a truncation warning emitted by gcc.
2017-12-17 09:02:44 -08:00