summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Willem Ferguson <willemferguson@zoology.up.ac.za>2018-04-05 14:13:34 +0200
committerGravatar Lubomir I. Ivanov <neolit123@gmail.com>2018-05-14 23:47:00 +0300
commit0e08c0870a1c82ded398e1d2fb830d61ffe6a647 (patch)
treedd61315c48a16c4f598a4e32dc3ac829a1ce8487 /core
parentc1d04ef7dcbbe34eccf4515a59063ed807e8d5e5 (diff)
downloadsubsurface-0e08c0870a1c82ded398e1d2fb830d61ffe6a647.tar.gz
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>
Diffstat (limited to 'core')
-rw-r--r--core/dive.c49
-rw-r--r--core/dive.h2
-rw-r--r--core/divelist.c2
-rw-r--r--core/plannernotes.c4
-rw-r--r--core/profile.c6
5 files changed, 17 insertions, 46 deletions
diff --git a/core/dive.c b/core/dive.c
index f296a8486..ac34be7f4 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -241,59 +241,29 @@ void add_extra_data(struct divecomputer *dc, const char *key, const char *value)
}
}
-struct event *get_next_divemodechange(struct event **evd)
+struct event *get_next_divemodechange(struct event **evd, bool update_pointer)
{ /* Starting at the event pointed to by evd, find the next divemode change event and initialise its
* type and divemode. Requires an external pointer (evd) to a divemode change event, usually
- * a copy of dc->events. This function is self-tracking and the value of evd needs no
- * setting or manipulation outside of this function. */
+ * a copy of dc->events. This function is self-tracking if update_pointer is TRUE and the value
+ * of evd needs no manipulation outside of this function. If update_pointer is FALSE, pointer evd
+ * is NOT updated with the address of the last examined event in the while() loop. */
struct event *ev = *evd;
while (ev) { // Step through the events.
for (int i=0; i<3; i++) { // For each event name search for one of the above strings
if (!strcmp(ev->name,divemode_text[i])) { // if the event name is one of the divemode names
ev->divemode = i; // set the event type to the dive mode
- *evd = ev->next;
+ if (update_pointer)
+ *evd = ev->next;
return (ev);
}
}
ev = ev->next;
}
- *evd = NULL;
+ if (update_pointer)
+ *evd = NULL;
return (NULL);
}
-struct event *peek_next_divemodechange(struct event *evd)
-{ // Starting at event evd, return the subsequent divemode change event, remembering its divemode.
- struct event *ev = evd;
- while (ev) { // Step through the events.
- for (int i=0; i<3; i++) { // For each event name search for one of the above strings
- if (!strcmp(ev->name,divemode_text[i])) { // if the event name is one of the divemode names
- ev->divemode = i;
- return (ev); // ... then return the event.
- }
- }
- ev = ev->next;
- }
- return (NULL);
-}
-
-/*
-enum dive_comp_type get_divemode_at_time(struct divecomputer *dc, int divetime, struct event **ev_dmc)
-{ // The dummy version of this function, call parameters compatible with self-tracking version.
- return dc->divemode;
-}
-
-enum dive_comp_type get_divemode_at_time(struct divecomputer *dc, int divetime, struct event **ev_dmc)
-{ // The non-self-tracking version of this function, call parameters compatible with self-tracking version.
- struct event *ev, *ev_ndc = dc->events;
- enum dive_comp_type mode = dc->divemode;
- ev = get_next_divemodechange(&ev_ndc);
- while (ev && (divetime >= ev->time.seconds)) {
- mode = ev->divemode;
- ev = get_next_divemodechange(&ev_ndc);
- }
- return mode;
-} */
-
enum dive_comp_type get_divemode_at_time(struct divecomputer *dc, int dtime, struct event **ev_dmc)
{ /* For a particular dive computer and its linked list of events, find the divemode dtime seconds
* into the dive. Requires an external pointer (ev_dmc) to a divemode change event, usually
@@ -304,7 +274,8 @@ enum dive_comp_type get_divemode_at_time(struct divecomputer *dc, int dtime, str
while (ev && (dtime >= ev->time.seconds)) { // If dtime is AFTER this event time, store divemode
mode = ev->divemode;
ev_last = ev;
- ev = peek_next_divemodechange(ev->next); // peek at the time of the following divemode change event
+// ev = peek_next_divemodechange(ev->next); // peek at the time of the following divemode change event
+ ev = get_next_divemodechange(&ev->next, FALSE);
}
*ev_dmc = ev_last;
return (mode);
diff --git a/core/dive.h b/core/dive.h
index c46b9d64a..6fb1509b4 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -362,7 +362,7 @@ struct dive_components {
unsigned int weights : 1;
};
-extern struct event *get_next_divemodechange(struct event **evd);
+extern struct event *get_next_divemodechange(struct event **evd, bool update_pointer);
extern enum dive_comp_type get_divemode_at_time(struct divecomputer *dc, int dtime, struct event **ev_dmc);
/* picture list and methods related to dive picture handling */
diff --git a/core/divelist.c b/core/divelist.c
index c79cb56b5..d70130b31 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -415,7 +415,7 @@ static void add_dive_to_deco(struct deco_state *ds, struct dive *dive)
struct divecomputer *dc = &dive->dc;
struct gasmix *gasmix = NULL;
struct event *ev = NULL;
- struct event *ev_dmc = dc->events, *ev_dmt = get_next_divemodechange(&ev_dmc);
+ struct event *ev_dmc = dc->events, *ev_dmt = get_next_divemodechange(&ev_dmc, TRUE);
int i;
if (!dc)
diff --git a/core/plannernotes.c b/core/plannernotes.c
index 269b391a8..4d70b9af9 100644
--- a/core/plannernotes.c
+++ b/core/plannernotes.c
@@ -542,7 +542,7 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
struct event *nextev, *evd = dive->dc.events;
current_divemode = dive->dc.divemode;
- nextev = get_next_divemodechange(&evd);
+ nextev = get_next_divemodechange(&evd, TRUE);
if (dive->dc.divemode != CCR) {
while (dp) {
@@ -552,7 +552,7 @@ void add_plan_to_notes(struct diveplan *diveplan, struct dive *dive, bool show_d
if (nextev && (dp->time >= nextev->time.seconds)) { // If there are divemode changes and divedatapoint time
current_divemode = nextev->divemode; // has reached that of the current divemode event, then set the
- nextev = get_next_divemodechange(&evd); // current divemode and find the next divemode event
+ nextev = get_next_divemodechange(&evd, TRUE); // current divemode and find the next divemode event
}
amb = depth_to_atm(dp->depth.mm, dive);
diff --git a/core/profile.c b/core/profile.c
index b8dd17728..789727635 100644
--- a/core/profile.c
+++ b/core/profile.c
@@ -1018,7 +1018,7 @@ void calculate_deco_information(struct deco_state *ds, struct deco_state *planne
if (decoMode() == VPMB)
ds->first_ceiling_pressure.mbar = depth_to_mbar(first_ceiling, dive);
struct gasmix *gasmix = NULL;
- struct event *ev = NULL, *ev_dmc = dc->events, *ev_dmt = get_next_divemodechange(&ev_dmc);
+ struct event *ev = NULL, *ev_dmc = dc->events, *ev_dmt = get_next_divemodechange(&ev_dmc, TRUE);
for (i = 1; i < pi->nr; i++) {
struct plot_data *entry = pi->entry + i;
@@ -1211,7 +1211,7 @@ static void calculate_gas_information_new(struct dive *dive, struct divecomputer
struct event *nextev, *evg = NULL, *evd = dc->events;
current_divemode = dc->divemode;
- nextev = get_next_divemodechange(&evd);
+ nextev = get_next_divemodechange(&evd, TRUE);
for (i = 1; i < pi->nr; i++) {
int fn2, fhe;
@@ -1220,7 +1220,7 @@ static void calculate_gas_information_new(struct dive *dive, struct divecomputer
gasmix = get_gasmix(dive, dc, entry->sec, &evg, gasmix);
if (nextev && (entry->sec > nextev->time.seconds)) { // If there are divemode changes and sample time
current_divemode = nextev->divemode; // has reached that of the current divemode event, then set the
- nextev = get_next_divemodechange(&evd); // current divemode and find the next divemode event
+ nextev = get_next_divemodechange(&evd, TRUE); // current divemode and find the next divemode event
}
amb_pressure = depth_to_bar(entry->depth, dive);
fill_pressures(&entry->pressures, amb_pressure, gasmix, (current_divemode == OC) ? 0.0 : entry->o2pressure.mbar / 1000.0, current_divemode);