Convert the C code to using stdbool and true/false

Earlier we converted the C++ code to using true/false, and this converts
the C code to using the same style.

We already depended on stdbool.h in subsurfacestartup.[ch], and we build
with -std=gnu99 so nobody could build subsurface without a c99 compiler.

[Dirk Hohndel: small change suggested by Thiago Macieira: don't include
               stdbool.h for C++]

Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Anton Lundin 2014-01-15 19:54:41 +01:00 committed by Dirk Hohndel
parent dca59f06d7
commit 33391a77e9
14 changed files with 131 additions and 147 deletions

6
deco.c
View file

@ -27,9 +27,9 @@ struct buehlmann_config {
double gf_high; //! gradient factor high (at surface). double gf_high; //! gradient factor high (at surface).
double gf_low; //! gradient factor low (at bottom/start of deco calculation). double gf_low; //! gradient factor low (at bottom/start of deco calculation).
double gf_low_position_min; //! gf_low_position below surface_min_shallow. double gf_low_position_min; //! gf_low_position below surface_min_shallow.
bool gf_low_at_maxdepth; //! if TRUE, gf_low applies at max depth instead of at deepest ceiling. bool gf_low_at_maxdepth; //! if true, gf_low applies at max depth instead of at deepest ceiling.
}; };
struct buehlmann_config buehlmann_config = { 1.0, 1.01, 0, 0.75, 0.35, 2.0, FALSE }; struct buehlmann_config buehlmann_config = { 1.0, 1.01, 0, 0.75, 0.35, 2.0, false };
const double buehlmann_N2_a[] = {1.1696, 1.0, 0.8618, 0.7562, const double buehlmann_N2_a[] = {1.1696, 1.0, 0.8618, 0.7562,
0.62, 0.5043, 0.441, 0.4, 0.62, 0.5043, 0.441, 0.4,
@ -92,7 +92,7 @@ static double tissue_tolerance_calc(const struct dive *dive)
double ret_tolerance_limit_ambient_pressure = 0.0; double ret_tolerance_limit_ambient_pressure = 0.0;
double gf_high = buehlmann_config.gf_high; double gf_high = buehlmann_config.gf_high;
double gf_low = buehlmann_config.gf_low; double gf_low = buehlmann_config.gf_low;
double surface = get_surface_pressure_in_mbar(dive, TRUE) / 1000.0; double surface = get_surface_pressure_in_mbar(dive, true) / 1000.0;
for (ci = 0; ci < 16; ci++) for (ci = 0; ci < 16; ci++)
{ {

12
dive.c
View file

@ -570,12 +570,12 @@ static void sanitize_cylinder_info(struct dive *dive)
static bool is_potentially_redundant(struct event *event) static bool is_potentially_redundant(struct event *event)
{ {
if (!strcmp(event->name, "gaschange")) if (!strcmp(event->name, "gaschange"))
return FALSE; return false;
if (!strcmp(event->name, "bookmark")) if (!strcmp(event->name, "bookmark"))
return FALSE; return false;
if (!strcmp(event->name, "heading")) if (!strcmp(event->name, "heading"))
return FALSE; return false;
return TRUE; return true;
} }
/* match just by name - we compare the details in the code that uses this helper */ /* match just by name - we compare the details in the code that uses this helper */
@ -760,7 +760,7 @@ static void fixup_dc_events(struct divecomputer *dc)
if (prev && prev->value == event->value && if (prev && prev->value == event->value &&
prev->flags == event->flags && prev->flags == event->flags &&
event->time.seconds - prev->time.seconds < 61) event->time.seconds - prev->time.seconds < 61)
event->deleted = TRUE; event->deleted = true;
} }
event = event->next; event = event->next;
} }
@ -1053,7 +1053,7 @@ add_sample_b:
if (as->stopdepth.mm) if (as->stopdepth.mm)
sample.stopdepth = as->stopdepth; sample.stopdepth = as->stopdepth;
if (as->in_deco) if (as->in_deco)
sample.in_deco = TRUE; sample.in_deco = true;
merge_one_sample(&sample, at, res); merge_one_sample(&sample, at, res);

16
dive.h
View file

@ -28,23 +28,7 @@
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#else #else
#if __STDC_VERSION__ >= 199901L
#include <stdbool.h> #include <stdbool.h>
#ifndef TRUE
#define TRUE true
#endif
#ifndef FALSE
#define FALSE false
#endif
#else
typedef int bool;
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#endif
#endif #endif
#define O2_IN_AIR 209 // permille #define O2_IN_AIR 209 // permille

View file

