mirror of
https://github.com/felt/tippecanoe.git
synced 2026-10-06 18:35:41 +02:00
Flatten out error-handling so it isn't nested so deeply
This commit is contained in:
@@ -49,7 +49,6 @@ void read_json(FILE *f) {
|
||||
|
||||
while (1) {
|
||||
json_object *j = json_read(jp);
|
||||
|
||||
if (j == NULL) {
|
||||
if (jp->error != NULL) {
|
||||
fprintf(stderr, "%d: %s\n", jp->line, jp->error);
|
||||
@@ -60,25 +59,47 @@ void read_json(FILE *f) {
|
||||
}
|
||||
|
||||
json_object *type = json_hash_get(j, "type");
|
||||
if (type != NULL && type->type == JSON_STRING && strcmp(type->string, "Feature") == 0) {
|
||||
if (type == NULL || type->type != JSON_STRING || strcmp(type->string, "Feature") != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
json_object *geometry = json_hash_get(j, "geometry");
|
||||
if (geometry == NULL) {
|
||||
fprintf(stderr, "%d: feature with no geometry\n", jp->line);
|
||||
goto next_feature;
|
||||
}
|
||||
|
||||
if (geometry != NULL) {
|
||||
json_object *geometry_type = json_hash_get(geometry, "type");
|
||||
if (geometry_type != NULL && geometry_type->type == JSON_STRING) {
|
||||
int t;
|
||||
if (geometry_type == NULL || geometry_type->type != JSON_STRING) {
|
||||
fprintf(stderr, "%d: geometry without type string\n", jp->line);
|
||||
goto next_feature;
|
||||
}
|
||||
|
||||
json_object *properties = json_hash_get(j, "properties");
|
||||
if (properties == NULL || properties->type != JSON_HASH) {
|
||||
fprintf(stderr, "%d: feature without properties hash\n", jp->line);
|
||||
goto next_feature;
|
||||
}
|
||||
|
||||
json_object *coordinates = json_hash_get(geometry, "coordinates");
|
||||
if (coordinates == NULL || coordinates->type != JSON_ARRAY) {
|
||||
fprintf(stderr, "%d: feature without coordinates array\n", jp->line);
|
||||
goto next_feature;
|
||||
}
|
||||
|
||||
int t;
|
||||
for (t = 0; t < GEOM_TYPES; t++) {
|
||||
if (strcmp(geometry_type->string, geometry_names[t]) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (t >= GEOM_TYPES) {
|
||||
fprintf(stderr, "%d: Can't handle geometry type %s\n", jp->line, geometry_type->string);
|
||||
goto next_feature;
|
||||
}
|
||||
|
||||
if (t < GEOM_TYPES) {
|
||||
json_object *properties = json_hash_get(j, "properties");
|
||||
json_object *coordinates = json_hash_get(geometry, "coordinates");
|
||||
|
||||
if (properties != NULL && properties->type == JSON_HASH) {
|
||||
/* scope for variable-length arrays */
|
||||
{
|
||||
char *metakey[properties->length];
|
||||
char *metaval[properties->length];
|
||||
int metatype[properties->length];
|
||||
@@ -103,9 +124,7 @@ void read_json(FILE *f) {
|
||||
}
|
||||
}
|
||||
|
||||
if (coordinates != NULL && coordinates->type == JSON_ARRAY) {
|
||||
int n;
|
||||
|
||||
if (t == GEOM_POINT) {
|
||||
n = 1;
|
||||
} else {
|
||||
@@ -137,26 +156,16 @@ void read_json(FILE *f) {
|
||||
}
|
||||
|
||||
if (ok) {
|
||||
for (i = 0; i < n; i++) {
|
||||
printf("%f,%f ", lat[i], lon[i]);
|
||||
}
|
||||
printf("\n");
|
||||
// XXX encode(destdir, files, maxn, extra, xoff, pool, n, lat, lon, m, metakey, metaval, metatype);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "%d: feature geometry with no coordinates\n", jp->line);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "%d: feature with no properties\n", jp->line);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "%d: Can't handle geometry type %s\n", jp->line, geometry_type->string);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "%d: geometry has no type\n", jp->line);
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "%d: feature with no geometry\n", jp->line);
|
||||
}
|
||||
|
||||
next_feature:
|
||||
json_free(j);
|
||||
}
|
||||
|
||||
/* XXX check for any non-features in the outer object */
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user