From 82ba236859b8bc7552462f6cc5dfd3d28c758795 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 10 Mar 2024 16:35:53 +0100 Subject: [PATCH] core: port save-html.c to C++ Signed-off-by: Berthold Stoeger --- Subsurface-mobile.pro | 2 +- core/CMakeLists.txt | 2 +- core/{save-html.c => save-html.cpp} | 24 ++++++++++++------------ 3 files changed, 14 insertions(+), 14 deletions(-) rename core/{save-html.c => save-html.cpp} (97%) diff --git a/Subsurface-mobile.pro b/Subsurface-mobile.pro index b604f4858..cb9652ed9 100644 --- a/Subsurface-mobile.pro +++ b/Subsurface-mobile.pro @@ -73,7 +73,7 @@ SOURCES += subsurface-mobile-main.cpp \ core/import-cobalt.cpp \ core/import-divinglog.cpp \ core/import-csv.cpp \ - core/save-html.c \ + core/save-html.cpp \ core/statistics.c \ core/worldmap-save.cpp \ core/libdivecomputer.cpp \ diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 5e07de60c..9b177167f 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -156,7 +156,7 @@ set(SUBSURFACE_CORE_LIB_SRCS sample.cpp sample.h save-git.cpp - save-html.c + save-html.cpp save-html.h save-profiledata.c save-xml.cpp diff --git a/core/save-html.c b/core/save-html.cpp similarity index 97% rename from core/save-html.c rename to core/save-html.cpp index acbec067a..13dd66c65 100644 --- a/core/save-html.c +++ b/core/save-html.cpp @@ -36,7 +36,7 @@ static void save_photos(struct membuffer *b, const char *photos_dir, struct dive if (dive->pictures.nr <= 0) return; - char *separator = "\"photos\":["; + const char *separator = "\"photos\":["; FOR_EACH_PICTURE(dive) { put_string(b, separator); separator = ", "; @@ -54,7 +54,7 @@ static void write_divecomputers(struct membuffer *b, struct dive *dive) { put_string(b, "\"divecomputers\":["); struct divecomputer *dc; - char *separator = ""; + const char *separator = ""; for_each_dc (dive, dc) { put_string(b, separator); separator = ", "; @@ -87,7 +87,7 @@ static void put_HTML_bookmarks(struct membuffer *b, struct dive *dive) if (!ev) return; - char *separator = "\"events\":["; + const char *separator = "\"events\":["; do { put_string(b, separator); separator = ", "; @@ -110,7 +110,7 @@ static void put_weightsystem_HTML(struct membuffer *b, struct dive *dive) put_string(b, "\"Weights\":["); - char *separator = ""; + const char *separator = ""; for (i = 0; i < nr; i++) { weightsystem_t ws = dive->weightsystems.weightsystems[i]; @@ -130,7 +130,7 @@ static void put_weightsystem_HTML(struct membuffer *b, struct dive *dive) static void put_cylinder_HTML(struct membuffer *b, struct dive *dive) { int i, nr; - char *separator = "\"Cylinders\":["; + const char *separator = "\"Cylinders\":["; nr = nr_cylinders(dive); if (!nr) @@ -143,7 +143,7 @@ static void put_cylinder_HTML(struct membuffer *b, struct dive *dive) write_attribute(b, "Type", cylinder->type.description, ", "); if (cylinder->type.size.mliter) { int volume = cylinder->type.size.mliter; - if (prefs.units.volume == CUFT && cylinder->type.workingpressure.mbar) + if (prefs.units.volume == units::CUFT && cylinder->type.workingpressure.mbar) volume = lrint(volume * bar_to_atm(cylinder->type.workingpressure.mbar / 1000.0)); put_HTML_volume_units(b, volume, "\"Size\":\"", " \", "); } else { @@ -187,7 +187,7 @@ static void put_HTML_samples(struct membuffer *b, struct dive *dive) if (!dive->dc.samples) return; - char *separator = "\"samples\":["; + const char *separator = "\"samples\":["; for (i = 0; i < dive->dc.samples; i++) { put_format(b, "%s[%d,%d,%d,%d]", separator, s->time.seconds, s->depth.mm, s->pressure[0].mbar, s->temperature.mkelvin); separator = ", "; @@ -292,11 +292,11 @@ void put_HTML_depth(struct membuffer *b, struct dive *dive, const char *pre, con value = get_depth_units(dive->maxdepth.mm, NULL, &unit); switch (units_p->length) { - case METERS: + case units::METERS: default: put_format(b, "%s%.1f %s%s", pre, value, unit, post); break; - case FEET: + case units::FEET: put_format(b, "%s%.0f %s%s", pre, value, unit, post); break; } @@ -336,7 +336,7 @@ static void put_HTML_tags(struct membuffer *b, struct dive *dive, const char *pr if (!tag) put_string(b, "[\"--\""); - char *separator = "["; + const char *separator = "["; while (tag) { put_format(b, "%s\"", separator); separator = ", "; @@ -393,7 +393,7 @@ static void write_no_trip(struct membuffer *b, int *dive_no, bool selected_only, { int i; struct dive *dive; - char *separator = ""; + const char *separator = ""; bool found_sel_dive = 0; for_each_dive (i, dive) { @@ -419,7 +419,7 @@ static void write_no_trip(struct membuffer *b, int *dive_no, bool selected_only, static void write_trip(struct membuffer *b, dive_trip_t *trip, int *dive_no, bool selected_only, const char *photos_dir, const bool list_only, char *sep) { struct dive *dive; - char *separator = ""; + const char *separator = ""; bool found_sel_dive = 0; for (int i = 0; i < trip->dives.nr; i++) {