@ -43,9 +43,9 @@
#include "divelist.h" #include "divelist.h"
#include "display.h" #include "display.h"
static short dive_list_changed = FALSE; static short dive_list_changed = false;
short autogroup = FALSE; short autogroup = false;
dive_trip_t *dive_trip_list; dive_trip_t *dive_trip_list;
@ -386,9 +386,9 @@ double init_decompression(struct dive *dive)
int i, divenr = -1; int i, divenr = -1;
unsigned int surface_time; unsigned int surface_time;
timestamp_t when, lasttime = 0; timestamp_t when, lasttime = 0;
bool deco_init = FALSE; bool deco_init = false;
double tissue_tolerance, surface_pressure; double tissue_tolerance, surface_pressure;
tissue_tolerance = surface_pressure = get_surface_pressure_in_mbar(dive, TRUE) / 1000.0; tissue_tolerance = surface_pressure = get_surface_pressure_in_mbar(dive, true) / 1000.0;
if (!dive) if (!dive)
return 0.0; return 0.0;
@ -411,10 +411,10 @@ double init_decompression(struct dive *dive)
/* again skip dives from different trips */ /* again skip dives from different trips */
if (dive->divetrip && dive->divetrip != pdive->divetrip) if (dive->divetrip && dive->divetrip != pdive->divetrip)
continue; continue;
surface_pressure = get_surface_pressure_in_mbar(pdive, TRUE) / 1000.0; surface_pressure = get_surface_pressure_in_mbar(pdive, true) / 1000.0;
if (!deco_init) { if (!deco_init) {
clear_deco(surface_pressure); clear_deco(surface_pressure);
deco_init = TRUE; deco_init = true;
#if DECO_CALC_DEBUG & 2 #if DECO_CALC_DEBUG & 2
dump_tissues(); dump_tissues();
#endif #endif
@ -437,7 +437,7 @@ double init_decompression(struct dive *dive)
/* add the final surface time */ /* add the final surface time */
if (lasttime && dive->when > lasttime) { if (lasttime && dive->when > lasttime) {
surface_time = dive->when - lasttime; surface_time = dive->when - lasttime;
surface_pressure = get_surface_pressure_in_mbar(dive, TRUE) / 1000.0; surface_pressure = get_surface_pressure_in_mbar(dive, true) / 1000.0;
tissue_tolerance = add_segment(surface_pressure, &air, surface_time, 0, dive); tissue_tolerance = add_segment(surface_pressure, &air, surface_time, 0, dive);
#if DECO_CALC_DEBUG & 2 #if DECO_CALC_DEBUG & 2
printf("after surface intervall of %d:%02u\n", FRACTION(surface_time,60)); printf("after surface intervall of %d:%02u\n", FRACTION(surface_time,60));
@ -445,7 +445,7 @@ double init_decompression(struct dive *dive)
#endif #endif
} }
if (!deco_init) { if (!deco_init) {
surface_pressure = get_surface_pressure_in_mbar(dive, TRUE) / 1000.0; surface_pressure = get_surface_pressure_in_mbar(dive, true) / 1000.0;
clear_deco(surface_pressure); clear_deco(surface_pressure);
#if DECO_CALC_DEBUG & 2 #if DECO_CALC_DEBUG & 2
printf("no previous dive\n"); printf("no previous dive\n");
@ -647,7 +647,7 @@ void add_dive_to_trip(struct dive *dive, dive_trip_t *trip)
if (dive->divetrip == trip) if (dive->divetrip == trip)
return; return;
assert(trip->when); assert(trip->when);
remove_dive_from_trip(dive, FALSE); remove_dive_from_trip(dive, false);
trip->nrdives++; trip->nrdives++;
dive->divetrip = trip; dive->divetrip = trip;
dive->tripflag = ASSIGNED_TRIP; dive->tripflag = ASSIGNED_TRIP;
@ -725,7 +725,7 @@ void delete_single_dive(int idx)
struct dive *dive = get_dive(idx); struct dive *dive = get_dive(idx);
if (!dive) if (!dive)
return; /* this should never happen */ return; /* this should never happen */
remove_dive_from_trip(dive, FALSE); remove_dive_from_trip(dive, false);
if (dive->selected) if (dive->selected)
deselect_dive(idx); deselect_dive(idx);
for (i = idx; i < dive_table.nr - 1; i++) for (i = idx; i < dive_table.nr - 1; i++)
@ -768,21 +768,21 @@ bool consecutive_selected()
{ {
struct dive *d; struct dive *d;
int i; int i;
bool consecutive = TRUE; bool consecutive = true;
bool firstfound = FALSE; bool firstfound = false;
bool lastfound = FALSE; bool lastfound = false;
if (amount_selected == 0 || amount_selected == 1) if (amount_selected == 0 || amount_selected == 1)
return TRUE; return true;
for_each_dive(i, d) { for_each_dive(i, d) {
if (d->selected) { if (d->selected) {
if (!firstfound) if (!firstfound)
firstfound = TRUE; firstfound = true;
else if (lastfound) else if (lastfound)
consecutive = FALSE; consecutive = false;
} else if (firstfound) { } else if (firstfound) {
lastfound = TRUE; lastfound = true;
} }
} }
return consecutive; return consecutive;
@ -798,7 +798,7 @@ struct dive *merge_two_dives(struct dive *a, struct dive *b)
return NULL; return NULL;
i = get_divenr(a); i = get_divenr(a);
j = get_divenr(b); j = get_divenr(b);
res = merge_dives(a, b, b->when - a->when, FALSE); res = merge_dives(a, b, b->when - a->when, false);
if (!res) if (!res)
return NULL; return NULL;
@ -809,7 +809,7 @@ struct dive *merge_two_dives(struct dive *a, struct dive *b)
// why? // why?
// because this way one of the previously selected ids is still around // because this way one of the previously selected ids is still around
res->id = id; res->id = id;
mark_divelist_changed(TRUE); mark_divelist_changed(true);
return res; return res;
} }
@ -871,7 +871,7 @@ void remove_autogen_trips()
dive_trip_t *trip = dive->divetrip; dive_trip_t *trip = dive->divetrip;
if (trip && trip->autogen) if (trip && trip->autogen)
remove_dive_from_trip(dive, TRUE); remove_dive_from_trip(dive, true);
} }
} }
@ -990,7 +990,7 @@ void process_dives(bool is_imported, bool prefer_imported)
} }
/* make sure no dives are still marked as downloaded */ /* make sure no dives are still marked as downloaded */
for (i = 1; i < dive_table.nr; i++) for (i = 1; i < dive_table.nr; i++)
dive_table.dives[i]->downloaded = FALSE; dive_table.dives[i]->downloaded = false;
if (is_imported) { if (is_imported) {
/* If there are dives in the table, are they numbered */ /* If there are dives in the table, are they numbered */
@ -999,6 +999,6 @@ void process_dives(bool is_imported, bool prefer_imported)
/* did we add dives to the dive table? */ /* did we add dives to the dive table? */
if (preexisting != dive_table.nr) if (preexisting != dive_table.nr)
mark_divelist_changed(TRUE); mark_divelist_changed(true);
} }
} }

