summaryrefslogtreecommitdiff
path: root/navit/tools
diff options
context:
space:
mode:
authorJoseph Herlant <herlantj@gmail.com>2018-05-25 22:06:51 -0700
committerJoseph Herlant <aerostitch@users.noreply.github.com>2018-05-25 22:17:50 -0700
commit8a76acb966f7059caf9d72c853175bd923b1e9d7 (patch)
tree1735178f7a0718831b88d2c36ea18a9955de3224 /navit/tools
parent032f15287b472f1a4b5349533f3e5b468684b281 (diff)
downloadnavit-8a76acb966f7059caf9d72c853175bd923b1e9d7.tar.gz
cleanup:global:Use astyle to reformat everything
Diffstat (limited to 'navit/tools')
-rw-r--r--navit/tools/gpx2navit_txt/src/elementControl.c242
-rw-r--r--navit/tools/gpx2navit_txt/src/geod_for.c138
-rw-r--r--navit/tools/gpx2navit_txt/src/geod_inv.c81
-rw-r--r--navit/tools/gpx2navit_txt/src/geod_set.c127
-rw-r--r--navit/tools/gpx2navit_txt/src/main.c497
-rw-r--r--navit/tools/gpx2navit_txt/src/misc.c128
-rw-r--r--navit/tools/gpx2navit_txt/src/parser.c121
-rw-r--r--navit/tools/gpx2navit_txt/src/setmeta.c29
-rw-r--r--navit/tools/gpx2navit_txt/src/setpath.c198
-rw-r--r--navit/tools/gpx2navit_txt/src/setwpt.c37
-rw-r--r--navit/tools/gpx2navit_txt/src/utils.c135
-rw-r--r--navit/tools/latlon2bookmark/latlon2bookmark.c130
12 files changed, 905 insertions, 958 deletions
diff --git a/navit/tools/gpx2navit_txt/src/elementControl.c b/navit/tools/gpx2navit_txt/src/elementControl.c
index 924e10803..fcc269e44 100644
--- a/navit/tools/gpx2navit_txt/src/elementControl.c
+++ b/navit/tools/gpx2navit_txt/src/elementControl.c
@@ -20,7 +20,7 @@
#include "gpx2navit_txt.h"
void startElementControl(parsedata * pdata, const char *element,
- const char **attr);
+ const char **attr);
void endElementControl(parsedata * pdata, const char *element);
/*
@@ -29,64 +29,63 @@ void endElementControl(parsedata * pdata, const char *element);
*/
void
startElementControl(parsedata * pdata, const char *element,
- const char **attr)
-{
+ const char **attr) {
int i;
static int isFirstTrk = 1;
static int isFirstRte = 1;
static int isFirstPathpt = 1;
for (i = 0; attr[i]; i += 2) {
- if (!strcmp(attr[i], "lon")) {
- pdata->attr->lon = atof(attr[i + 1]);
- }
- if (!strcmp(attr[i], "lat")) {
- pdata->attr->lat = atof(attr[i + 1]);
- }
- if (!strcmp(attr[i], "minlon")) {
- pdata->attr->minlon = atof(attr[i + 1]);
- }
- if (!strcmp(attr[i], "minlat")) {
- pdata->attr->minlat = atof(attr[i + 1]);
- }
- if (!strcmp(attr[i], "maxlon")) {
- pdata->attr->maxlon = atof(attr[i + 1]);
- }
- if (!strcmp(attr[i], "maxlat")) {
- pdata->attr->maxlat = atof(attr[i + 1]);
- }
- if (!strcmp(attr[i], "author")) {
- strcpy(pdata->attr->author, attr[i + 1]);
- }
+ if (!strcmp(attr[i], "lon")) {
+ pdata->attr->lon = atof(attr[i + 1]);
+ }
+ if (!strcmp(attr[i], "lat")) {
+ pdata->attr->lat = atof(attr[i + 1]);
+ }
+ if (!strcmp(attr[i], "minlon")) {
+ pdata->attr->minlon = atof(attr[i + 1]);
+ }
+ if (!strcmp(attr[i], "minlat")) {
+ pdata->attr->minlat = atof(attr[i + 1]);
+ }
+ if (!strcmp(attr[i], "maxlon")) {
+ pdata->attr->maxlon = atof(attr[i + 1]);
+ }
+ if (!strcmp(attr[i], "maxlat")) {
+ pdata->attr->maxlat = atof(attr[i + 1]);
+ }
+ if (!strcmp(attr[i], "author")) {
+ strcpy(pdata->attr->author, attr[i + 1]);
+ }
}
if (pdata->prop->parseTrk) {
- if (!strcmp(element, "trk")) {
- if (isFirstTrk) {
- isFirstTrk = 0;
- }
- }
- if (!strcmp(element, "trkseg")) {
- isFirstPathpt = 1;
- }
- if (!strcmp(element, "trkpt")) {
- if (isFirstPathpt) {
- initPathAttr(pdata->pattr, pdata->attr);
- isFirstPathpt = 0;
- }
- }
+ if (!strcmp(element, "trk")) {
+ if (isFirstTrk) {
+ isFirstTrk = 0;
+ }
+ }
+ if (!strcmp(element, "trkseg")) {
+ isFirstPathpt = 1;
+ }
+ if (!strcmp(element, "trkpt")) {
+ if (isFirstPathpt) {
+ initPathAttr(pdata->pattr, pdata->attr);
+ isFirstPathpt = 0;
+ }
+ }
}
if (pdata->prop->parseRte) {
- if (!strcmp(element, "rte")) {
- if (isFirstRte) {
- isFirstRte = 0;
- isFirstPathpt = 1;
- }
- }
- if (!strcmp(element, "rtept")) {
- if (isFirstPathpt) {
- initPathAttr(pdata->pattr, pdata->attr);
- isFirstPathpt = 0;
- }
- }
+ if (!strcmp(element, "rte")) {
+ if (isFirstRte) {
+ isFirstRte = 0;
+ isFirstPathpt = 1;
+ }
+ }
+ if (!strcmp(element, "rtept")) {
+ if (isFirstPathpt) {
+ initPathAttr(pdata->pattr, pdata->attr);
+ isFirstPathpt = 0;
+ }
+ }
}
}
@@ -95,151 +94,150 @@ startElementControl(parsedata * pdata, const char *element,
* It corrects char elements when the element tag has some data,
* then start to convert when tag is top level tag like <wpt>.
*/
-void endElementControl(parsedata * pdata, const char *element)
-{
+void endElementControl(parsedata * pdata, const char *element) {
static int isFirstWpt = 1;
static int isFirstTrkAsPoint = 1;
static int isFirstRteAsPoint = 1;
/* common elements */
if (!strcmp(element, "name")) {
- strcpy(pdata->attr->name, pdata->databuf);
+ strcpy(pdata->attr->name, pdata->databuf);
}
if (!strcmp(element, "cmt")) {
- strcpy(pdata->attr->cmt, pdata->databuf);
+ strcpy(pdata->attr->cmt, pdata->databuf);
}
if (!strcmp(element, "desc")) {
- strcpy(pdata->attr->desc, pdata->databuf);
+ strcpy(pdata->attr->desc, pdata->databuf);
}
if (!strcmp(element, "src")) {
- strcpy(pdata->attr->src, pdata->databuf);
+ strcpy(pdata->attr->src, pdata->databuf);
}
if (!strcmp(element, "link")) {
- strcpy(pdata->attr->link, pdata->databuf);
+ strcpy(pdata->attr->link, pdata->databuf);
}
if (!strcmp(element, "type")) {
- strcpy(pdata->attr->type, pdata->databuf);
+ strcpy(pdata->attr->type, pdata->databuf);
}
/* waypoint and metadata elements */
if (!strcmp(element, "time")) {
- strcpy(pdata->attr->time, pdata->databuf);
+ strcpy(pdata->attr->time, pdata->databuf);
}
/* route and track point elements */
if (!strcmp(element, "number")) {
- pdata->attr->number = atoi(pdata->databuf);
+ pdata->attr->number = atoi(pdata->databuf);
}
/* waypoint elements */
if (!strcmp(element, "ele")) {
- pdata->attr->ele = atof(pdata->databuf);
+ pdata->attr->ele = atof(pdata->databuf);
}
if (!strcmp(element, "magvar")) {
- pdata->attr->magvar = atof(pdata->databuf);
+ pdata->attr->magvar = atof(pdata->databuf);
}
if (!strcmp(element, "geoidheight")) {
- pdata->attr->geoidheight = atof(pdata->databuf);
+ pdata->attr->geoidheight = atof(pdata->databuf);
}
if (!strcmp(element, "sym")) {
- strcpy(pdata->attr->sym, pdata->databuf);
+ strcpy(pdata->attr->sym, pdata->databuf);
}
if (!strcmp(element, "fix")) {
- strcpy(pdata->attr->fix, pdata->databuf);
+ strcpy(pdata->attr->fix, pdata->databuf);
}
if (!strcmp(element, "sat")) {
- pdata->attr->sat = atoi(pdata->databuf);
+ pdata->attr->sat = atoi(pdata->databuf);
}
if (!strcmp(element, "hdop")) {
- pdata->attr->hdop = atof(pdata->databuf);
+ pdata->attr->hdop = atof(pdata->databuf);
}
if (!strcmp(element, "vdop")) {
- pdata->attr->vdop = atof(pdata->databuf);
+ pdata->attr->vdop = atof(pdata->databuf);
}
if (!strcmp(element, "pdop")) {
- pdata->attr->pdop = atof(pdata->databuf);
+ pdata->attr->pdop = atof(pdata->databuf);
}
if (!strcmp(element, "ageofdgpsdata")) {
- pdata->attr->ageofdgpsdata = atof(pdata->databuf);
+ pdata->attr->ageofdgpsdata = atof(pdata->databuf);
}
/* metadata elements */
if (!strcmp(element, "author")) {
- strcpy(pdata->attr->author, pdata->databuf);
+ strcpy(pdata->attr->author, pdata->databuf);
}
if (!strcmp(element, "keywords")) {
- strcpy(pdata->attr->keywords, pdata->databuf);
+ strcpy(pdata->attr->keywords, pdata->databuf);
}
if (!strcmp(element, "copyright")) {
- strcpy(pdata->attr->copyright, pdata->databuf);
+ strcpy(pdata->attr->copyright, pdata->databuf);
}
if (!strcmp(element, "year")) {
- pdata->attr->year = atoi(pdata->databuf);
+ pdata->attr->year = atoi(pdata->databuf);
}
if (!strcmp(element, "license")) {
- strcpy(pdata->attr->license, pdata->databuf);
+ strcpy(pdata->attr->license, pdata->databuf);
}
if (!strcmp(element, "bounds")) {
- /* none */
+ /* none */
}
/* top elements */
/* set waypoint data */
if (!strcmp(element, "wpt")) {
- if (pdata->prop->parseWpt) {
- if (isFirstWpt) {
- isFirstWpt = 0;
- }
- //todo
- if (DEBUG) {
- fprintf(stderr,"\neectrl wpt %s %s",
- pdata->attr->desc,pdata->attr->name);
- }
- setWpt(pdata);
- wipeAttr(pdata->attr);
- }
+ if (pdata->prop->parseWpt) {
+ if (isFirstWpt) {
+ isFirstWpt = 0;
+ }
+ //todo
+ if (DEBUG) {
+ fprintf(stderr,"\neectrl wpt %s %s",
+ pdata->attr->desc,pdata->attr->name);
+ }
+ setWpt(pdata);
+ wipeAttr(pdata->attr);
+ }
}
/* set trackpoint data */
if (!strcmp(element, "trkpt")) {
- if (pdata->prop->parseTrk) {
- setPathData(pdata->pattr, pdata->attr);
- if (!pdata->prop->isFast)
- setPathInterval(pdata);
- }
- /* set trackpoint data as point */
- if (pdata->prop->isPoint) {
- if (isFirstTrkAsPoint) {
- isFirstTrkAsPoint = 0;
- }
- setWpt(pdata);
- }
- wipeAttr(pdata->attr);
+ if (pdata->prop->parseTrk) {
+ setPathData(pdata->pattr, pdata->attr);
+ if (!pdata->prop->isFast)
+ setPathInterval(pdata);
+ }
+ /* set trackpoint data as point */
+ if (pdata->prop->isPoint) {
+ if (isFirstTrkAsPoint) {
+ isFirstTrkAsPoint = 0;
+ }
+ setWpt(pdata);
+ }
+ wipeAttr(pdata->attr);
}
/* write trackpoint */
if (!strcmp(element, "trkseg")) {
- if (pdata->prop->parseTrk) {
- setPath( pdata);
- }
+ if (pdata->prop->parseTrk) {
+ setPath( pdata);
+ }
}
/* set route data */
if (!strcmp(element, "rtept")) {
- if (pdata->prop->parseRte) {
- setPathData(pdata->pattr, pdata->attr);
- if (!pdata->prop->isFast)
- setPathInterval(pdata);
- }
- /* set route data as point */
- if (pdata->prop->isPoint) {
- if (isFirstRteAsPoint) {
- isFirstRteAsPoint = 0;
- }
- setWpt( pdata);
- }
- wipeAttr(pdata->attr);
+ if (pdata->prop->parseRte) {
+ setPathData(pdata->pattr, pdata->attr);
+ if (!pdata->prop->isFast)
+ setPathInterval(pdata);
+ }
+ /* set route data as point */
+ if (pdata->prop->isPoint) {
+ if (isFirstRteAsPoint) {
+ isFirstRteAsPoint = 0;
+ }
+ setWpt( pdata);
+ }
+ wipeAttr(pdata->attr);
}
/* write route */
if (!strcmp(element, "rte")) {
- if (pdata->prop->parseRte) {
- setPath( pdata);
- }
+ if (pdata->prop->parseRte) {
+ setPath( pdata);
+ }
}
if (!strcmp(element, "metadata")) {
- setMetadata(pdata);
- wipeAttr(pdata->attr);
+ setMetadata(pdata);
+ wipeAttr(pdata->attr);
}
pdata->bufptr = NULL; //reset bufptr now
}
diff --git a/navit/tools/gpx2navit_txt/src/geod_for.c b/navit/tools/gpx2navit_txt/src/geod_for.c
index ebff3bcb4..30fa829e3 100644
--- a/navit/tools/gpx2navit_txt/src/geod_for.c
+++ b/navit/tools/gpx2navit_txt/src/geod_for.c
@@ -26,102 +26,100 @@ static const char SCCSID[] =
# define MERI_TOL 1e-9
static double th1, costh1, sinth1, sina12, cosa12, M, N, c1, c2, D, P, s1;
static int merid, signS;
-void geod_pre(void)
-{
+void geod_pre(void) {
al12 = adjlon(al12); /* reduce to +- 0-PI */
signS = fabs(al12) > HALFPI ? 1 : 0;
th1 = ellipse ? atan(onef * tan(phi1)) : phi1;
costh1 = cos(th1);
sinth1 = sin(th1);
if ((merid = fabs(sina12 = sin(al12)) < MERI_TOL)) {
- sina12 = 0.;
- cosa12 = fabs(al12) < HALFPI ? 1. : -1.;
- M = 0.;
+ sina12 = 0.;
+ cosa12 = fabs(al12) < HALFPI ? 1. : -1.;
+ M = 0.;
} else {
- cosa12 = cos(al12);
- M = costh1 * sina12;
+ cosa12 = cos(al12);
+ M = costh1 * sina12;
}
N = costh1 * cosa12;
if (ellipse) {
- if (merid) {
- c1 = 0.;
- c2 = f4;
- D = 1. - c2;
- D *= D;
- P = c2 / D;
- } else {
- c1 = geod_f * M;
- c2 = f4 * (1. - M * M);
- D = (1. - c2) * (1. - c2 - c1 * M);
- P = (1. + .5 * c1 * M) * c2 / D;
- }
+ if (merid) {
+ c1 = 0.;
+ c2 = f4;
+ D = 1. - c2;
+ D *= D;
+ P = c2 / D;
+ } else {
+ c1 = geod_f * M;
+ c2 = f4 * (1. - M * M);
+ D = (1. - c2) * (1. - c2 - c1 * M);
+ P = (1. + .5 * c1 * M) * c2 / D;
+ }
}
if (merid)
- s1 = HALFPI - th1;
+ s1 = HALFPI - th1;
else {
- s1 = (fabs(M) >= 1.) ? 0. : acos(M);
- s1 = sinth1 / sin(s1);
- s1 = (fabs(s1) >= 1.) ? 0. : acos(s1);
+ s1 = (fabs(M) >= 1.) ? 0. : acos(M);
+ s1 = sinth1 / sin(s1);
+ s1 = (fabs(s1) >= 1.) ? 0. : acos(s1);
}
}
-void geod_for(void)
-{
+void geod_for(void) {
double d, sind, u, V, X, ds, cosds, sinds, ss = 0, de;
if (ellipse) {
- d = geod_S / (D * geod_a);
- if (signS)
- d = -d;
- u = 2. * (s1 - d);
- V = cos(u + d);
- X = c2 * c2 * (sind = sin(d)) * cos(d) * (2. * V * V - 1.);
- ds = d + X - 2. * P * V * (1. - 2. * P * cos(u)) * sind;
- ss = s1 + s1 - ds;
+ d = geod_S / (D * geod_a);
+ if (signS)
+ d = -d;
+ u = 2. * (s1 - d);
+ V = cos(u + d);
+ X = c2 * c2 * (sind = sin(d)) * cos(d) * (2. * V * V - 1.);
+ ds = d + X - 2. * P * V * (1. - 2. * P * cos(u)) * sind;
+ ss = s1 + s1 - ds;
} else {
- ds = geod_S / geod_a;
- if (signS)
- ds = -ds;
+ ds = geod_S / geod_a;
+ if (signS)
+ ds = -ds;
}
cosds = cos(ds);
sinds = sin(ds);
if (signS)
- sinds = -sinds;
+ sinds = -sinds;
al21 = N * cosds - sinth1 * sinds;
if (merid) {
- phi2 = atan(tan(HALFPI + s1 - ds) / onef);
- if (al21 > 0.) {
- al21 = PI;
- if (signS)
- de = PI;
- else {
- phi2 = -phi2;
- de = 0.;
- }
- } else {
- al21 = 0.;
- if (signS) {
- phi2 = -phi2;
- de = 0;
- } else
- de = PI;
- }
+ phi2 = atan(tan(HALFPI + s1 - ds) / onef);
+ if (al21 > 0.) {
+ al21 = PI;
+ if (signS)
+ de = PI;
+ else {
+ phi2 = -phi2;
+ de = 0.;
+ }
+ } else {
+ al21 = 0.;
+ if (signS) {
+ phi2 = -phi2;
+ de = 0;
+ } else
+ de = PI;
+ }
} else {
- al21 = atan(M / al21);
- if (al21 > 0)
- al21 += PI;
- if (al12 < 0.)
- al21 -= PI;
- al21 = adjlon(al21);
- phi2 = atan(-(sinth1 * cosds + N * sinds) * sin(al21) /
- (ellipse ? onef * M : M));
- de = atan2(sinds * sina12,
- (costh1 * cosds - sinth1 * sinds * cosa12));
- if (ellipse) {
- if (signS)
- de += c1 * ((1. - c2) * ds + c2 * sinds * cos(ss));
- else
- de -= c1 * ((1. - c2) * ds - c2 * sinds * cos(ss));
- }
+ al21 = atan(M / al21);
+ if (al21 > 0)
+ al21 += PI;
+ if (al12 < 0.)
+ al21 -= PI;
+ al21 = adjlon(al21);
+ phi2 = atan(-(sinth1 * cosds + N * sinds) * sin(al21) /
+ (ellipse ? onef * M : M));
+ de = atan2(sinds * sina12,
+ (costh1 * cosds - sinth1 * sinds * cosa12));
+ if (ellipse) {
+ if (signS)
+ de += c1 * ((1. - c2) * ds + c2 * sinds * cos(ss));
+ else
+ de -= c1 * ((1. - c2) * ds - c2 * sinds * cos(ss));
+ }
}
lam2 = adjlon(lam1 + de);
}
diff --git a/navit/tools/gpx2navit_txt/src/geod_inv.c b/navit/tools/gpx2navit_txt/src/geod_inv.c
index a54128256..826f4e3fd 100644
--- a/navit/tools/gpx2navit_txt/src/geod_inv.c
+++ b/navit/tools/gpx2navit_txt/src/geod_inv.c
@@ -24,33 +24,32 @@ static const char SCCSID[] =
# include "projects.h"
# include "geodesic.h"
# define DTOL 1e-12
-void geod_inv(void)
-{
+void geod_inv(void) {
double th1,
- th2,
- thm,
- dthm,
- dlamm,
- dlam,
- sindlamm,
- costhm,
- sinthm,
- cosdthm,
- sindthm, L, E, cosd, d, X, Y, T, sind, tandlammp, u, v, D, A, B;
+ th2,
+ thm,
+ dthm,
+ dlamm,
+ dlam,
+ sindlamm,
+ costhm,
+ sinthm,
+ cosdthm,
+ sindthm, L, E, cosd, d, X, Y, T, sind, tandlammp, u, v, D, A, B;
if (ellipse) {
- th1 = atan(onef * tan(phi1));
- th2 = atan(onef * tan(phi2));
+ th1 = atan(onef * tan(phi1));
+ th2 = atan(onef * tan(phi2));
} else {
- th1 = phi1;
- th2 = phi2;
+ th1 = phi1;
+ th2 = phi2;
}
thm = .5 * (th1 + th2);
dthm = .5 * (th2 - th1);
dlamm = .5 * (dlam = adjlon(lam2 - lam1));
if (fabs(dlam) < DTOL && fabs(dthm) < DTOL) {
- al12 = al21 = geod_S = 0.;
- return;
+ al12 = al21 = geod_S = 0.;
+ return;
}
sindlamm = sin(dlamm);
costhm = cos(thm);
@@ -58,32 +57,32 @@ void geod_inv(void)
cosdthm = cos(dthm);
sindthm = sin(dthm);
L = sindthm * sindthm + (cosdthm * cosdthm - sinthm * sinthm)
- * sindlamm * sindlamm;
+ * sindlamm * sindlamm;
d = acos(cosd = 1 - L - L);
if (ellipse) {
- E = cosd + cosd;
- sind = sin(d);
- Y = sinthm * cosdthm;
- Y *= (Y + Y) / (1. - L);
- T = sindthm * costhm;
- T *= (T + T) / L;
- X = Y + T;
- Y -= T;
- T = d / sind;
- D = 4. * T * T;
- A = D * E;
- B = D + D;
- geod_S = geod_a * sind * (T - f4 * (T * X - Y) +
- f64 * (X * (A + (T - .5 * (A - E)) * X) -
- Y * (B + E * Y) + D * X * Y));
- tandlammp = tan(.5 * (dlam - .25 * (Y + Y - E * (4. - X)) *
- (f2 * T + f64 * (32. * T - (20. * T - A)
- * X - (B +
- 4.) * Y)) *
- tan(dlam)));
+ E = cosd + cosd;
+ sind = sin(d);
+ Y = sinthm * cosdthm;
+ Y *= (Y + Y) / (1. - L);
+ T = sindthm * costhm;
+ T *= (T + T) / L;
+ X = Y + T;
+ Y -= T;
+ T = d / sind;
+ D = 4. * T * T;
+ A = D * E;
+ B = D + D;
+ geod_S = geod_a * sind * (T - f4 * (T * X - Y) +
+ f64 * (X * (A + (T - .5 * (A - E)) * X) -
+ Y * (B + E * Y) + D * X * Y));
+ tandlammp = tan(.5 * (dlam - .25 * (Y + Y - E * (4. - X)) *
+ (f2 * T + f64 * (32. * T - (20. * T - A)
+ * X - (B +
+ 4.) * Y)) *
+ tan(dlam)));
} else {
- geod_S = geod_a * d;
- tandlammp = tan(dlamm);
+ geod_S = geod_a * d;
+ tandlammp = tan(dlamm);
}
u = atan2(sindthm, (tandlammp * costhm));
v = atan2(cosdthm, (tandlammp * sinthm));
diff --git a/navit/tools/gpx2navit_txt/src/geod_set.c b/navit/tools/gpx2navit_txt/src/geod_set.c
index 4dc4b1d79..65c6fffaf 100644
--- a/navit/tools/gpx2navit_txt/src/geod_set.c
+++ b/navit/tools/gpx2navit_txt/src/geod_set.c
@@ -29,86 +29,87 @@
#include "projects.h"
#include "geodesic.h"
#include "emess.h"
-void geod_set(int argc, char **argv)
-{
+void geod_set(int argc, char **argv) {
paralist *start = 0, *curr = NULL; /* added NULL */
double es;
char *name;
int i;
-/*
- * put arguments into internal linked list
- */
+ /*
+ * put arguments into internal linked list
+ */
if (argc <= 0)
- emess(1, "no arguments in initialization list");
+ emess(1, "no arguments in initialization list");
for (i = 0; i < argc; ++i)
- if (i)
- curr = curr->next = pj_mkparam(argv[i]);
- else
- start = curr = pj_mkparam(argv[i]);
-/*
- * set elliptical parameters
- */
+ if (i)
+ curr = curr->next = pj_mkparam(argv[i]);
+ else
+ start = curr = pj_mkparam(argv[i]);
+ /*
+ * set elliptical parameters
+ */
if (pj_ell_set(start, &geod_a, &es))
- emess(1, "ellipse setup failure");
-/*
- * set units
- */
+ emess(1, "ellipse setup failure");
+ /*
+ * set units
+ */
if ((name = pj_param(start, "sunits").s)) { /* added parentheses */
- char *s;
+ char *s;
- for (i = 0; (s = pj_units[i].id) && strcmp(name, s); ++i);
- if (!s)
- emess(1, "%s unknown unit conversion id", name);
- fr_meter = 1. / (to_meter = atof(pj_units[i].to_meter));
+ for (i = 0; (s = pj_units[i].id) && strcmp(name, s); ++i);
+ if (!s)
+ emess(1, "%s unknown unit conversion id", name);
+ fr_meter = 1. / (to_meter = atof(pj_units[i].to_meter));
} else
- to_meter = fr_meter = 1.;
+ to_meter = fr_meter = 1.;
if ((ellipse = es != 0.)) { /* added parentheses */
- onef = sqrt(1. - es);
- geod_f = 1 - onef;
- f2 = geod_f / 2;
- f4 = geod_f / 4;
- f64 = geod_f * geod_f / 64;
+ onef = sqrt(1. - es);
+ geod_f = 1 - onef;
+ f2 = geod_f / 2;
+ f4 = geod_f / 4;
+ f64 = geod_f * geod_f / 64;
} else {
- onef = 1.;
- geod_f = f2 = f4 = f64 = 0.;
+ onef = 1.;
+ geod_f = f2 = f4 = f64 = 0.;
}
-/*
- * check if line or arc mode
- */
+ /*
+ * check if line or arc mode
+ */
if (pj_param(start, "tlat_1").i) {
- double del_S;
+ double del_S;
#undef f
- phi1 = pj_param(start, "rlat_1").f;
- lam1 = pj_param(start, "rlon_1").f;
- if (pj_param(start, "tlat_2").i) {
- phi2 = pj_param(start, "rlat_2").f;
- lam2 = pj_param(start, "rlon_2").f;
- geod_inv();
- geod_pre();
- } else if ((geod_S = pj_param(start, "dS").f)) { /* added
- * parentheses
- */
- al12 = pj_param(start, "rA").f;
- geod_pre();
- geod_for();
- } else
- emess(1, "incomplete geodesic/arc info");
- if ((n_alpha = pj_param(start, "in_A").i) > 0) {
- if (!(del_alpha = pj_param(start, "rdel_A").f))
- emess(1, "del azimuth == 0");
- } else if ((del_S = fabs(pj_param(start, "ddel_S").f))) { /* added
- * parentheses
- */
- n_S = geod_S / del_S + .5;
- } else if ((n_S = pj_param(start, "in_S").i) <= 0)
- emess(1, "no interval divisor selected");
+ phi1 = pj_param(start, "rlat_1").f;
+ lam1 = pj_param(start, "rlon_1").f;
+ if (pj_param(start, "tlat_2").i) {
+ phi2 = pj_param(start, "rlat_2").f;
+ lam2 = pj_param(start, "rlon_2").f;
+ geod_inv();
+ geod_pre();
+ } else if ((geod_S = pj_param(start, "dS").f)) {
+ /* added
+ * parentheses
+ */
+ al12 = pj_param(start, "rA").f;
+ geod_pre();
+ geod_for();
+ } else
+ emess(1, "incomplete geodesic/arc info");
+ if ((n_alpha = pj_param(start, "in_A").i) > 0) {
+ if (!(del_alpha = pj_param(start, "rdel_A").f))
+ emess(1, "del azimuth == 0");
+ } else if ((del_S = fabs(pj_param(start, "ddel_S").f))) {
+ /* added
+ * parentheses
+ */
+ n_S = geod_S / del_S + .5;
+ } else if ((n_S = pj_param(start, "in_S").i) <= 0)
+ emess(1, "no interval divisor selected");
}
-/*
- * free up linked list
- */
+ /*
+ * free up linked list
+ */
for (; start; start = curr) {
- curr = start->next;
- pj_dalloc(start);
+ curr = start->next;
+ pj_dalloc(start);
}
}
diff --git a/navit/tools/gpx2navit_txt/src/main.c b/navit/tools/gpx2navit_txt/src/main.c
index e244957fc..24164abcb 100644
--- a/navit/tools/gpx2navit_txt/src/main.c
+++ b/navit/tools/gpx2navit_txt/src/main.c
@@ -28,8 +28,7 @@ void setOptions(int argc, char **argv, g2sprop * prop);
/**
* Shows a version
*/
-void version(void)
-{
+void version(void) {
fprintf(stdout, "gpx2navit_txt 0.1\n");
fprintf(stdout, "\n");
fprintf(stdout, "by Toshihiro Hiraoka\n");
@@ -39,89 +38,88 @@ void version(void)
/**
* Shows a usage message
*/
-void usage(char **argv)
-{
+void usage(char **argv) {
fprintf(stdout, "Usage: %s gpxfile [options] [-o output basename]\n",
- argv[0]);
+ argv[0]);
fprintf(stdout,
- "-o, --output Sets output basename. The default is (source file\n");
+ "-o, --output Sets output basename. The default is (source file\n");
fprintf(stdout, " name) - (extention name)\n");
fprintf
- (stdout,
- "-w, --waypoints Converts only waypoints data from a gpx file.\n");
+ (stdout,
+ "-w, --waypoints Converts only waypoints data from a gpx file.\n");
fprintf(stdout,
- "-t, --trackpoints Converts only trackpoints data from a gpx file.\n");
+ "-t, --trackpoints Converts only trackpoints data from a gpx file.\n");
fprintf(stdout,
- "-r, --routes Converts only routes data from a gpx file.\n");
+ "-r, --routes Converts only routes data from a gpx file.\n");
fprintf(stdout,
- "-a, --all Converts all types of data from a gpx file.(default)\n");
+ "-a, --all Converts all types of data from a gpx file.(default)\n");
fprintf(stdout,
- "-e, --as-edge Makes a separated output by each edges.\n");
+ "-e, --as-edge Makes a separated output by each edges.\n");
fprintf(stdout,
- "-p, --as-point Makes a separated output by each points.\n");
+ "-p, --as-point Makes a separated output by each points.\n");
fprintf(stdout,
- "-s, --stats Shows simple statistics of the outputs.\n");
+ "-s, --stats Shows simple statistics of the outputs.\n");
fprintf(stdout,
- "-b, --basic-columns Stores only basic data as attribures to \n");
+ "-b, --basic-columns Stores only basic data as attribures to \n");
fprintf(stdout,
- " reduce memory and storage usage.\n");
+ " reduce memory and storage usage.\n");
fprintf(stdout,
- " (ele, name, cmt, type, time, fix, sym and number).\n");
+ " (ele, name, cmt, type, time, fix, sym and number).\n");
fprintf(stdout,
- "-L, --no-length Removes length column from a waypoint or trackpoint\n");
+ "-L, --no-length Removes length column from a waypoint or trackpoint\n");
fprintf(stdout, " attribute table.\n");
fprintf
- (stdout,
- "-S, --no-speed Removes speed column from a waypoint or trackpoint\n");
+ (stdout,
+ "-S, --no-speed Removes speed column from a waypoint or trackpoint\n");
fprintf(stdout, " attribute table.\n");
fprintf
- (stdout,
- "-T, --no-time Removes time column from an attribute table.\n");
+ (stdout,
+ "-T, --no-time Removes time column from an attribute table.\n");
fprintf(stdout,
- "-g, --gpxline Adds line number of GPX file as attribures.\n");
+ "-g, --gpxline Adds line number of GPX file as attribures.\n");
fprintf
- (stdout,
- "-f, --fast Make it faster without any checks.\n");
+ (stdout,
+ "-f, --fast Make it faster without any checks.\n");
fprintf(stdout,
- "-3, --3d Converts data using 3d format. (It's not compatible\n");
+ "-3, --3d Converts data using 3d format. (It's not compatible\n");
fprintf(stdout, " for Arcview 3.x.)\n");
fprintf(stdout,
- " --min-points Sets path minimum points to convert for noise reduction.\n");
+ " --min-points Sets path minimum points to convert for noise reduction.\n");
fprintf(stdout, " Default is 2.\n");
fprintf(stdout,
- " --min-length Sets path minimum length to convert for noise reduction.\n");
+ " --min-length Sets path minimum length to convert for noise reduction.\n");
fprintf(stdout, " Default is 0.\n");
fprintf(stdout,
- " --min-time Sets path minimum time period to convert for noise\n");
+ " --min-time Sets path minimum time period to convert for noise\n");
fprintf(stdout, " reduction.\n");
fprintf(stdout, " Default is 0.\n");
fprintf(stdout,
- " --length-unit Sets length unit from m,km,feet,mi and etc.\n");
+ " --length-unit Sets length unit from m,km,feet,mi and etc.\n");
fprintf(stdout, " The default is m.\n");
fprintf(stdout,
- " You can see the unit list from \"geod -lu\" command.\n");
+ " You can see the unit list from \"geod -lu\" command.\n");
fprintf
- (stdout,
- " --time-unit Sets time unit. The default is sec.\n");
+ (stdout,
+ " --time-unit Sets time unit. The default is sec.\n");
fprintf(stdout,
- " You can set from day, hour, min and sec.\n");
+ " You can set from day, hour, min and sec.\n");
fprintf(stdout,
- " --speed-length-unit Sets length unit for speed.\n");
+ " --speed-length-unit Sets length unit for speed.\n");
fprintf(stdout, " The default is km.\n");
fprintf(stdout,
- " You can see the unit list from \"geod -lu\" command.\n");
+ " You can see the unit list from \"geod -lu\" command.\n");
fprintf(stdout,
- " --speed-time-unit Sets time unit for speed calulation. Default is hour.\n");
+ " --speed-time-unit Sets time unit for speed calulation. Default is hour.\n");
fprintf(stdout,
- " You can set from day, hour, min and sec.\n");
+ " You can set from day, hour, min and sec.\n");
fprintf(stdout,
- " --length-ellipsoid Sets length ellipsoid like UGS84, clrk66. The default is\n");
+ " --length-ellipsoid Sets length ellipsoid like UGS84, clrk66. The default is\n");
fprintf(stdout, " UGS84.\n");
fprintf
- (stdout,
- " You can see the unit list from \"geod -le\" command.\n");
+ (stdout,
+ " You can see the unit list from \"geod -le\" command.\n");
fprintf(stdout,
- " --no-speed-check Disables track check for speed to be non-zero.\n");
+ " --no-speed-check Disables track check for speed to be non-zero.\n");
fprintf(stdout, "-v, --verbose Gives many messages.\n");
fprintf(stdout, " --version Shows version.\n");
fprintf(stdout, "-h, --help Shows this list.\n");
@@ -130,56 +128,55 @@ void usage(char **argv)
/**
* Sets default values to the properties when there is no user setting.
*/
-void setDefault(g2sprop * prop)
-{
+void setDefault(g2sprop * prop) {
char *pargv[2];
int pargc = 2;
char *ellps;
/* if there are no options like -p,-w,-e, sets as -a */
if (!(prop->parseWpt | prop->parseTrk | prop->parseRte)) {
- prop->parseWpt = 1;
- prop->parseTrk = 1;
- prop->parseRte = 1;
+ prop->parseWpt = 1;
+ prop->parseTrk = 1;
+ prop->parseRte = 1;
}
/* if there is no output setting, sets it as [sourcefile name] - ".gpx" */
if (prop->output == NULL) {
- char *dot = strrchr(prop->sourcefile, '.');
- prop->output =
- (char *) malloc(sizeof(char) * strlen(prop->sourcefile) + 1);
- if (0 == strcmp(dot, ".gpx")) {
- int len = dot - prop->sourcefile;
- strncpy(prop->output, prop->sourcefile, len);
- prop->output[len] = 0;
- } else {
- fprintf(stderr,
- "The source file doesn't have .gpx extension.\n");
- exit(ERR_ISNOTGPX);
- }
+ char *dot = strrchr(prop->sourcefile, '.');
+ prop->output =
+ (char *) malloc(sizeof(char) * strlen(prop->sourcefile) + 1);
+ if (0 == strcmp(dot, ".gpx")) {
+ int len = dot - prop->sourcefile;
+ strncpy(prop->output, prop->sourcefile, len);
+ prop->output[len] = 0;
+ } else {
+ fprintf(stderr,
+ "The source file doesn't have .gpx extension.\n");
+ exit(ERR_ISNOTGPX);
+ }
}
/* sets ellipsoid "WGS84" */
if (prop->ellipsoid == NULL) {
- prop->ellipsoid = (char *) malloc(sizeof(char) * 7);
- strcpy(prop->ellipsoid, "WGS84");
+ prop->ellipsoid = (char *) malloc(sizeof(char) * 7);
+ strcpy(prop->ellipsoid, "WGS84");
}
/* sets lengthUnit "m" */
if (prop->lengthUnit == NULL) {
- prop->lengthUnit = (char *) malloc(sizeof(char) * 2);
- strcpy(prop->lengthUnit, "m");
+ prop->lengthUnit = (char *) malloc(sizeof(char) * 2);
+ strcpy(prop->lengthUnit, "m");
}
/* sets timeUnit "sec" */
if (prop->timeUnit == NULL) {
- prop->timeUnit = (char *) malloc(sizeof(char) * 4);
- strcpy(prop->timeUnit, "sec");
+ prop->timeUnit = (char *) malloc(sizeof(char) * 4);
+ strcpy(prop->timeUnit, "sec");
}
/* sets speedLengthUnit "km" */
if (prop->speedLengthUnit == NULL) {
- prop->speedLengthUnit = (char *) malloc(sizeof(char) * 3);
- strcpy(prop->speedLengthUnit, "km");
+ prop->speedLengthUnit = (char *) malloc(sizeof(char) * 3);
+ strcpy(prop->speedLengthUnit, "km");
}
/* sets speedTimeUnit "hour" */
if (prop->speedTimeUnit == NULL) {
- prop->speedTimeUnit = (char *) malloc(sizeof(char) * 5);
- strcpy(prop->speedTimeUnit, "hour");
+ prop->speedTimeUnit = (char *) malloc(sizeof(char) * 5);
+ strcpy(prop->speedTimeUnit, "hour");
}
/* sets ellipsoid setting to geod* programs */
ellps = malloc(sizeof(char) * (strlen(prop->ellipsoid) + 8));
@@ -194,8 +191,8 @@ void setDefault(g2sprop * prop)
prop->speed2sec = checkTimeUnit(prop->speedTimeUnit);
geod_set(pargc, pargv);
if (prop->verbose) {
- printf("source filename:\t%s\n", prop->sourcefile);
- printf("output file base name:\t%s\n", prop->output);
+ printf("source filename:\t%s\n", prop->sourcefile);
+ printf("output file base name:\t%s\n", prop->output);
}
free(ellps);
}
@@ -203,196 +200,195 @@ void setDefault(g2sprop * prop)
/**
* Set options from command arguments
*/
-void setOptions(int argc, char **argv, g2sprop * prop)
-{
+void setOptions(int argc, char **argv, g2sprop * prop) {
int result;
/* option struct for getopt_long */
struct option const long_options[] = {
- {"waypoints", no_argument, 0, 'w'},
- {"trackpoints", no_argument, 0, 't'},
- {"routes", no_argument, 0, 'r'},
- {"output", required_argument, 0, 'o'},
- {"as-edge", no_argument, 0, 'e'},
- {"as-point", no_argument, 0, 'p'},
- {"min-points", required_argument, 0, 'P'},
- {"min-length", required_argument, 0, 'l'},
- {"min-time", required_argument, 0, 'm'},
- {"stats", no_argument, 0, 's'},
- {"basic-columns", no_argument, 0, 'b'},
- {"fast", no_argument, 0, 'f'},
- {"length-unit", required_argument, 0, '4'},
- {"time-unit", required_argument, 0, '8'},
- {"length-ellipsoid", required_argument, 0, '7'},
- {"speed-length-unit", required_argument, 0, '5'},
- {"speed-time-unit", required_argument, 0, '6'},
- {"no-speed", no_argument, 0, 'S'},
- {"no-length", no_argument, 0, 'L'},
- {"no-time", no_argument, 0, 'T'},
- {"verbose", no_argument, 0, 'v'},
- {"gpxline", no_argument, 0, 'g'},
- {"all", no_argument, 0, 'a'},
- {"no-speed-check", no_argument, 0, '9'},
- {"version", no_argument, 0, 'V'},
- {"help", no_argument, 0, '?'},
- {0, no_argument, 0, '0'},
+ {"waypoints", no_argument, 0, 'w'},
+ {"trackpoints", no_argument, 0, 't'},
+ {"routes", no_argument, 0, 'r'},
+ {"output", required_argument, 0, 'o'},
+ {"as-edge", no_argument, 0, 'e'},
+ {"as-point", no_argument, 0, 'p'},
+ {"min-points", required_argument, 0, 'P'},
+ {"min-length", required_argument, 0, 'l'},
+ {"min-time", required_argument, 0, 'm'},
+ {"stats", no_argument, 0, 's'},
+ {"basic-columns", no_argument, 0, 'b'},
+ {"fast", no_argument, 0, 'f'},
+ {"length-unit", required_argument, 0, '4'},
+ {"time-unit", required_argument, 0, '8'},
+ {"length-ellipsoid", required_argument, 0, '7'},
+ {"speed-length-unit", required_argument, 0, '5'},
+ {"speed-time-unit", required_argument, 0, '6'},
+ {"no-speed", no_argument, 0, 'S'},
+ {"no-length", no_argument, 0, 'L'},
+ {"no-time", no_argument, 0, 'T'},
+ {"verbose", no_argument, 0, 'v'},
+ {"gpxline", no_argument, 0, 'g'},
+ {"all", no_argument, 0, 'a'},
+ {"no-speed-check", no_argument, 0, '9'},
+ {"version", no_argument, 0, 'V'},
+ {"help", no_argument, 0, '?'},
+ {0, no_argument, 0, '0'},
};
if (argc <= 1) {
- fprintf(stderr, "There is no argument.\n");
- usage(argv);
- exit(ERR_NOARGS);
+ fprintf(stderr, "There is no argument.\n");
+ usage(argv);
+ exit(ERR_NOARGS);
}
/* set option attributes */
while ((result =
- getopt_long(argc, argv, "3wtrao:epfP:l:m:bS4:5:6:7:8:LTSsvg09",
- long_options, NULL)) != -1) {
- switch (result) {
- case '3': /* 3d output */
- prop->is3d = 1;
- break;
- case 'w': /* converts only waypoint */
- prop->parseWpt = 1;
- break;
- case 't': /* converts only trackpoint */
- prop->parseTrk = 1;
- break;
- case 'r': /* converts only route */
- prop->parseRte = 1;
- break;
- case 'a': /* converts all */
- prop->parseWpt = 1;
- prop->parseTrk = 1;
- prop->parseRte = 1;
- break;
- case 'o': /* sets basename of output file */
- prop->output =
- (char *) malloc(sizeof(char) * strlen(optarg) + 1);
- strcpy(prop->output, optarg);
- break;
- case 'e': /* make output by each edges */
- if (prop->isEdge) {
- fprintf(stderr, "option -e cannot use with -f\n");
- exit(ERR_OPTIONCONFRICT);
- }
- prop->isEdge = 1;
- break;
- case 'p': /* make output by each edges */
- prop->isPoint = 1;
- break;
- case 'f': /* make it faster */
- if (prop->isEdge) {
- fprintf(stderr, "option -f cannot use with -e\n");
- exit(ERR_OPTIONCONFRICT);
- }
- prop->isFast = 1;
- prop->cols->desc = 0;
- prop->cols->src = 0;
- prop->cols->link = 0;
- prop->cols->magvar = 0;
- prop->cols->geoidheight = 0;
- prop->cols->sat = 0;
- prop->cols->hdop = 0;
- prop->cols->vdop = 0;
- prop->cols->pdop = 0;
- prop->cols->ageofdgpsdata = 0;
- prop->cols->dgpsid = 0;
- prop->cols->length = 0;
- prop->cols->interval = 0;
- prop->cols->speed = 0;
- break;
- case 'P': /* sets minimun points as a path */
- prop->minpoints = atoi(optarg);
- break;
- case 'l': /* sets minimun length as a path */
- prop->minlength = atoi(optarg);
- break;
- case 'm': /* sets minimun time as a path */
- prop->mintime = atoi(optarg);
- break;
- case 'b': /* use only some columns */
- prop->cols->desc = 0;
- prop->cols->src = 0;
- prop->cols->link = 0;
- prop->cols->magvar = 0;
- prop->cols->geoidheight = 0;
- prop->cols->sat = 0;
- prop->cols->hdop = 0;
- prop->cols->vdop = 0;
- prop->cols->pdop = 0;
- prop->cols->ageofdgpsdata = 0;
- prop->cols->dgpsid = 0;
- prop->cols->length = 0;
- prop->cols->interval = 0;
- prop->cols->speed = 0;
- break;
- case 'S': /* doesn't make speed column */
- prop->cols->speed = 0;
- break;
- case '4': /* sets length unit */
- prop->lengthUnit = malloc(sizeof(char) * (strlen(optarg) + 1));
- strcpy(prop->lengthUnit, optarg);
- break;
- case '5': /* sets length unit for calculating speed */
- prop->speedLengthUnit =
- malloc(sizeof(char) * (strlen(optarg) + 1));
- strcpy(prop->speedLengthUnit, optarg);
- break;
- case '6': /* sets time unit for calculating speed */
- prop->speedTimeUnit =
- malloc(sizeof(char) * (strlen(optarg) + 1));
- strcpy(prop->speedTimeUnit, optarg);
- break;
- case '7': /* sets ellipsoid for calculating length */
- prop->ellipsoid = malloc(sizeof(char) * (strlen(optarg) + 1));
- strcpy(prop->ellipsoid, optarg);
- break;
- case '8': /* sets time unit */
- prop->timeUnit = malloc(sizeof(char) * (strlen(optarg) + 1));
- strcpy(prop->timeUnit, optarg);
- break;
- case '9': /* disables speed check */
- prop->nospeedcheck=1;
- break;
- case 'L': /* doesn't make length column */
- prop->cols->length = 0;
- break;
- case 'T': /* doesn't make time column */
- prop->cols->interval = 0;
- break;
- case 's': /* shows source file stats */
- prop->needsStats = 1;
- break;
- case 'v': /* verbose mode */
- prop->verbose = 1;
- break;
- case 'V': /* shows version */
- version();
- exit(EXIT_SUCCESS);
- break;
- case 'g': /* adds gpx line number column */
- prop->cols->gpxline = 1;
- break;
- case ':':
- usage(argv);
- exit(ERR_WRONGOPTION);
- break;
- case '0':
- usage(argv);
- exit(ERR_WRONGOPTION);
- break;
- default:
- usage(argv);
- exit(ERR_WRONGOPTION);
- break;
- }
+ getopt_long(argc, argv, "3wtrao:epfP:l:m:bS4:5:6:7:8:LTSsvg09",
+ long_options, NULL)) != -1) {
+ switch (result) {
+ case '3': /* 3d output */
+ prop->is3d = 1;
+ break;
+ case 'w': /* converts only waypoint */
+ prop->parseWpt = 1;
+ break;
+ case 't': /* converts only trackpoint */
+ prop->parseTrk = 1;
+ break;
+ case 'r': /* converts only route */
+ prop->parseRte = 1;
+ break;
+ case 'a': /* converts all */
+ prop->parseWpt = 1;
+ prop->parseTrk = 1;
+ prop->parseRte = 1;
+ break;
+ case 'o': /* sets basename of output file */
+ prop->output =
+ (char *) malloc(sizeof(char) * strlen(optarg) + 1);
+ strcpy(prop->output, optarg);
+ break;
+ case 'e': /* make output by each edges */
+ if (prop->isEdge) {
+ fprintf(stderr, "option -e cannot use with -f\n");
+ exit(ERR_OPTIONCONFRICT);
+ }
+ prop->isEdge = 1;
+ break;
+ case 'p': /* make output by each edges */
+ prop->isPoint = 1;
+ break;
+ case 'f': /* make it faster */
+ if (prop->isEdge) {
+ fprintf(stderr, "option -f cannot use with -e\n");
+ exit(ERR_OPTIONCONFRICT);
+ }
+ prop->isFast = 1;
+ prop->cols->desc = 0;
+ prop->cols->src = 0;
+ prop->cols->link = 0;
+ prop->cols->magvar = 0;
+ prop->cols->geoidheight = 0;
+ prop->cols->sat = 0;
+ prop->cols->hdop = 0;
+ prop->cols->vdop = 0;
+ prop->cols->pdop = 0;
+ prop->cols->ageofdgpsdata = 0;
+ prop->cols->dgpsid = 0;
+ prop->cols->length = 0;
+ prop->cols->interval = 0;
+ prop->cols->speed = 0;
+ break;
+ case 'P': /* sets minimun points as a path */
+ prop->minpoints = atoi(optarg);
+ break;
+ case 'l': /* sets minimun length as a path */
+ prop->minlength = atoi(optarg);
+ break;
+ case 'm': /* sets minimun time as a path */
+ prop->mintime = atoi(optarg);
+ break;
+ case 'b': /* use only some columns */
+ prop->cols->desc = 0;
+ prop->cols->src = 0;
+ prop->cols->link = 0;
+ prop->cols->magvar = 0;
+ prop->cols->geoidheight = 0;
+ prop->cols->sat = 0;
+ prop->cols->hdop = 0;
+ prop->cols->vdop = 0;
+ prop->cols->pdop = 0;
+ prop->cols->ageofdgpsdata = 0;
+ prop->cols->dgpsid = 0;
+ prop->cols->length = 0;
+ prop->cols->interval = 0;
+ prop->cols->speed = 0;
+ break;
+ case 'S': /* doesn't make speed column */
+ prop->cols->speed = 0;
+ break;
+ case '4': /* sets length unit */
+ prop->lengthUnit = malloc(sizeof(char) * (strlen(optarg) + 1));
+ strcpy(prop->lengthUnit, optarg);
+ break;
+ case '5': /* sets length unit for calculating speed */
+ prop->speedLengthUnit =
+ malloc(sizeof(char) * (strlen(optarg) + 1));
+ strcpy(prop->speedLengthUnit, optarg);
+ break;
+ case '6': /* sets time unit for calculating speed */
+ prop->speedTimeUnit =
+ malloc(sizeof(char) * (strlen(optarg) + 1));
+ strcpy(prop->speedTimeUnit, optarg);
+ break;
+ case '7': /* sets ellipsoid for calculating length */
+ prop->ellipsoid = malloc(sizeof(char) * (strlen(optarg) + 1));
+ strcpy(prop->ellipsoid, optarg);
+ break;
+ case '8': /* sets time unit */
+ prop->timeUnit = malloc(sizeof(char) * (strlen(optarg) + 1));
+ strcpy(prop->timeUnit, optarg);
+ break;
+ case '9': /* disables speed check */
+ prop->nospeedcheck=1;
+ break;
+ case 'L': /* doesn't make length column */
+ prop->cols->length = 0;
+ break;
+ case 'T': /* doesn't make time column */
+ prop->cols->interval = 0;
+ break;
+ case 's': /* shows source file stats */
+ prop->needsStats = 1;
+ break;
+ case 'v': /* verbose mode */
+ prop->verbose = 1;
+ break;
+ case 'V': /* shows version */
+ version();
+ exit(EXIT_SUCCESS);
+ break;
+ case 'g': /* adds gpx line number column */
+ prop->cols->gpxline = 1;
+ break;
+ case ':':
+ usage(argv);
+ exit(ERR_WRONGOPTION);
+ break;
+ case '0':
+ usage(argv);
+ exit(ERR_WRONGOPTION);
+ break;
+ default:
+ usage(argv);
+ exit(ERR_WRONGOPTION);
+ break;
+ }
}
/* gets a source file name */
if(argv[optind] == NULL) {
- fprintf(stderr, "There is no gpxfile description.\n");
- usage(argv);
- exit(ERR_WRONGOPTION);
+ fprintf(stderr, "There is no gpxfile description.\n");
+ usage(argv);
+ exit(ERR_WRONGOPTION);
}
prop->sourcefile = malloc(sizeof(char) * (strlen(argv[optind]) + 1));
- /** @note needs to change here to support
+ /** @note needs to change here to support
* a several files convertion */
strcpy(prop->sourcefile, argv[optind]);
setDefault(prop);
@@ -401,14 +397,13 @@ void setOptions(int argc, char **argv, g2sprop * prop)
/**
* Main
*/
-int main(int argc, char **argv)
-{
+int main(int argc, char **argv) {
g2sprop *prop;
prop = createProp();
setOptions(argc, argv, prop);
parseMain(prop);
if (prop->needsStats)
- showStats(prop);
+ showStats(prop);
closeProp(prop);
return (0);
}
diff --git a/navit/tools/gpx2navit_txt/src/misc.c b/navit/tools/gpx2navit_txt/src/misc.c
index fc272e8cb..c34f1ff06 100644
--- a/navit/tools/gpx2navit_txt/src/misc.c
+++ b/navit/tools/gpx2navit_txt/src/misc.c
@@ -37,70 +37,67 @@ void closeParsedata(parsedata * pdata);
/**
* message when fail to write attribute
*/
-void failToWriteAttrRep(int iShape, int col, char *file, int line)
-{
+void failToWriteAttrRep(int iShape, int col, char *file, int line) {
printf("Fail to write a attribute at %s:%i. shapeid:%i col:%i\n", file,
- line, iShape, col);
+ line, iShape, col);
}
/**
* shows short statistics
*/
-void showStats(g2sprop * prop)
-{
+void showStats(g2sprop * prop) {
g2sstats *stats = prop->stats;
double ratio;
if (prop->needsStats) {
- if (prop->parseTrk) {
- if (stats->trkunconverted != 0) {
- ratio =
- (double) stats->trkunconverted / (stats->trkcount +
- stats->
- trkunconverted) *
- 100;
- } else {
- ratio = 0;
- }
- printf("Track Points:\n");
- printf("\ttrack count:\t%i\n", stats->trkcount);
- printf("\tpoint count:\t%i\n", stats->trkpoints);
- if (!prop->isFast) {
- printf("\ttotal length:\t%f\n", stats->trklength);
- printf("\tunconverted:\t%i(%5.2f%%)\n",
- stats->trkunconverted, ratio);
- }
- }
- if (prop->parseRte) {
- if (stats->rteunconverted != 0) {
- ratio =
- (double) stats->rteunconverted / (stats->rtecount +
- stats->
- rteunconverted) *
- 100;
- } else {
- ratio = 0;
- }
- printf("Routes:\n");
- printf("\troute count:\t%i\n", stats->rtecount);
- printf("\tpoint count:\t%i\n", stats->rtepoints);
- if (!prop->isFast) {
- printf("\ttotal length:\t%f\n", stats->rtelength);
- printf("\tunconverted:\t%i(%5.2f%%)\n",
- stats->rteunconverted, ratio);
- }
- }
- if (prop->parseWpt) {
- printf("Waypoints:\n");
- printf("\tpoint count:\t%i\n", stats->wptpoints);
- }
+ if (prop->parseTrk) {
+ if (stats->trkunconverted != 0) {
+ ratio =
+ (double) stats->trkunconverted / (stats->trkcount +
+ stats->
+ trkunconverted) *
+ 100;
+ } else {
+ ratio = 0;
+ }
+ printf("Track Points:\n");
+ printf("\ttrack count:\t%i\n", stats->trkcount);
+ printf("\tpoint count:\t%i\n", stats->trkpoints);
+ if (!prop->isFast) {
+ printf("\ttotal length:\t%f\n", stats->trklength);
+ printf("\tunconverted:\t%i(%5.2f%%)\n",
+ stats->trkunconverted, ratio);
+ }
+ }
+ if (prop->parseRte) {
+ if (stats->rteunconverted != 0) {
+ ratio =
+ (double) stats->rteunconverted / (stats->rtecount +
+ stats->
+ rteunconverted) *
+ 100;
+ } else {
+ ratio = 0;
+ }
+ printf("Routes:\n");
+ printf("\troute count:\t%i\n", stats->rtecount);
+ printf("\tpoint count:\t%i\n", stats->rtepoints);
+ if (!prop->isFast) {
+ printf("\ttotal length:\t%f\n", stats->rtelength);
+ printf("\tunconverted:\t%i(%5.2f%%)\n",
+ stats->rteunconverted, ratio);
+ }
+ }
+ if (prop->parseWpt) {
+ printf("Waypoints:\n");
+ printf("\tpoint count:\t%i\n", stats->wptpoints);
+ }
}
}
/**
- * clears a path attribute structure
+ * clears a path attribute structure
*/
-void wipePathAttr(pathattr * pattr)
-{
+void wipePathAttr(pathattr * pattr) {
pattr->name[0] = '\0';
pattr->cmt[0] = '\0';
pattr->desc[0] = '\0';
@@ -116,10 +113,9 @@ void wipePathAttr(pathattr * pattr)
}
/**
- * creates a new path attribute
+ * creates a new path attribute
*/
-pathattr *createPathAttr(void)
-{
+pathattr *createPathAttr(void) {
pathattr *pattr;
pattr = (pathattr *) malloc(sizeof(pathattr));
wipePathAttr(pattr);
@@ -127,10 +123,9 @@ pathattr *createPathAttr(void)
}
/**
- * clears a element attribute structure
+ * clears a element attribute structure
*/
-void wipeAttr(g2sattr * attr)
-{
+void wipeAttr(g2sattr * attr) {
attr->lon = 0;
attr->lat = 0;
attr->minlon = 0;
@@ -170,8 +165,7 @@ void wipeAttr(g2sattr * attr)
/**
* sets default values to a column properties.
*/
-void setColsDefault(g2scolumns * cols)
-{
+void setColsDefault(g2scolumns * cols) {
cols->name = 1;
cols->cmt = 1;
cols->desc = 1;
@@ -201,8 +195,7 @@ void setColsDefault(g2scolumns * cols)
/**
* creates a column structure
*/
-g2scolumns *createCols(void)
-{
+g2scolumns *createCols(void) {
g2scolumns *cols;
cols = (g2scolumns *) malloc(sizeof(g2scolumns));
setColsDefault(cols);
@@ -212,8 +205,7 @@ g2scolumns *createCols(void)
/**
* creates a element attribute structure.
*/
-g2sattr *createAttr(void)
-{
+g2sattr *createAttr(void) {
g2sattr *attr;
attr = (g2sattr *) malloc(sizeof(g2sattr));
wipeAttr(attr);
@@ -223,8 +215,7 @@ g2sattr *createAttr(void)
/**
* creates a properties structure for gpx2shp
*/
-g2sprop *createProp(void)
-{
+g2sprop *createProp(void) {
g2sprop *prop;
g2sstats *stats;
g2scolumns *cols;
@@ -266,8 +257,7 @@ g2sprop *createProp(void)
/**
* close and free a propertires structure
*/
-void closeProp(g2sprop * prop)
-{
+void closeProp(g2sprop * prop) {
free(prop->stats);
free(prop->sourcefile);
free(prop->ellipsoid);
@@ -317,8 +307,7 @@ void closeProp(g2sprop * prop)
/**
* creates a parse structure
*/
-parsedata *createParsedata(XML_Parser parser, g2sprop * prop)
-{
+parsedata *createParsedata(XML_Parser parser, g2sprop * prop) {
parsedata *pdata = (parsedata *) malloc(sizeof(parsedata));
pdata->fp = NULL;
//shphandles *shps = createShps();
@@ -350,8 +339,7 @@ parsedata *createParsedata(XML_Parser parser, g2sprop * prop)
/*
* close and free resoures
*/
-void closeParsedata(parsedata * pdata)
-{
+void closeParsedata(parsedata * pdata) {
//free(pdata->shps);
//free(pdata->dbfs);
free(pdata->parent);
diff --git a/navit/tools/gpx2navit_txt/src/parser.c b/navit/tools/gpx2navit_txt/src/parser.c
index dc62d71f1..d15a17e55 100644
--- a/navit/tools/gpx2navit_txt/src/parser.c
+++ b/navit/tools/gpx2navit_txt/src/parser.c
@@ -27,8 +27,7 @@ void parseMain(g2sprop * prop);
/**
* a handler to parse charctor data on expat
*/
-void charHandle(void *userdata, const XML_Char * data, int length)
-{
+void charHandle(void *userdata, const XML_Char * data, int length) {
static int bufsize = DATABUFSIZE;
static int string_length = 0;
int new_length;
@@ -36,40 +35,39 @@ void charHandle(void *userdata, const XML_Char * data, int length)
int i;
parsedata *pdata = (parsedata *) userdata;
if (pdata->bufptr == NULL) {
- //start of buffer -->pdata->bufptr set to 0 at endelement
- string_length = 0;
+ //start of buffer -->pdata->bufptr set to 0 at endelement
+ string_length = 0;
begin_copy = 0; //begin to copy after first space
- pdata->bufptr= pdata->databuf;
+ pdata->bufptr= pdata->databuf;
}
new_length = string_length + length + 1; //additonal 0
if (bufsize < new_length) {
- pdata->databuf =
- realloc(pdata->databuf, new_length);
- bufsize = new_length;
- //because of realloc the pointer may have changed
- pdata->bufptr = pdata->databuf + string_length;
+ pdata->databuf =
+ realloc(pdata->databuf, new_length);
+ bufsize = new_length;
+ //because of realloc the pointer may have changed
+ pdata->bufptr = pdata->databuf + string_length;
}
// because expat calls this routine several times on special chars
// we need to do following
// --concat strings until reset (bufptr set to NULL)
// --filter out blank chars at begin of string
- for (i=0; i<length;i++) {
- if (begin_copy || !isspace(data[i])) {
- *pdata->bufptr = data[i];
- pdata->bufptr++;
- string_length ++;
- begin_copy = 1;
- if (DEBUG) fprintf(stderr,"%c",data[i]);
- }
- }
+ for (i=0; i<length; i++) {
+ if (begin_copy || !isspace(data[i])) {
+ *pdata->bufptr = data[i];
+ pdata->bufptr++;
+ string_length ++;
+ begin_copy = 1;
+ if (DEBUG) fprintf(stderr,"%c",data[i]);
+ }
+ }
*pdata->bufptr = '\0';
}
/**
* a handler when a element starts
*/
-void startElement(void *userdata, const char *element, const char **attr)
-{
+void startElement(void *userdata, const char *element, const char **attr) {
parsedata *pdata = (parsedata *) userdata;
pdata->parent = pdata->current;
pdata->current = malloc(sizeof(parent));
@@ -78,14 +76,14 @@ void startElement(void *userdata, const char *element, const char **attr)
pdata->current->parentptr = pdata->parent;
startElementControl(pdata, element, attr);
if (pdata->prop->verbose) {
- int i;
- for (i = 0; i < pdata->depth; i++)
- printf(" ");
- printf("<%s>: ", element);
- for (i = 0; attr[i]; i += 2) {
- printf(" %s='%s'", attr[i], attr[i + 1]);
- }
- printf("\n");
+ int i;
+ for (i = 0; i < pdata->depth; i++)
+ printf(" ");
+ printf("<%s>: ", element);
+ for (i = 0; attr[i]; i += 2) {
+ printf(" %s='%s'", attr[i], attr[i + 1]);
+ }
+ printf("\n");
}
pdata->depth++;
}
@@ -93,16 +91,15 @@ void startElement(void *userdata, const char *element, const char **attr)
/**
* a handler when a element ends
*/
-void endElement(void *userdata, const char *element)
-{
+void endElement(void *userdata, const char *element) {
parsedata *pdata = (parsedata *) userdata;
endElementControl(pdata, element);
pdata->depth--;
if (pdata->prop->verbose) {
- int i;
- for (i = 0; i < pdata->depth; i++)
- printf(" ");
- printf("</%s>:%s\n ", element,pdata->parent->name);
+ int i;
+ for (i = 0; i < pdata->depth; i++)
+ printf(" ");
+ printf("</%s>:%s\n ", element,pdata->parent->name);
}
free(pdata->current->name);
free(pdata->current);
@@ -110,33 +107,31 @@ void endElement(void *userdata, const char *element)
pdata->parent = pdata->parent->parentptr;
}
-void parseMain(g2sprop * prop)
-{
+void parseMain(g2sprop * prop) {
FILE *fp;
char buff[BUFFSIZE];
XML_Parser parser;
parsedata *pdata;
fp = fopen(prop->sourcefile, "r");
if (fp == NULL) {
- fprintf(stderr, "Cannot open gpx file: %s\n", prop->sourcefile);
- exit(ERR_CANNOTOPEN);
+ fprintf(stderr, "Cannot open gpx file: %s\n", prop->sourcefile);
+ exit(ERR_CANNOTOPEN);
}
parser = XML_ParserCreate(NULL);
if (!parser) {
- fprintf(stderr, "Couldn't allocate memory for parser\n");
- exit(ERR_OUTOFMEMORY);
+ fprintf(stderr, "Couldn't allocate memory for parser\n");
+ exit(ERR_OUTOFMEMORY);
}
pdata = createParsedata(parser, prop);
char *output_wpt =
- (char *) malloc(sizeof(char) * (strlen(pdata->prop->output) + 9));
+ (char *) malloc(sizeof(char) * (strlen(pdata->prop->output) + 9));
strcpy(output_wpt, pdata->prop->output);
strcat(output_wpt, "_nav.txt");
pdata->fp = fopen(output_wpt,"w");
- if (pdata->fp == NULL)
- {
- //todo
- fprintf(stderr,"Failure opening File %s for writing",output_wpt);
+ if (pdata->fp == NULL) {
+ //todo
+ fprintf(stderr,"Failure opening File %s for writing",output_wpt);
exit(1);
}
free(output_wpt);
@@ -144,23 +139,23 @@ void parseMain(g2sprop * prop)
XML_SetElementHandler(parser, startElement, endElement);
XML_SetCharacterDataHandler(parser, charHandle);
for (;;) {
- int done;
- int len;
- fgets(buff, BUFFSIZE, fp);
- len = (int) strlen(buff);
- if (ferror(fp)) {
- fprintf(stderr, "Read error file: %s\n", prop->sourcefile);
- exit(ERR_READERROR);
- }
- done = feof(fp);
- if (done)
- break;
- if (!XML_Parse(parser, buff, len, done)) {
- fprintf(stderr, "Parse error at line %d:\n%s\n",
- XML_GetCurrentLineNumber(parser),
- XML_ErrorString(XML_GetErrorCode(parser)));
- exit(ERR_PARSEERROR);
- }
+ int done;
+ int len;
+ fgets(buff, BUFFSIZE, fp);
+ len = (int) strlen(buff);
+ if (ferror(fp)) {
+ fprintf(stderr, "Read error file: %s\n", prop->sourcefile);
+ exit(ERR_READERROR);
+ }
+ done = feof(fp);
+ if (done)
+ break;
+ if (!XML_Parse(parser, buff, len, done)) {
+ fprintf(stderr, "Parse error at line %d:\n%s\n",
+ XML_GetCurrentLineNumber(parser),
+ XML_ErrorString(XML_GetErrorCode(parser)));
+ exit(ERR_PARSEERROR);
+ }
}
fclose(pdata->fp); //close out file
closeParsedata(pdata);
diff --git a/navit/tools/gpx2navit_txt/src/setmeta.c b/navit/tools/gpx2navit_txt/src/setmeta.c
index 86a22f70b..07bd0eab9 100644
--- a/navit/tools/gpx2navit_txt/src/setmeta.c
+++ b/navit/tools/gpx2navit_txt/src/setmeta.c
@@ -22,8 +22,7 @@
/**
* store gpx metadata into text file
*/
-void setMetadata(parsedata * pdata)
-{
+void setMetadata(parsedata * pdata) {
g2sprop *prop = pdata->prop;
g2sattr *attr = pdata->attr;
FILE *metafile;
@@ -32,41 +31,41 @@ void setMetadata(parsedata * pdata)
strcat(output, "_meta.txt");
metafile = fopen(output, "w");
if (metafile == NULL) {
- fprintf(stderr, "Cannot create file: %s\n", output);
- exit(ERR_CREATEFILE);
+ fprintf(stderr, "Cannot create file: %s\n", output);
+ exit(ERR_CREATEFILE);
}
if (attr->name) {
- fprintf(metafile, "name\t%s\n", attr->name);
+ fprintf(metafile, "name\t%s\n", attr->name);
}
if (attr->desc) {
- fprintf(metafile, "description\t%s\n", attr->desc);
+ fprintf(metafile, "description\t%s\n", attr->desc);
}
if (attr->author) {
- fprintf(metafile, "author\t%s\n", attr->author);
+ fprintf(metafile, "author\t%s\n", attr->author);
}
if (attr->copyright) {
- fprintf(metafile, "copyright\t%s\n", attr->copyright);
+ fprintf(metafile, "copyright\t%s\n", attr->copyright);
}
if (attr->link) {
- fprintf(metafile, "link\t%s\n", attr->link);
+ fprintf(metafile, "link\t%s\n", attr->link);
}
if (attr->time) {
- fprintf(metafile, "time\t%s\n", attr->time);
+ fprintf(metafile, "time\t%s\n", attr->time);
}
if (attr->keywords) {
- fprintf(metafile, "keywords\t%s\n", attr->keywords);
+ fprintf(metafile, "keywords\t%s\n", attr->keywords);
}
if (attr->minlat) {
- fprintf(metafile, "min latitude\t%f\n", attr->minlat);
+ fprintf(metafile, "min latitude\t%f\n", attr->minlat);
}
if (attr->minlon) {
- fprintf(metafile, "min longitude\t%f\n", attr->minlon);
+ fprintf(metafile, "min longitude\t%f\n", attr->minlon);
}
if (attr->maxlat) {
- fprintf(metafile, "max latitude\t%f\n", attr->maxlat);
+ fprintf(metafile, "max latitude\t%f\n", attr->maxlat);
}
if (attr->maxlon) {
- fprintf(metafile, "max longitude\t%f\n", attr->maxlon);
+ fprintf(metafile, "max longitude\t%f\n", attr->maxlon);
}
fclose(metafile);
free(output);
diff --git a/navit/tools/gpx2navit_txt/src/setpath.c b/navit/tools/gpx2navit_txt/src/setpath.c
index 3642415a8..6350f4e1f 100644
--- a/navit/tools/gpx2navit_txt/src/setpath.c
+++ b/navit/tools/gpx2navit_txt/src/setpath.c
@@ -21,7 +21,7 @@
void initPathAttr(pathattr * pattr, g2sattr * attr);
void setEdge(parsedata * pdata, double _x, double _y, double _z,
- double length, double interval, double speed);
+ double length, double interval, double speed);
void setPathInterval(parsedata * pdata);
void setPathData(pathattr * pattr, g2sattr * attr);
void countUnconverted(parsedata * pdata);
@@ -34,8 +34,7 @@ void setPath( parsedata * pdata);
/**
* initialize a path attribute
*/
-void initPathAttr(pathattr * pattr, g2sattr * attr)
-{
+void initPathAttr(pathattr * pattr, g2sattr * attr) {
strcpy(pattr->name, attr->name);
strcpy(pattr->cmt, attr->cmt);
strcpy(pattr->desc, attr->desc);
@@ -55,21 +54,20 @@ void initPathAttr(pathattr * pattr, g2sattr * attr)
* set edge data and store it
*/
void setEdge(parsedata * pdata, double _x, double _y, double _z,
- double length, double interval, double speed)
-{
+ double length, double interval, double speed) {
pathattr *pattr = pdata->pattr;
static int isFirstTrkAsEdge = 1;
static int isFirstRteAsEdge = 1;
double x[2], y[2], z[2];
double _length, _interval, _speed;
if (!strcmp(pdata->current->name, "trkpt")) {
- if (isFirstTrkAsEdge) {
- isFirstTrkAsEdge = 0;
- }
+ if (isFirstTrkAsEdge) {
+ isFirstTrkAsEdge = 0;
+ }
} else {
- if (isFirstRteAsEdge) {
- isFirstRteAsEdge = 0;
- }
+ if (isFirstRteAsEdge) {
+ isFirstRteAsEdge = 0;
+ }
}
_length = pattr->length;
_interval = pattr->interval;
@@ -94,8 +92,7 @@ void setEdge(parsedata * pdata, double _x, double _y, double _z,
/**
* sets interval data between two track points
*/
-void setPathInterval(parsedata * pdata)
-{
+void setPathInterval(parsedata * pdata) {
pathattr *pattr = pdata->pattr;
g2sattr *attr = pdata->attr;
g2sprop *prop = pdata->prop;
@@ -105,21 +102,21 @@ void setPathInterval(parsedata * pdata)
double leng = 0;
double spd;
if (pattr->count == 1) {
- strcpy(_t, attr->time);
+ strcpy(_t, attr->time);
} else {
- /* time interval */
- intvl = getTimeInterval(_t, attr->time);
- pattr->interval = pattr->interval + intvl;
- strcpy(_t, attr->time);
- /* length interval */
- leng = getDistance(_x, _y, attr->lon, attr->lat);
- pattr->length = pattr->length + leng;
- /* interval speed */
- spd = getSpeed(leng, intvl, prop->speed2meter, prop->speed2sec);
- /* sets edge data */
- if (prop->isEdge) {
- setEdge(pdata, _x, _y, _z, leng, intvl, spd);
- }
+ /* time interval */
+ intvl = getTimeInterval(_t, attr->time);
+ pattr->interval = pattr->interval + intvl;
+ strcpy(_t, attr->time);
+ /* length interval */
+ leng = getDistance(_x, _y, attr->lon, attr->lat);
+ pattr->length = pattr->length + leng;
+ /* interval speed */
+ spd = getSpeed(leng, intvl, prop->speed2meter, prop->speed2sec);
+ /* sets edge data */
+ if (prop->isEdge) {
+ setEdge(pdata, _x, _y, _z, leng, intvl, spd);
+ }
}
_x = attr->lon;
_y = attr->lat;
@@ -129,16 +126,15 @@ void setPathInterval(parsedata * pdata)
/**
* sets each track point data in array.
*/
-void setPathData(pathattr * pattr, g2sattr * attr)
-{
+void setPathData(pathattr * pattr, g2sattr * attr) {
const int reallocsize = 100;
if (pattr->count == 0) {
- pattr->point = malloc(sizeof(double) * 3 * reallocsize);
+ pattr->point = malloc(sizeof(double) * 3 * reallocsize);
}
if ((pattr->count % reallocsize) == 0) {
- pattr->point = realloc(pattr->point,
- sizeof(double) * 3 * (pattr->count +
- reallocsize));
+ pattr->point = realloc(pattr->point,
+ sizeof(double) * 3 * (pattr->count +
+ reallocsize));
}
pattr->point[pattr->count * 3] = attr->lon;
pattr->point[pattr->count * 3 + 1] = attr->lat;
@@ -149,72 +145,69 @@ void setPathData(pathattr * pattr, g2sattr * attr)
/**
* counts paths that wasn't converted
*/
-void countUnconverted(parsedata * pdata)
-{
+void countUnconverted(parsedata * pdata) {
g2sstats *stats = pdata->prop->stats;
if (!strcmp(pdata->current->name, "trkseg"))
- stats->trkunconverted++;
+ stats->trkunconverted++;
else
- stats->rteunconverted++;
+ stats->rteunconverted++;
}
/**
- * counts paths
+ * counts paths
*/
-void countPath(parsedata * pdata)
-{
+void countPath(parsedata * pdata) {
g2sstats *stats = pdata->prop->stats;
pathattr *pattr = pdata->pattr;
if (!strcmp(pdata->current->name, "trkseg")) {
- stats->trkcount++;
- stats->trklength += pattr->length;
- stats->trkpoints += pattr->count;
+ stats->trkcount++;
+ stats->trklength += pattr->length;
+ stats->trkpoints += pattr->count;
} else {
- stats->rtecount++;
- stats->rtelength += pattr->length;
- stats->rtepoints += pattr->count;
+ stats->rtecount++;
+ stats->rtelength += pattr->length;
+ stats->rtepoints += pattr->count;
}
}
-int checkPath(parsedata * pdata)
-{
+int checkPath(parsedata * pdata) {
pathattr *pattr = pdata->pattr;
g2sprop *prop = pdata->prop;
/* check point count. */
if (pattr->count < prop->minpoints) {
- fprintf
- (stderr,
- "gpx2navit_txt:%s:%i track was not converted because of less then %d points. \n",
- prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
- prop->minpoints);
- countUnconverted(pdata);
- return 0;
- /* check path length */
+ fprintf
+ (stderr,
+ "gpx2navit_txt:%s:%i track was not converted because of less then %d points. \n",
+ prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
+ prop->minpoints);
+ countUnconverted(pdata);
+ return 0;
+ /* check path length */
} else if (pattr->length < prop->minlength * prop->length2meter) {
- fprintf
- (stderr,
- "gpx2navit_txt:%s:%i track was not converted because it is shorter than %dm.\n",
- prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
- prop->minlength);
- countUnconverted(pdata);
- return 0;
- /* check path time */
+ fprintf
+ (stderr,
+ "gpx2navit_txt:%s:%i track was not converted because it is shorter than %dm.\n",
+ prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
+ prop->minlength);
+ countUnconverted(pdata);
+ return 0;
+ /* check path time */
} else if (pattr->interval < prop->mintime * prop->time2sec) {
- fprintf
- (stderr,
- "gpx2navit_txt:%s:%i track was not converted because it is shorter than %d sed.\n",
- prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
- prop->mintime);
- countUnconverted(pdata);
- return 0;
- /* check path speed */
+ fprintf
+ (stderr,
+ "gpx2navit_txt:%s:%i track was not converted because it is shorter than %d sed.\n",
+ prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser),
+ prop->mintime);
+ countUnconverted(pdata);
+ return 0;
+ /* check path speed */
} else if (!prop->nospeedcheck && pattr->speed == .0) {
- fprintf
- (stderr,
- "gpx2navit_txt:%s:%i track was not converted because no move recorded. Use --no-speed-check option to bypass this check.\n",
- prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser));
- countUnconverted(pdata);
- return 0;
+ fprintf
+ (stderr,
+ "gpx2navit_txt:%s:%i track was not converted because no move recorded. Use --no-speed-check option to bypass this check.\n",
+ prop->sourcefile, XML_GetCurrentLineNumber(pdata->parser));
+ countUnconverted(pdata);
+ return 0;
}
return 1;
}
@@ -222,39 +215,38 @@ int checkPath(parsedata * pdata)
/**
* saves path data into files.
*/
-void setPath( parsedata * pdata)
-{
+void setPath( parsedata * pdata) {
pathattr *pattr = pdata->pattr;
g2sprop *prop = pdata->prop;
int isOk = 0;
pattr->speed =
- getSpeed(pattr->length, pattr->interval, prop->speed2meter,
- prop->speed2sec);
+ getSpeed(pattr->length, pattr->interval, prop->speed2meter,
+ prop->speed2sec);
if (prop->isFast) {
- isOk = 1;
+ isOk = 1;
} else {
- isOk = checkPath(pdata);
+ isOk = checkPath(pdata);
}
if (isOk) {
- double x[pattr->count];
- double y[pattr->count];
- double z[pattr->count];
- int i;
- fprintf(pdata->fp,"type=track label=\"%s\" desc=\"%s\" type=\"%s\"\ length=\"%5.3f\" count=\"%5d\"\n"
- ,pdata->pattr->name,pdata->pattr->desc,
- pdata->pattr->type,pdata->pattr->length,
- pdata->pattr->count);
-
- for (i = 0; i < pattr->count; i++) {
- x[i] = pattr->point[i * 3];
- y[i] = pattr->point[i * 3 + 1];
- z[i] = pattr->point[i * 3 + 2];
- fprintf(pdata->fp,"%3.6f %4.6f\n",x[i],y[i]);
- }
- if (pdata->prop->is3d) {
- } else {
- }
- countPath(pdata);
+ double x[pattr->count];
+ double y[pattr->count];
+ double z[pattr->count];
+ int i;
+ fprintf(pdata->fp,"type=track label=\"%s\" desc=\"%s\" type=\"%s\"\ length=\"%5.3f\" count=\"%5d\"\n"
+ ,pdata->pattr->name,pdata->pattr->desc,
+ pdata->pattr->type,pdata->pattr->length,
+ pdata->pattr->count);
+
+ for (i = 0; i < pattr->count; i++) {
+ x[i] = pattr->point[i * 3];
+ y[i] = pattr->point[i * 3 + 1];
+ z[i] = pattr->point[i * 3 + 2];
+ fprintf(pdata->fp,"%3.6f %4.6f\n",x[i],y[i]);
+ }
+ if (pdata->prop->is3d) {
+ } else {
+ }
+ countPath(pdata);
}
free(pattr->point);
}
diff --git a/navit/tools/gpx2navit_txt/src/setwpt.c b/navit/tools/gpx2navit_txt/src/setwpt.c
index 3fc04f71b..24768caa1 100644
--- a/navit/tools/gpx2navit_txt/src/setwpt.c
+++ b/navit/tools/gpx2navit_txt/src/setwpt.c
@@ -24,46 +24,45 @@ void setWpt(parsedata * pdata);
/**
* save point objects in *_wpt or *_pnt file
*/
-void setWpt( parsedata * pdata)
-{
+void setWpt( parsedata * pdata) {
double x[1], y[1], z[1];
x[0] = pdata->attr->lon;
y[0] = pdata->attr->lat;
z[0] = pdata->attr->ele;
if (pdata->prop->is3d) {
- //nothing at the moment
+ //nothing at the moment
} else {
- //do not know if i will change something here
+ //do not know if i will change something here
}
// Write attributes to file first line waypoint-info, second line coords
char poi_type[20]="poi_attraction";
if (!strcmp(pdata->attr->type,"Geocache|Traditional Cache"))
- strcpy(poi_type,"poi_gc_tradi");
+ strcpy(poi_type,"poi_gc_tradi");
if (!strcmp(pdata->attr->type,"Geocache|Multi-cache"))
- strcpy(poi_type,"poi_gc_multi");
+ strcpy(poi_type,"poi_gc_multi");
if (!strcmp(pdata->attr->type,"Geocache|Unknown Cache"))
- strcpy(poi_type,"poi_gc_mystery");
+ strcpy(poi_type,"poi_gc_mystery");
if (!strcmp(pdata->attr->type,"Geocache|Event Cache"))
- strcpy(poi_type,"poi_gc_event");
+ strcpy(poi_type,"poi_gc_event");
if (!strcmp(pdata->attr->type,"Geocache")) //for OC
- strcpy(poi_type,"poi_gc_tradi");
- if (!strcmp(pdata->attr->type,"Waypoint|Parking Area"))
- strcpy(poi_type,"poi_car_parking");
- if (!strcmp(pdata->attr->type,"Waypoint|Question to Answer"))
- strcpy(poi_type,"poi_gc_question");
- if (!strcmp(pdata->attr->type,"Waypoint|Reference Point"))
- strcpy(poi_type,"poi_gc_reference");
- if (!strcmp(pdata->attr->type,"Waypoint|Stages of a Multicache"))
- strcpy(poi_type,"poi_gc_stages");
+ strcpy(poi_type,"poi_gc_tradi");
+ if (!strcmp(pdata->attr->type,"Waypoint|Parking Area"))
+ strcpy(poi_type,"poi_car_parking");
+ if (!strcmp(pdata->attr->type,"Waypoint|Question to Answer"))
+ strcpy(poi_type,"poi_gc_question");
+ if (!strcmp(pdata->attr->type,"Waypoint|Reference Point"))
+ strcpy(poi_type,"poi_gc_reference");
+ if (!strcmp(pdata->attr->type,"Waypoint|Stages of a Multicache"))
+ strcpy(poi_type,"poi_gc_stages");
//generate the file
fprintf(pdata->fp,"type=%s label=\"%s\" description=\"%s\" gc_type=\"%s\"\n",
- poi_type,pdata->attr->name,pdata->attr->desc,pdata->attr->type);
+ poi_type,pdata->attr->name,pdata->attr->desc,pdata->attr->type);
fprintf(pdata->fp,"%3.6f %4.6f\n",x[0],y[0]);
//writeWptAttribute(hDBF, pdata, iShape);
if (!strcmp(pdata->current->name, "wpt")) {
- pdata->prop->stats->wptpoints++;
+ pdata->prop->stats->wptpoints++;
}
return;
}
diff --git a/navit/tools/gpx2navit_txt/src/utils.c b/navit/tools/gpx2navit_txt/src/utils.c
index 4a215fd9d..11fae97d1 100644
--- a/navit/tools/gpx2navit_txt/src/utils.c
+++ b/navit/tools/gpx2navit_txt/src/utils.c
@@ -32,86 +32,82 @@ double getDistance(double _x, double _y, double x, double y);
// todo void closeDbfFiles(dbfhandles * dbfs);
void *myMallocRep(size_t size, const char *fileName, int line);
-void checkEllpsUnit(char *unit)
-{
-/*
- * checks ellipse unit can be used by proj4
- */
+void checkEllpsUnit(char *unit) {
+ /*
+ * checks ellipse unit can be used by proj4
+ */
int isOK = 0;
struct PJ_ELLPS *el; /* project.h of proj4 */
for (el = pj_ellps; el->id; ++el) {
- if (!strcmp(el->id, unit)) {
- isOK = 1;
- }
+ if (!strcmp(el->id, unit)) {
+ isOK = 1;
+ }
}
if (!isOK) {
- fputs
- ("The ellipse argument is not correct or supported by libproj\n",
- stderr);
- fputs("You can choose the argument from a list below.\n\n",
- stderr);
- for (el = pj_ellps; el->id; el++) {
- printf("%10s\t%s\n", el->id, el->name);
- }
- exit(ERR_ELLPSUNIT);
+ fputs
+ ("The ellipse argument is not correct or supported by libproj\n",
+ stderr);
+ fputs("You can choose the argument from a list below.\n\n",
+ stderr);
+ for (el = pj_ellps; el->id; el++) {
+ printf("%10s\t%s\n", el->id, el->name);
+ }
+ exit(ERR_ELLPSUNIT);
}
}
-double checkLengthUnit(char *unit)
-{
-/*
- * checks length unit can be used by proj4
- * then returns unit value to meter
- */
+double checkLengthUnit(char *unit) {
+ /*
+ * checks length unit can be used by proj4
+ * then returns unit value to meter
+ */
int isOK = 0;
double to_meter = 0;
struct PJ_UNITS *ut; /* project.h of proj4 */
for (ut = pj_units; ut->id; ut++) {
- if (!strcmp(ut->id, unit)) {
- isOK = 1;
- to_meter = atof(ut->to_meter);
- }
+ if (!strcmp(ut->id, unit)) {
+ isOK = 1;
+ to_meter = atof(ut->to_meter);
+ }
}
if (!isOK) {
- fputs
- ("The length unit argument is not correct or supported by libproj.\n",
- stderr);
- fputs("You can choose the argument from a list below.\n\n",
- stderr);
- for (ut = pj_units; ut->id; ut++) {
- printf("%s\t%s\n", ut->id, ut->name);
- }
- exit(ERR_LENGTHUNIT);
+ fputs
+ ("The length unit argument is not correct or supported by libproj.\n",
+ stderr);
+ fputs("You can choose the argument from a list below.\n\n",
+ stderr);
+ for (ut = pj_units; ut->id; ut++) {
+ printf("%s\t%s\n", ut->id, ut->name);
+ }
+ exit(ERR_LENGTHUNIT);
}
return to_meter;
}
-int checkTimeUnit(char *unit)
-{
+int checkTimeUnit(char *unit) {
char *u[8] = { "sec", "s", "min", "m", "hour", "h", "day", "d" };
int p[8] = { 1, 1, 60, 60, 3600, 3600, 86400, 86400 };
int i, to_sec = 0;
for (i = 0; i < 8; i++) {
- if (!strcmp(u[i], unit)) {
- to_sec = p[i];
- }
+ if (!strcmp(u[i], unit)) {
+ to_sec = p[i];
+ }
}
if (!to_sec) {
- fputs("The time unit argument is not correct.\n", stderr);
- fputs("You can choose the argument from sec, min, hour or day.\n",
- stderr);
- exit(ERR_TIMEUNIT);
+ fputs("The time unit argument is not correct.\n", stderr);
+ fputs("You can choose the argument from sec, min, hour or day.\n",
+ stderr);
+ exit(ERR_TIMEUNIT);
}
return to_sec;
}
-double getTimeInterval(char *_t, char *t)
-{
-/*
- * Returns a time interval between _t and t.
- * The arguments should be "YYYY-MM-DDThh:mm:ssZ" (xml schema
- * datetime format without time zone) format.
- */
+double getTimeInterval(char *_t, char *t) {
+ /*
+ * Returns a time interval between _t and t.
+ * The arguments should be "YYYY-MM-DDThh:mm:ssZ" (xml schema
+ * datetime format without time zone) format.
+ */
double ti;
struct tm _tt;
struct tm tt;
@@ -119,11 +115,11 @@ double getTimeInterval(char *_t, char *t)
memset(&_tt, 0, sizeof(_tt));
memset(&tt, 0, sizeof(tt));
sscanf(_t, "%d-%d-%dT%d:%d:%dZ", &_tt.tm_year, &_tt.tm_mon,
- &_tt.tm_mday, &_tt.tm_hour, &_tt.tm_min, &_tt.tm_sec);
+ &_tt.tm_mday, &_tt.tm_hour, &_tt.tm_min, &_tt.tm_sec);
_tt.tm_year -= 1900;
_tt.tm_mon -= 1;
sscanf(t, "%d-%d-%dT%d:%d:%d", &tt.tm_year, &tt.tm_mon, &tt.tm_mday,
- &tt.tm_hour, &tt.tm_min, &tt.tm_sec);
+ &tt.tm_hour, &tt.tm_min, &tt.tm_sec);
tt.tm_year -= 1900;
tt.tm_mon -= 1;
_tmt = mktime(&_tt);
@@ -132,21 +128,19 @@ double getTimeInterval(char *_t, char *t)
return ti;
}
-double getSpeed(double length, double ti, double to_meter, int to_sec)
-{
-/*
- * Culculates speed from length and time.
- */
+double getSpeed(double length, double ti, double to_meter, int to_sec) {
+ /*
+ * Culculates speed from length and time.
+ */
double speed;
if (!length || !ti)
- speed = 0;
+ speed = 0;
else
- speed = (length / to_meter) / (ti / to_sec);
+ speed = (length / to_meter) / (ti / to_sec);
return speed;
}
-double getDistanceCore(char *p1, char *l1, char *p2, char *l2)
-{
+double getDistanceCore(char *p1, char *l1, char *p2, char *l2) {
/*
* Culculates a geodesic length between two points
* using geod_*.c
@@ -159,8 +153,7 @@ double getDistanceCore(char *p1, char *l1, char *p2, char *l2)
return geod_S;
}
-double getDistance(double _x, double _y, double x, double y)
-{
+double getDistance(double _x, double _y, double x, double y) {
/*
* Culculates a geodesic length between two points
*/
@@ -176,9 +169,9 @@ double getDistance(double _x, double _y, double x, double y)
//todo void closeShpFiles(shphandles * shps)
//{
- /*
- * Closes all SHP files if they opened
- */
+/*
+ * Closes all SHP files if they opened
+ */
// if (shps->wpt)
// SHPClose(shps->wpt);
// if (shps->trk)
@@ -197,9 +190,9 @@ double getDistance(double _x, double _y, double x, double y)
//todo void closeDbfFiles(dbfhandles * dbfs)
//{
- /*
- * Closes all DBF files if they opened
- */
+/*
+ * Closes all DBF files if they opened
+ */
// if (dbfs->wpt)
// DBFClose(dbfs->wpt);
// if (dbfs->trk)
diff --git a/navit/tools/latlon2bookmark/latlon2bookmark.c b/navit/tools/latlon2bookmark/latlon2bookmark.c
index 4f5fe54cb..dfe1e5a7e 100644
--- a/navit/tools/latlon2bookmark/latlon2bookmark.c
+++ b/navit/tools/latlon2bookmark/latlon2bookmark.c
@@ -31,8 +31,7 @@
#include <math.h>
#include <string.h>
-int main( int argc, char **argv )
-{
+int main( int argc, char **argv ) {
char description[256];
char lngsign[10];
char latsign[10];
@@ -43,18 +42,17 @@ int main( int argc, char **argv )
int i;
int n;
- if ( argc < 4 )
- {
- printf("\n");
- printf("This program converts a lat/lon coordinates pair\n");
- printf("into a bookmark you can use with navit.\n");
- printf("This program expects 3 arguments in the following order:\n");
- printf("Lat, Lon and a description\n");
- printf("and will print a bookmark.\n");
- printf("for example: latlon2bookmark 51.980344 4.358005 this is my house \n");
- printf("\n");
- return 1;
- }
+ if ( argc < 4 ) {
+ printf("\n");
+ printf("This program converts a lat/lon coordinates pair\n");
+ printf("into a bookmark you can use with navit.\n");
+ printf("This program expects 3 arguments in the following order:\n");
+ printf("Lat, Lon and a description\n");
+ printf("and will print a bookmark.\n");
+ printf("for example: latlon2bookmark 51.980344 4.358005 this is my house \n");
+ printf("\n");
+ return 1;
+ }
lat=atof(argv[1]);
lng=atof(argv[2]);
@@ -62,74 +60,66 @@ int main( int argc, char **argv )
/* concatenate all parts of the description string */
strcpy(description, argv[3]);
n=0;
- for (i=4; i < argc; i++)
- {
- /* add spaces between the parts of the description */
- if ( i < argc )
- {
- strcat(description, " ");
- }
- strcat(description, argv[i]);
- n=n+1;
- }
-
- if ( lat < -90 )
- {
- printf("\n");
- printf("The first argument must be the lattitude\n");
- printf("and can't be smaller then -90 (southpole)\n");
- printf("\n");
- return 2;
- }
-
- if ( lat > 90 )
- {
- printf("\n");
- printf("The first argument must be the lattitude\n");
- printf("and can't be bigger then 90 (northpole)\n");
- printf("\n");
- return 3;
- }
-
- if ( lng < -180 )
- {
- printf("\n");
- printf("The second argument must be the longitude\n");
- printf("and can't be smaller then -180 (oposite the 0 meridian)\n");
- printf("\n");
- return 4;
- }
-
- if ( lng > 180 )
- {
- printf("\n");
- printf("The first argument must be the longitude\n");
- printf("and can't be bigger then 180 (oposite the 0 meridian)\n");
- printf("\n");
- return 5;
- }
+ for (i=4; i < argc; i++) {
+ /* add spaces between the parts of the description */
+ if ( i < argc ) {
+ strcat(description, " ");
+ }
+ strcat(description, argv[i]);
+ n=n+1;
+ }
+
+ if ( lat < -90 ) {
+ printf("\n");
+ printf("The first argument must be the lattitude\n");
+ printf("and can't be smaller then -90 (southpole)\n");
+ printf("\n");
+ return 2;
+ }
+
+ if ( lat > 90 ) {
+ printf("\n");
+ printf("The first argument must be the lattitude\n");
+ printf("and can't be bigger then 90 (northpole)\n");
+ printf("\n");
+ return 3;
+ }
+
+ if ( lng < -180 ) {
+ printf("\n");
+ printf("The second argument must be the longitude\n");
+ printf("and can't be smaller then -180 (oposite the 0 meridian)\n");
+ printf("\n");
+ return 4;
+ }
+
+ if ( lng > 180 ) {
+ printf("\n");
+ printf("The first argument must be the longitude\n");
+ printf("and can't be bigger then 180 (oposite the 0 meridian)\n");
+ printf("\n");
+ return 5;
+ }
/* convert the longitude to an integer */
intlng=lng*6371000.0*M_PI/180;
/* aparently if inlng < 0 , inlng needs to be inverted and a - sign used in the output */
strcpy(lngsign, "0x");
- if ( intlng < 0)
- {
- intlng=(intlng ^ 0xffffffff);
- strcpy(lngsign, "-0x");
- }
+ if ( intlng < 0) {
+ intlng=(intlng ^ 0xffffffff);
+ strcpy(lngsign, "-0x");
+ }
/* and the same for the latitude */
intlat=log(tan(M_PI_4+lat*M_PI/360))*6371000.0;
/* aparently if inlat < 0 , inlat needs to be inverted and a - sign used in the output */
strcpy(latsign, "0x");
- if ( intlat < 0)
- {
- intlat=(intlat ^ 0xffffffff);
- strcpy(latsign, "-0x");
- }
+ if ( intlat < 0) {
+ intlat=(intlat ^ 0xffffffff);
+ strcpy(latsign, "-0x");
+ }
/* print the bookmark */
fprintf(stderr,"\n");