diff --git a/Subsurface-mobile.pro b/Subsurface-mobile.pro
index 70eef0d06..5846536ff 100644
--- a/Subsurface-mobile.pro
+++ b/Subsurface-mobile.pro
@@ -25,7 +25,7 @@ SOURCES += subsurface-mobile-main.cpp \
core/devicedetails.cpp \
core/downloadfromdcthread.cpp \
core/qtserialbluetooth.cpp \
- core/plannernotes.c \
+ core/plannernotes.cpp \
core/uemis-downloader.cpp \
core/qthelper.cpp \
core/checkcloudconnection.cpp \
@@ -45,7 +45,7 @@ SOURCES += subsurface-mobile-main.cpp \
core/fulltext.cpp \
core/subsurfacestartup.cpp \
core/pref.c \
- core/profile.c \
+ core/profile.cpp \
core/device.cpp \
core/dive.cpp \
core/divecomputer.c \
@@ -81,10 +81,10 @@ SOURCES += subsurface-mobile-main.cpp \
core/save-git.cpp \
core/datatrak.cpp \
core/ostctools.c \
- core/planner.c \
+ core/planner.cpp \
core/save-xml.cpp \
core/cochran.cpp \
- core/deco.c \
+ core/deco.cpp \
core/divesite.c \
core/equipment.c \
core/gas.c \
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index 3e42257e5..88e1ea312 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -53,7 +53,7 @@ set(SUBSURFACE_CORE_LIB_SRCS
connectionlistmodel.h
datatrak.cpp
datatrak.h
- deco.c
+ deco.cpp
deco.h
device.cpp
device.h
@@ -141,12 +141,12 @@ set(SUBSURFACE_CORE_LIB_SRCS
picture.h
pictureobj.cpp
pictureobj.h
- planner.c
+ planner.cpp
planner.h
- plannernotes.c
+ plannernotes.cpp
pref.h
pref.c
- profile.c
+ profile.cpp
profile.h
qt-gui.h
qt-init.cpp
diff --git a/core/deco.c b/core/deco.cpp
similarity index 93%
rename from core/deco.c
rename to core/deco.cpp
index f422afa3d..7cb550f12 100644
--- a/core/deco.c
+++ b/core/deco.cpp
@@ -218,7 +218,7 @@ static double vpmb_tolerated_ambient_pressure(struct deco_state *ds, double refe
return ds->tissue_n2_sat[ci] + ds->tissue_he_sat[ci] + vpmb_config.other_gases_pressure - total_gradient;
}
-double tissue_tolerance_calc(struct deco_state *ds, const struct dive *dive, double pressure, bool in_planner)
+extern "C" double tissue_tolerance_calc(struct deco_state *ds, const struct dive *dive, double pressure, bool in_planner)
{
int ci = -1;
double ret_tolerance_limit_ambient_pressure = 0.0;
@@ -325,7 +325,7 @@ static double calc_surface_phase(double surface_pressure, double he_pressure, do
return 0;
}
-void vpmb_start_gradient(struct deco_state *ds)
+extern "C" void vpmb_start_gradient(struct deco_state *ds)
{
int ci;
@@ -335,7 +335,7 @@ void vpmb_start_gradient(struct deco_state *ds)
}
}
-void vpmb_next_gradient(struct deco_state *ds, double deco_time, double surface_pressure, bool in_planner)
+extern "C" void vpmb_next_gradient(struct deco_state *ds, double deco_time, double surface_pressure, bool in_planner)
{
int ci;
double n2_b, n2_c;
@@ -381,7 +381,7 @@ static double solve_cubic(double A, double B, double C)
}
-void nuclear_regeneration(struct deco_state *ds, double time)
+extern "C" void nuclear_regeneration(struct deco_state *ds, double time)
{
time /= 60.0;
int ci;
@@ -413,7 +413,7 @@ static double calc_inner_pressure(double crit_radius, double onset_tension, doub
}
// Calculates the crushing pressure in the given moment. Updates crushing_onset_tension and critical radius if needed
-void calc_crushing_pressure(struct deco_state *ds, double pressure)
+extern "C" void calc_crushing_pressure(struct deco_state *ds, double pressure)
{
int ci;
double gradient;
@@ -445,9 +445,8 @@ void calc_crushing_pressure(struct deco_state *ds, double pressure)
}
/* add period_in_seconds at the given pressure and gas to the deco calculation */
-void add_segment(struct deco_state *ds, double pressure, struct gasmix gasmix, int period_in_seconds, int ccpo2, enum divemode_t divemode, int sac, bool in_planner)
+extern "C" void add_segment(struct deco_state *ds, double pressure, struct gasmix gasmix, int period_in_seconds, int ccpo2, enum divemode_t divemode, int, bool in_planner)
{
- UNUSED(sac);
int ci;
struct gas_pressures pressures;
bool icd = false;
@@ -479,7 +478,7 @@ void add_segment(struct deco_state *ds, double pressure, struct gasmix gasmix, i
}
#if DECO_CALC_DEBUG
-void dump_tissues(struct deco_state *ds)
+extern "C" void dump_tissues(struct deco_state *ds)
{
int ci;
printf("N2 tissues:");
@@ -492,7 +491,7 @@ void dump_tissues(struct deco_state *ds)
}
#endif
-void clear_vpmb_state(struct deco_state *ds)
+extern "C" void clear_vpmb_state(struct deco_state *ds)
{
int ci;
for (ci = 0; ci < 16; ci++) {
@@ -504,7 +503,7 @@ void clear_vpmb_state(struct deco_state *ds)
ds->max_bottom_ceiling_pressure.mbar = 0;
}
-void clear_deco(struct deco_state *ds, double surface_pressure, bool in_planner)
+extern "C" void clear_deco(struct deco_state *ds, double surface_pressure, bool in_planner)
{
int ci;
@@ -523,18 +522,18 @@ void clear_deco(struct deco_state *ds, double surface_pressure, bool in_planner)
ds->ci_pointing_to_guiding_tissue = -1;
}
-void cache_deco_state(struct deco_state *src, struct deco_state **cached_datap)
+extern "C" void cache_deco_state(struct deco_state *src, struct deco_state **cached_datap)
{
struct deco_state *data = *cached_datap;
if (!data) {
- data = malloc(sizeof(struct deco_state));
+ data = (deco_state *)malloc(sizeof(struct deco_state));
*cached_datap = data;
}
*data = *src;
}
-void restore_deco_state(struct deco_state *data, struct deco_state *target, bool keep_vpmb_state)
+extern "C" void restore_deco_state(struct deco_state *data, struct deco_state *target, bool keep_vpmb_state)
{
if (keep_vpmb_state) {
int ci;
@@ -551,7 +550,7 @@ void restore_deco_state(struct deco_state *data, struct deco_state *target, bool
}
-int deco_allowed_depth(double tissues_tolerance, double surface_pressure, const struct dive *dive, bool smooth)
+extern "C" int deco_allowed_depth(double tissues_tolerance, double surface_pressure, const struct dive *dive, bool smooth)
{
int depth;
double pressure_delta;
@@ -570,7 +569,7 @@ int deco_allowed_depth(double tissues_tolerance, double surface_pressure, const
return depth;
}
-void set_gf(short gflow, short gfhigh)
+extern "C" void set_gf(short gflow, short gfhigh)
{
if (gflow != -1)
buehlmann_config.gf_low = (double)gflow / 100.0;
@@ -578,7 +577,7 @@ void set_gf(short gflow, short gfhigh)
buehlmann_config.gf_high = (double)gfhigh / 100.0;
}
-void set_vpmb_conservatism(short conservatism)
+extern "C" void set_vpmb_conservatism(short conservatism)
{
if (conservatism < 0)
vpmb_config.conservatism = 0;
@@ -588,7 +587,7 @@ void set_vpmb_conservatism(short conservatism)
vpmb_config.conservatism = conservatism;
}
-double get_gf(struct deco_state *ds, double ambpressure_bar, const struct dive *dive)
+extern "C" double get_gf(struct deco_state *ds, double ambpressure_bar, const struct dive *dive)
{
double surface_pressure_bar = get_surface_pressure_in_mbar(dive, true) / 1000.0;
double gf_low = buehlmann_config.gf_low;
@@ -602,7 +601,7 @@ double get_gf(struct deco_state *ds, double ambpressure_bar, const struct dive *
return gf;
}
-double regressiona(const struct deco_state *ds)
+extern "C" double regressiona(const struct deco_state *ds)
{
if (ds->sum1 > 1) {
double avxy = ds->sumxy / ds->sum1;
@@ -615,7 +614,7 @@ double regressiona(const struct deco_state *ds)
return 0.0;
}
-double regressionb(const struct deco_state *ds)
+extern "C" double regressionb(const struct deco_state *ds)
{
if (ds->sum1)
return ds->sumy / ds->sum1 - ds->sumx * regressiona(ds) / ds->sum1;
@@ -623,14 +622,14 @@ double regressionb(const struct deco_state *ds)
return 0.0;
}
-void reset_regression(struct deco_state *ds)
+extern "C" void reset_regression(struct deco_state *ds)
{
ds->sum1 = 0;
ds->sumxx = ds->sumx = 0L;
ds->sumy = ds->sumxy = 0.0;
}
-void update_regression(struct deco_state *ds, const struct dive *dive)
+extern "C" void update_regression(struct deco_state *ds, const struct dive *dive)
{
if (!ds->plot_depth)
return;
diff --git a/core/gas.c b/core/gas.c
index 96dc60479..7e8a98309 100644
--- a/core/gas.c
+++ b/core/gas.c
@@ -117,7 +117,7 @@ int pscr_o2(const double amb_pressure, struct gasmix mix)
* *pressures = structure for communicating o2 sensor values from and gas pressures to the calling function.
* *mix = structure containing cylinder gas mixture information.
* divemode = the dive mode pertaining to this point in the dive profile.
- * This function called by: calculate_gas_information_new() in profile.c; add_segment() in deco.c.
+ * This function called by: calculate_gas_information_new() in profile.cpp; add_segment() in deco.cpp.
*/
void fill_pressures(struct gas_pressures *pressures, const double amb_pressure, struct gasmix mix, double po2, enum divemode_t divemode)
{
diff --git a/core/gaspressures.c b/core/gaspressures.c
index 7661e40c6..8bbc869e4 100644
--- a/core/gaspressures.c
+++ b/core/gaspressures.c
@@ -2,9 +2,9 @@
/* gaspressures.c
* ---------------
* This file contains the routines to calculate the gas pressures in the cylinders.
- * The functions below support the code in profile.c.
+ * The functions below support the code in profile.cpp.
* The high-level function is populate_pressure_information(), called by function
- * create_plot_info_new() in profile.c. The other functions below are, in turn,
+ * create_plot_info_new() in profile.cpp. The other functions below are, in turn,
* called by populate_pressure_information(). The calling sequence is as follows:
*
* populate_pressure_information() -> calc_pressure_time()
@@ -362,7 +362,7 @@ static void debug_print_pressures(struct plot_info *pi)
* pr_track_alloc structures for each cylinder. These pr_track_alloc structures ultimately allow for filling
* the missing tank pressure values on the dive profile using the depth_pressure of the dive. To do this, it
* calculates the summed pressure-time value for the duration of the dive and stores these * in the pr_track_alloc
- * structures. This function is called by create_plot_info_new() in profile.c
+ * structures. This function is called by create_plot_info_new() in profile.cpp
*/
void populate_pressure_information(const struct dive *dive, const struct divecomputer *dc, struct plot_info *pi, int sensor)
{
diff --git a/core/planner.c b/core/planner.cpp
similarity index 97%
rename from core/planner.c
rename to core/planner.cpp
index 6d37d3101..926d976b8 100644
--- a/core/planner.c
+++ b/core/planner.cpp
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
-/* planner.c
+/* planner.cpp
*
* code that allows us to plan future dives
*
@@ -42,7 +42,7 @@ static int decostoplevels_imperial[] = { 0, 3048, 6096, 9144, 12192, 15240, 1828
325120, 345440, 365760, 386080 };
#if DEBUG_PLAN
-void dump_plan(struct diveplan *diveplan)
+extern "C" void dump_plan(struct diveplan *diveplan)
{
struct divedatapoint *dp;
struct tm tm;
@@ -65,7 +65,7 @@ void dump_plan(struct diveplan *diveplan)
}
#endif
-bool diveplan_empty(struct diveplan *diveplan)
+extern "C" bool diveplan_empty(struct diveplan *diveplan)
{
struct divedatapoint *dp;
if (!diveplan || !diveplan->dp)
@@ -80,7 +80,7 @@ bool diveplan_empty(struct diveplan *diveplan)
}
/* get the cylinder index at a certain time during the dive */
-int get_cylinderid_at_time(struct dive *dive, struct divecomputer *dc, duration_t time)
+extern "C" int get_cylinderid_at_time(struct dive *dive, struct divecomputer *dc, duration_t time)
{
// we start with the first cylinder unless an event tells us otherwise
int cylinder_idx = 0;
@@ -327,7 +327,7 @@ static void create_dive_from_plan(struct diveplan *diveplan, struct dive *dive,
return;
}
-void free_dps(struct diveplan *diveplan)
+extern "C" void free_dps(struct diveplan *diveplan)
{
if (!diveplan)
return;
@@ -344,7 +344,7 @@ static struct divedatapoint *create_dp(int time_incr, int depth, int cylinderid,
{
struct divedatapoint *dp;
- dp = malloc(sizeof(struct divedatapoint));
+ dp = (divedatapoint *)malloc(sizeof(struct divedatapoint));
dp->time = time_incr;
dp->depth.mm = depth;
dp->cylinderid = cylinderid;
@@ -371,7 +371,7 @@ static void add_to_end_of_diveplan(struct diveplan *diveplan, struct divedatapoi
dp->time += lasttime;
}
-struct divedatapoint *plan_add_segment(struct diveplan *diveplan, int duration, int depth, int cylinderid, int po2, bool entered, enum divemode_t divemode)
+extern "C" struct divedatapoint *plan_add_segment(struct diveplan *diveplan, int duration, int depth, int cylinderid, int po2, bool entered, enum divemode_t divemode)
{
struct divedatapoint *dp = create_dp(duration, depth, cylinderid, divemode == CCR ? po2 : 0);
dp->entered = entered;
@@ -413,7 +413,7 @@ static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive
if (dp->depth.mm <= depth) {
int i = 0;
nr++;
- gaschanges = realloc(gaschanges, nr * sizeof(struct gaschanges));
+ gaschanges = (struct gaschanges *)realloc(gaschanges, nr * sizeof(struct gaschanges));
while (i < nr - 1) {
if (dp->depth.mm < gaschanges[i].depth) {
memmove(gaschanges + i + 1, gaschanges + i, (nr - i - 1) * sizeof(struct gaschanges));
@@ -454,7 +454,7 @@ static int *sort_stops(int *dstops, int dnr, struct gaschanges *gstops, int gnr)
{
int i, gi, di;
int total = dnr + gnr;
- int *stoplevels = malloc(total * sizeof(int));
+ int *stoplevels = (int *)malloc(total * sizeof(int));
/* no gaschanges */
if (gnr == 0) {
@@ -502,9 +502,8 @@ static int *sort_stops(int *dstops, int dnr, struct gaschanges *gstops, int gnr)
return stoplevels;
}
-int ascent_velocity(int depth, int avg_depth, int bottom_time)
+extern "C" int ascent_velocity(int depth, int avg_depth, int)
{
- UNUSED(bottom_time);
/* We need to make this configurable */
/* As an example (and possibly reasonable default) this is the Tech 1 provedure according
@@ -655,7 +654,7 @@ static void average_max_depth(struct diveplan *dive, int *avg_depth, int *max_de
*avg_depth = *max_depth = 0;
}
-bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, int timestep, struct decostop *decostoptable, struct deco_state **cached_datap, bool is_planner, bool show_disclaimer)
+extern "C" bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, int timestep, struct decostop *decostoptable, struct deco_state **cached_datap, bool is_planner, bool show_disclaimer)
{
int bottom_depth;
@@ -715,7 +714,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
create_dive_from_plan(diveplan, dive, is_planner);
// Do we want deco stop array in metres or feet?
- if (prefs.units.length == METERS ) {
+ if (prefs.units.length == units::METERS ) {
decostoplevels = decostoplevels_metric;
decostoplevelcount = sizeof(decostoplevels_metric) / sizeof(int);
} else {
@@ -929,7 +928,7 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
last_segment_min_switch = false;
clock += TIMESTEP;
depth -= deltad;
- /* Print VPM-Gradient as gradient factor, this has to be done from within deco.c */
+ /* Print VPM-Gradient as gradient factor, this has to be done from within deco.cpp */
if (decodive)
ds->plot_depth = depth;
} while (depth > 0 && depth > stoplevels[stopidx]);
@@ -1179,7 +1178,7 @@ static int get_permille(const char *begin, const char **end)
return value;
}
-int validate_gas(const char *text, struct gasmix *gas)
+extern "C" int validate_gas(const char *text, struct gasmix *gas)
{
int o2, he;
@@ -1226,7 +1225,7 @@ int validate_gas(const char *text, struct gasmix *gas)
return 1;
}
-int validate_po2(const char *text, int *mbar_po2)
+extern "C" int validate_po2(const char *text, int *mbar_po2)
{
int po2;
diff --git a/core/plannernotes.c b/core/plannernotes.cpp
similarity index 89%
rename from core/plannernotes.c
rename to core/plannernotes.cpp
index e2f84284c..494f24348 100644
--- a/core/plannernotes.c
+++ b/core/plannernotes.cpp
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
-/* planner.c
+/* plannernotes.cpp
*
* code that allows us to plan future dives
*
@@ -75,7 +75,7 @@ static void add_icd_entry(struct membuffer *b, struct icd_data *icdvalues, bool
ambientpressure_mbar * -icdvalues->dHe / 5e6f, translate("gettextFromC", "bar"));
}
-const char *get_planner_disclaimer()
+extern "C" const char *get_planner_disclaimer()
{
return translate("gettextFromC", "DISCLAIMER / WARNING: THIS IMPLEMENTATION OF THE %s "
"ALGORITHM AND A DIVE PLANNER IMPLEMENTATION BASED ON THAT HAS "
@@ -84,7 +84,7 @@ const char *get_planner_disclaimer()
}
/* Returns newly allocated buffer. Must be freed by caller */
-char *get_planner_disclaimer_formatted()
+extern "C" char *get_planner_disclaimer_formatted()
{
struct membuffer buf = { 0 };
const char *deco = decoMode(true) == VPMB ? translate("gettextFromC", "VPM-B")
@@ -93,7 +93,7 @@ char *get_planner_disclaimer_formatted()
return detach_cstring(&buf);
}
-void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer, int error)
+extern "C" void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_disclaimer, int error)
{
struct membuffer buf = { 0 };
struct membuffer icdbuf = { 0 };
@@ -436,30 +436,34 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
}
put_string(&buf, "
\n");
- const char *depth_unit;
- int altitude = (int) get_depth_units((int) (pressure_to_altitude(diveplan->surface_pressure)), NULL, &depth_unit);
+ {
+ const char *depth_unit;
+ int altitude = (int) get_depth_units((int) (pressure_to_altitude(diveplan->surface_pressure)), NULL, &depth_unit);
- put_format_loc(&buf, translate("gettextFromC", "ATM pressure: %dmbar (%d%s)
\n\n"), diveplan->surface_pressure, altitude, depth_unit);
+ put_format_loc(&buf, translate("gettextFromC", "ATM pressure: %dmbar (%d%s)
\n\n"), diveplan->surface_pressure, altitude, depth_unit);
+ }
/* Get SAC values and units for printing it in gas consumption */
- double bottomsacvalue, decosacvalue;
- int sacdecimals;
- const char* sacunit;
+ {
+ double bottomsacvalue, decosacvalue;
+ int sacdecimals;
+ const char* sacunit;
- bottomsacvalue = get_volume_units(prefs.bottomsac, &sacdecimals, &sacunit);
- decosacvalue = get_volume_units(prefs.decosac, NULL, NULL);
+ bottomsacvalue = get_volume_units(prefs.bottomsac, &sacdecimals, &sacunit);
+ decosacvalue = get_volume_units(prefs.decosac, NULL, NULL);
- /* Reduce number of decimals from 1 to 0 for bar/min, keep 2 for cuft/min */
- if (sacdecimals==1) sacdecimals--;
+ /* Reduce number of decimals from 1 to 0 for bar/min, keep 2 for cuft/min */
+ if (sacdecimals==1) sacdecimals--;
- /* Print the gas consumption next.*/
- if (dive->dc.divemode == CCR)
- temp = strdup(translate("gettextFromC", "Gas consumption (CCR legs excluded):"));
- else
- asprintf_loc(&temp, "%s %.*f|%.*f%s/min):", translate("gettextFromC", "Gas consumption (based on SAC"),
- sacdecimals, bottomsacvalue, sacdecimals, decosacvalue, sacunit);
- put_format(&buf, "