From cd5e17cf79c2f1eb896efd0436c103221de446ae Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sat, 24 Feb 2018 23:28:13 +0100 Subject: Cleanup: Unify qthelper.h and qthelperfromc.h Since all qt-helpers are defined in qthelper.cpp, there seems to be no reason to have two include files. By unifying the two files, duplication and inconsistencies are removed. The C++-only part is simply compiled away with #ifdefs. Signed-off-by: Berthold Stoeger --- core/deco.c | 4 +- core/dive.c | 2 +- core/divelist.c | 2 +- core/file.c | 2 +- core/git-access.c | 2 +- core/import-csv.c | 2 +- core/load-git.c | 5 +- core/parse-xml.c | 3 - core/planner.c | 2 +- core/plannernotes.c | 2 +- core/profile.c | 4 +- core/qthelper.h | 66 +++++++++++++++++----- core/qthelperfromc.h | 31 ---------- core/save-git.c | 2 +- core/save-html.c | 2 +- core/save-xml.c | 2 +- core/subsurfacestartup.c | 2 +- map-widget/qmlmapwidgethelper.h | 2 - .../ios/Subsurface-mobile/Subsurface-mobile.pro | 1 - 19 files changed, 65 insertions(+), 73 deletions(-) delete mode 100644 core/qthelperfromc.h diff --git a/core/deco.c b/core/deco.c index 5c8b55e24..9943d470f 100644 --- a/core/deco.c +++ b/core/deco.c @@ -22,7 +22,7 @@ #include "dive.h" #include #include "core/planner.h" -#include "qthelperfromc.h" +#include "qthelper.h" #define cube(x) (x * x * x) @@ -31,8 +31,6 @@ // was introduced in v4.6.3 this can be set to a value of 1.0 which means no correction. #define subsurface_conservatism_factor 1.0 - -extern bool in_planner(); extern int plot_depth; //! Option structure for Buehlmann decompression. diff --git a/core/dive.c b/core/dive.c index f3d5981c9..528cf9efa 100644 --- a/core/dive.c +++ b/core/dive.c @@ -10,7 +10,7 @@ #include "libdivecomputer.h" #include "device.h" #include "divelist.h" -#include "qthelperfromc.h" +#include "qthelper.h" /* one could argue about the best place to have this variable - * it's used in the UI, but it seems to make the most sense to have it diff --git a/core/divelist.c b/core/divelist.c index 1f76246c9..1522cf348 100644 --- a/core/divelist.c +++ b/core/divelist.c @@ -44,7 +44,7 @@ #include "divelist.h" #include "display.h" #include "planner.h" -#include "qthelperfromc.h" +#include "qthelper.h" #include "git-access.h" static bool dive_list_changed = false; diff --git a/core/file.c b/core/file.c index 237056bed..ec0e256dc 100644 --- a/core/file.c +++ b/core/file.c @@ -13,7 +13,7 @@ #include "divelist.h" #include "file.h" #include "git-access.h" -#include "qthelperfromc.h" +#include "qthelper.h" #include "import-csv.h" /* For SAMPLE_* */ diff --git a/core/git-access.c b/core/git-access.c index e9f17609b..d8f75c4fa 100644 --- a/core/git-access.c +++ b/core/git-access.c @@ -19,7 +19,7 @@ #include "dive.h" #include "membuffer.h" #include "strndup.h" -#include "qthelperfromc.h" +#include "qthelper.h" #include "git-access.h" #include "gettext.h" diff --git a/core/import-csv.c b/core/import-csv.c index d3f665111..174f7fa92 100644 --- a/core/import-csv.c +++ b/core/import-csv.c @@ -9,7 +9,7 @@ #include "divelist.h" #include "gettext.h" #include "import-csv.h" -#include "qthelperfromc.h" +#include "qthelper.h" #define MATCH(buffer, pattern) \ memcmp(buffer, pattern, strlen(pattern)) diff --git a/core/load-git.c b/core/load-git.c index ef28498f2..cfb4a721b 100644 --- a/core/load-git.c +++ b/core/load-git.c @@ -24,7 +24,7 @@ #include "device.h" #include "membuffer.h" #include "git-access.h" -#include "qthelperfromc.h" +#include "qthelper.h" const char *saved_git_id = NULL; @@ -173,9 +173,6 @@ static int get_index(const char *line) static int get_hex(const char *line) { return strtoul(line, NULL, 16); } -/* this is in qthelper.cpp, so including the .h file is a pain */ -extern const char *printGPSCoords(int lat, int lon); - static void parse_dive_gps(char *line, struct membuffer *str, void *_dive) { (void) str; diff --git a/core/parse-xml.c b/core/parse-xml.c index d211921de..6564bdefd 100644 --- a/core/parse-xml.c +++ b/core/parse-xml.c @@ -1102,9 +1102,6 @@ static void gps_location(char *buffer, struct dive_site *ds) ds->longitude = parse_degrees(end, &end); } -/* this is in qthelper.cpp, so including the .h file is a pain */ -extern const char *printGPSCoords(int lat, int lon); - static void gps_in_dive(char *buffer, struct dive *dive) { char *end; diff --git a/core/planner.c b/core/planner.c index 3a66f2bfa..b4b842fcf 100644 --- a/core/planner.c +++ b/core/planner.c @@ -15,7 +15,7 @@ #include "planner.h" #include "gettext.h" #include "libdivecomputer/parser.h" -#include "qthelperfromc.h" +#include "qthelper.h" #include "version.h" #define TIMESTEP 2 /* second */ diff --git a/core/plannernotes.c b/core/plannernotes.c index 863df5f79..44e470948 100644 --- a/core/plannernotes.c +++ b/core/plannernotes.c @@ -15,7 +15,7 @@ #include "planner.h" #include "gettext.h" #include "libdivecomputer/parser.h" -#include "qthelperfromc.h" +#include "qthelper.h" #include "version.h" int diveplan_duration(struct diveplan *diveplan) diff --git a/core/profile.c b/core/profile.c index 373fb9640..4ea6d3a69 100644 --- a/core/profile.c +++ b/core/profile.c @@ -17,7 +17,7 @@ #include "libdivecomputer/parser.h" #include "libdivecomputer/version.h" #include "membuffer.h" -#include "qthelperfromc.h" +#include "qthelper.h" //#define DEBUG_GAS 1 @@ -30,8 +30,6 @@ unsigned int dc_number = 0; static struct plot_data *last_pi_entry_new = NULL; void populate_pressure_information(struct dive *, struct divecomputer *, struct plot_info *, int); -extern bool in_planner(); - #ifdef DEBUG_PI /* debugging tool - not normally used */ static void dump_pi(struct plot_info *pi) diff --git a/core/qthelper.h b/core/qthelper.h index c5aef1dd1..f86b5499b 100644 --- a/core/qthelper.h +++ b/core/qthelper.h @@ -2,19 +2,25 @@ #ifndef QTHELPER_H #define QTHELPER_H -#include -#include #include #include "dive.h" #include "divelist.h" + +// 1) Types + +enum inertgas {N2, HE}; + +// 2) Functions visible only to C++ parts + +#ifdef __cplusplus + +#include +#include #include #include - QString weight_string(int weight_in_grams); QString distance_string(int distanceInMeters); bool gpsHasChanged(struct dive *dive, struct dive *master, const QString &gps_text, bool *parsed_out = 0); -extern "C" const char *printGPSCoords(int lat, int lon); -extern "C" const char *get_current_date(); QList getDivesInTrip(dive_trip_t *trip); QString get_gas_string(struct gasmix gas); QString get_divepoint_gas_string(struct dive *d, const divedatapoint& dp); @@ -28,7 +34,6 @@ void hashPicture(struct picture *picture); QString localFilePath(const QString originalFilename); QString fileFromHash(const char *hash); void learnHash(struct picture *picture, QByteArray hash); -extern "C" void cache_picture(struct picture *picture); weight_t string_to_weight(const char *str); depth_t string_to_depth(const char *str); pressure_t string_to_pressure(const char *str); @@ -38,17 +43,48 @@ int getCloudURL(QString &filename); bool parseGpsText(const QString &gps_text, double *latitude, double *longitude); QByteArray getCurrentAppState(); void setCurrentAppState(QByteArray state); -extern "C" bool in_planner(); -extern "C" enum deco_mode decoMode(); -extern "C" void subsurface_mkdir(const char *dir); void init_proxy(); QString getUUID(); QStringList imageExtensionFilters(); char *intdup(int index); -extern "C" int parse_seabear_header(const char *filename, char **params, int pnr); -enum inertgas {N2, HE}; -extern "C" double cache_value(int tissue, int timestep, enum inertgas gas); -extern "C" void cache_insert(int tissue, int timestep, enum inertgas gas, double value); -extern "C" void lock_planner(); -extern "C" void unlock_planner(); +#endif + +// 3) Functions visible to C and C++ + +#ifdef __cplusplus +extern "C" { +#endif + +const char *printGPSCoords(int lat, int lon); +bool in_planner(); +bool getProxyString(char **buffer); +bool canReachCloudServer(); +void updateWindowTitle(); +void subsurface_mkdir(const char *dir); +char *get_file_name(const char *fileName); +void copy_image_and_overwrite(const char *cfileName, const char *path, const char *cnewName); +char *hashstring(const char *filename); +bool picture_exists(struct picture *picture); +char *move_away(const char *path); +const char *local_file_path(struct picture *picture); +void savePictureLocal(struct picture *picture, const char *data, int len); +void cache_picture(struct picture *picture); +char *cloud_url(); +char *hashfile_name_string(); +char *picturedir_string(); +const char *subsurface_user_agent(); +enum deco_mode decoMode(); +int parse_seabear_header(const char *filename, char **params, int pnr); +const char *get_current_date(); +double cache_value(int tissue, int timestep, enum inertgas gas); +void cache_insert(int tissue, int timestep, enum inertgas gas, double value); +void print_qt_versions(); +void lock_planner(); +void unlock_planner(); + +#ifdef __cplusplus +} +#endif + + #endif // QTHELPER_H diff --git a/core/qthelperfromc.h b/core/qthelperfromc.h deleted file mode 100644 index 631596110..000000000 --- a/core/qthelperfromc.h +++ /dev/null @@ -1,31 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -#ifndef QTHELPERFROMC_H -#define QTHELPERFROMC_H - -bool getProxyString(char **buffer); -bool canReachCloudServer(); -void updateWindowTitle(); -void subsurface_mkdir(const char *dir); -char *get_file_name(const char *fileName); -void copy_image_and_overwrite(const char *cfileName, const char *path, const char *cnewName); -char *hashstring(char *filename); -bool picture_exists(struct picture *picture); -char *move_away(const char *path); -const char *local_file_path(struct picture *picture); -void savePictureLocal(struct picture *picture, const char *data, int len); -void cache_picture(struct picture *picture); -char *cloud_url(); -char *hashfile_name_string(); -char *picturedir_string(); -const char *subsurface_user_agent(); -enum deco_mode decoMode(); -int parse_seabear_header(const char *filename, char **params, int pnr); -extern const char *get_current_date(); -enum inertgas {N2, HE}; -double cache_value(int tissue, int timestep, enum inertgas gas); -void cache_insert(int tissue, int timestep, enum inertgas gas, double value); -void print_qt_versions(); -void lock_planner(); -void unlock_planner(); - -#endif // QTHELPERFROMC_H diff --git a/core/save-git.c b/core/save-git.c index 1c68e9652..dceb45902 100644 --- a/core/save-git.c +++ b/core/save-git.c @@ -22,7 +22,7 @@ #include "membuffer.h" #include "git-access.h" #include "version.h" -#include "qthelperfromc.h" +#include "qthelper.h" #include "gettext.h" #define VA_BUF(b, fmt) do { va_list args; va_start(args, fmt); put_vformat(b, fmt, args); va_end(args); } while (0) diff --git a/core/save-html.c b/core/save-html.c index 6a50868ec..1825c51a1 100644 --- a/core/save-html.c +++ b/core/save-html.c @@ -5,7 +5,7 @@ #endif #include "save-html.h" -#include "qthelperfromc.h" +#include "qthelper.h" #include "gettext.h" #include "stdio.h" diff --git a/core/save-xml.c b/core/save-xml.c index 2a1b31d12..0f3000ace 100644 --- a/core/save-xml.c +++ b/core/save-xml.c @@ -19,7 +19,7 @@ #include "membuffer.h" #include "strndup.h" #include "git-access.h" -#include "qthelperfromc.h" +#include "qthelper.h" /* * We're outputting utf8 in xml. diff --git a/core/subsurfacestartup.c b/core/subsurfacestartup.c index d4d191072..1f71d2117 100644 --- a/core/subsurfacestartup.c +++ b/core/subsurfacestartup.c @@ -4,7 +4,7 @@ #include #include #include "gettext.h" -#include "qthelperfromc.h" +#include "qthelper.h" #include "git-access.h" #include "libdivecomputer/version.h" diff --git a/map-widget/qmlmapwidgethelper.h b/map-widget/qmlmapwidgethelper.h index 22388e237..58f7c4dad 100644 --- a/map-widget/qmlmapwidgethelper.h +++ b/map-widget/qmlmapwidgethelper.h @@ -49,6 +49,4 @@ signals: void pluginObjectChanged(); }; -extern "C" const char *printGPSCoords(int lat, int lon); - #endif diff --git a/packaging/ios/Subsurface-mobile/Subsurface-mobile.pro b/packaging/ios/Subsurface-mobile/Subsurface-mobile.pro index 985cf2bfc..2cd294870 100644 --- a/packaging/ios/Subsurface-mobile/Subsurface-mobile.pro +++ b/packaging/ios/Subsurface-mobile/Subsurface-mobile.pro @@ -137,7 +137,6 @@ HEADERS += \ ../../../core/save-html.h \ ../../../core/statistics.h \ ../../../core/units.h \ - ../../../core/qthelperfromc.h \ ../../../core/version.h \ ../../../core/planner.h \ ../../../core/divesite.h \ -- cgit v1.2.3-70-g09d2