Fix indentation

This commit is contained in:
Eric Fischer 2018-03-02 10:35:58 -08:00
parent 18e345efb0
commit 2b936af96a
4 changed files with 73 additions and 72 deletions

View File

@ -152,48 +152,48 @@ std::vector<zxy> enumerate_dirtiles(const char *fname) {
} }
sqlite3 *dirmeta2tmp(const char *fname) { sqlite3 *dirmeta2tmp(const char *fname) {
sqlite3 *db; sqlite3 *db;
char *err = NULL; char *err = NULL;
if (sqlite3_open("", &db) != SQLITE_OK) { if (sqlite3_open("", &db) != SQLITE_OK) {
fprintf(stderr, "Temporary db: %s\n", sqlite3_errmsg(db)); fprintf(stderr, "Temporary db: %s\n", sqlite3_errmsg(db));
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (sqlite3_exec(db, "CREATE TABLE metadata (name text, value text);", NULL, NULL, &err) != SQLITE_OK) { if (sqlite3_exec(db, "CREATE TABLE metadata (name text, value text);", NULL, NULL, &err) != SQLITE_OK) {
fprintf(stderr, "Create metadata table: %s\n", err); fprintf(stderr, "Create metadata table: %s\n", err);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
std::string name = fname; std::string name = fname;
name += "/metadata.json"; name += "/metadata.json";
FILE *f = fopen(name.c_str(), "r"); FILE *f = fopen(name.c_str(), "r");
if (f == NULL) { if (f == NULL) {
perror(name.c_str()); perror(name.c_str());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
json_pull *jp = json_begin_file(f); json_pull *jp = json_begin_file(f);
json_object *o = json_read_tree(jp); json_object *o = json_read_tree(jp);
if (o->type != JSON_HASH) { if (o->type != JSON_HASH) {
fprintf(stderr, "%s: bad metadata format\n", name.c_str()); fprintf(stderr, "%s: bad metadata format\n", name.c_str());
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
for (size_t i = 0; i < o->length; i++) { for (size_t i = 0; i < o->length; i++) {
if (o->keys[i]->type != JSON_STRING || o->values[i]->type != JSON_STRING) { if (o->keys[i]->type != JSON_STRING || o->values[i]->type != JSON_STRING) {
fprintf(stderr, "%s: non-string in metadata\n", name.c_str()); fprintf(stderr, "%s: non-string in metadata\n", name.c_str());
} }
char *sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES (%Q, %Q);", o->keys[i]->string, o->values[i]->string); char *sql = sqlite3_mprintf("INSERT INTO metadata (name, value) VALUES (%Q, %Q);", o->keys[i]->string, o->values[i]->string);
if (sqlite3_exec(db, sql, NULL, NULL, &err) != SQLITE_OK) { if (sqlite3_exec(db, sql, NULL, NULL, &err) != SQLITE_OK) {
fprintf(stderr, "set %s in metadata: %s\n", o->keys[i]->string, err); fprintf(stderr, "set %s in metadata: %s\n", o->keys[i]->string, err);
} }
sqlite3_free(sql); sqlite3_free(sql);
} }
json_end(jp); json_end(jp);
fclose(f); fclose(f);
return db; return db;
} }

View File

@ -1195,7 +1195,7 @@ int read_input(std::vector<source> &sources, char *fname, int maxzoom, int minzo
} }
// Trim out characters that can't be part of selector // Trim out characters that can't be part of selector
std::string out; std::string out;
for (size_t p = 0; p < trunc.size(); p++) { for (size_t p = 0; p < trunc.size(); p++) {
if (isalpha(trunc[p]) || isdigit(trunc[p]) || trunc[p] == '_' || (trunc[p] & 0x80) != 0) { if (isalpha(trunc[p]) || isdigit(trunc[p]) || trunc[p] == '_' || (trunc[p] & 0x80) != 0) {
out.append(trunc, p, 1); out.append(trunc, p, 1);
@ -2518,7 +2518,8 @@ int main(int argc, char **argv) {
src.layer = std::string(optarg).substr(0, cp - optarg); src.layer = std::string(optarg).substr(0, cp - optarg);
src.file = std::string(cp + 1); src.file = std::string(cp + 1);
sources.push_back(src); sources.push_back(src);
} break; break;
}
case 'z': case 'z':
if (strcmp(optarg, "g") == 0) { if (strcmp(optarg, "g") == 0) {
@ -2695,7 +2696,8 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
} break; break;
}
case 'a': { case 'a': {
char *cp; char *cp;
@ -2707,7 +2709,8 @@ int main(int argc, char **argv) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
} break; break;
}
case 'v': case 'v':
fprintf(stderr, VERSION); fprintf(stderr, VERSION);

View File

@ -896,7 +896,8 @@ int main(int argc, char **argv) {
std::string before = std::string(optarg).substr(0, cp - optarg); std::string before = std::string(optarg).substr(0, cp - optarg);
std::string after = std::string(cp + 1); std::string after = std::string(cp + 1);
renames.insert(std::pair<std::string, std::string>(before, after)); renames.insert(std::pair<std::string, std::string>(before, after));
} break; break;
}
case 'q': case 'q':
quiet = true; quiet = true;

View File

@ -439,7 +439,7 @@ void *partial_feature_worker(void *v) {
} }
} }
(*partials)[i].geoms.clear(); // avoid keeping two copies in memory (*partials)[i].geoms.clear(); // avoid keeping two copies in memory
signed char t = (*partials)[i].t; signed char t = (*partials)[i].t;
int z = (*partials)[i].z; int z = (*partials)[i].z;
int line_detail = (*partials)[i].line_detail; int line_detail = (*partials)[i].line_detail;
@ -1501,46 +1501,43 @@ void preserve_attribute(attribute_op op, std::map<std::string, accum_state> &att
p.full_values[i].type = mvt_double; p.full_values[i].type = mvt_double;
break; break;
case op_max: case op_max: {
{ double existing = atof(p.full_values[i].s.c_str());
double existing = atof(p.full_values[i].s.c_str()); double maybe = atof(val.s.c_str());
double maybe = atof(val.s.c_str()); if (maybe > existing) {
if (maybe > existing) { p.full_values[i].s = val.s.c_str();
p.full_values[i].s = val.s.c_str(); p.full_values[i].type = mvt_double;
p.full_values[i].type = mvt_double;
}
} }
break; break;
}
case op_min: case op_min: {
{ double existing = atof(p.full_values[i].s.c_str());
double existing = atof(p.full_values[i].s.c_str()); double maybe = atof(val.s.c_str());
double maybe = atof(val.s.c_str()); if (maybe < existing) {
if (maybe < existing) { p.full_values[i].s = val.s.c_str();
p.full_values[i].s = val.s.c_str(); p.full_values[i].type = mvt_double;
p.full_values[i].type = mvt_double;
}
} }
break; break;
}
case op_mean: case op_mean: {
{ auto state = attribute_accum_state.find(key);
auto state = attribute_accum_state.find(key); if (state == attribute_accum_state.end()) {
if (state == attribute_accum_state.end()) { accum_state s;
accum_state s; s.sum = atof(p.full_values[i].s.c_str()) + atof(val.s.c_str());
s.sum = atof(p.full_values[i].s.c_str()) + atof(val.s.c_str()); s.count = 2;
s.count = 2; attribute_accum_state.insert(std::pair<std::string, accum_state>(key, s));
attribute_accum_state.insert(std::pair<std::string, accum_state>(key, s));
p.full_values[i].s = milo::dtoa_milo(s.sum / s.count); p.full_values[i].s = milo::dtoa_milo(s.sum / s.count);
} else { } else {
state->second.sum += atof(val.s.c_str()); state->second.sum += atof(val.s.c_str());
state->second.count += 1; state->second.count += 1;
p.full_values[i].s = milo::dtoa_milo(state->second.sum / state->second.count); p.full_values[i].s = milo::dtoa_milo(state->second.sum / state->second.count);
}
} }
break; break;
}
case op_concat: case op_concat:
p.full_values[i].s += val.s; p.full_values[i].s += val.s;