View file

@ -91,8 +91,8 @@ bool no_weightsystems(weightsystem_t *ws)
for (i = 0; i < MAX_WEIGHTSYSTEMS; i++) for (i = 0; i < MAX_WEIGHTSYSTEMS; i++)
if (!weightsystem_none(ws + i)) if (!weightsystem_none(ws + i))
return FALSE; return false;
return TRUE; return true;
} }
static bool one_weightsystem_equal(weightsystem_t *ws1, weightsystem_t *ws2) static bool one_weightsystem_equal(weightsystem_t *ws1, weightsystem_t *ws2)
@ -107,8 +107,8 @@ bool weightsystems_equal(weightsystem_t *ws1, weightsystem_t *ws2)
for (i = 0; i < MAX_WEIGHTSYSTEMS; i++) for (i = 0; i < MAX_WEIGHTSYSTEMS; i++)
if (!one_weightsystem_equal(ws1 + i, ws2 + i)) if (!one_weightsystem_equal(ws1 + i, ws2 + i))
return FALSE; return false;
return TRUE; return true;
} }
/* /*

View file

@ -70,7 +70,7 @@ static bool get_tanksize(device_data_t *devdata, const unsigned char *data, cyli
* right data */ * right data */
if (*(uint32_t *)data != 0xFFFEFFFE) { if (*(uint32_t *)data != 0xFFFEFFFE) {
printf("incorrect header for Atomics dive\n"); printf("incorrect header for Atomics dive\n");
return FALSE; return false;
} }
atomics_gas_info = (void*)(data + COBALT_HEADER); atomics_gas_info = (void*)(data + COBALT_HEADER);
switch (atomics_gas_info[idx].tankspecmethod) { switch (atomics_gas_info[idx].tankspecmethod) {
@ -90,9 +90,9 @@ static bool get_tanksize(device_data_t *devdata, const unsigned char *data, cyli
cyl[idx].type.size.mliter = atomics_gas_info[idx].tanksize * 100; cyl[idx].type.size.mliter = atomics_gas_info[idx].tanksize * 100;
break; break;
} }
return TRUE; return true;
} }
return FALSE; return false;
} }
static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t *parser, int ngases, static int parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_parser_t *parser, int ngases,
@ -247,15 +247,15 @@ sample_cb(dc_sample_type_t type, dc_sample_value_t value, void *userdata)
if (value.deco.type == DC_DECO_NDL) { if (value.deco.type == DC_DECO_NDL) {
sample->ndl.seconds = ndl = value.deco.time; sample->ndl.seconds = ndl = value.deco.time;
sample->stopdepth.mm = stopdepth = value.deco.depth * 1000.0 + 0.5; sample->stopdepth.mm = stopdepth = value.deco.depth * 1000.0 + 0.5;
sample->in_deco = in_deco = FALSE; sample->in_deco = in_deco = false;
} else if (value.deco.type == DC_DECO_DECOSTOP || } else if (value.deco.type == DC_DECO_DECOSTOP ||
value.deco.type == DC_DECO_DEEPSTOP) { value.deco.type == DC_DECO_DEEPSTOP) {
sample->in_deco = in_deco = TRUE; sample->in_deco = in_deco = true;
sample->stopdepth.mm = stopdepth = value.deco.depth * 1000.0 + 0.5; sample->stopdepth.mm = stopdepth = value.deco.depth * 1000.0 + 0.5;
sample->stoptime.seconds = stoptime = value.deco.time; sample->stoptime.seconds = stoptime = value.deco.time;
ndl = 0; ndl = 0;
} else if (value.deco.type == DC_DECO_SAFETYSTOP) { } else if (value.deco.type == DC_DECO_SAFETYSTOP) {
sample->in_deco = in_deco = FALSE; sample->in_deco = in_deco = false;
sample->stopdepth.mm = stopdepth = value.deco.depth * 1000.0 + 0.5; sample->stopdepth.mm = stopdepth = value.deco.depth * 1000.0 + 0.5;
sample->stoptime.seconds = stoptime = value.deco.time; sample->stoptime.seconds = stoptime = value.deco.time;
} }
@ -394,7 +394,7 @@ static int dive_cb(const unsigned char *data, unsigned int size,
/* reset the deco / ndl data */ /* reset the deco / ndl data */
ndl = stoptime = stopdepth = 0; ndl = stoptime = stopdepth = 0;
in_deco = FALSE; in_deco = false;
rc = create_parser(devdata, &parser); rc = create_parser(devdata, &parser);
if (rc != DC_STATUS_SUCCESS) { if (rc != DC_STATUS_SUCCESS) {
@ -511,9 +511,9 @@ static int dive_cb(const unsigned char *data, unsigned int size,
dive->dc.sample[0].temperature.mkelvin = 0; dive->dc.sample[0].temperature.mkelvin = 0;
} }
dive->downloaded = TRUE; dive->downloaded = true;
record_dive(dive); record_dive(dive);
mark_divelist_changed(TRUE); mark_divelist_changed(true);
return 1; return 1;
} }

View file

