mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-12 13:36:16 +00:00
Cleanup: move parse_location() declaration into header file
The parse_location() function was used in three places. In two of them, the declaration was in the translation unit. Instead, move the declaration into a header file, to avoid duplication and the possibility of inconsistencies. The "units.h" header was chosen as this is where location_t is defined. Moreover, make the string argument to parse_location() "const char *", so that it can be used on non-owned buffers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
ae6f17af0c
commit
6586ba5579
4 changed files with 7 additions and 8 deletions
|
@ -570,8 +570,6 @@ static void set_dc_serial(struct divecomputer *dc, const char *serial)
|
||||||
dc->deviceid = calculate_string_hash(serial);
|
dc->deviceid = calculate_string_hash(serial);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern void parse_location(char *, location_t *);
|
|
||||||
|
|
||||||
static void parse_string_field(device_data_t *devdata, struct dive *dive, dc_field_string_t *str)
|
static void parse_string_field(device_data_t *devdata, struct dive *dive, dc_field_string_t *str)
|
||||||
{
|
{
|
||||||
// Our dive ID is the string hash of the "Dive ID" string
|
// Our dive ID is the string hash of the "Dive ID" string
|
||||||
|
|
|
@ -31,7 +31,6 @@ struct keyword_action {
|
||||||
};
|
};
|
||||||
#define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0]))
|
#define ARRAY_SIZE(array) (sizeof(array)/sizeof(array[0]))
|
||||||
|
|
||||||
extern void parse_location(char *buf, location_t *);
|
|
||||||
git_blob *git_tree_entry_blob(git_repository *repo, const git_tree_entry *entry);
|
git_blob *git_tree_entry_blob(git_repository *repo, const git_tree_entry *entry);
|
||||||
|
|
||||||
static char *get_utf8(struct membuffer *b)
|
static char *get_utf8(struct membuffer *b)
|
||||||
|
|
|
@ -1088,7 +1088,7 @@ static int uddf_dive_match(struct dive *dive, const char *name, char *buf, struc
|
||||||
* We don't do exponentials etc, if somebody does
|
* We don't do exponentials etc, if somebody does
|
||||||
* GPS locations in that format, they are insane.
|
* GPS locations in that format, they are insane.
|
||||||
*/
|
*/
|
||||||
static degrees_t parse_degrees(char *buf, char **end)
|
static degrees_t parse_degrees(const char *buf, const char **end)
|
||||||
{
|
{
|
||||||
int sign = 1, decimals = 6, value = 0;
|
int sign = 1, decimals = 6, value = 0;
|
||||||
degrees_t ret;
|
degrees_t ret;
|
||||||
|
@ -1133,7 +1133,7 @@ static degrees_t parse_degrees(char *buf, char **end)
|
||||||
|
|
||||||
static void gps_lat(char *buffer, struct dive *dive, struct parser_state *state)
|
static void gps_lat(char *buffer, struct dive *dive, struct parser_state *state)
|
||||||
{
|
{
|
||||||
char *end;
|
const char *end;
|
||||||
location_t location = { };
|
location_t location = { };
|
||||||
struct dive_site *ds = get_dive_site_for_dive(dive);
|
struct dive_site *ds = get_dive_site_for_dive(dive);
|
||||||
|
|
||||||
|
@ -1149,7 +1149,7 @@ static void gps_lat(char *buffer, struct dive *dive, struct parser_state *state)
|
||||||
|
|
||||||
static void gps_long(char *buffer, struct dive *dive, struct parser_state *state)
|
static void gps_long(char *buffer, struct dive *dive, struct parser_state *state)
|
||||||
{
|
{
|
||||||
char *end;
|
const char *end;
|
||||||
location_t location = { };
|
location_t location = { };
|
||||||
struct dive_site *ds = get_dive_site_for_dive(dive);
|
struct dive_site *ds = get_dive_site_for_dive(dive);
|
||||||
|
|
||||||
|
@ -1164,9 +1164,9 @@ static void gps_long(char *buffer, struct dive *dive, struct parser_state *state
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We allow either spaces or a comma between the decimal degrees */
|
/* We allow either spaces or a comma between the decimal degrees */
|
||||||
void parse_location(char *buffer, location_t *loc)
|
void parse_location(const char *buffer, location_t *loc)
|
||||||
{
|
{
|
||||||
char *end;
|
const char *end;
|
||||||
loc->lat = parse_degrees(buffer, &end);
|
loc->lat = parse_degrees(buffer, &end);
|
||||||
if (*end == ',') end++;
|
if (*end == ',') end++;
|
||||||
loc->lon = parse_degrees(end, &end);
|
loc->lon = parse_degrees(end, &end);
|
||||||
|
|
|
@ -137,6 +137,8 @@ typedef struct pos {
|
||||||
degrees_t lat, lon;
|
degrees_t lat, lon;
|
||||||
} location_t;
|
} location_t;
|
||||||
|
|
||||||
|
extern void parse_location(const char *, location_t *);
|
||||||
|
|
||||||
static inline bool has_location(const location_t *loc)
|
static inline bool has_location(const location_t *loc)
|
||||||
{
|
{
|
||||||
return loc->lat.udeg || loc->lon.udeg;
|
return loc->lat.udeg || loc->lon.udeg;
|
||||||
|
|
Loading…
Add table
Reference in a new issue