summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Dirk Hohndel <dirk@hohndel.org>2018-05-11 08:25:41 -0700
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-05-14 10:13:39 -0700
commitd577467f97e262d52ed2e1d1da94c14168480844 (patch)
treecd9e3242d839efda7264a7e5063311a5735bc034 /core
parentc71a5d74135d8ebf9dce6de6633499c1c41c07ff (diff)
downloadsubsurface-d577467f97e262d52ed2e1d1da94c14168480844.tar.gz
Core: introduce new subsurface-string header
First small step to shrinking dive.h. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'core')
-rw-r--r--core/datatrak.c1
-rw-r--r--core/deco.c1
-rw-r--r--core/device.c1
-rw-r--r--core/dive.c1
-rw-r--r--core/dive.h68
-rw-r--r--core/divecomputer.cpp1
-rw-r--r--core/divelist.c1
-rw-r--r--core/divesite.c1
-rw-r--r--core/divesitehelpers.cpp1
-rw-r--r--core/file.c1
-rw-r--r--core/git-access.c1
-rw-r--r--core/import-cobalt.c1
-rw-r--r--core/import-csv.c1
-rw-r--r--core/import-divinglog.c1
-rw-r--r--core/import-shearwater.c1
-rw-r--r--core/import-suunto.c1
-rw-r--r--core/libdivecomputer.c1
-rw-r--r--core/linux.c1
-rw-r--r--core/load-git.c1
-rw-r--r--core/macos.c1
-rw-r--r--core/ostctools.c1
-rw-r--r--core/parse-xml.c1
-rw-r--r--core/parse.c1
-rw-r--r--core/planner.c1
-rw-r--r--core/prefs-macros.h1
-rw-r--r--core/profile.c1
-rw-r--r--core/qt-ble.cpp1
-rw-r--r--core/qthelper.cpp2
-rw-r--r--core/save-git.c1
-rw-r--r--core/save-xml.c1
-rw-r--r--core/strtod.c2
-rw-r--r--core/subsurface-qt/DiveObjectHelper.cpp7
-rw-r--r--core/subsurface-string.h81
-rw-r--r--core/subsurfacestartup.c1
-rw-r--r--core/uemis-downloader.c1
35 files changed, 122 insertions, 68 deletions
diff --git a/core/datatrak.c b/core/datatrak.c
index 4b9a28577..84bcf2f60 100644
--- a/core/datatrak.c
+++ b/core/datatrak.c
@@ -11,6 +11,7 @@
#include "gettext.h"
#include "datatrak.h"
#include "dive.h"
+#include "subsurface-string.h"
#include "units.h"
#include "device.h"
#include "file.h"
diff --git a/core/deco.c b/core/deco.c
index f72454b9b..5135860b8 100644
--- a/core/deco.c
+++ b/core/deco.c
@@ -20,6 +20,7 @@
#include <math.h>
#include <string.h>
#include "dive.h"
+#include "subsurface-string.h"
#include <assert.h>
#include "core/planner.h"
#include "qthelper.h"
diff --git a/core/device.c b/core/device.c
index a22815633..125c349e1 100644
--- a/core/device.c
+++ b/core/device.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include <string.h>
#include "dive.h"
+#include "subsurface-string.h"
#include "device.h"
/*
diff --git a/core/dive.c b/core/dive.c
index 00c232215..685618b91 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -7,6 +7,7 @@
#include <limits.h>
#include "gettext.h"
#include "dive.h"
+#include "subsurface-string.h"
#include "libdivecomputer.h"
#include "device.h"
#include "divelist.h"
diff --git a/core/dive.h b/core/dive.h
index 3d7eb5979..9d1805b86 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -2,6 +2,8 @@
#ifndef DIVE_H
#define DIVE_H
+// dive and dive computer related structures and helpers
+
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
@@ -13,56 +15,6 @@
#include <sys/stat.h>
#include "divesite.h"
-/* Windows has no MIN/MAX macros - so let's just roll our own */
-#define MIN(x, y) ({ \
- __typeof__(x) _min1 = (x); \
- __typeof__(y) _min2 = (y); \
- (void) (&_min1 == &_min2); \
- _min1 < _min2 ? _min1 : _min2; })
-
-#define MAX(x, y) ({ \
- __typeof__(x) _max1 = (x); \
- __typeof__(y) _max2 = (y); \
- (void) (&_max1 == &_max2); \
- _max1 > _max2 ? _max1 : _max2; })
-
-#define IS_FP_SAME(_a, _b) (fabs((_a) - (_b)) <= 0.000001 * MAX(fabs(_a), fabs(_b)))
-
-static inline bool same_string(const char *a, const char *b)
-{
- return !strcmp(a ?: "", b ?: "");
-}
-
-static inline bool same_string_caseinsensitive(const char *a, const char *b)
-{
- return !strcasecmp(a ?: "", b ?: "");
-}
-
-static inline bool empty_string(const char *s)
-{
- return !s || !*s;
-}
-
-static inline bool includes_string_caseinsensitive(const char *haystack, const char *needle)
-{
- if (!needle)
- return 1; /* every string includes the NULL string */
- if (!haystack)
- return 0; /* nothing is included in the NULL string */
- int len = strlen(needle);
- while (*haystack) {
- if (strncasecmp(haystack, needle, len))
- return 1;
- haystack++;
- }
- return 0;
-}
-
-static inline char *copy_string(const char *s)
-{
- return (s && *s) ? strdup(s) : NULL;
-}
-
#include <libxml/tree.h>
#include <libxslt/transform.h>
#include <libxslt/xsltutils.h>
@@ -230,7 +182,7 @@ struct sample // BASE TYPE BYTES UNITS RANGE
volume_t sac; // 4 ml/min predefined SAC
bool in_deco; // bool 1 y/n y/n this sample is part of deco
bool manually_entered; // bool 1 y/n y/n this sample was entered by the user,
- // not calculated when planning a dive
+ // not calculated when planning a dive
}; // Total size of structure: 57 bytes, excluding padding at end
struct divetag {
@@ -1000,25 +952,13 @@ extern void reset_cylinders(struct dive *dive, bool track_gas);
extern void dump_cylinders(struct dive *dive, bool verbose);
#endif
-/*
- * String handling.
- */
-#define STRTOD_NO_SIGN 0x01
-#define STRTOD_NO_DOT 0x02
-#define STRTOD_NO_COMMA 0x04
-#define STRTOD_NO_EXPONENT 0x08
-extern double strtod_flags(const char *str, const char **ptr, unsigned int flags);
-
-#define STRTOD_ASCII (STRTOD_NO_COMMA)
-
-#define ascii_strtod(str, ptr) strtod_flags(str, ptr, STRTOD_ASCII)
-
extern void set_userid(const char *user_id);
extern void set_informational_units(const char *units);
extern void set_git_prefs(const char *prefs);
extern char *get_dive_date_c_string(timestamp_t when);
extern void update_setpoint_events(struct dive *dive, struct divecomputer *dc);
+
#ifdef __cplusplus
}
#endif
diff --git a/core/divecomputer.cpp b/core/divecomputer.cpp
index 08b6948d4..5c9f76f00 100644
--- a/core/divecomputer.cpp
+++ b/core/divecomputer.cpp
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
#include "divecomputer.h"
#include "dive.h"
+#include "subsurface-string.h"
#include "subsurface-qt/SettingsObjectWrapper.h"
DiveComputerList dcList;
diff --git a/core/divelist.c b/core/divelist.c
index 1522cf348..ea036ee75 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -41,6 +41,7 @@
#include <libxslt/transform.h>
#include "dive.h"
+#include "subsurface-string.h"
#include "divelist.h"
#include "display.h"
#include "planner.h"
diff --git a/core/divesite.c b/core/divesite.c
index 889c94572..e3fb05966 100644
--- a/core/divesite.c
+++ b/core/divesite.c
@@ -2,6 +2,7 @@
/* divesite.c */
#include "divesite.h"
#include "dive.h"
+#include "subsurface-string.h"
#include "divelist.h"
#include "membuffer.h"
diff --git a/core/divesitehelpers.cpp b/core/divesitehelpers.cpp
index aed19eed8..30a5ac608 100644
--- a/core/divesitehelpers.cpp
+++ b/core/divesitehelpers.cpp
@@ -6,6 +6,7 @@
#include "divesitehelpers.h"
#include "divesite.h"
+#include "subsurface-string.h"
#include "helpers.h"
#include "membuffer.h"
#include <QDebug>
diff --git a/core/file.c b/core/file.c
index ec0e256dc..69454f298 100644
--- a/core/file.c
+++ b/core/file.c
@@ -10,6 +10,7 @@
#include <time.h>
#include "dive.h"
+#include "subsurface-string.h"
#include "divelist.h"
#include "file.h"
#include "git-access.h"
diff --git a/core/git-access.c b/core/git-access.c
index d8f75c4fa..5fa4beb42 100644
--- a/core/git-access.c
+++ b/core/git-access.c
@@ -17,6 +17,7 @@
#include <git2.h>
#include "dive.h"
+#include "subsurface-string.h"
#include "membuffer.h"
#include "strndup.h"
#include "qthelper.h"
diff --git a/core/import-cobalt.c b/core/import-cobalt.c
index 524ab3673..f6a983734 100644
--- a/core/import-cobalt.c
+++ b/core/import-cobalt.c
@@ -5,6 +5,7 @@
#endif
#include "dive.h"
+#include "subsurface-string.h"
#include "parse.h"
#include "divelist.h"
#include "device.h"
diff --git a/core/import-csv.c b/core/import-csv.c
index 174f7fa92..898dfdbd0 100644
--- a/core/import-csv.c
+++ b/core/import-csv.c
@@ -3,6 +3,7 @@
#include <libdivecomputer/parser.h>
#include "dive.h"
+#include "subsurface-string.h"
#include "divelist.h"
#include "file.h"
#include "parse.h"
diff --git a/core/import-divinglog.c b/core/import-divinglog.c
index 02145a631..7ddb0be46 100644
--- a/core/import-divinglog.c
+++ b/core/import-divinglog.c
@@ -5,6 +5,7 @@
#endif
#include "dive.h"
+#include "subsurface-string.h"
#include "parse.h"
#include "divelist.h"
#include "device.h"
diff --git a/core/import-shearwater.c b/core/import-shearwater.c
index 3b8410989..00a3614c8 100644
--- a/core/import-shearwater.c
+++ b/core/import-shearwater.c
@@ -5,6 +5,7 @@
#endif
#include "dive.h"
+#include "subsurface-string.h"
#include "parse.h"
#include "divelist.h"
#include "device.h"
diff --git a/core/import-suunto.c b/core/import-suunto.c
index 86298e722..c9cf1119a 100644
--- a/core/import-suunto.c
+++ b/core/import-suunto.c
@@ -5,6 +5,7 @@
#endif
#include "dive.h"
+#include "subsurface-string.h"
#include "parse.h"
#include "divelist.h"
#include "device.h"
diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c
index 603738daf..ca5f474c7 100644
--- a/core/libdivecomputer.c
+++ b/core/libdivecomputer.c
@@ -13,6 +13,7 @@
#include <fcntl.h>
#include "gettext.h"
#include "dive.h"
+#include "subsurface-string.h"
#include "device.h"
#include "divelist.h"
#include "display.h"
diff --git a/core/linux.c b/core/linux.c
index cbd71bcc8..de2e6c136 100644
--- a/core/linux.c
+++ b/core/linux.c
@@ -2,6 +2,7 @@
/* linux.c */
/* implements Linux specific functions */
#include "dive.h"
+#include "subsurface-string.h"
#include "display.h"
#include "membuffer.h"
#include <string.h>
diff --git a/core/load-git.c b/core/load-git.c
index d5a91d109..4af7221c3 100644
--- a/core/load-git.c
+++ b/core/load-git.c
@@ -20,6 +20,7 @@
#include "gettext.h"
#include "dive.h"
+#include "subsurface-string.h"
#include "divelist.h"
#include "device.h"
#include "membuffer.h"
diff --git a/core/macos.c b/core/macos.c
index d2a760863..1fcd53511 100644
--- a/core/macos.c
+++ b/core/macos.c
@@ -5,6 +5,7 @@
#include <dirent.h>
#include <fnmatch.h>
#include "dive.h"
+#include "subsurface-string.h"
#include "display.h"
#include <CoreFoundation/CoreFoundation.h>
#if !defined(__IPHONE_5_0)
diff --git a/core/ostctools.c b/core/ostctools.c
index 53dab4aaa..84ef23301 100644
--- a/core/ostctools.c
+++ b/core/ostctools.c
@@ -4,6 +4,7 @@
#include <string.h>
#include "dive.h"
+#include "subsurface-string.h"
#include "gettext.h"
#include "divelist.h"
#include "libdivecomputer.h"
diff --git a/core/parse-xml.c b/core/parse-xml.c
index 8b4830b2c..47358865b 100644
--- a/core/parse-xml.c
+++ b/core/parse-xml.c
@@ -22,6 +22,7 @@
#include "gettext.h"
#include "dive.h"
+#include "subsurface-string.h"
#include "parse.h"
#include "divelist.h"
#include "device.h"
diff --git a/core/parse.c b/core/parse.c
index d83d8e331..d6ec39a7a 100644
--- a/core/parse.c
+++ b/core/parse.c
@@ -7,6 +7,7 @@
#include <libdivecomputer/parser.h>
#include "dive.h"
+#include "subsurface-string.h"
#include "parse.h"
#include "divelist.h"
#include "device.h"
diff --git a/core/planner.c b/core/planner.c
index 93f0c233b..33a61094d 100644
--- a/core/planner.c
+++ b/core/planner.c
@@ -10,6 +10,7 @@
#include <ctype.h>
#include <string.h>
#include "dive.h"
+#include "subsurface-string.h"
#include "deco.h"
#include "divelist.h"
#include "planner.h"
diff --git a/core/prefs-macros.h b/core/prefs-macros.h
index 72d5c60b2..53361a19f 100644
--- a/core/prefs-macros.h
+++ b/core/prefs-macros.h
@@ -3,6 +3,7 @@
#define PREFSMACROS_H
#include "core/qthelper.h"
+#include "subsurface-string.h"
#define SB(V, B) s.setValue(V, (int)(B->isChecked() ? 1 : 0))
diff --git a/core/profile.c b/core/profile.c
index c5105c4f5..1bdb8e956 100644
--- a/core/profile.c
+++ b/core/profile.c
@@ -8,6 +8,7 @@
#include <assert.h>
#include "dive.h"
+#include "subsurface-string.h"
#include "display.h"
#include "divelist.h"
diff --git a/core/qt-ble.cpp b/core/qt-ble.cpp
index d54b145ba..16363de18 100644
--- a/core/qt-ble.cpp
+++ b/core/qt-ble.cpp
@@ -17,6 +17,7 @@
#include "libdivecomputer.h"
#include "core/qt-ble.h"
#include "core/btdiscovery.h"
+#include "core/subsurface-string.h"
#define BLE_TIMEOUT 12000 // 12 seconds seems like a very long time to wait
#define DEBUG_THRESHOLD 50
diff --git a/core/qthelper.cpp b/core/qthelper.cpp
index 737e424ff..b44ef7d6f 100644
--- a/core/qthelper.cpp
+++ b/core/qthelper.cpp
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: GPL-2.0
#include "qthelper.h"
+#include "subsurface-string.h"
#include "helpers.h"
+#include "subsurface-string.h"
#include "gettextfromc.h"
#include "statistics.h"
#include "membuffer.h"
diff --git a/core/save-git.c b/core/save-git.c
index dceb45902..395490d83 100644
--- a/core/save-git.c
+++ b/core/save-git.c
@@ -17,6 +17,7 @@
#include <git2.h>
#include "dive.h"
+#include "subsurface-string.h"
#include "divelist.h"
#include "device.h"
#include "membuffer.h"
diff --git a/core/save-xml.c b/core/save-xml.c
index 0f3000ace..adf9ec2f1 100644
--- a/core/save-xml.c
+++ b/core/save-xml.c
@@ -14,6 +14,7 @@
#include <fcntl.h>
#include "dive.h"
+#include "subsurface-string.h"
#include "divelist.h"
#include "device.h"
#include "membuffer.h"
diff --git a/core/strtod.c b/core/strtod.c
index f0170ac3b..74720783c 100644
--- a/core/strtod.c
+++ b/core/strtod.c
@@ -28,7 +28,7 @@
* they have locales with commas", just pass in a zero flag.
*/
#include <ctype.h>
-#include "dive.h"
+#include "subsurface-string.h"
double strtod_flags(const char *str, const char **ptr, unsigned int flags)
{
diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp
index 084da4fd3..a1cfa4540 100644
--- a/core/subsurface-qt/DiveObjectHelper.cpp
+++ b/core/subsurface-qt/DiveObjectHelper.cpp
@@ -4,9 +4,10 @@
#include <QDateTime>
#include <QTextDocument>
-#include "../qthelper.h"
-#include "../helpers.h"
-#include "../../qt-models/tankinfomodel.h"
+#include "core/qthelper.h"
+#include "core/helpers.h"
+#include "core/subsurface-string.h"
+#include "qt-models/tankinfomodel.h"
static QString EMPTY_DIVE_STRING = QStringLiteral("");
enum returnPressureSelector {START_PRESSURE, END_PRESSURE};
diff --git a/core/subsurface-string.h b/core/subsurface-string.h
new file mode 100644
index 000000000..33849e217
--- /dev/null
+++ b/core/subsurface-string.h
@@ -0,0 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef SUBSURFACE_STRING_H
+#define SUBSURFACE_STRING_H
+
+#include <stdbool.h>
+#include <string.h>
+#include <time.h>
+
+// shared generic definitions and macros
+// mostly about strings, but a couple of math macros are here as well
+
+/* Windows has no MIN/MAX macros - so let's just roll our own */
+#define MIN(x, y) ({ \
+ __typeof__(x) _min1 = (x); \
+ __typeof__(y) _min2 = (y); \
+ (void) (&_min1 == &_min2); \
+ _min1 < _min2 ? _min1 : _min2; })
+
+#define MAX(x, y) ({ \
+ __typeof__(x) _max1 = (x); \
+ __typeof__(y) _max2 = (y); \
+ (void) (&_max1 == &_max2); \
+ _max1 > _max2 ? _max1 : _max2; })
+
+#define IS_FP_SAME(_a, _b) (fabs((_a) - (_b)) <= 0.000001 * MAX(fabs(_a), fabs(_b)))
+
+// string handling
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static inline bool same_string(const char *a, const char *b)
+{
+ return !strcmp(a ?: "", b ?: "");
+}
+
+static inline bool same_string_caseinsensitive(const char *a, const char *b)
+{
+ return !strcasecmp(a ?: "", b ?: "");
+}
+
+static inline bool empty_string(const char *s)
+{
+ return !s || !*s;
+}
+
+static inline bool includes_string_caseinsensitive(const char *haystack, const char *needle)
+{
+ if (!needle)
+ return 1; /* every string includes the NULL string */
+ if (!haystack)
+ return 0; /* nothing is included in the NULL string */
+ int len = strlen(needle);
+ while (*haystack) {
+ if (strncasecmp(haystack, needle, len))
+ return 1;
+ haystack++;
+ }
+ return 0;
+}
+
+static inline char *copy_string(const char *s)
+{
+ return (s && *s) ? strdup(s) : NULL;
+}
+
+#define STRTOD_NO_SIGN 0x01
+#define STRTOD_NO_DOT 0x02
+#define STRTOD_NO_COMMA 0x04
+#define STRTOD_NO_EXPONENT 0x08
+extern double strtod_flags(const char *str, const char **ptr, unsigned int flags);
+
+#define STRTOD_ASCII (STRTOD_NO_COMMA)
+
+#define ascii_strtod(str, ptr) strtod_flags(str, ptr, STRTOD_ASCII)
+
+#ifdef __cplusplus
+}
+#endif
+#endif // SUBSURFACE_STRING_H
diff --git a/core/subsurfacestartup.c b/core/subsurfacestartup.c
index 9d7d9494b..18332742b 100644
--- a/core/subsurfacestartup.c
+++ b/core/subsurfacestartup.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0
#include "subsurfacestartup.h"
+#include "subsurface-string.h"
#include "version.h"
#include <stdbool.h>
#include <string.h>
diff --git a/core/uemis-downloader.c b/core/uemis-downloader.c
index 6ad2fcc1d..b5969f2cc 100644
--- a/core/uemis-downloader.c
+++ b/core/uemis-downloader.c
@@ -24,6 +24,7 @@
#include "libdivecomputer.h"
#include "uemis.h"
#include "divelist.h"
+#include "core/subsurface-string.h"
#define ERR_FS_ALMOST_FULL QT_TRANSLATE_NOOP("gettextFromC", "Uemis Zurich: the file system is almost full.\nDisconnect/reconnect the dive computer\nand click \'Retry\'")
#define ERR_FS_FULL QT_TRANSLATE_NOOP("gettextFromC", "Uemis Zurich: the file system is full.\nDisconnect/reconnect the dive computer\nand click Retry")