@ -134,7 +134,7 @@ struct {
const char *nickname, *serial_nr, *firmware; const char *nickname, *serial_nr, *firmware;
} dc; } dc;
} cur_settings; } cur_settings;
static bool in_settings = FALSE; static bool in_settings = false;
static struct tm cur_tm; static struct tm cur_tm;
static int cur_cylinder_index, cur_ws_index; static int cur_cylinder_index, cur_ws_index;
static int lastndl, laststoptime, laststopdepth, lastcns, lastpo2, lastindeco; static int lastndl, laststoptime, laststopdepth, lastcns, lastpo2, lastindeco;
@ -266,7 +266,7 @@ enum number_type {
static enum number_type parse_float(const char *buffer, double *res, const char **endp) static enum number_type parse_float(const char *buffer, double *res, const char **endp)
{ {
double val; double val;
static bool first_time = TRUE; static bool first_time = true;
errno = 0; errno = 0;
val = ascii_strtod(buffer, endp); val = ascii_strtod(buffer, endp);
@ -279,7 +279,7 @@ static enum number_type parse_float(const char *buffer, double *res, const char
* that information available */ * that information available */
if (first_time) { if (first_time) {
fprintf(stderr, "Floating point value with decimal comma (%s)?\n", buffer); fprintf(stderr, "Floating point value with decimal comma (%s)?\n", buffer);
first_time = FALSE; first_time = false;
} }
/* Try again in permissive mode*/ /* Try again in permissive mode*/
val = strtod_flags(buffer, endp, 0); val = strtod_flags(buffer, endp, 0);
@ -1222,12 +1222,12 @@ static void reset_dc_settings(void)
static void settings_start(void) static void settings_start(void)
{ {
in_settings = TRUE; in_settings = true;
} }
static void settings_end(void) static void settings_end(void)
{ {
in_settings = FALSE; in_settings = false;
} }
static void dc_settings_start(void) static void dc_settings_start(void)

View file

@ -50,7 +50,7 @@ void dump_plan(struct diveplan *diveplan)
void set_last_stop(bool last_stop_6m) void set_last_stop(bool last_stop_6m)
{ {
if (last_stop_6m == TRUE) if (last_stop_6m == true)
decostoplevels[1] = 6000; decostoplevels[1] = 6000;
else else
decostoplevels[1] = 3000; decostoplevels[1] = 3000;
@ -341,7 +341,7 @@ struct divedatapoint *create_dp(int time_incr, int depth, int o2, int he, int po
dp->o2 = o2; dp->o2 = o2;
dp->he = he; dp->he = he;
dp->po2 = po2; dp->po2 = po2;
dp->entered = FALSE; dp->entered = false;
dp->next = NULL; dp->next = NULL;
return dp; return dp;
} }

View file

@ -138,7 +138,7 @@ void remember_event(const char *eventname)
return; return;
} }
ev_namelist[evn_used].ev_name = strdup(eventname); ev_namelist[evn_used].ev_name = strdup(eventname);
ev_namelist[evn_used].plot_ev = TRUE; ev_namelist[evn_used].plot_ev = true;
evn_used++; evn_used++;
} }
@ -195,12 +195,12 @@ int get_cylinder_pressure_range(struct graphics_context *gc)
gc->bottomy = 0; gc->bottomy = 0;
gc->topy = gc->pi.maxpressure * 1.5; gc->topy = gc->pi.maxpressure * 1.5;
if (!gc->pi.maxpressure) if (!gc->pi.maxpressure)
return FALSE; return false;
while (gc->pi.endtempcoord <= SCALEY(gc, gc->pi.minpressure - (gc->topy) * 0.1)) while (gc->pi.endtempcoord <= SCALEY(gc, gc->pi.minpressure - (gc->topy) * 0.1))
gc->bottomy -= gc->topy * 0.1 * gc->maxy/abs(gc->maxy); gc->bottomy -= gc->topy * 0.1 * gc->maxy/abs(gc->maxy);
return TRUE; return true;
} }
@ -968,7 +968,7 @@ static void populate_pressure_information(struct dive *dive, struct divecomputer
int i, cylinderindex; int i, cylinderindex;
pr_track_t *track_pr[MAX_CYLINDERS] = {NULL, }; pr_track_t *track_pr[MAX_CYLINDERS] = {NULL, };
pr_track_t *current; pr_track_t *current;
bool missing_pr = FALSE; bool missing_pr = false;
cylinderindex = -1; cylinderindex = -1;
current = NULL; current = NULL;
@ -1051,7 +1051,7 @@ static void calculate_ndl_tts(double tissue_tolerance, struct plot_data *entry,
} }
/* We are in deco */ /* We are in deco */
entry->in_deco_calc = TRUE; entry->in_deco_calc = true;
/* Add segments for movement to stopdepth */ /* Add segments for movement to stopdepth */
for (; ascent_depth > next_stop; ascent_depth -= ascent_mm_per_step, entry->tts_calc += ascent_s_per_step) { for (; ascent_depth > next_stop; ascent_depth -= ascent_mm_per_step, entry->tts_calc += ascent_s_per_step) {
@ -1093,7 +1093,7 @@ static void calculate_ndl_tts(double tissue_tolerance, struct plot_data *entry,
static void calculate_deco_information(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool print_mode) static void calculate_deco_information(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool print_mode)
{ {
int i; int i;
double surface_pressure = (dc->surface_pressure.mbar ? dc->surface_pressure.mbar : get_surface_pressure_in_mbar(dive, TRUE)) / 1000.0; double surface_pressure = (dc->surface_pressure.mbar ? dc->surface_pressure.mbar : get_surface_pressure_in_mbar(dive, true)) / 1000.0;
double tissue_tolerance = 0; double tissue_tolerance = 0;
for (i = 1; i < pi->nr; i++) { for (i = 1; i < pi->nr; i++) {
struct plot_data *entry = pi->entry + i; struct plot_data *entry = pi->entry + i;

View file

@ -569,7 +569,7 @@ static void save_one_device(FILE *f, const char * model, uint32_t deviceid,
void save_dives(const char *filename) void save_dives(const char *filename)
{ {
save_dives_logic(filename, FALSE); save_dives_logic(filename, false);
} }
void save_dives_logic(const char *filename, const bool select_only) void save_dives_logic(const char *filename, const bool select_only)

View file

@ -126,7 +126,7 @@ void process_all_dives(struct dive *dive, struct dive **prev_dive)
memset(stats_yearly, 0, size); memset(stats_yearly, 0, size);
memset(stats_monthly, 0, size); memset(stats_monthly, 0, size);
memset(stats_by_trip, 0, size); memset(stats_by_trip, 0, size);
stats_yearly[0].is_year = TRUE; stats_yearly[0].is_year = true;
/* this relies on the fact that the dives in the dive_table /* this relies on the fact that the dives in the dive_table
* are in chronological order */ * are in chronological order */
@ -147,7 +147,7 @@ void process_all_dives(struct dive *dive, struct dive **prev_dive)
if (current_year != tm.tm_year + 1900) { if (current_year != tm.tm_year + 1900) {
current_year = tm.tm_year + 1900; current_year = tm.tm_year + 1900;
process_dive(dp, &(stats_yearly[++year_iter])); process_dive(dp, &(stats_yearly[++year_iter]));
stats_yearly[year_iter].is_year = TRUE; stats_yearly[year_iter].is_year = true;
} else { } else {
process_dive(dp, &(stats_yearly[year_iter])); process_dive(dp, &(stats_yearly[year_iter]));
} }
@ -163,12 +163,12 @@ void process_all_dives(struct dive *dive, struct dive **prev_dive)
/* stats_by_trip[0] is all the dives combined */ /* stats_by_trip[0] is all the dives combined */
stats_by_trip[0].selection_size++; stats_by_trip[0].selection_size++;
process_dive(dp, &(stats_by_trip[0])); process_dive(dp, &(stats_by_trip[0]));
stats_by_trip[0].is_trip = TRUE; stats_by_trip[0].is_trip = true;
stats_by_trip[0].location = strdup("All (by trip stats)"); stats_by_trip[0].location = strdup("All (by trip stats)");
process_dive(dp, &(stats_by_trip[trip_iter])); process_dive(dp, &(stats_by_trip[trip_iter]));
stats_by_trip[trip_iter].selection_size++; stats_by_trip[trip_iter].selection_size++;
stats_by_trip[trip_iter].is_trip = TRUE; stats_by_trip[trip_iter].is_trip = true;
stats_by_trip[trip_iter].location = dp->divetrip->location; stats_by_trip[trip_iter].location = dp->divetrip->location;
} }
@ -295,24 +295,24 @@ void get_selected_dives_text(char *buffer, int size)
static bool is_gas_used(struct dive *dive, int idx) static bool is_gas_used(struct dive *dive, int idx)
{ {
struct divecomputer *dc = &dive->dc; struct divecomputer *dc = &dive->dc;
bool firstGasExplicit = FALSE; bool firstGasExplicit = false;
if (cylinder_none(&dive->cylinder[idx])) if (cylinder_none(&dive->cylinder[idx]))
return FALSE; return false;
while (dc) { while (dc) {
struct event *event = get_next_event(dc->events, "gaschange"); struct event *event = get_next_event(dc->events, "gaschange");
while (event) { while (event) {
if (event->time.seconds < 30) if (event->time.seconds < 30)
firstGasExplicit = TRUE; firstGasExplicit = true;
if (get_cylinder_index(dive, event) == idx) if (get_cylinder_index(dive, event) == idx)
return TRUE; return true;
event = get_next_event(event->next, "gaschange"); event = get_next_event(event->next, "gaschange");
} }
dc = dc->next; dc = dc->next;
} }
if (idx == 0 && !firstGasExplicit) if (idx == 0 && !firstGasExplicit)
return TRUE; return true;
return FALSE; return false;
} }
void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS]) void get_gas_used(struct dive *dive, volume_t gases[MAX_CYLINDERS])

View file

@ -8,28 +8,28 @@ struct preferences default_prefs = {
.units = SI_UNITS, .units = SI_UNITS,
.unit_system = METRIC, .unit_system = METRIC,
.pp_graphs = { .pp_graphs = {
.po2 = FALSE, .po2 = false,
.pn2 = FALSE, .pn2 = false,
.phe = FALSE, .phe = false,
.po2_threshold = 1.6, .po2_threshold = 1.6,
.pn2_threshold = 4.0, .pn2_threshold = 4.0,
.phe_threshold = 13.0, .phe_threshold = 13.0,
}, },
.mod = FALSE, .mod = false,
.mod_ppO2 = 1.6, .mod_ppO2 = 1.6,
.ead = FALSE, .ead = false,
.profile_dc_ceiling = TRUE, .profile_dc_ceiling = true,
.profile_red_ceiling = FALSE, .profile_red_ceiling = false,
.profile_calc_ceiling = FALSE, .profile_calc_ceiling = false,
.calc_ceiling_3m_incr = FALSE, .calc_ceiling_3m_incr = false,
.calc_ndl_tts = FALSE, .calc_ndl_tts = false,
.gflow = 30, .gflow = 30,
.gfhigh = 75, .gfhigh = 75,
.gf_low_at_maxdepth = FALSE, .gf_low_at_maxdepth = false,
.font_size = 14.0, .font_size = 14.0,
.display_invalid_dives = FALSE, .display_invalid_dives = false,
.show_sac = FALSE, .show_sac = false,
.display_unused_tanks = FALSE .display_unused_tanks = false
}; };
struct units *get_units() struct units *get_units()
@ -77,7 +77,7 @@ const char *monthname(int mon)
/* /*
* track whether we switched to importing dives * track whether we switched to importing dives
*/ */
bool imported = FALSE; bool imported = false;
static void print_version() { static void print_version() {
printf("Subsurface v%s, ", VERSION_STRING); printf("Subsurface v%s, ", VERSION_STRING);
@ -116,7 +116,7 @@ void parse_argument(const char *arg)
exit(0); exit(0);
} }
if (strcmp(arg, "--import") == 0) { if (strcmp(arg, "--import") == 0) {
imported = TRUE; /* mark the dives so far as the base, * everything after is imported */ imported = true; /* mark the dives so far as the base, * everything after is imported */
return; return;
} }
if (strcmp(arg, "--verbose") == 0) { if (strcmp(arg, "--verbose") == 0) {
@ -149,7 +149,7 @@ void renumber_dives(int nr)
struct dive *dive = dive_table.dives[i]; struct dive *dive = dive_table.dives[i];
dive->number = nr + i; dive->number = nr + i;
} }
mark_divelist_changed(TRUE); mark_divelist_changed(true);
} }
/* /*

View file

@ -109,7 +109,7 @@ static void uemis_get_weight(char *buffer, weightsystem_t *weight, int diveid)
static struct dive *uemis_start_dive(uint32_t deviceid) static struct dive *uemis_start_dive(uint32_t deviceid)
{ {
struct dive *dive = alloc_dive(); struct dive *dive = alloc_dive();
dive->downloaded = TRUE; dive->downloaded = true;
dive->dc.model = strdup("Uemis Zurich"); dive->dc.model = strdup("Uemis Zurich");
dive->dc.deviceid = deviceid; dive->dc.deviceid = deviceid;
return dive; return dive;
@ -191,7 +191,7 @@ static bool uemis_init(const char *path)
int i; int i;
if (!path) if (!path)
return FALSE; return false;
/* let's check if this is indeed a Uemis DC */ /* let's check if this is indeed a Uemis DC */
reqtxt_path = build_filename(path,"req.txt"); reqtxt_path = build_filename(path,"req.txt");
reqtxt_file = subsurface_open(reqtxt_path, O_RDONLY, 0666); reqtxt_file = subsurface_open(reqtxt_path, O_RDONLY, 0666);
@ -199,7 +199,7 @@ static bool uemis_init(const char *path)
#if UEMIS_DEBUG & 1 #if UEMIS_DEBUG & 1
fprintf(debugfile, ":EE req.txt can't be opened\n"); fprintf(debugfile, ":EE req.txt can't be opened\n");
#endif #endif
return FALSE; return false;
} }
if (bytes_available(reqtxt_file) > 5) { if (bytes_available(reqtxt_file) > 5) {
char tmp[6]; char tmp[6];
@ -209,7 +209,7 @@ static bool uemis_init(const char *path)
fprintf(debugfile, "::r req.txt \"%s\"\n", tmp); fprintf(debugfile, "::r req.txt \"%s\"\n", tmp);
#endif #endif
if (sscanf(tmp + 1, "%d", &filenr) != 1) if (sscanf(tmp + 1, "%d", &filenr) != 1)
return FALSE; return false;
} else { } else {
filenr = 0; filenr = 0;
#if UEMIS_DEBUG & 2 #if UEMIS_DEBUG & 2
@ -226,7 +226,7 @@ static bool uemis_init(const char *path)
/* initialize the array in which we collect the answers */ /* initialize the array in which we collect the answers */
for (i = 0; i < NUM_PARAM_BUFS; i++) for (i = 0; i < NUM_PARAM_BUFS; i++)
param_buff[i] = ""; param_buff[i] = "";
return TRUE; return true;
} }
static void str_append_with_delim(char *s, char *t) static void str_append_with_delim(char *s, char *t)
@ -276,7 +276,7 @@ static char *next_segment(char *buf, int *offset, int size)
{ {
int i = *offset; int i = *offset;
int seg_size; int seg_size;
bool done = FALSE; bool done = false;
char *segment; char *segment;
while (!done) { while (!done) {
@ -285,10 +285,10 @@ static char *next_segment(char *buf, int *offset, int size)
(buf[i+1] == '\\' || buf[i+1] == '{')) (buf[i+1] == '\\' || buf[i+1] == '{'))
memcpy(buf + i, buf + i + 1, size - i - 1); memcpy(buf + i, buf + i + 1, size - i - 1);
else if (buf[i] == '{') else if (buf[i] == '{')
done = TRUE; done = true;
i++; i++;
} else { } else {
done = TRUE; done = true;
} }
} }
seg_size = i - *offset - 1; seg_size = i - *offset - 1;
@ -324,9 +324,9 @@ static void buffer_add(char **buffer, int *buffer_size, char *buf)
static bool next_file(int max) static bool next_file(int max)
{ {
if (filenr >= max) if (filenr >= max)
return FALSE; return false;
filenr++; filenr++;
return TRUE; return true;
} }
static char *first_object_id_val(char* buf) static char *first_object_id_val(char* buf)
@ -390,12 +390,12 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
char fl[13]; char fl[13];
char tmp[101]; char tmp[101];
const char *what = translate("gettextFromC","data"); const char *what = translate("gettextFromC","data");
bool searching = TRUE; bool searching = true;
bool assembling_mbuf = FALSE; bool assembling_mbuf = false;
bool ismulti = FALSE; bool ismulti = false;
bool found_answer = FALSE; bool found_answer = false;
bool more_files = TRUE; bool more_files = true;
bool answer_in_mbuf = FALSE; bool answer_in_mbuf = false;
char *ans_path; char *ans_path;
int ans_file; int ans_file;
int timeout = UEMIS_LONG_TIMEOUT; int timeout = UEMIS_LONG_TIMEOUT;
@ -407,7 +407,7 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
str_append_with_delim(sb, param_buff[i]); str_append_with_delim(sb, param_buff[i]);
if (! strcmp(request, "getDivelogs") || ! strcmp(request, "getDeviceData") || ! strcmp(request, "getDirectory") || if (! strcmp(request, "getDivelogs") || ! strcmp(request, "getDeviceData") || ! strcmp(request, "getDirectory") ||
! strcmp(request, "getDivespot") || ! strcmp(request, "getDive")) { ! strcmp(request, "getDivespot") || ! strcmp(request, "getDive")) {
answer_in_mbuf = TRUE; answer_in_mbuf = true;
str_append_with_delim(sb, ""); str_append_with_delim(sb, "");
if (! strcmp(request, "getDivelogs")) if (! strcmp(request, "getDivelogs"))
what = translate("gettextFromC","divelog entry id"); what = translate("gettextFromC","divelog entry id");
@ -425,11 +425,11 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
#endif #endif
if (write(reqtxt_file, sb, strlen(sb)) != strlen(sb)) { if (write(reqtxt_file, sb, strlen(sb)) != strlen(sb)) {
*error_text = translate("gettextFromC",ERR_FS_SHORT_WRITE); *error_text = translate("gettextFromC",ERR_FS_SHORT_WRITE);
return FALSE; return false;
} }
if (! next_file(number_of_files)) { if (! next_file(number_of_files)) {
*error_text = translate("gettextFromC",ERR_FS_FULL); *error_text = translate("gettextFromC",ERR_FS_FULL);
more_files = FALSE; more_files = false;
} }
trigger_response(reqtxt_file, "n", filenr, file_length); trigger_response(reqtxt_file, "n", filenr, file_length);
usleep(timeout); usleep(timeout);
@ -437,7 +437,7 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
mbuf_size = 0; mbuf_size = 0;
while (searching || assembling_mbuf) { while (searching || assembling_mbuf) {
if (import_thread_cancelled) if (import_thread_cancelled)
return FALSE; return false;
progress_bar_fraction = filenr / 4000.0; progress_bar_fraction = filenr / 4000.0;
snprintf(fl, 13, "ANS%d.TXT", filenr - 1); snprintf(fl, 13, "ANS%d.TXT", filenr - 1);
ans_path = build_filename(build_filename(path, "ANS"), fl); ans_path = build_filename(build_filename(path, "ANS"), fl);
@ -457,18 +457,18 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
#endif #endif
free(ans_path); free(ans_path);
if (tmp[0] == '1') { if (tmp[0] == '1') {
searching = FALSE; searching = false;
if (tmp[1] == 'm') { if (tmp[1] == 'm') {
assembling_mbuf = TRUE; assembling_mbuf = true;
ismulti = TRUE; ismulti = true;
} }
if (tmp[2] == 'e') if (tmp[2] == 'e')
assembling_mbuf = FALSE; assembling_mbuf = false;
if (assembling_mbuf) { if (assembling_mbuf) {
if (! next_file(number_of_files)) { if (! next_file(number_of_files)) {
*error_text = translate("gettextFromC",ERR_FS_FULL); *error_text = translate("gettextFromC",ERR_FS_FULL);
more_files = FALSE; more_files = false;
assembling_mbuf = FALSE; assembling_mbuf = false;
} }
reqtxt_file = subsurface_open(reqtxt_path, O_RDWR | O_CREAT, 0666); reqtxt_file = subsurface_open(reqtxt_path, O_RDWR | O_CREAT, 0666);
trigger_response(reqtxt_file, "n", filenr, file_length); trigger_response(reqtxt_file, "n", filenr, file_length);
@ -476,9 +476,9 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
} else { } else {
if (! next_file(number_of_files - 1)) { if (! next_file(number_of_files - 1)) {
*error_text = translate("gettextFromC",ERR_FS_FULL); *error_text = translate("gettextFromC",ERR_FS_FULL);
more_files = FALSE; more_files = false;
assembling_mbuf = FALSE; assembling_mbuf = false;
searching = FALSE; searching = false;
} }
reqtxt_file = subsurface_open(reqtxt_path, O_RDWR | O_CREAT, 0666); reqtxt_file = subsurface_open(reqtxt_path, O_RDWR | O_CREAT, 0666);
trigger_response(reqtxt_file, "r", filenr, file_length); trigger_response(reqtxt_file, "r", filenr, file_length);
@ -529,7 +529,7 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
close(ans_file); close(ans_file);
free(ans_path); free(ans_path);
} else { } else {
ismulti = FALSE; ismulti = false;
} }
#if UEMIS_DEBUG & 8 #if UEMIS_DEBUG & 8
fprintf(debugfile,":r: %s\n", buf); fprintf(debugfile,":r: %s\n", buf);
@ -537,7 +537,7 @@ static bool uemis_get_answer(const char *path, char *request, int n_param_in,
if (!answer_in_mbuf) if (!answer_in_mbuf)
for (i = 0; i < n_param_out && j < size; i++) for (i = 0; i < n_param_out && j < size; i++)
param_buff[i] = next_segment(buf, &j, size); param_buff[i] = next_segment(buf, &j, size);
found_answer = TRUE; found_answer = true;
free(buf); free(buf);
} }
#if UEMIS_DEBUG & 1 #if UEMIS_DEBUG & 1
@ -643,10 +643,10 @@ static void process_raw_buffer(uint32_t deviceid, char *inbuf, char **max_divenr
{ {
char *buf = strdup(inbuf); char *buf = strdup(inbuf);
char *tp, *bp, *tag, *type, *val; char *tp, *bp, *tag, *type, *val;
bool done = FALSE; bool done = false;
int inbuflen = strlen(inbuf); int inbuflen = strlen(inbuf);
char *endptr = buf + inbuflen; char *endptr = buf + inbuflen;
bool log = FALSE; bool log = false;
char *sections[10]; char *sections[10];
int s, nr_sections = 0; int s, nr_sections = 0;
struct dive *dive = NULL; struct dive *dive = NULL;
@ -657,7 +657,7 @@ static void process_raw_buffer(uint32_t deviceid, char *inbuf, char **max_divenr
tp = next_token(&bp); tp = next_token(&bp);
if (strcmp(tp, "divelog") == 0) { if (strcmp(tp, "divelog") == 0) {
/* this is a divelog */ /* this is a divelog */
log = TRUE; log = true;
tp = next_token(&bp); tp = next_token(&bp);
if (strcmp(tp,"1.0") != 0) { if (strcmp(tp,"1.0") != 0) {
free(buf); free(buf);
@ -720,22 +720,22 @@ static void process_raw_buffer(uint32_t deviceid, char *inbuf, char **max_divenr
parse_tag(dive, tag, val); parse_tag(dive, tag, val);
} }
if (log && ! strcmp(tag, "file_content")) if (log && ! strcmp(tag, "file_content"))
done = TRUE; done = true;
/* done with one dive (got the file_content tag), but there could be more: /* done with one dive (got the file_content tag), but there could be more:
* a '{' indicates the end of the record - but we need to see another "{{" * a '{' indicates the end of the record - but we need to see another "{{"
* later in the buffer to know that the next record is complete (it could * later in the buffer to know that the next record is complete (it could
* be a short read because of some error */ * be a short read because of some error */
if (done && ++bp < endptr && *bp != '{' && strstr(bp, "{{")) { if (done && ++bp < endptr && *bp != '{' && strstr(bp, "{{")) {
done = FALSE; done = false;
record_dive(dive); record_dive(dive);
mark_divelist_changed(TRUE); mark_divelist_changed(true);
dive = uemis_start_dive(deviceid); dive = uemis_start_dive(deviceid);
} }
} }
if (log) { if (log) {
if (dive->dc.diveid) { if (dive->dc.diveid) {
record_dive(dive); record_dive(dive);
mark_divelist_changed(TRUE); mark_divelist_changed(true);
} else { /* partial dive */ } else { /* partial dive */
free(dive); free(dive);
} }
@ -774,10 +774,10 @@ const char *do_uemis_import(const char *mountpath, short force_download)
char *deviceid = NULL; char *deviceid = NULL;
const char *result = NULL; const char *result = NULL;
char *endptr; char *endptr;
bool success, keep_number = FALSE, once = TRUE; bool success, keep_number = false, once = true;
if (dive_table.nr == 0) if (dive_table.nr == 0)
keep_number = TRUE; keep_number = true;
uemis_info(translate("gettextFromC","Init Communication")); uemis_info(translate("gettextFromC","Init Communication"));
if (! uemis_init(mountpath)) if (! uemis_init(mountpath))
return translate("gettextFromC","Uemis init failed"); return translate("gettextFromC","Uemis init failed");
@ -817,7 +817,7 @@ const char *do_uemis_import(const char *mountpath, short force_download)
if (t && atoi(t) > start) if (t && atoi(t) > start)
start = atoi(t); start = atoi(t);
free(t); free(t);
once = FALSE; once = false;
} }
/* if the user clicked cancel, exit gracefully */ /* if the user clicked cancel, exit gracefully */
if (import_thread_cancelled) if (import_thread_cancelled)
@ -856,7 +856,7 @@ const char *do_uemis_import(const char *mountpath, short force_download)
success = uemis_get_answer(mountpath, "getDive", 3, 0, &result); success = uemis_get_answer(mountpath, "getDive", 3, 0, &result);
if (mbuf) { if (mbuf) {
int divenr; int divenr;
process_raw_buffer(deviceidnr, mbuf, &newmax, FALSE, &divenr); process_raw_buffer(deviceidnr, mbuf, &newmax, false, &divenr);
if (divenr > -1 && divenr != i) { if (divenr > -1 && divenr != i) {
offset = i - divenr; offset = i - divenr;
#if UEMIS_DEBUG & 2 #if UEMIS_DEBUG & 2
@ -869,7 +869,7 @@ const char *do_uemis_import(const char *mountpath, short force_download)
if (!success || import_thread_cancelled) if (!success || import_thread_cancelled)
break; break;
} }
success = TRUE; success = true;
for (i = 0; i <= nr_divespots; i++) { for (i = 0; i <= nr_divespots; i++) {
char divespotnr[10]; char divespotnr[10];
snprintf(divespotnr, sizeof(divespotnr), "%d", i); snprintf(divespotnr, sizeof(divespotnr), "%d", i);

View file

@ -252,20 +252,20 @@ static void uemis_event(struct dive *dive, struct divecomputer *dc, struct sampl
stopdepth = rel_mbar_to_depth(u_sample->hold_depth, dive); stopdepth = rel_mbar_to_depth(u_sample->hold_depth, dive);
if ((flags[3] & 1) | (flags[5] & 2)) { if ((flags[3] & 1) | (flags[5] & 2)) {
/* deco */ /* deco */
sample->in_deco = TRUE; sample->in_deco = true;
sample->stopdepth.mm = stopdepth; sample->stopdepth.mm = stopdepth;
sample->stoptime.seconds = u_sample->hold_time *60; sample->stoptime.seconds = u_sample->hold_time *60;
sample->ndl.seconds = 0; sample->ndl.seconds = 0;
} else if (flags[0] & 128) { } else if (flags[0] & 128) {
/* safety stop - distinguished from deco stop by having /* safety stop - distinguished from deco stop by having
* both ndl and stop information */ * both ndl and stop information */
sample->in_deco = FALSE; sample->in_deco = false;
sample->stopdepth.mm = stopdepth; sample->stopdepth.mm = stopdepth;
sample->stoptime.seconds = u_sample->hold_time *60; sample->stoptime.seconds = u_sample->hold_time *60;
sample->ndl.seconds = lastndl; sample->ndl.seconds = lastndl;
} else { } else {
/* NDL */ /* NDL */
sample->in_deco = FALSE; sample->in_deco = false;
lastndl = sample->ndl.seconds = u_sample->hold_time *60; lastndl = sample->ndl.seconds = u_sample->hold_time *60;
sample->stopdepth.mm = 0; sample->stopdepth.mm = 0;
sample->stoptime.seconds = 0; sample->stoptime.seconds = 0;