limestone

A KDE marble commandline interface.
git clone git://r-36.net/limestone
Log | Files | Refs | LICENSE

commit 94b54d915f62c5335f9dce047ab7337f4d9fefec
parent 4b97facdcdc9e8f09dd65c2eaf3307d7231bdd06
Author: Christoph Lohmann <20h@r-36.net>
Date:   Thu, 23 Oct 2014 17:09:29 +0200

Support the marble "copy coordinates" format.

The parseposition() function now tries some heuristics to detect if the
position is copied from marble. For now only the decimal format is supported.

Diffstat:
limestone.cpp | 45++++++++++++++++++++++++++++++++++++---------
1 file changed, 36 insertions(+), 9 deletions(-)

diff --git a/limestone.cpp b/limestone.cpp @@ -26,24 +26,54 @@ using namespace Marble; int parseposition(char *s, float *lat, float *lon, float *alt) { - char *s1 = NULL, *s2 = NULL; + char *sb = NULL, *s1 = NULL, *s2 = NULL, *sd = NULL, + *sd1 = NULL; int isgood = 0; + sb = s; + for (; *sb == ' '; sb++); + + sd = strstr(sb, "°"); s1 = strchr(s, ','); + if (sd > s1) { + *s1 = '.'; + s1 = strchr(sb, ','); + } + if (s1 != NULL) { *s1++ = '\0'; + for (; *s1 == ' '; s1++); s2 = strchr(s1, ','); + sd1 = strstr(s1, "°"); } - if (s2 != NULL) + + if (sd1 > s2) { + *s2 = '.'; + s2 = strchr(s2, ','); + } + + if (s2 != NULL) { *s2++ = '\0'; + for (; *s2 == ' '; s2++); + } if (lon != NULL) { - *lon = strtof(s, NULL); + *lon = strtof(sb, NULL); isgood++; + if (sd != NULL) { + for (; *sd != 'W' && *sd != 'E' && *sd; sd++); + if (*sd == 'W') + *lon *= -1; + } } if (lat != NULL && s1 != NULL) { *lat = strtof(s1, NULL); isgood++; + if (sd1 != NULL) { + for (; *sd1 != 'S' && *sd1 != 'N' && *sd1; sd1++); + if (*sd1 == 'S') + *lat *= -1; + } } if (alt != NULL && s2 != NULL) *alt = strtof(s2, NULL); @@ -61,7 +91,7 @@ applystylestring(MarbleWidget *mw, char *sstr) if (ss == NULL) return; - while(*ss) { + while (*ss) { if (*ss >= 'A' && *ss <= 'Z') { *ss = (*ss) - 'A' + 'a'; sv = true; @@ -181,6 +211,8 @@ main(int argc, char *argv[]) char *winid = NULL; + setlocale(LC_NUMERIC, "C"); + ARGBEGIN { case 'h': case 'v': @@ -207,8 +239,6 @@ main(int argc, char *argv[]) break; } ARGEND; - setlocale(LC_NUMERIC, "C"); - if (argc > 0) uri = argv[0]; @@ -217,9 +247,6 @@ main(int argc, char *argv[]) uscheme = qurl.scheme().toUtf8().data(); upath = qurl.path().toUtf8().data(); - printf("scheme: %s\n", uscheme); - printf("path: %s\n", upath); - if (!strncmp(uri, "worldview:", 10)) { if (parseposition(upath+1, &lat, &lon, &alt)) usage();