Also remove the UNUSED() macro, as there were no users left.
The macro was silly anyway - there were many falso positives.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
We can now return mutable/imutable depending on const-ness of
the parameter, owing to parameter overloading.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Makes the code much nicer to read.
Default initialize cylinder_t to the empty cylinder.
This produces lots of warnings, because most structure are now
not PODs anymore and shouldn't be erased using memset().
These memset()s will be removed one-by-one and replaced by
proper constructors.
The whole ordeal made it necessary to add a constructor to
struct event. To simplify things the whole optimization of
the variable-size event names was removed. In upcoming commits
this will be replaced by std::string anyway.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
To my understanding, declaring empty parameter lists using "(void)"
is an artifact from the bad old K&R times, when functions were
declared without(!) parameters. Which in hindsight was an absolute
recipe for disaster. So for backwards compatibility, functions
without parameters had to be declared using "(void)" as "()"
could also mean "any function".
That was 40 years ago. Meanwhile, C++ introduced references,
which made it a necessity to declare the function parameters.
So "(void)" is redundant and inconsistent in C++ code and
just makes no sense.
Remove it.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The divesite-helper.cpp only existed because C-string manipulation
was too tedious. Now that divesite.cpp is C++ anyway, the split
is not necessary anymore.
Moreover, return an std::string, since this is a core-function.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since this is now in C++, we don't have to use our crazy
TABLE_* macros.
This contains a logic change: the dives associated to a
dive site are now unsorted.
The old code was subtly buggy: dives were added in a sorted
manner, but when the dive was edited the list was not
resorted. Very unlikely that this leads to a serious
problem, still not good.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Since the taxonomy is now a real C++ struct with constructor
and destructor, dive_site has to be converted to C++ as well.
A bit hairy for now, but will ultimately be distinctly simpler.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Use std::vector<> instead of fixed size array.
Doesn't do any logic change, even though the back-translation
logic is ominous.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Use more C++ style memory management for plot_info: Use std::vector
for array data. Return the plot_info instead of filling an output
parameter. Add a constructor/destructor pair so that the caller
isn't bothered with memory management.
The bulk of the commit is replacement of pointers with references,
which is kind of gratuitous. But I started and then went on...
Default initializiation of gas_pressures made it necessary to convert
gas.c to c++, though with minimal changes to the code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Replace malloc/free of one structure by C++ idioms and add a
destructor to the struct. Otherwise, don't touch the code.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
It seems that smartrak was the only part of the code that cared
about freeing the dc_descriptor. Make that a general feature
of the new device_data_t destructor, which we could implement
now that things are in C++.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
It was never clear what was a pointer to a static string from
libdivecomputer and what was allocated.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
These can all just be local objects.
Also, don't overwrite them with 0. We later want to convert the
string to std::string, where this would be very sketchy.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Convert both files simultanously, because the SI_UNITS define works
either under C or under C++.
This was painful, because initialization of struct-members has to
be done in order of definition in C++. And it was completely out
of order. However, as long as not all is C++, we can't use
default initialization directly in the struct definition. :(
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The old code was wild: For the yearly statistics it would allocate
one entry per dive in the log. Of course, it would also leak
C-style strings.
Convert the whole thing to somewhat idiomatic C++.
Somewhat wasted work, because I'd like to convert the whole thing
to the new statistics code. But let's finish the conversion to C++
first.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
All have been converted to std::min() and std::max().
Moreover, this was Windows only and since we cross-compile, it
is not even clear if this is needed.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was the umpteenth inefficient reinvention of a trivial
map. Replace by a hash-map (std::unordered_map). Might just
as well use a balanced binary tree or a sorted array. In the
end, it probably doesn't matter at all.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
uemis_get_divenr() returns maxdiveid and passes mindiveid as a
global variable.
Make this more reasonable by returning a min, max pair.
The way mindiveid is an unsigned int and then reinterpreted as
int is very sketchy. This commit attempts to not change that
behavior.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This is only initialized and used in one loop. Very mysterious
why this should be a global variable.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This global variable is used in two function independently of
each other. I don't see how there should be transport of this
value from one function to the other. Ominous.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
uemis_get_answer() would put the raw response into a global variable.
This could be anywhere in the call stack and thus you never knew
when the existing buffer was removed under your feet.
Instead, return the buffer explicitly from uemis_get_answer().
I'm nit perfectly happy about the new interface: an error is
indicated by an empty buffer, which is awkward to test for.
If an empty buffer turns out to be a valid response, this
should be replaced by an std::optional<> or std::expected<>.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The string code of uemis-downloader.cpp was broken in more ways
than can be listed here. Notably, it brazenly refused to free any
memory allocated for the parameters buffer.
Using std::string and std::string_view should plug all those
memory holes. That made it necessary to do some major refactoring.
This was done blind and therefore will break.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
newmax was an integer variable kept as a string. Very ominous.
Moreover, memory management seems to be broken:
1) The string is never freed.
2) The string is passed as value from do_uemis_import() to
get_matching_dives(), which passes it as reference to
process_raw_buffer(), which may reallocate it, which means
that do_uemis_import() now possesses a pointer to a free()d
string.
Simplify all that by making newmax an integer variable and
passing it as a reference from do_uemis_import() to
get_matching_dives().
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
There were a number of fprintf()s that escaped the conversion
to report_info(), because they used "debugfile" instead of
"stderr" as target. However, debugfile was just #defined to
be stderr, so we might just use report_info() for consistency.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
The uemis code is wild. It simply doesn't deallocate memory
and uses global variables. To get this under control, create
a "struct uemis" and make the functions exported by "uemis.h"
members of "struct uemis". Thus, we don't have to carry around
a parameter for the state of the importing process.
Turn a linked list of "helper" structures (one per imported dive)
into a std::unordered_map, to fix leaking of the helper structures.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This was very obscure: the function that parses into a struct
dive was passed a void-pointer instead of a struct dive-pointer.
Why? Just pass the correct type.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>