forked from GPSBabel/gpsbabel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter_vecs.cc
390 lines (352 loc) · 8.41 KB
/
filter_vecs.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
/*
Describe vectors containing filter operations.
Copyright (C) 2002-2014 Robert Lipe, robertlipe+source@gpsbabel.org
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA
*/
#include "defs.h"
#include "filterdefs.h"
#include "inifile.h"
#include "gbversion.h"
#include <QtCore/QStringList>
#include <stdlib.h> // qsort
#include <stdio.h>
#include <stdlib.h>
typedef struct {
filter_vecs_t* vec;
const char* name;
const char* desc;
} fl_vecs_t;
extern filter_vecs_t bend_vecs;
extern filter_vecs_t position_vecs;
extern filter_vecs_t radius_vecs;
extern filter_vecs_t duplicate_vecs;
extern filter_vecs_t arcdist_vecs;
extern filter_vecs_t polygon_vecs;
extern filter_vecs_t routesimple_vecs;
extern filter_vecs_t reverse_route_vecs;
extern filter_vecs_t sort_vecs;
extern filter_vecs_t stackfilt_vecs;
extern filter_vecs_t trackfilter_vecs;
extern filter_vecs_t discard_vecs;
extern filter_vecs_t nuke_vecs;
extern filter_vecs_t interpolatefilt_vecs;
extern filter_vecs_t transform_vecs;
extern filter_vecs_t height_vecs;
extern filter_vecs_t swapdata_vecs;
extern filter_vecs_t validate_vecs;
static
fl_vecs_t filter_vec_list[] = {
#if FILTERS_ENABLED
{
&arcdist_vecs,
"arc",
"Include Only Points Within Distance of Arc",
},
{
&bend_vecs,
"bend",
"Add points before and after bends in routes"
},
{
&discard_vecs,
"discard",
"Remove unreliable points with high hdop or vdop"
},
{
&duplicate_vecs,
"duplicate",
"Remove Duplicates",
},
{
&interpolatefilt_vecs,
"interpolate",
"Interpolate between trackpoints"
},
{
&nuke_vecs,
"nuketypes",
"Remove all waypoints, tracks, or routes"
},
{
&polygon_vecs,
"polygon",
"Include Only Points Inside Polygon",
},
{
&position_vecs,
"position",
"Remove Points Within Distance",
},
{
&radius_vecs,
"radius",
"Include Only Points Within Radius",
},
{
&routesimple_vecs,
"simplify",
"Simplify routes",
},
{
&sort_vecs,
"sort",
"Rearrange waypoints by resorting",
},
{
&stackfilt_vecs,
"stack",
"Save and restore waypoint lists"
},
{
&reverse_route_vecs,
"reverse",
"Reverse stops within routes",
},
{
&trackfilter_vecs,
"track",
"Manipulate track lists"
},
{
&transform_vecs,
"transform",
"Transform waypoints into a route, tracks into routes, ..."
},
{
&height_vecs,
"height",
"Manipulate altitudes"
},
{
&swapdata_vecs,
"swap",
"Swap latitude and longitude of all loaded points"
},
{
&validate_vecs,
"validate",
"Validate internal data structures"
},
#elif defined (MINIMAL_FILTERS)
{
&trackfilter_vecs,
"track",
"Manipulate track lists"
},
#endif
{
NULL,
NULL,
NULL
}
};
filter_vecs_t*
find_filter_vec(char* const vecname, char** opts)
{
fl_vecs_t* vec = filter_vec_list;
char* v = xstrdup(vecname);
QString svecname = QString(v).split(",")[0];
int found = 0;
while (vec->vec) {
arglist_t* ap;
char* res;
if (svecname.compare(vec->name, Qt::CaseInsensitive)) {
vec++;
continue;
}
/* step 1: initialize by inifile or default values */
if (vec->vec->args) {
for (ap = vec->vec->args; ap->argstring; ap++) {
const char* temp;
temp = inifile_readstr(global_opts.inifile, vec->name, ap->argstring);
if (temp == NULL) {
temp = inifile_readstr(global_opts.inifile, "Common filter settings", ap->argstring);
}
if (temp == NULL) {
temp = ap->defaultvalue;
}
assign_option(vec->name, ap, temp);
}
}
/* step 2: override settings with command-line values */
res = strchr(vecname, ',');
if (res) {
*opts = res+1;
if (vec->vec->args) {
for (ap = vec->vec->args; ap->argstring; ap++) {
char* opt;
opt = get_option(*opts, ap->argstring);
if (opt) {
found = 1;
assign_option(vec->name, ap, opt);
xfree(opt);
}
}
}
} else {
*opts = NULL;
}
if (opts && opts[0] && !found) {
warning("'%s' is an unknown option to %s.\n", *opts, vec->name);
}
if (global_opts.debug_level >= 1) {
disp_vec_options(vec->name, vec->vec->args);
}
xfree(v);
return vec->vec;
}
xfree(v);
return NULL;
}
void
free_filter_vec(filter_vecs_t* fvec)
{
arglist_t* ap;
if (fvec->args) {
for (ap = fvec->args; ap->argstring; ap++) {
if (ap->argvalptr) {
xfree(ap->argvalptr);
ap->argvalptr = *ap->argval = NULL;
}
}
}
}
void
init_filter_vecs(void)
{
fl_vecs_t* vec = filter_vec_list;
while (vec->vec) {
arglist_t* ap;
if (vec->vec->args) {
for (ap = vec->vec->args; ap->argstring; ap++) {
ap->argvalptr = NULL;
}
}
vec++;
}
}
void
exit_filter_vecs(void)
{
fl_vecs_t* vec = filter_vec_list;
while (vec->vec) {
if (vec->vec->f_exit) {
(vec->vec->f_exit)();
}
vec++;
}
}
/*
* Display the available formats in a format that's easy for humans to
* parse for help on available command line options.
*/
void
disp_filter_vecs(void)
{
fl_vecs_t* vec;
arglist_t* ap;
for (vec = filter_vec_list; vec->vec; vec++) {
printf(" %-20.20s %-50.50s\n",
vec->name, vec->desc);
for (ap = vec->vec->args; ap && ap->argstring; ap++) {
if (!(ap->argtype & ARGTYPE_HIDDEN))
printf(" %-18.18s %-.50s %s\n",
ap->argstring, ap->helpstring,
(ap->argtype&ARGTYPE_REQUIRED)?"(required)":"");
}
}
}
void
disp_filter_vec(const char* vecname)
{
fl_vecs_t* vec;
arglist_t* ap;
for (vec = filter_vec_list; vec->vec; vec++) {
if (case_ignore_strcmp(vec->name, vecname)) {
continue;
}
printf(" %-20.20s %-50.50s\n",
vec->name, vec->desc);
for (ap = vec->vec->args; ap && ap->argstring; ap++) {
if (!(ap->argtype & ARGTYPE_HIDDEN))
printf(" %-18.18s %-.50s %s\n",
ap->argstring, ap->helpstring,
(ap->argtype&ARGTYPE_REQUIRED)?"(required)":"");
}
}
}
static signed int
alpha(const void* a, const void* b)
{
const fl_vecs_t* const ap = (const fl_vecs_t*) a;
const fl_vecs_t* const bp = (const fl_vecs_t*) b;
return case_ignore_strcmp(ap->desc , bp->desc);
}
static
void disp_help_url(const fl_vecs_t* vec, arglist_t* arg)
{
printf("\t" WEB_DOC_DIR "/fmt_%s.html", vec->name);
if (arg) {
printf("#fmt_%s_o_%s",vec->name, arg->argstring);
}
}
static void
disp_v1(const fl_vecs_t* vec)
{
arglist_t* ap;
disp_help_url(vec, NULL);
printf("\n");
for (ap = vec->vec->args; ap && ap->argstring; ap++) {
if (!(ap->argtype & ARGTYPE_HIDDEN)) {
printf("option\t%s\t%s\t%s\t%s\t%s\t%s\t%s",
vec->name,
ap->argstring,
ap->helpstring,
name_option(ap->argtype),
ap->defaultvalue? ap->defaultvalue : "",
ap->minvalue? ap->minvalue : "",
ap->maxvalue? ap->maxvalue : "");
disp_help_url(vec, ap);
printf("\n");
}
}
}
/*
* Display the available formats in a format that's easy to machine
* parse. Typically invoked by programs like graphical wrappers to
* determine what formats are supported.
*/
void
disp_filters(int version)
{
fl_vecs_t* vec;
qsort(filter_vec_list,
sizeof(filter_vec_list) / sizeof(filter_vec_list[0]) - 1,
sizeof(filter_vec_list[0]),
alpha);
switch (version) {
case 0:
case 1:
for (vec = filter_vec_list; vec->vec; vec++) {
if (version == 0) {
printf("%s\t%s\n", vec->name, vec->desc);
} else {
printf("%s\t%s", vec->name, vec->desc);
disp_v1(vec);
}
}
break;
default:
;
}
}