Merge pull request #148 from mapbox/option-check

Give an error if -p or -a is used with an undefined option letter
This commit is contained in:
Eric Fischer 2016-01-11 12:25:30 -08:00
commit 20bd661693
3 changed files with 59 additions and 11 deletions

View File

@ -1826,6 +1826,18 @@ int read_json(int argc, char **argv, char *fname, const char *layername, int max
return ret; return ret;
} }
int int_in(int v, int *a, int len) {
int i;
for (i = 0; i < len; i++) {
if (a[i] == v) {
return 1;
}
}
return 0;
}
int main(int argc, char **argv) { int main(int argc, char **argv) {
#ifdef MTRACE #ifdef MTRACE
mtrace(); mtrace();
@ -1961,14 +1973,24 @@ int main(int argc, char **argv) {
case 'p': { case 'p': {
char *cp; char *cp;
for (cp = optarg; *cp != '\0'; cp++) { for (cp = optarg; *cp != '\0'; cp++) {
if (int_in(*cp, prevent_options, sizeof(prevent_options) / sizeof(prevent_options[0]))) {
prevent[*cp & 0xFF] = 1; prevent[*cp & 0xFF] = 1;
} else {
fprintf(stderr, "%s: Unknown option -p%c\n", argv[0], *cp);
exit(EXIT_FAILURE);
}
} }
} break; } break;
case 'a': { case 'a': {
char *cp; char *cp;
for (cp = optarg; *cp != '\0'; cp++) { for (cp = optarg; *cp != '\0'; cp++) {
if (int_in(*cp, additional_options, sizeof(additional_options) / sizeof(additional_options[0]))) {
additional[*cp & 0xFF] = 1; additional[*cp & 0xFF] = 1;
} else {
fprintf(stderr, "%s: Unknown option -a%c\n", argv[0], *cp);
exit(EXIT_FAILURE);
}
} }
} break; } break;

18
tile.cc
View File

@ -502,7 +502,7 @@ void *partial_feature_worker(void *v) {
char *additional = (*partials)[i].additional; char *additional = (*partials)[i].additional;
int maxzoom = (*partials)[i].maxzoom; int maxzoom = (*partials)[i].maxzoom;
if ((t == VT_LINE || t == VT_POLYGON) && !(prevent['s' & 0xFF] || (z == maxzoom && prevent['S' & 0xFF]))) { if ((t == VT_LINE || t == VT_POLYGON) && !(prevent[P_SIMPLIFY] || (z == maxzoom && prevent[P_SIMPLIFY_LOW]))) {
if (1 /* !reduced */) { // XXX why did this not simplify if reduced? if (1 /* !reduced */) { // XXX why did this not simplify if reduced?
if (t == VT_LINE) { if (t == VT_LINE) {
geom = remove_noop(geom, t, 32 - z - line_detail); geom = remove_noop(geom, t, 32 - z - line_detail);
@ -518,7 +518,7 @@ void *partial_feature_worker(void *v) {
} }
#endif #endif
if (t == VT_LINE && additional['r' & 0xFF]) { if (t == VT_LINE && additional[A_REVERSE]) {
geom = reorder_lines(geom); geom = reorder_lines(geom);
} }
@ -746,7 +746,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
continue; continue;
} }
if (gamma >= 0 && (t == VT_POINT || (additional['l' & 0xFF] && t == VT_LINE))) { if (gamma >= 0 && (t == VT_POINT || (additional[A_LINE_DROP] && t == VT_LINE))) {
seq++; seq++;
if (seq >= 0) { if (seq >= 0) {
seq -= interval; seq -= interval;
@ -880,7 +880,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
} }
for (j = 0; j < nlayers; j++) { for (j = 0; j < nlayers; j++) {
if (additional['o' & 0xFF]) { if (additional[A_REORDER]) {
std::sort(features[j].begin(), features[j].end()); std::sort(features[j].begin(), features[j].end());
} }
@ -895,7 +895,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
} }
#endif #endif
if (additional['c' & 0xFF] && out.size() > 0 && out[y].geom.size() + features[j][x].geom.size() < 20000 && coalcmp(&features[j][x], &out[y]) == 0 && features[j][x].type != VT_POINT) { if (additional[A_COALESCE] && out.size() > 0 && out[y].geom.size() + features[j][x].geom.size() < 20000 && coalcmp(&features[j][x], &out[y]) == 0 && features[j][x].type != VT_POINT) {
unsigned z; unsigned z;
for (z = 0; z < features[j][x].geom.size(); z++) { for (z = 0; z < features[j][x].geom.size(); z++) {
out[y].geom.push_back(features[j][x].geom[z]); out[y].geom.push_back(features[j][x].geom[z]);
@ -920,7 +920,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
} }
features[j] = out; features[j] = out;
if (prevent['i' & 0xFF]) { if (prevent[P_INPUT_ORDER]) {
std::sort(features[j].begin(), features[j].end(), preservecmp); std::sort(features[j].begin(), features[j].end(), preservecmp);
} }
} }
@ -936,7 +936,7 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
} }
if (totalsize > 0) { if (totalsize > 0) {
if (totalsize > 200000 && !prevent['f' & 0xFF]) { if (totalsize > 200000 && !prevent[P_FEATURE_LIMIT]) {
fprintf(stderr, "tile %d/%u/%u has %lld features, >200000 \n", z, tx, ty, totalsize); fprintf(stderr, "tile %d/%u/%u has %lld features, >200000 \n", z, tx, ty, totalsize);
fprintf(stderr, "Try using -z to set a higher base zoom level.\n"); fprintf(stderr, "Try using -z to set a higher base zoom level.\n");
return -1; return -1;
@ -956,12 +956,12 @@ long long write_tile(char **geoms, char *metabase, char *stringpool, int z, unsi
tile.SerializeToString(&s); tile.SerializeToString(&s);
compress(s, compressed); compress(s, compressed);
if (compressed.size() > 500000 && !prevent['k' & 0xFF]) { if (compressed.size() > 500000 && !prevent[P_KILOBYTE_LIMIT]) {
if (!quiet) { if (!quiet) {
fprintf(stderr, "tile %d/%u/%u size is %lld with detail %d, >500000 \n", z, tx, ty, (long long) compressed.size(), line_detail); fprintf(stderr, "tile %d/%u/%u size is %lld with detail %d, >500000 \n", z, tx, ty, (long long) compressed.size(), line_detail);
} }
if (prevent['d' & 0xFF]) { if (prevent[P_DYNAMIC_DROP]) {
// The 95% is a guess to avoid too many retries // The 95% is a guess to avoid too many retries
// and probably actually varies based on how much duplicated metadata there is // and probably actually varies based on how much duplicated metadata there is

26
tile.h
View File

@ -35,3 +35,29 @@ extern int quiet;
extern int CPUS; extern int CPUS;
extern int TEMP_FILES; extern int TEMP_FILES;
static int additional_options[] = {
#define A_COALESCE ((int) 'c')
A_COALESCE,
#define A_REVERSE ((int) 'r')
A_REVERSE,
#define A_REORDER ((int) 'o')
A_REORDER,
#define A_LINE_DROP ((int) 'l')
A_LINE_DROP,
};
static int prevent_options[] = {
#define P_SIMPLIFY ((int) 's')
P_SIMPLIFY,
#define P_SIMPLIFY_LOW ((int) 'S')
P_SIMPLIFY_LOW,
#define P_FEATURE_LIMIT ((int) 'f')
P_FEATURE_LIMIT,
#define P_KILOBYTE_LIMIT ((int) 'k')
P_KILOBYTE_LIMIT,
#define P_DYNAMIC_DROP ((int) 'd')
P_DYNAMIC_DROP,
#define P_INPUT_ORDER ((int) 'i')
P_INPUT_ORDER,
};