aboutsummaryrefslogtreecommitdiffstats
path: root/common-address.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2021-04-05 22:25:05 +0200
committerMattias Andrée <maandree@kth.se>2021-04-05 22:25:05 +0200
commitb843dec3932b5904af4a019f75d05ba8e0bdf191 (patch)
tree02868d4f6def9a26dae77dfbd0eaafdc3afe6250 /common-address.c
parentAdd find-contact-by-address and get-contact-addresses (diff)
downloadcontacts-b843dec3932b5904af4a019f75d05ba8e0bdf191.tar.gz
contacts-b843dec3932b5904af4a019f75d05ba8e0bdf191.tar.bz2
contacts-b843dec3932b5904af4a019f75d05ba8e0bdf191.tar.xz
m + add set-contact-addresses + use -n instead of -l for country
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'common-address.c')
-rw-r--r--common-address.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/common-address.c b/common-address.c
index 8ad8712..2f66208 100644
--- a/common-address.c
+++ b/common-address.c
@@ -3,7 +3,7 @@
int
-parse_coord(char *s, double *lat_min, double *lat_max, double *lon_min, double *lon_max)
+parse_coord(char *s, double *lat, double *lat_min, double *lat_max, double *lon, double *lon_min, double *lon_max)
{
int withsign = 0, neg;
long int tmp;
@@ -12,6 +12,7 @@ parse_coord(char *s, double *lat_min, double *lat_max, double *lon_min, double *
errno = 0;
if (s[0] == ':') {
+ *lat = 0;
*lat_min = -90;
*lat_max = +90;
} else {
@@ -25,24 +26,24 @@ parse_coord(char *s, double *lat_min, double *lat_max, double *lon_min, double *
if (errno || tmp > INT_MAX)
return -1;
}
- *lat_min = (double)tmp;
+ *lat = (double)tmp;
if (s[0] == '.') {
for (s++; isdigit(*s); s++) {
- *lat_min *= 10;
- *lat_min += (double)(*s & 15);
+ *lat *= 10;
+ *lat += (double)(*s & 15);
prec *= 10;
}
- *lat_min /= prec;
+ *lat /= prec;
}
if (!withsign && (s[0] == 'N' || s[0] == 'S')) {
neg = s[0] == 'S';
s = &s[1];
}
if (neg)
- *lat_min = -*lat_min;
+ *lat = -*lat;
prec = (1 / prec) / 2;
- *lat_max = *lat_min + prec;
- *lat_min -= prec;
+ *lat_min = *lat - prec;
+ *lat_max = *lat + prec;
if (s[0] != ':')
return -1;
}
@@ -50,6 +51,7 @@ parse_coord(char *s, double *lat_min, double *lat_max, double *lon_min, double *
s = &s[1];
if (!s[0]) {
+ *lon = 0;
*lon_min = -180;
*lon_max = +180;
} else {
@@ -63,24 +65,24 @@ parse_coord(char *s, double *lat_min, double *lat_max, double *lon_min, double *
if (errno || tmp > INT_MAX)
return -1;
}
- *lon_min = (double)tmp;
+ *lon = (double)tmp;
if (s[0] == '.') {
for (s++; isdigit(*s); s++) {
- *lon_min *= 10;
- *lon_min += (double)(*s & 15);
+ *lon *= 10;
+ *lon += (double)(*s & 15);
prec *= 10;
}
- *lon_min /= prec;
+ *lon /= prec;
}
if (!withsign && (s[0] == 'E' || s[0] == 'W')) {
neg = s[0] == 'W';
s = &s[1];
}
if (neg)
- *lon_min = -*lon_min;
+ *lon = -*lon;
prec = (1 / prec) / 2;
- *lon_max = *lon_min + prec;
- *lon_min -= prec;
+ *lon_min = *lon - prec;
+ *lon_max = *lon + prec;
if (s[0])
return -1;
}